Querying for summary and genbank file with a search term
Programming Language: Perl
Modules required: Bio::DB::EUtilities
EUtilities is a very useful resource to retrieve data from NCBI database.
This script retrieves a brief summary and the genbank file for genes that are relevant to a search word.
There is also an option to limit you number of results returns (very handy).
Bio::DB::EUtilities is required to execute the search.
This method is much faster than using Bio::DB::Query::GenBank module.
If you require more information than the summary output, you can always get it from the genbank file.
The summary does not provide information such as references and sequences.
Chapter 10 of ‘Beginning Perl for Bioinformatics’ is a good and simple reference for retrieving data from from files in genbank format. This resource is freely available here.
Note that you can query for proteins as well. (uncomment line 15)
Installing new modules: this can be easily done using cpan.
Here is the documentation for cpan.
Or, here is documentation for installing modules manually.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #!/usr/bin/perl -w use Bio::DB::EUtilities; use strict; #specify search term my $search_term = 'breast cancer'; #maximum number of results to retrieve my $retmax = 10; #first search for a list of genbank ids that match your search term my $factory = Bio::DB::EUtilities->new(-eutil => 'esearch', # -db => 'protein', -db => 'nucleotide', -term => $search_term, -retmax => $retmax); #list of Genbank IDs my @ids = $factory->get_ids; #loop through the list of IDs foreach my $id (@ids){ # get a summary and print details $factory->reset_parameters(-eutil => 'esummary',-db => 'nucleotide',-id => $id); my $ds = $factory->next_DocSum; # print flattened mode from summary above while (my $item = $ds->next_Item('flattened')) { # checks id itens has contents printf("%-20s:%s\n",$item->get_name,$item->get_content) if $item->get_content; } # download the full genbank file $factory = Bio::DB::EUtilities->new(-eutil => 'efetch', -db => 'nucleotide', -id => $id, -rettype => 'gbwithparts'); $factory->get_Response(-file => "$id.gb"); } |
#!/usr/bin/perl -w use Bio::DB::EUtilities; use strict; #specify search term my $search_term = 'breast cancer'; #maximum number of results to retrieve my $retmax = 10; #first search for a list of genbank ids that match your search term my $factory = Bio::DB::EUtilities->new(-eutil => 'esearch', # -db => 'protein', -db => 'nucleotide', -term => $search_term, -retmax => $retmax); #list of Genbank IDs my @ids = $factory->get_ids; #loop through the list of IDs foreach my $id (@ids){ # get a summary and print details $factory->reset_parameters(-eutil => 'esummary',-db => 'nucleotide',-id => $id); my $ds = $factory->next_DocSum; # print flattened mode from summary above while (my $item = $ds->next_Item('flattened')) { # checks id itens has contents printf("%-20s:%s\n",$item->get_name,$item->get_content) if $item->get_content; } # download the full genbank file $factory = Bio::DB::EUtilities->new(-eutil => 'efetch', -db => 'nucleotide', -id => $id, -rettype => 'gbwithparts'); $factory->get_Response(-file => "$id.gb"); }
This entry was posted by Risha on March 17, 2010 at 7:18 pm, and is filed under EUtilities, Perl, Querying for summary and genbank file. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site.
Leave a Reply