NCBIHelper.pm

filter: Statementstmt 85.5% 118 / 138 Branchbran 67.5% 54 / 80 Conditioncond 36.8% 21 / 57 MC/DCmcdc 10.0% 3 / 30 Subroutinesub 80.0% 20 / 25 Podpod 100% 16 / 16 totaltotal 67.0% 232 / 346 CC 60 SCAR 35.6
CC
60
Cov
70%
get_request
83.6
strand
14.9
new
9.4
CRAP 35.0
« Taxonomy/entrez.pm ↑ Summary Query/GenBank.pm »
1 #
2 # BioPerl module for Bio::DB::NCBIHelper
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich
7 #
8 # Copyright Jason Stajich
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 # Interfaces with new WebDBSeqI interface
15  
16 =head1 NAME
17  
18 Bio::DB::NCBIHelper - A collection of routines useful for queries to
19 NCBI databases.
20  
21 =head1 SYNOPSIS
22  
23 # Do not use this module directly.
24  
25 # get a Bio::DB::NCBIHelper object somehow
26 my $seqio = $db->get_Stream_by_acc(['J00522']);
27 foreach my $seq ( $seqio->next_seq ) {
28 # process seq
29 }
30  
31 =head1 DESCRIPTION
32  
33 Provides a single place to setup some common methods for querying NCBI
34 web databases. This module just centralizes the methods for
35 constructing a URL for querying NCBI GenBank and NCBI GenPept and the
36 common HTML stripping done in L<postprocess_data>().
37  
38 The base NCBI query URL used is:
39 https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi
40  
41 =head1 FEEDBACK
42  
43 =head2 Mailing Lists
44  
45 User feedback is an integral part of the
46 evolution of this and other Bioperl modules. Send
47 your comments and suggestions preferably to one
48 of the Bioperl mailing lists. Your participation
49 is much appreciated.
50  
51 bioperl-l@bioperl.org - General discussion
52 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53  
54 =head2 Support
55  
56 Please direct usage questions or support issues to the mailing list:
57  
58 I<bioperl-l@bioperl.org>
59  
60 rather than to the module maintainer directly. Many experienced and
61 reponsive experts will be able look at the problem and quickly
62 address it. Please include a thorough description of the problem
63 with code and data examples if at all possible.
64  
65 =head2 Reporting Bugs
66  
67 Report bugs to the Bioperl bug tracking system to
68 help us keep track the bugs and their resolution.
69 Bug reports can be submitted via the web.
70  
71 https://github.com/bioperl/bioperl-live/issues
72  
73 =head1 AUTHOR - Jason Stajich
74  
75 Email jason@bioperl.org
76  
77 =head1 APPENDIX
78  
79 The rest of the documentation details each of the
80 object methods. Internal methods are usually
81 preceded with a _
82  
83 =cut
84  
85 # Let the code begin...
86  
87 package Bio::DB::NCBIHelper;
88 11 $Bio::DB::NCBIHelper::VERSION = '1.7.3';
89 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 11 ▶use Bio::DB::Query::GenBank;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 11 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 11 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 11 ▶use Bio::Root::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 # use Bio::DB::RefSeq;
96 11 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 11 ▶use base qw(Bio::DB::WebDBSeqI Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 11 our $HOSTBASE = 'https://eutils.ncbi.nlm.nih.gov';
101 11 our $MAX_ENTRIES = 19000;
102 11 our $REQUEST_DELAY = 3;
103 11 our %CGILOCATION = (
104 'batch' => [ 'post' => '/entrez/eutils/epost.fcgi' ],
105 'query' => [ 'get' => '/entrez/eutils/efetch.fcgi' ],
106 'single' => [ 'get' => '/entrez/eutils/efetch.fcgi' ],
107 'version' => [ 'get' => '/entrez/eutils/efetch.fcgi' ],
108 'gi' => [ 'get' => '/entrez/eutils/efetch.fcgi' ],
109 'webenv' => [ 'get' => '/entrez/eutils/efetch.fcgi' ]
110 );
111 11 our %FORMATMAP = (
112 'gb' => 'genbank',
113 'gp' => 'genbank',
114 'fasta' => 'fasta',
115 'asn.1' => 'entrezgene',
116 'gbwithparts' => 'genbank',
117 );
118 11 our $DEFAULTFORMAT = 'gb';
119  
120 =head2 new
121  
122 Title : new
123 Usage :
124 Function: the new way to make modules a little more lightweight
125 Returns :
126 Args :
127  
128 =cut
129  
130 sub new {
131 13 ▶ my ( $class, @args ) = @_;
Subroutine new: called CC=9 SCAR=22.4
Pod documented
132 13 my $self = $class->SUPER::new(@args);
133 13 my ($seq_start, $seq_stop, $no_redirect,
134 $redirect, $complexity, $strand
135 )
136 = $self->_rearrange(
137 [ qw(SEQ_START SEQ_STOP NO_REDIRECT REDIRECT_REFSEQ COMPLEXITY STRAND) ],
138 @args
139 );
140 13 ▶ $seq_start && $self->seq_start($seq_start);
Branch: 1 branch
BranchTrueFalseTotal
$seq_start and $self->seq_start($seq_start) 1 12 13
141 13 ▶ $seq_stop && $self->seq_stop($seq_stop);
Branch: 1 branch
BranchTrueFalseTotal
$seq_stop and $self->seq_stop($seq_stop) 1 12 13
142 13 ▶ $no_redirect && $self->no_redirect($no_redirect);
Branch: 1 branch
BranchTrueFalseTotal
$no_redirect and $self->no_redirect($no_redirect) 0 13 13
143 13 ▶ $redirect && $self->redirect_refseq($redirect);
Branch: 1 branch
BranchTrueFalseTotal
$redirect and $self->redirect_refseq($redirect) 0 13 13
144 13 ▶ $strand && $self->strand($strand);
Branch: 1 branch
BranchTrueFalseTotal
$strand and $self->strand($strand) 0 13 13
145  
146 # adjust statement to accept zero value
147 13 ▶ if (defined $complexity && $complexity >= 0 && $complexity <= 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $complexity and $complexity >= 0 and $complexity <= 4) 1 12 13
Condition66%4/6
defined $complexity and $complexity >= 0 and $complexity <= 4
!ll&&!rl&&r
1201
defined $complexity and $complexity >= 0
!ll&&!rl&&r
1201
MC/DC33%1/3
defined $complexity and $complexity >= 0 and $complexity <= 4
defined $complexity $complexity >= 0 $complexity <= 4
Truth table50%2/4
A and B and C
A= defined $complexityB= $complexity >= 0C= $complexity <= 4
ABCresult
0XX0
10X0
1100
1111
148 1 $self->complexity($complexity)
149 }
150 13 return $self;
151 }
152  
153  
154 =head2 get_params
155  
156 Title : get_params
157 Usage : my %params = $self->get_params($mode)
158 Function: returns key,value pairs to be passed to NCBI database
159 for either 'batch' or 'single' sequence retrieval method
160 Returns : a key,value pair hash
161 Args : 'single' or 'batch' mode for retrieval
162  
163 =cut
164  
165 sub get_params {
166 0 ▶ my ($self, $mode) = @_;
Subroutine get_params: not called CC=1 SCAR=6.9
Pod documented
167 0 $self->throw("subclass did not implement get_params");
168 }
169  
170 =head2 default_format
171  
172 Title : default_format
173 Usage : my $format = $self->default_format
174 Function: returns default sequence format for this module
175 Returns : string
176 Args : none
177  
178 =cut
179  
180 sub default_format {
181 0 ▶ return $DEFAULTFORMAT;
Subroutine default_format: not called CC=1 SCAR=6.9
Pod documented
182 }
183  
184 =head2 get_request
185  
186 Title : get_request
187 Usage : my $url = $self->get_request
188 Function: HTTP::Request
189 Returns :
190 Args : %qualifiers = a hash of qualifiers (ids, format, etc)
191  
192 =cut
193  
194 sub get_request {
195 25 ▶ my ( $self, @qualifiers ) = @_;
Subroutine get_request: called CC=32 SCAR=44.3
Pod documented
196 25 my ( $mode, $uids, $format, $query, $seq_start, $seq_stop, $strand,
197 $complexity )
198 = $self->_rearrange(
199 [qw(MODE UIDS FORMAT QUERY SEQ_START SEQ_STOP STRAND COMPLEXITY)],
200 @qualifiers );
201 25 $mode = lc $mode;
202 25 ▶ ($format) = $self->request_format() unless ( defined $format );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format 0 25 25
203 25 ▶ if ( !defined $mode || $mode eq '' ) { $mode = 'single'; }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mode or $mode eq "") 0 25 25
Condition33%1/3
not defined $mode or $mode eq ""
l!l&&r!l&&!r
0025
MC/DC0%0/2
not defined $mode or $mode eq ""
not defined $mode $mode eq ""
Truth table33%1/3
not(A) or B
A= not defined $modeB= $mode eq ""
ABresult
1X1
011
000
204 25 my %params = $self->get_params($mode);
205 25 ▶ if ( !%params ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%params) 0 25 25
206 0 $self->throw(
207 "must specify a valid retrieval mode 'single' or 'batch' not '$mode'"
208 );
209 }
210 25 my $url = URI->new( $HOSTBASE . $CGILOCATION{$mode}[1] );
211 25 ▶ unless ( $mode eq 'webenv' || defined $uids || defined $query ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode eq "webenv" or defined $uids or defined $query) 0 25 25
Condition83%5/6
$mode eq "webenv" or defined $uids or defined $query
l!l&&r!l&&!r
2320
$mode eq "webenv" or defined $uids
l!l&&r!l&&!r
2212
MC/DC0%0/3
$mode eq "webenv" or defined $uids or defined $query
$mode eq "webenv" defined $uids defined $query
Truth table75%3/4
A or B or C
A= $mode eq "webenv"B= defined $uidsC= defined $query
ABCresult
1XX1
01X1
0011
0000
212 0 $self->throw("Must specify a query or list of uids to fetch");
213 }
214 25 ▶ if ( $query && $query->can('cookie') ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($query and $query->can('cookie')) { } 2 23 25
elsif ($query) { } 0 23 23
elsif ($mode eq 'webenv' and $self->can('cookie')) { } 2 21 23
elsif ($uids) { } 21 0 21
Condition66%2/3
$query and $query->can("cookie")
!ll&&!rl&&r
2302
MC/DC50%1/2
$query and $query->can("cookie")
$query $query->can("cookie")
Truth table66%2/3
A and B
A= $queryB= $query->can("cookie")
ABresult
0X0
100
111
215 2 @params{ 'WebEnv', 'query_key' } = $query->cookie;
216 2 $params{'db'} = $query->db;
217 }
218 elsif ($query) {
219 0 $params{'id'} = join ',', $query->ids;
220 }
221  
222 # for batch retrieval, non-query style
223 ▶ elsif ( $mode eq 'webenv' && $self->can('cookie') ) {
Condition66%2/3
$mode eq "webenv" and $self->can("cookie")
!ll&&!rl&&r
2102
MC/DC50%1/2
$mode eq "webenv" and $self->can("cookie")
$mode eq "webenv" $self->can("cookie")
Truth table66%2/3
A and B
A= $mode eq "webenv"B= $self->can("cookie")
ABresult
0X0
100
111
224 2 @params{ 'WebEnv', 'query_key' } = $self->cookie;
225 }
226 elsif ($uids) {
227 21 ▶ if ( ref($uids) =~ /array/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($uids) =~ /array/i) 12 9 21
228 12 $uids = join( ",", @$uids );
229 }
230 21 $params{'id'} = $uids;
231 }
232 25 ▶ $seq_start && ( $params{'seq_start'} = $seq_start );
Branch: 1 branch
BranchTrueFalseTotal
$seq_start and $params{"seq_start"} = $seq_start 1 24 25
233 25 ▶ $seq_stop && ( $params{'seq_stop'} = $seq_stop );
Branch: 1 branch
BranchTrueFalseTotal
$seq_stop and $params{"seq_stop"} = $seq_stop 1 24 25
234 25 ▶ $strand && ( $params{'strand'} = $strand );
Branch: 1 branch
BranchTrueFalseTotal
$strand and $params{"strand"} = $strand 0 25 25
235 25 ▶ if ( defined $complexity && ( $seq_start || $seq_stop || $strand ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $complexity and $seq_start || $seq_stop || $strand) 0 25 25
Condition44%4/9
defined $complexity and $seq_start || $seq_stop || $strand
!ll&&!rl&&r
2410
$seq_start or $seq_stop or $strand
l!l&&r!l&&!r
001
$seq_start or $seq_stop
l!l&&r!l&&!r
001
MC/DC0%0/4
defined $complexity and $seq_start || $seq_stop || $strand
defined $complexity $seq_start $seq_stop $strand
Truth table40%2/5
A and B or C or D
A= defined $complexityB= $seq_startC= $seq_stopD= $strand
ABCDresult
0XXX0
10000
11XX1
101X1
10011
236 0 ▶ $self->warn(
Branch: 1 branch
BranchTrueFalseTotal
if $complexity != 1 and $seq_start || $seq_stop 0 0 0
Condition0%0/6
$complexity != 1 and $seq_start || $seq_stop
!ll&&!rl&&r
000
$seq_start or $seq_stop
l!l&&r!l&&!r
000
MC/DC0%0/3
$complexity != 1 and $seq_start || $seq_stop
$complexity != 1 $seq_start $seq_stop
Truth table0%0/4
A and B or C
A= $complexity != 1B= $seq_startC= $seq_stop
ABCresult
0XX0
1000
11X1
1011
237 "Complexity set to $complexity; seq_start and seq_stop may not work!"
238 ) if ( $complexity != 1 && ( $seq_start || $seq_stop ) );
239 0 ▶ $self->warn(
Branch: 1 branch
BranchTrueFalseTotal
if $complexity == 0 and $strand == 2 and $format eq "fasta" 0 0 0
Condition0%0/6
$complexity == 0 and $strand == 2 and $format eq "fasta"
!ll&&!rl&&r
000
$complexity == 0 and $strand == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$complexity == 0 and $strand == 2 and $format eq "fasta"
$complexity == 0 $strand == 2 $format eq "fasta"
Truth table0%0/4
A and B and C
A= $complexity == 0B= $strand == 2C= $format eq "fasta"
ABCresult
0XX0
10X0
1100
1111
240 "Complexity set to 0; expect strange results with strand set to 2"
241 ) if ( $complexity == 0 && $strand == 2 && $format eq 'fasta' );
242 }
243 25 ▶ defined $complexity && ( $params{'complexity'} = $complexity );
Branch: 1 branch
BranchTrueFalseTotal
defined $complexity and $params{"complexity"} = $complexity 1 24 25
244 25 ▶ $params{'rettype'} = $format unless $mode eq 'batch';
Branch: 1 branch
BranchTrueFalseTotal
unless $mode eq "batch" 23 2 25
245  
246 # for now, 'post' is batch retrieval
247 25 ▶ if ( $CGILOCATION{$mode}[0] eq 'post' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::DB::NCBIHelper::CGILOCATION{$mode}[0] eq 'post') { } 2 23 25
248 2 my $response = $self->ua->request( POST $url, [%params] );
249 2 ▶ $response->proxy_authorization_basic( $self->authentication )
Branch: 1 branch
BranchTrueFalseTotal
if $self->authentication 0 2 2
250 if ( $self->authentication );
251 2 $self->_parse_response( $response->content );
252 2 my ( $cookie, $querykey ) = $self->cookie;
253 2 my %qualifiers = (
254 '-mode' => 'webenv',
255 '-seq_start' => $seq_start,
256 '-seq_stop' => $seq_stop,
257 '-strand' => $strand,
258 '-complexity' => $complexity,
259 '-format' => $format
260 );
261 2 return $self->get_request(%qualifiers);
262 }
263 else {
264 #print STDERR join(",", $_, $params{$_})."\n" for keys %params;
265 23 $url->query_form(%params);
266 23 return GET $url;
267 }
268 }
269  
270  
271 =head2 get_Stream_by_batch
272  
273 Title : get_Stream_by_batch
274 Usage : $seq = $db->get_Stream_by_batch($ref);
275 Function: Retrieves Seq objects from Entrez 'en masse', rather than one
276 at a time. For large numbers of sequences, this is far superior
277 than get_Stream_by_id or get_Stream_by_acc.
278 Example :
279 Returns : a Bio::SeqIO stream object
280 Args : $ref : either an array reference, a filename, or a filehandle
281 from which to get the list of unique ids/accession numbers.
282  
283 NOTE: deprecated API. Use get_Stream_by_id() instead.
284  
285 =cut
286  
287 *get_Stream_by_batch = sub {
288 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
289 0 $self->deprecated('get_Stream_by_batch() is deprecated; use get_Stream_by_id() instead');
290 0 $self->get_Stream_by_id(@_)
291 11 };
292  
293 =head2 get_Stream_by_query
294  
295 Title : get_Stream_by_query
296 Usage : $seq = $db->get_Stream_by_query($query);
297 Function: Retrieves Seq objects from Entrez 'en masse', rather than one
298 at a time. For large numbers of sequences, this is far superior
299 to get_Stream_by_id and get_Stream_by_acc.
300 Example :
301 Returns : a Bio::SeqIO stream object
302 Args : An Entrez query string or a Bio::DB::Query::GenBank object.
303 It is suggested that you create a Bio::DB::Query::GenBank object and get
304 the entry count before you fetch a potentially large stream.
305  
306 =cut
307  
308 sub get_Stream_by_query {
309 2 ▶ my ($self, $query) = @_;
Subroutine get_Stream_by_query: called CC=3 SCAR=13.3
Pod documented
310 2 ▶ unless (ref $query && $query->can('query')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $query and $query->can("query")) 0 2 2
Condition33%1/3
ref $query and $query->can("query")
!ll&&!rl&&r
002
MC/DC0%0/2
ref $query and $query->can("query")
ref $query $query->can("query")
Truth table33%1/3
A and B
A= ref $queryB= $query->can("query")
ABresult
0X0
100
111
311 0 $query = Bio::DB::Query::GenBank->new($query);
312 }
313 2 return $self->get_seq_stream('-query' => $query, '-mode'=>'query');
314 }
315  
316 =head2 postprocess_data
317  
318 Title : postprocess_data
319 Usage : $self->postprocess_data ( 'type' => 'string',
320 'location' => \$datastr );
321 Function: Process downloaded data before loading into a Bio::SeqIO. This
322 works for Genbank and Genpept, other classes should override
323 it with their own method.
324 Returns : void
325 Args : hash with two keys:
326  
327 'type' can be 'string' or 'file'
328 'location' either file location or string reference containing data
329  
330 =cut
331  
332 ▶sub postprocess_data {
Subroutine postprocess_data: called CC=1 SCAR=0.0
Pod documented
333 # retain this in case postprocessing is needed at a future date
334 }
335  
336  
337 =head2 request_format
338  
339 Title : request_format
340 Usage : my ($req_format, $ioformat) = $self->request_format;
341 $self->request_format("genbank");
342 $self->request_format("fasta");
343 Function: Get/Set sequence format retrieval. The get-form will normally not
344 be used outside of this and derived modules.
345 Returns : Array of two strings, the first representing the format for
346 retrieval, and the second specifying the corresponding SeqIO format.
347 Args : $format = sequence format
348  
349 =cut
350  
351 sub request_format {
352 75 ▶ my ( $self, $value ) = @_;
Subroutine request_format: called CC=3 SCAR=11.1
Pod documented
353 75 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 46 29 75
354 46 $value = lc $value;
355 46 ▶ if ( defined $FORMATMAP{$value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Bio::DB::NCBIHelper::FORMATMAP{$value}) { } 46 0 46
356 46 $self->{'_format'} = [ $value, $FORMATMAP{$value} ];
357 }
358 else {
359 # Try to fall back to a default. Alternatively, we could throw
360 # an exception
361 0 $self->{'_format'} = [ $value, $value ];
362 }
363 }
364 75 return @{ $self->{'_format'} };
365 }
366  
367  
368 =head2 redirect_refseq
369  
370 Title : redirect_refseq
371 Usage : $db->redirect_refseq(1)
372 Function: simple getter/setter which redirects RefSeqs to use Bio::DB::RefSeq
373 Returns : Boolean value
374 Args : Boolean value (optional)
375 Throws : 'unparseable output exception'
376 Note : This replaces 'no_redirect' as a more straightforward flag to
377 redirect possible RefSeqs to use Bio::DB::RefSeq (EBI interface)
378 instead of retrieving the NCBI records
379  
380 =cut
381  
382 sub redirect_refseq {
383 shift->throw(
384 0 ▶ "Use of redirect_refseq() is deprecated. Bio::DB::GenBank default is to\n".
Subroutine redirect_refseq: not called CC=1 SCAR=6.9
Pod documented
385 "always retrieve from NCBI, including RefSeq sequences. Please use\n".
386 "Bio::DB::EMBL to retrieve records from EBI");
387 }
388  
389 =head2 complexity
390  
391 Title : complexity
392 Usage : $db->complexity(3)
393 Function: get/set complexity value
394 Returns : value from 0-4 indicating level of complexity
395 Args : value from 0-4 (optional); if unset server assumes 1
396 Throws : if arg is not an integer or falls outside of noted range above
397 Note : From efetch docs, the complexity regulates the display:
398  
399 0 - get the whole blob
400 1 - get the bioseq for gi of interest (default in Entrez)
401 2 - get the minimal bioseq-set containing the gi of interest
402 3 - get the minimal nuc-prot containing the gi of interest
403 4 - get the minimal pub-set containing the gi of interest
404  
405 =cut
406  
407 sub complexity {
408 34 ▶ my ( $self, $comp ) = @_;
Subroutine complexity: called CC=5 SCAR=17.8
Pod documented
409 34 ▶ if ( defined $comp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comp) 1 33 34
410 1 ▶ $self->throw("Complexity value must be integer between 0 and 4")
Branch: 1 branch
BranchTrueFalseTotal
if not $comp =~ /^\d+$/ or $comp < 0 or $comp > 4 0 1 1
Condition33%2/6
not $comp =~ /^\d+$/ or $comp < 0 or $comp > 4
l!l&&r!l&&!r
001
not $comp =~ /^\d+$/ or $comp < 0
l!l&&r!l&&!r
001
MC/DC0%0/3
not $comp =~ /^\d+$/ or $comp < 0 or $comp > 4
not $comp =~ /^\d+$/ $comp < 0 $comp > 4
Truth table25%1/4
not(A) or B or C
A= not $comp =~ /^\d+$/B= $comp < 0C= $comp > 4
ABCresult
1XX1
01X1
0011
0000
411 if $comp !~ /^\d+$/ || $comp < 0 || $comp > 4;
412 1 $self->{'_complexity'} = $comp;
413 }
414 34 return $self->{'_complexity'};
415 }
416  
417 =head2 strand
418  
419 Title : strand
420 Usage : $db->strand(1)
421 Function: get/set strand value
422 Returns : strand value if set
423 Args : value of 1 (plus) or 2 (minus); if unset server assumes 1
424 Throws : if arg is not an integer or is not 1 or 2
425 Note : This differs from BioPerl's use of strand: 1 = plus, -1 = minus 0 = not relevant.
426 We should probably add in some functionality to convert over in the future.
427  
428 =cut
429  
430 sub strand {
431 18 ▶ my ($self, $str) = @_;
Subroutine strand: called CC=5 SCAR=27.0
Pod documented
432 18 ▶ if ($str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 0 18 18
433 0 ▶ $self->throw("strand() must be integer value of 1 (plus strand) or 2 (minus strand) if set") if
Branch: 1 branch
BranchTrueFalseTotal
if not $str =~ /^\d+$/ or $str < 1 or $str > 2 0 0 0
Condition0%0/6
not $str =~ /^\d+$/ or $str < 1 or $str > 2
l!l&&r!l&&!r
000
not $str =~ /^\d+$/ or $str < 1
l!l&&r!l&&!r
000
MC/DC0%0/3
not $str =~ /^\d+$/ or $str < 1 or $str > 2
not $str =~ /^\d+$/ $str < 1 $str > 2
Truth table0%0/4
not(A) or B or C
A= not $str =~ /^\d+$/B= $str < 1C= $str > 2
ABCresult
1XX1
01X1
0011
0000
434 $str !~ /^\d+$/ || $str < 1 || $str > 2;
435 0 $self->{'_strand'} = $str;
436 }
437 18 return $self->{'_strand'};
438 }
439  
440 =head2 seq_start
441  
442 Title : seq_start
443 Usage : $db->seq_start(123)
444 Function: get/set sequence start location
445 Returns : sequence start value if set
446 Args : integer; if unset server assumes 1
447 Throws : if arg is not an integer
448  
449 =cut
450  
451 sub seq_start {
452 20 ▶ my ($self, $start) = @_;
Subroutine seq_start: called CC=3 SCAR=11.0
Pod documented
453 20 ▶ if ($start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start) 1 19 20
454 1 ▶ $self->throw("seq_start() must be integer value if set") if
Branch: 1 branch
BranchTrueFalseTotal
unless $start =~ /^\d+$/ 0 1 1
455 $start !~ /^\d+$/;
456 1 $self->{'_seq_start'} = $start;
457 }
458 20 return $self->{'_seq_start'};
459 }
460  
461 =head2 seq_stop
462  
463 Title : seq_stop
464 Usage : $db->seq_stop(456)
465 Function: get/set sequence stop (end) location
466 Returns : sequence stop (end) value if set
467 Args : integer; if unset server assumes 1
468 Throws : if arg is not an integer
469  
470 =cut
471  
472 sub seq_stop {
473 20 ▶ my ($self, $stop) = @_;
Subroutine seq_stop: called CC=3 SCAR=11.0
Pod documented
474 20 ▶ if ($stop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stop) 1 19 20
475 1 ▶ $self->throw("seq_stop() must be integer if set") if
Branch: 1 branch
BranchTrueFalseTotal
unless $stop =~ /^\d+$/ 0 1 1
476 $stop !~ /^\d+$/;
477 1 $self->{'_seq_stop'} = $stop;
478 }
479 20 return $self->{'_seq_stop'};
480 }
481  
482 =head2 Bio::DB::WebDBSeqI methods
483  
484 Overriding WebDBSeqI method to help newbies to retrieve sequences
485  
486 =head2 get_Stream_by_acc
487  
488 Title : get_Stream_by_acc
489 Usage : $seq = $db->get_Stream_by_acc([$acc1, $acc2]);
490 Function: gets a series of Seq objects by accession numbers
491 Returns : a Bio::SeqIO stream object
492 Args : $ref : a reference to an array of accession numbers for
493 the desired sequence entries
494 Note : For GenBank, this just calls the same code for get_Stream_by_id()
495  
496 =cut
497  
498 sub get_Stream_by_acc {
499 8 ▶ my ( $self, $ids ) = @_;
Subroutine get_Stream_by_acc: called CC=2 SCAR=6.9
Pod documented
500 8 ▶ $self->throw("NT_ contigs are whole chromosome files which are not part of regular"
Branch: 1 branch
BranchTrueFalseTotal
if $ids =~ /NT_/ 1 7 8
501 . "database distributions. Go to ftp://ftp.ncbi.nih.gov/genomes/.")
502 if $ids =~ /NT_/;
503 7 return $self->get_seq_stream( '-uids' => $ids, '-mode' => 'single' );
504 }
505  
506 =head2 delay_policy
507  
508 Title : delay_policy
509 Usage : $secs = $self->delay_policy
510 Function: NCBI requests a delay of 3 seconds between requests. This method
511 implements that policy.
512 Returns : number of seconds to delay
513 Args : none
514  
515 =cut
516  
517 sub delay_policy {
518 5 ▶ my $self = shift;
Subroutine delay_policy: called CC=1 SCAR=0.0
Pod documented
519 5 return $REQUEST_DELAY;
520 }
521  
522 =head2 cookie
523  
524 Title : cookie
525 Usage : ($cookie,$querynum) = $db->cookie
526 Function: return the NCBI query cookie, this information is used by
527 Bio::DB::GenBank in conjunction with efetch, ripped from
528 Bio::DB::Query::GenBank
529 Returns : list of (cookie,querynum)
530 Args : none
531  
532 =cut
533  
534 sub cookie {
535 6 ▶ my $self = shift;
Subroutine cookie: called CC=2 SCAR=6.9
Pod documented
536 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 4 6
537 2 $self->{'_cookie'} = shift;
538 2 $self->{'_querynum'} = shift;
539 }
540 else {
541 4 return @{$self}{qw(_cookie _querynum)};
542 }
543 }
544  
545 =head2 _parse_response
546  
547 Title : _parse_response
548 Usage : $db->_parse_response($content)
549 Function: parse out response for cookie, this is a trimmed-down version
550 of _parse_response from Bio::DB::Query::GenBank
551 Returns : empty
552 Args : none
553 Throws : 'unparseable output exception'
554  
555 =cut
556  
557 sub _parse_response {
558 2 ▶ my $self = shift;
Subroutine _parse_response: called CC=3 SCAR=11.8
559 2 my $content = shift;
560 2 ▶ if ( my ($warning) = $content =~ m!<ErrorList>(.+)</ErrorList>!s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($warning) = $content =~ m[<ErrorList>(.+)</ErrorList>]s) 0 2 2
561 0 $self->warn("Warning(s) from GenBank: $warning\n");
562 }
563 2 ▶ if ( my ($error) = $content =~ /<OutputMessage>([^<]+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($error) = $content =~ /<OutputMessage>([^<]+)/) 0 2 2
564 0 $self->throw("Error from Genbank: $error");
565 }
566 2 my ($cookie) = $content =~ m!<WebEnv>(\S+)</WebEnv>!;
567 2 my ($querykey) = $content =~ m!<QueryKey>(\d+)!;
568 2 $self->cookie( uri_unescape($cookie), $querykey );
569 }
570  
571 =head2 no_redirect
572  
573 Title : no_redirect
574 Usage : $db->no_redirect($content)
575 Function: DEPRECATED - Used to indicate that Bio::DB::GenBank instance retrieves
576 possible RefSeqs from EBI instead; default behavior is now to
577 retrieve directly from NCBI
578 Returns : None
579 Args : None
580 Throws : Method is deprecated in favor of positive flag method 'redirect_refseq'
581  
582 =cut
583  
584 sub no_redirect {
585 shift->throw(
586 0 ▶ "Use of no_redirect() is deprecated. Bio::DB::GenBank new default is to always\n".
Subroutine no_redirect: not called CC=1 SCAR=6.9
Pod documented
587 "retrieve from NCBI. Please use Bio::DB::EMBL to retrieve records\n").
588 "from EBI";
589 }
590  
591 11 1;
592  
593 __END__
« Taxonomy/entrez.pm ↑ Summary Query/GenBank.pm »