Created
June 14, 2011 10:37
-
-
Save gaurav/1024657 to your computer and use it in GitHub Desktop.
ReadGB.pl: Reading a GenBank file with BioPerl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.0100; | |
use strict; | |
use warnings; | |
# Load the SeqIO module. | |
use Bio::SeqIO; | |
# Load the GenBank file. | |
my $input = Bio::SeqIO->new( | |
-file => "<input.gb", # to read ('<') from 'input.gb'. | |
-format => "genbank" # optional: SeqIO can detect filetypes from the extension. | |
); | |
# Iterate over every sequence in this file. | |
my $seq; | |
while( $seq = $input->next_seq() ) { | |
# $seq is a Bio::Seq::RichSeq, which is a Bio::Seq. | |
# All the Bio::Seq methods can be called on this object, | |
# including: | |
say "Sequence name: " . $seq->description(); | |
say "Accession number: " . $seq->accession_number(); | |
# Not all sequences have actual sequence data. | |
if(defined $seq->seq()) { | |
say "Sequence: " . $seq->seq(); | |
} | |
say ""; # Blank line. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment