Create a gist now

Instantly share code, notes, and snippets.

Get the full FASTA header or Full GenPept record for retrieval
#!/usr/bin/perl -w
# Jason Stajich jason<at>bioperl.org
use strict;
use Bio::DB::GenPept;
use Bio::DB::GenBank;
use Bio::SeqIO;
# get the FASTA formatted header for BLAST database
my $db = Bio::DB::GenBank->new(-format => 'fasta');
my $out = Bio::SeqIO->new(-format => 'fasta');
my $seq = $db->get_Seq_by_id('NP_006959.1');
$out->write_seq($seq);
# get the full GenPept record
$db = Bio::DB::GenBank->new(-format => 'gp');
$out = Bio::SeqIO->new(-format => 'genbank');
$seq = $db->get_Seq_by_id('NP_006959.1');
$out->write_seq($seq);
# works when you use the wrong DB (genbank)
eval {
$db = Bio::DB::GenBank->new(-format => 'gb');
$out = Bio::SeqIO->new(-format => 'genbank');
$seq = $db->get_Seq_by_id('NP_006959.1');
$out->write_seq($seq);
};
if($@) {
# should never get here
warn("couldn't request a protein record from GenBank\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment