Bio-KBase
view release on metacpan or search on metacpan
lib/Bio/KBase/CDMI/CDMILoader.pm view on Meta::CPAN
Returns a list of the fields in the next input line. Note that fields
containing a single period (C<.>) will be converted to null strings.
=back
=cut
sub GetLine {
# Get the parameters. Note we allow for both static and object-oriented
# calls.
shift if UNIVERSAL::isa($_[0],__PACKAGE__);
my ($ih) = @_;
# Read the line and chomp off the new-line character.
my $line = <$ih>;
chomp $line;
# Return the individual fields.
my @retVal = map { ($_ eq '.' ? '' : $_) } split /\t/, $line;
return @retVal;
}
=head3 ReadFastaRecord
my ($sequence, $nextID, $nextComment) = Bio::KBase::CDMI::CDMILoader::ReadFastaRecord($ih);
or
my ($sequence, $nextID, $nextComment) = $loader->ReadFastaRecord($ih);
Read a sequence record from a FASTA file. The comment and identifier
for the next sequence record will be returned along with the sequence. If
end-of-file is reached, the returned comment and ID will be undefined.
=over 4
=item ih
Open file handle to the input file, which must be positioned after a
sequence header. At the end of the method call, the file will be
positioned after the next sequence header or at end-of-file.
=item RETURN
Returns a three-element list containing (0) the sequence read, (1) the
ID of the next sequence record in the file, and (2) the comment for
the next sequence record in the file.
=back
=cut
sub ReadFastaRecord {
# Get the parameters. Note we allow for both static and object-oriented
# calls.
shift if UNIVERSAL::isa($_[0],__PACKAGE__);
my ($ih) = @_;
# Declare the return variables for the ID and comment. When we read a
# header record, we'll set the next-ID variable and that will stop the
# read loop.
my ($nextID, $nextComment);
# This will hold the sequence fragments.
my @lines;
# Loop until we've read the whole sequence.
while (! eof $ih && ! defined $nextID) {
# Read the next line.
my $line = <$ih>;
chomp $line;
# Check for a header.
if (substr($line,0,1) eq '>') {
# This is a header line. Save the ID and comment.
($nextID, $nextComment) = split /\s+/, substr($line, 1), 2;
} else {
# This is a data line. Save the sequence.
push @lines, $line;
}
}
# Form the lines read into a sequence.
my $sequence = join("", @lines);
# Return everything read.
return ($sequence, $nextID, $nextComment);
}
=head3 ParseMetadata
my $metaHash = Bio::KBase::CDMI::CDMILoader::ParseMetadata($fileName);
or
my $metaHash = $loader->ParseMetadata($fileName);
Parse a metadata file to extract the attributes and values. A
metadata file contains one or more multi-line records separated
by a record containing nothing but a double slash (C<//>). The
first line of the record is the attribute name. The remaining
lines form the attribute value.
=over 4
=item fileName
Name of the metadata file to parse.
=item RETURN
Returns a reference to a hash mapping attribute names to their
values. Multi-line values may contain embedded line-feeds.
=back
=cut
sub ParseMetadata {
# Get the parameters. Note we allow for both static and object-oriented
# calls.
shift if UNIVERSAL::isa($_[0],__PACKAGE__);
my ($fileName) = @_;
# Declare the return hash.
my %retVal;
# Only proceed if the file exists.
if (-f $fileName) {
# Open the file.
( run in 1.190 second using v1.01-cache-2.11-cpan-364913b4093 )