Bio-Procedural
view release on metacpan or search on metacpan
examples/bioperl.pl view on Meta::CPAN
waitenter
# PARSING GENBANK RECORDS
# -----------------------
# to parse genbank files, use
# the read_seq() method, or
# simply use the '<' command.
#
# First of all we're going to
# take a look at the file
# 't/data/test.genbank'
# Let's examine the file itself
# using the unix command "cat"
# (you can use any unix command
# using the ! at the beginning
# of a line)
^!cat t/data/test.genbank
waitenter
# Ok, you can see this is a
# typical file of genbank records.
# Let's get the first sequence
# from the file
^<t/data/test.genbank
waitenter
# we have parsed the first
# record of the file, and placed
# the sequence object into
# the variable $seq
#
# if you are familiar with perl
# objects and the bioperl object
# model, you can interact with
# the object; for instance, to
# display the residues we use the
# seq() method like this:
^print $seq->seq()
waitenter
#
# we can cycle through all the
# sequences in the file using
# the ',' command.
^,
waitenter
# this fetched the second sequence
# and placed it in the $seq variable
#
# we can change the output format
# by setting the 'outformat' parameter
# like this:
^+outformat fasta
^,
waitenter
# now the sequences are output in
# fasta format
# to change to embl format:
^+outformat embl
^,
waitenter
# we can also fetch _all_ seqs from
# a file; for this example we will
# use t/data/swiss.dat, which is in
# swiss format. usually bioperl can guess
# the file format from the file extension
# but this isn't possible here, so we
# must help by setting the input format:
^+format swiss
# now lets get all the sequences, like this:
^<*t/data/swiss.dat
waitenter
# typing <* is equivalent to
# using the read_seqs() function,
# like this:
^read_seqs('t/data/swiss.dat')
waitenter
# we now have all the sequences in
# the array @seqs
# we can write these all out as fasta
^+outformat fasta
^>*
# we can also write these out to a file:
^>*myfile.tmp
^!cat myfile.tmp
#
# RANDOM ACCESS OF FASTA FILES
# END
+echo 0
%$options = %keep
]);
@lines =
map {
s/^ *//;
$_;
} @lines;
}
sub error {
if ($error) {
print "Error:\n$error";
}
else {
print "No errors have been reported\n";
}
}
sub fmt {
$options->{format} = shift if @_;
print "format=$options->{format}\n";
}
# should this move to Bio::Perl ?
sub seqio {
my $filename = shift;
$options->{format} = shift if @_;
if( !defined $filename ) {
warn "read_sequence($filename) - usage incorrect";
}
if( defined $options->{format} ) {
$seqio = Bio::SeqIO->new( '-file' => $filename, '-format' => $options->{format});
} else {
( run in 1.012 second using v1.01-cache-2.11-cpan-39bf76dae61 )