Skip to content

Instantly share code, notes, and snippets.

@gaurav
Created June 14, 2011 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurav/1024657 to your computer and use it in GitHub Desktop.
Save gaurav/1024657 to your computer and use it in GitHub Desktop.
ReadGB.pl: Reading a GenBank file with BioPerl
#!/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