Bio::DB::GenBank(3pm)
π Bio::DB::GenBank(3pm) β the vibe-coded manual, bestie edition π
okay so. You found the manpage for Bio::DB::GenBank β the Database object interface to GenBank. This is a Perl module, it lives in the Bioperl universe, and it's about to be your bestie for pulling sequence data off NCBI. Sit down, grab a boba, let's go. π§β¨
β¨ NAME β¨
Bio::DB::GenBank β Database object interface to GenBank. that's it, that's the whole name. iconic. π
πΈ SYNOPSIS πΈ
Here's the whole flex, verbatim, no cap:
use Bio::DB::GenBank;
$gb = Bio::DB::GenBank->new();
$seq = $gb->get_Seq_by_id('J00522'); # Unique ID, *not always the LOCUS ID*
# or ...
$seq = $gb->get_Seq_by_acc('J00522'); # Accession Number
$seq = $gb->get_Seq_by_version('J00522.1'); # Accession.version
$seq = $gb->get_Seq_by_gi('405830'); # GI Number
# get a stream via a query string
my $query = Bio::DB::Query::GenBank->new
(-query =>'Oryza sativa[Organism] AND EST',
-reldate => '30',
-db => 'nucleotide');
my $seqio = $gb->get_Stream_by_query($query);
while( my $seq = $seqio->next_seq ) {
print "seq length is ", $seq->length,"\n";
}
# or ... best when downloading very large files, prevents
# keeping all of the file in memory
# also don't want features, just sequence so let's save bandwidth
# and request Fasta sequence
$gb = Bio::DB::GenBank->new(-retrievaltype => 'tempfile' ,
-format => 'Fasta');
my $seqio = $gb->get_Stream_by_acc(['AC013798', 'AC021953'] );
while( my $clone = $seqio->next_seq ) {
print "cloneid is ", $clone->display_id, " ",
$clone->accession_number, "\n";
}
# note that get_Stream_by_version is not implemented
# don't want the entire sequence or more options
my $gb = Bio::DB::GenBank->new(-format => 'Fasta',
-seq_start => 100,
-seq_stop => 200,
-strand => 1,
-complexity => 4);
my $seqi = $gb->get_Stream_by_query($query);
okay so real talk, notice the comment <cyan># note that get_Stream_by_version is not implemented</cyan> β bestie, that one is NOT implemented. Do not go looking for it. It's giving ghosted. π»
π¦ DESCRIPTION π¦
This whole thing lets you dynamically retrieve Bio::Seq sequence objects from the GenBank database over at NCBI, via an Entrez query. Slay.
β οΈ WARNING: Please do NOT spam the Entrez web server with multiple requests. NCBI offers Batch Entrez for this purpose. Like, seriously, do not. Be a good citizen, bestie. π
Heads up about NT_ accessions: when you're querying for GenBank accessions starting with 'NT_' you will need to call $gb->request_format('fasta') beforehand, because in GenBank format (which is the default) the sequence part will be left out. The reason? NT contigs are rather annotation with references to clones. So yeah, no sequence for you unless you switch formats. π
Some work has been done to automatically detect and retrieve whole NT_ clones when the data is in that format (NCBI RefSeq clones). The former behavior prior to bioperl 1.6 was to retrieve these from EBI, but now these are retrieved directly from NCBI. You can get that older behavior back by setting the 'redirect_refseq' flag to a value evaluating to TRUE. Nostalgia unlocked, ig. π
π Running
Alternate methods are described at <https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EFetch>
NOTE:strandshould be1for plus or2for minus. Memorize it, that's the whole assignment. β¨
Complexity: gi is often a part of a biological blob, containing other gis. (a blob. a whole biological blob. we love a blob. π«§)
complexity regulates the display:
0β get the whole blob1β get the bioseq for gi of interest (default in Entrez)2β get the minimal bioseq-set containing the gi of interest3β get the minimal nuc-prot containing the gi of interest4β get the minimal pub-set containing the gi of interest
'seq_start' and 'seq_stop' will not work when setting complexity to any value other than 1. Periodt. And 'strand' works for any setting other than a complexity of 0 (whole glob); when you try this with a GenBank return format nothing happens, whereas using FASTA works but causes display problems with the other sequences in the glob. As Tao Tao says from NCBI, "Better left it out or set it to 1." take the advice, bestie, they work there. π
π«Ά FEEDBACK π«Ά
π Mailing Lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated. fr fr.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
π§ Support
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. (yes the original says "reponsive" β we keep it, we don't fix, we only vibe π)
π Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web:
https://github.com/bioperl/bioperl-live/issues
π AUTHOR - Aaron Mackey, Jason Stajich π
Email amackey@virginia.edu Email jason@bioperl.org
π APPENDIX π
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ (iykyk).
πΈ new
Title : new
Usage : $gb = Bio::DB::GenBank->new(@options)
Function: Creates a new genbank handle
Returns : a new Bio::DB::Genbank object
Args : -delay number of seconds to delay between fetches (3s)
NOTE: There are other options that are used internally. By NCBI policy, this module introduces a 3s delay between fetches. If you are fetching multiple genbank ids, it is a good idea to use get. The 3s delay is not optional, it's the law, respect the delay bestie π
π« get_params
Title : get_params
Usage : my %params = $self->get_params($mode)
Function: Returns key,value pairs to be passed to NCBI database
for either 'batch' or 'single' sequence retrieval method
Returns : a key,value pair hash
Args : 'single' or 'batch' mode for retrieval
π Routines Bio::DB::WebDBSeqI from Bio::DB::RandomAccessI π
π₯ get_Seq_by_id
Title : get_Seq_by_id
Usage : $seq = $db->get_Seq_by_id('ROA1_HUMAN')
Function: Gets a Bio::Seq object by its name
Returns : a Bio::Seq object
Args : the id (as a string) of a sequence
Throws : "id does not exist" exception
π get_Seq_by_acc
Title : get_Seq_by_acc
Usage : $seq = $db->get_Seq_by_acc($acc);
Function: Gets a Seq object by accession numbers
Returns : a Bio::Seq object
Args : the accession number as a string
Note : For GenBank, this just calls the same code for get_Seq_by_id().
Caveat: this normally works, but in rare cases simply passing the
accession can lead to odd results, possibly due to unsynchronized
NCBI ID servers. Using get_Seq_by_version() is slightly better, but
using the unique identifier (GI) and get_Seq_by_id is the most
consistent
Throws : "id does not exist" exception
𧬠get_Seq_by_gi
Title : get_Seq_by_gi
Usage : $seq = $db->get_Seq_by_gi('405830');
Function: Gets a Bio::Seq object by gi number
Returns : A Bio::Seq object
Args : gi number (as a string)
Throws : "gi does not exist" exception
π get_Seq_by_version
Title : get_Seq_by_version
Usage : $seq = $db->get_Seq_by_version('X77802.1');
Function: Gets a Bio::Seq object by sequence version
Returns : A Bio::Seq object
Args : accession.version (as a string)
Note : Caveat: this normally works, but using the unique identifier (GI) and
get_Seq_by_id is the most consistent
Throws : "acc.version does not exist" exception
π Routines implemented by Bio::DB::NCBIHelper π
π¦ get_Stream_by_query
Title : get_Stream_by_query
Usage : $seq = $db->get_Stream_by_query($query);
Function: Retrieves Seq objects from Entrez 'en masse', rather than one
at a time. For large numbers of sequences, this is far superior
than get_Stream_by_[id/acc]().
Example :
Returns : a Bio::SeqIO stream object
Args : $query : An Entrez query string or a
Bio::DB::Query::GenBank object. It is suggested that you
create a Bio::DB::Query::GenBank object and get the entry
count before you fetch a potentially large stream.
β¨ get_Stream_by_id
Title : get_Stream_by_id
Usage : $stream = $db->get_Stream_by_id( [$uid1, $uid2] );
Function: Gets a series of Seq objects by unique identifiers
Returns : a Bio::SeqIO stream object
Args : $ref : a reference to an array of unique identifiers for
the desired sequence entries
π get_Stream_by_acc
Title : get_Stream_by_acc
Usage : $seq = $db->get_Stream_by_acc([$acc1, $acc2]);
Function: Gets a series of Seq objects by accession numbers
Returns : a Bio::SeqIO stream object
Args : $ref : a reference to an array of accession numbers for
the desired sequence entries
Note : For GenBank, this just calls the same code for get_Stream_by_id()
π get_Stream_by_gi
Title : get_Stream_by_gi
Usage : $seq = $db->get_Seq_by_gi([$gi1, $gi2]);
Function: Gets a series of Seq objects by gi numbers
Returns : a Bio::SeqIO stream object
Args : $ref : a reference to an array of gi numbers for
the desired sequence entries
Note : For GenBank, this just calls the same code for get_Stream_by_id()
πΈ get_Stream_by_batch
Title : get_Stream_by_batch
Usage : $seq = $db->get_Stream_by_batch($ref);
Function: Retrieves Seq objects from Entrez 'en masse', rather than one
at a time.
Example :
Returns : a Bio::SeqIO stream object
Args : $ref : either an array reference, a filename, or a filehandle
from which to get the list of unique ids/accession numbers.
NOTE: This method is redundant and deprecated. Use get_Stream_by_id() instead. Deprecated!! Like, retired. Respectfully, don't. π«
π get_request
Title : get_request
Usage : my $url = $self->get_request
Function: HTTP::Request
Returns :
Args : %qualifiers = a hash of qualifiers (ids, format, etc)
β default_format
Title : default_format
Usage : my $format = $self->default_format
Function: Returns default sequence format for this module
Returns : string
Args : none
that's the whole page bestie, every option, every caveat, every Throws, all of it. π
this was perl v5.36.0, dated 2023-12-17, and it's the Bio::DB::GenBank(3pm) page β now go fetch some sequences responsibly, mind the 3s delay, and don't spam Entrez. mwah π«Άβ¨π
π¦ where this page comes from
- debian trixie: libbio-db-ncbihelper-perl 1.7.8-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbio-db-ncbihelper-perl 1.7.8-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libbio-db-ncbihelper-perl 1.7.8-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libbio-db-ncbihelper-perl 1.7.8-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms