| 1 | # | ||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::DB::Query::GenBank.pm | ||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||
| 6 | # Cared for by Lincoln Stein <lstein@cshl.org> | ||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||
| 8 | # Copyright Lincoln Stein | ||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | Bio::DB::Query::GenBank - Build a GenBank Entrez Query | ||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | use Bio::DB::Query::GenBank; | ||||||||||||||||||||||||||||||
| 22 | use Bio::DB::GenBank; | ||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | my $query_string = 'Oryza[Organism] AND EST[Keyword]'; | ||||||||||||||||||||||||||||||
| 25 | my $query = Bio::DB::Query::GenBank->new(-db => 'nucleotide', | ||||||||||||||||||||||||||||||
| 26 | -query => $query_string, | ||||||||||||||||||||||||||||||
| 27 | -mindate => '2001', | ||||||||||||||||||||||||||||||
| 28 | -maxdate => '2002'); | ||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | print $query->count,"\n"; | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | # get a Genbank database handle | ||||||||||||||||||||||||||||||
| 33 | my $gb = Bio::DB::GenBank->new(); | ||||||||||||||||||||||||||||||
| 34 | my $stream = $gb->get_Stream_by_query($query); | ||||||||||||||||||||||||||||||
| 35 | while (my $seq = $stream->next_seq) { | ||||||||||||||||||||||||||||||
| 36 | # do something with the sequence object | ||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | # initialize the list yourself | ||||||||||||||||||||||||||||||
| 40 | my $query = Bio::DB::Query::GenBank->new(-ids=>[195052,2981014,11127914]); | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | This class encapsulates NCBI Entrez queries. It can be used to store | ||||||||||||||||||||||||||||||
| 46 | a list of GI numbers, to translate an Entrez query expression into a | ||||||||||||||||||||||||||||||
| 47 | list of GI numbers, or to count the number of terms that would be | ||||||||||||||||||||||||||||||
| 48 | returned by a query. Once created, the query object can be passed to | ||||||||||||||||||||||||||||||
| 49 | a Bio::DB::GenBank object in order to retrieve the entries | ||||||||||||||||||||||||||||||
| 50 | corresponding to the query. | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | User feedback is an integral part of the | ||||||||||||||||||||||||||||||
| 57 | evolution of this and other Bioperl modules. Send | ||||||||||||||||||||||||||||||
| 58 | your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||
| 59 | of the Bioperl mailing lists. Your participation | ||||||||||||||||||||||||||||||
| 60 | is much appreciated. | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||
| 63 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | =head2 Support | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||
| 72 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||
| 73 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||
| 74 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||
| 79 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||
| 80 | web: | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | =head1 AUTHOR - Lincoln Stein | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | Email lstein@cshl.org | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | =head1 APPENDIX | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | The rest of the documentation details each of the | ||||||||||||||||||||||||||||||
| 91 | object methods. Internal methods are usually | ||||||||||||||||||||||||||||||
| 92 | preceded with a _ | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | # Let the code begin... | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | package Bio::DB::Query::GenBank; | ||||||||||||||||||||||||||||||
| 99 | 11 | $Bio::DB::Query::GenBank::VERSION = '1.7.3'; | |||||||||||||||||||||||||||||
| 100 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 101 | 11 | ▶ | use URI::Escape 'uri_unescape'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 102 | 11 | ▶ | use Bio::DB::NCBIHelper; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | #use constant EPOST => $Bio::DB::NCBIHelper::HOSTBASE . '/entrez/eutils/epost.fcgi'; | ||||||||||||||||||||||||||||||
| 106 | #use constant ESEARCH => $Bio::DB::NCBIHelper::HOSTBASE . '/entrez/eutils/esearch.fcgi'; | ||||||||||||||||||||||||||||||
| 107 | # the reference to the our variable of the $Bio::DB::NCBIHelper::HOSTBASE doesn't seem to work in | ||||||||||||||||||||||||||||||
| 108 | # the constant definition in perl 5.10.1 or 5.16.3 | ||||||||||||||||||||||||||||||
| 109 | 11 | ▶ | use constant EPOST => '/entrez/eutils/epost.fcgi'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 110 | 11 | ▶ | use constant ESEARCH => '/entrez/eutils/esearch.fcgi'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 111 | 11 | ▶ | use constant DEFAULT_DB => 'protein'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 112 | 11 | ▶ | use constant MAXENTRY => 100; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | 11 | ▶ | use vars qw(@ATTRIBUTES); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | 11 | ▶ | use base qw(Bio::DB::Query::WebQuery); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | BEGIN { | ||||||||||||||||||||||||||||||
| 119 | 11 | ▶ | @ATTRIBUTES = qw(db reldate mindate maxdate datetype maxids); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 120 | 11 | for my $method (@ATTRIBUTES) { | |||||||||||||||||||||||||||||
| 121 | 66 | ▶ | eval <<END; | ||||||||||||||||||||||||||||
|
Subroutine
datetype: called CC=2 SCAR=6.9
Subroutine
db: called CC=2 SCAR=6.9
Subroutine
maxdate: called CC=2 SCAR=6.9
Subroutine
maxids: called CC=2 SCAR=6.9
Subroutine
mindate: called CC=2 SCAR=6.9
Subroutine
reldate: called CC=2 SCAR=6.9
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Pod
undocumented
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 122 | sub $method { | ||||||||||||||||||||||||||||||
| 123 | my \$self = shift; | ||||||||||||||||||||||||||||||
| 124 | my \$d = \$self->{'_$method'}; | ||||||||||||||||||||||||||||||
| 125 | \$self->{'_$method'} = shift if \@_; | ||||||||||||||||||||||||||||||
| 126 | \$d; | ||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||
| 128 | END | ||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | =head2 new | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | Title : new | ||||||||||||||||||||||||||||||
| 135 | Usage : $db = Bio::DB::Query::GenBank->new(@args) | ||||||||||||||||||||||||||||||
| 136 | Function: create new query object | ||||||||||||||||||||||||||||||
| 137 | Returns : new query object | ||||||||||||||||||||||||||||||
| 138 | Args : -db database (see below for allowable values) | ||||||||||||||||||||||||||||||
| 139 | -query query string | ||||||||||||||||||||||||||||||
| 140 | -mindate minimum date to retrieve from (YYYY/MM/DD) | ||||||||||||||||||||||||||||||
| 141 | -maxdate maximum date to retrieve from (YYYY/MM/DD) | ||||||||||||||||||||||||||||||
| 142 | -reldate relative date to retrieve from (days) | ||||||||||||||||||||||||||||||
| 143 | -datetype date field to use ('edat' or 'mdat') | ||||||||||||||||||||||||||||||
| 144 | -ids array ref of gids (overrides query) | ||||||||||||||||||||||||||||||
| 145 | -maxids the maximum number of IDs you wish to collect | ||||||||||||||||||||||||||||||
| 146 | (defaults to 100) | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | This method creates a new query object. Typically you will specify a | ||||||||||||||||||||||||||||||
| 149 | -db and a -query argument, possibly modified by -mindate, -maxdate, or | ||||||||||||||||||||||||||||||
| 150 | -reldate. -mindate and -maxdate specify minimum and maximum dates for | ||||||||||||||||||||||||||||||
| 151 | entries you are interested in retrieving, expressed in the form | ||||||||||||||||||||||||||||||
| 152 | YYYY/MM/DD. -reldate is used to fetch entries that are more recent | ||||||||||||||||||||||||||||||
| 153 | than the indicated number of days. | ||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | If you provide an array reference of IDs in -ids, the query will be | ||||||||||||||||||||||||||||||
| 156 | ignored and the list of IDs will be used when the query is passed to a | ||||||||||||||||||||||||||||||
| 157 | Bio::DB::GenBank object's get_Stream_by_query() method. A variety of | ||||||||||||||||||||||||||||||
| 158 | IDs are automatically recognized, including GI numbers, Accession | ||||||||||||||||||||||||||||||
| 159 | numbers, Accession.version numbers and locus names. | ||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | By default, the query will collect only the first 100 IDs and will | ||||||||||||||||||||||||||||||
| 162 | generate an exception if you call the ids() method and the query | ||||||||||||||||||||||||||||||
| 163 | returned more than that number. To increase this maximum, set -maxids | ||||||||||||||||||||||||||||||
| 164 | to a number larger than the number of IDs you expect to obtain. This | ||||||||||||||||||||||||||||||
| 165 | only affects the list of IDs you obtain when you call the ids() | ||||||||||||||||||||||||||||||
| 166 | method, and does not affect in any way the number of entries you | ||||||||||||||||||||||||||||||
| 167 | receive when you generate a SeqIO stream from the query. | ||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||
| 169 | -db option values: | ||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | The most commonly used databases are: | ||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | protein | ||||||||||||||||||||||||||||||
| 174 | nucleotide | ||||||||||||||||||||||||||||||
| 175 | nuccore | ||||||||||||||||||||||||||||||
| 176 | nucgss | ||||||||||||||||||||||||||||||
| 177 | nucest | ||||||||||||||||||||||||||||||
| 178 | unigene | ||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | An up to date list of database names supported by NCBI eUtils is | ||||||||||||||||||||||||||||||
| 181 | always available at: | ||||||||||||||||||||||||||||||
| 182 | https://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi? | ||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | However, note that not all of these databases return datatypes that | ||||||||||||||||||||||||||||||
| 185 | are parsable by Bio::DB::GenBank | ||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | =cut | ||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | sub new { | ||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 191 | 3 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||
| 192 | 3 | my ($query,$db,$reldate,$mindate,$maxdate,$datetype,$ids,$maxids) | |||||||||||||||||||||||||||||
| 193 | = $self->_rearrange([qw(QUERY DB RELDATE MINDATE MAXDATE DATETYPE IDS MAXIDS)],@_); | ||||||||||||||||||||||||||||||
| 194 | 3 | ▶ | $self->db($db || DEFAULT_DB); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$db || 'protein'
MC/DC100%1/1
$db || 'protein'
$db
Truth table100%2/2
A
A= $db
| |||||||||||||||||||||||||||||||
| 195 | 3 | ▶ | $reldate && $self->reldate($reldate); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 196 | 3 | ▶ | $mindate && $self->mindate($mindate); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | $maxdate && $self->maxdate($maxdate); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 198 | 3 | ▶ | $maxids && $self->maxids($maxids); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | $datetype ||= 'mdat'; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$datetype ||= "mdat"
MC/DC0%0/1
$datetype ||= "mdat"
$datetype
Truth table50%1/2
A
A= $datetype
| |||||||||||||||||||||||||||||||
| 200 | 3 | ▶ | $datetype && $self->datetype($datetype); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 201 | 3 | $self; | |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | =head2 cookie | ||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | Title : cookie | ||||||||||||||||||||||||||||||
| 207 | Usage : ($cookie,$querynum) = $db->cookie | ||||||||||||||||||||||||||||||
| 208 | Function: return the NCBI query cookie | ||||||||||||||||||||||||||||||
| 209 | Returns : list of (cookie,querynum) | ||||||||||||||||||||||||||||||
| 210 | Args : none | ||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | NOTE: this information is used by Bio::DB::GenBank in | ||||||||||||||||||||||||||||||
| 213 | conjunction with efetch. | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||
| 217 | sub cookie { | ||||||||||||||||||||||||||||||
| 218 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
cookie: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | if (@_) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 220 | 2 | $self->{'_cookie'} = shift; | |||||||||||||||||||||||||||||
| 221 | 2 | $self->{'_querynum'} = shift; | |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||
| 224 | else { | ||||||||||||||||||||||||||||||
| 225 | 2 | $self->_run_query; | |||||||||||||||||||||||||||||
| 226 | 2 | @{$self}{qw(_cookie _querynum)}; | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||
| 230 | =head2 _request_parameters | ||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | Title : _request_parameters | ||||||||||||||||||||||||||||||
| 233 | Usage : ($method,$base,@params = $db->_request_parameters | ||||||||||||||||||||||||||||||
| 234 | Function: return information needed to construct the request | ||||||||||||||||||||||||||||||
| 235 | Returns : list of method, url base and key=>value pairs | ||||||||||||||||||||||||||||||
| 236 | Args : none | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | =cut | ||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||
| 240 | sub _request_parameters { | ||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
_request_parameters: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||
| 242 | 2 | my ($method,$base); | |||||||||||||||||||||||||||||
| 243 | 2 | ▶ | my @params = map {eval("\$self->$_") ? ($_ => eval("\$self->$_")) : () } @ATTRIBUTES; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 244 | 2 | push @params,('usehistory'=>'y','tool'=>'bioperl'); | |||||||||||||||||||||||||||||
| 245 | 2 | $method = 'get'; | |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | 2 | $base = $Bio::DB::NCBIHelper::HOSTBASE.ESEARCH; # this seems to need to be dynamic | |||||||||||||||||||||||||||||
| 248 | 2 | push @params,('term' => $self->query); | |||||||||||||||||||||||||||||
| 249 | # Providing 'retmax' limits queries to 500 sequences ?? I don't think so LS | ||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | push @params,('retmax' => $self->maxids || MAXENTRY); | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->maxids || 100
MC/DC0%0/1
$self->maxids || 100
$self->maxids
Truth table50%1/2
A
A= $self->maxids
| |||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||
| 252 | # And actually, it seems that we need 'retstart' equal to 0 ?? I don't think so LS | ||||||||||||||||||||||||||||||
| 253 | # push @params, ('retstart' => 0); | ||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||
| 255 | 2 | ($method,$base,@params); | |||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||
| 259 | =head2 count | ||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | Title : count | ||||||||||||||||||||||||||||||
| 262 | Usage : $count = $db->count; | ||||||||||||||||||||||||||||||
| 263 | Function: return count of number of entries retrieved by query | ||||||||||||||||||||||||||||||
| 264 | Returns : integer | ||||||||||||||||||||||||||||||
| 265 | Args : none | ||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | Returns the number of entries that are matched by the query. | ||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||
| 271 | sub count { | ||||||||||||||||||||||||||||||
| 272 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
count: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 273 | 6 | ▶ | if (@_) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 274 | 2 | my $d = $self->{'_count'}; | |||||||||||||||||||||||||||||
| 275 | 2 | $self->{'_count'} = shift; | |||||||||||||||||||||||||||||
| 276 | 2 | return $d; | |||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||
| 279 | 4 | $self->_run_query; | |||||||||||||||||||||||||||||
| 280 | 4 | return $self->{'_count'}; | |||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||
| 284 | =head2 ids | ||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||
| 286 | Title : ids | ||||||||||||||||||||||||||||||
| 287 | Usage : @ids = $db->ids([@ids]) | ||||||||||||||||||||||||||||||
| 288 | Function: get/set matching ids | ||||||||||||||||||||||||||||||
| 289 | Returns : array of sequence ids | ||||||||||||||||||||||||||||||
| 290 | Args : (optional) array ref with new set of ids | ||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||
| 292 | =cut | ||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||
| 294 | =head2 query | ||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | Title : query | ||||||||||||||||||||||||||||||
| 297 | Usage : $query = $db->query([$query]) | ||||||||||||||||||||||||||||||
| 298 | Function: get/set query string | ||||||||||||||||||||||||||||||
| 299 | Returns : string | ||||||||||||||||||||||||||||||
| 300 | Args : (optional) new query string | ||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||
| 302 | =cut | ||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||
| 304 | =head2 _parse_response | ||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||
| 306 | Title : _parse_response | ||||||||||||||||||||||||||||||
| 307 | Usage : $db->_parse_response($content) | ||||||||||||||||||||||||||||||
| 308 | Function: parse out response | ||||||||||||||||||||||||||||||
| 309 | Returns : empty | ||||||||||||||||||||||||||||||
| 310 | Args : none | ||||||||||||||||||||||||||||||
| 311 | Throws : 'unparseable output exception' | ||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||
| 313 | =cut | ||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||
| 315 | sub _parse_response { | ||||||||||||||||||||||||||||||
| 316 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
_parse_response: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||
| 317 | 2 | my $content = shift; | |||||||||||||||||||||||||||||
| 318 | 2 | ▶ | if (my ($warning) = $content =~ m!<ErrorList>(.+)</ErrorList>!s) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 319 | 0 | $self->warn("Warning(s) from GenBank: $warning\n"); | |||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||
| 321 | 2 | ▶ | if (my ($error) = $content =~ /<OutputMessage>([^<]+)/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 322 | 0 | $self->throw("Error from Genbank: $error"); | |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 2 | my ($count) = $content =~ /<Count>(\d+)/; | |||||||||||||||||||||||||||||
| 326 | 2 | my ($max) = $content =~ /<RetMax>(\d+)/; | |||||||||||||||||||||||||||||
| 327 | 2 | my $truncated = $count > $max; | |||||||||||||||||||||||||||||
| 328 | 2 | $self->count($count); | |||||||||||||||||||||||||||||
| 329 | 2 | ▶ | if (!$truncated) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 330 | 2 | my @ids = $content =~ /<Id>(\d+)/g; | |||||||||||||||||||||||||||||
| 331 | 2 | $self->ids(\@ids); | |||||||||||||||||||||||||||||
| 332 | } else { | ||||||||||||||||||||||||||||||
| 333 | 0 | $self->debug("ids truncated at $max\n"); | |||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||
| 335 | 2 | $self->_truncated($truncated); | |||||||||||||||||||||||||||||
| 336 | 2 | my ($cookie) = $content =~ m!<WebEnv>(\S+)</WebEnv>!; | |||||||||||||||||||||||||||||
| 337 | 2 | my ($querykey) = $content =~ m!<QueryKey>(\d+)!; | |||||||||||||||||||||||||||||
| 338 | 2 | $self->cookie(uri_unescape($cookie),$querykey); | |||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||
| 341 | =head2 _generate_id_string | ||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||
| 343 | Title : _generate_id_string | ||||||||||||||||||||||||||||||
| 344 | Usage : $string = $db->_generate_id_string | ||||||||||||||||||||||||||||||
| 345 | Function: joins IDs together in string (possibly implementation-dependent) | ||||||||||||||||||||||||||||||
| 346 | Returns : string of concatenated IDs | ||||||||||||||||||||||||||||||
| 347 | Args : array ref of ids (normally passed into the constructor) | ||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||
| 349 | =cut | ||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||
| 351 | sub _generate_id_string { | ||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | my ($self, $ids) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_generate_id_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 353 | # this attempts to separate out accs (alphanumeric) from UIDs (numeric only) | ||||||||||||||||||||||||||||||
| 354 | # recent changes to esearch has wrought this upon us.. cjf 4/19/07 | ||||||||||||||||||||||||||||||
| 355 | return sprintf('%s',join('|',map { | ||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | ($_ =~ m{^\d+$}) ? $_.'[UID]' : $_.'[PACC]' | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 357 | } @$ids)); | ||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||
| 360 | 11 | 1; | |||||||||||||||||||||||||||||