Skip to content

Instantly share code, notes, and snippets.

@hyphaltip
Created November 30, 2010 02:11
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 hyphaltip/721012 to your computer and use it in GitHub Desktop.
Save hyphaltip/721012 to your computer and use it in GitHub Desktop.
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