| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::DB::WebDBSeqI | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Cared for by Jason Stajich <jason@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | Bio::DB::WebDBSeqI - Object Interface to generalize Web Databases | ||||||||||||||||||||||||||||||||||||||||||
| 18 | for retrieving sequences | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # get a WebDBSeqI object somehow | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # assuming it is a nucleotide db | ||||||||||||||||||||||||||||||||||||||||||
| 24 | my $seq = $db->get_Seq_by_id('ROA1_HUMAN') | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | Provides core set of functionality for connecting to a web based | ||||||||||||||||||||||||||||||||||||||||||
| 29 | database for retrieving sequences. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | Users wishing to add another Web Based Sequence Dabatase will need to | ||||||||||||||||||||||||||||||||||||||||||
| 32 | extend this class (see L<Bio::DB::SwissProt> or L<Bio::DB::NCBIHelper> for | ||||||||||||||||||||||||||||||||||||||||||
| 33 | examples) and implement the get_request method which returns a | ||||||||||||||||||||||||||||||||||||||||||
| 34 | HTTP::Request for the specified uids (accessions, ids, etc depending | ||||||||||||||||||||||||||||||||||||||||||
| 35 | on what query types the database accepts). | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | User feedback is an integral part of the | ||||||||||||||||||||||||||||||||||||||||||
| 42 | evolution of this and other Bioperl modules. Send | ||||||||||||||||||||||||||||||||||||||||||
| 43 | your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||||||||||||
| 44 | of the Bioperl mailing lists. Your participation | ||||||||||||||||||||||||||||||||||||||||||
| 45 | is much appreciated. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||||||||
| 48 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||
| 57 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||
| 58 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||
| 59 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | Report bugs to the Bioperl bug tracking system to | ||||||||||||||||||||||||||||||||||||||||||
| 64 | help us keep track the bugs and their resolution. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | Bug reports can be submitted via the web. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head1 AUTHOR - Jason Stajich | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | Email E<lt> jason@bioperl.org E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | The rest of the documentation details each of the | ||||||||||||||||||||||||||||||||||||||||||
| 76 | object methods. Internal methods are usually | ||||||||||||||||||||||||||||||||||||||||||
| 77 | preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | package Bio::DB::WebDBSeqI; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | $Bio::DB::WebDBSeqI::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | use vars qw($MODVERSION %RETRIEVAL_TYPES $DEFAULT_RETRIEVAL_TYPE | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | $DEFAULTFORMAT $LAST_INVOCATION_TIME @ATTRIBUTES); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | use Bio::SeqIO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | use Bio::Root::IO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | use POSIX 'setsid'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | use IO::Pipe; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | use IO::String; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | use Bio::Root::Root; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | use base qw(Bio::DB::RandomAccessI); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | $MODVERSION = '0.8'; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | %RETRIEVAL_TYPES = ('io_string' => 1, | |||||||||||||||||||||||||||||||||||||||||
| 108 | 'tempfile' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 'pipeline' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | $DEFAULT_RETRIEVAL_TYPE = 'pipeline'; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | $DEFAULTFORMAT = 'fasta'; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | $LAST_INVOCATION_TIME = 0; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($baseaddress, $params, $ret_type, $format,$delay,$db) = | |||||||||||||||||||||||||||||||||||||||||
| 120 | $self->_rearrange([qw(BASEADDRESS PARAMS RETRIEVALTYPE FORMAT DELAY DB)], | ||||||||||||||||||||||||||||||||||||||||||
| 121 | @args); | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $ret_type = $DEFAULT_RETRIEVAL_TYPE unless ( $ret_type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $baseaddress && $self->url_base_address($baseaddress); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $params && $self->url_params($params); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $db && $self->db($db); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $ret_type && $self->retrieval_type($ret_type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $delay = $self->delay_policy unless defined $delay; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->delay($delay); | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # insure we always have a default format set for retrieval | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # even though this will be immedietly overwritten by most sub classes | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $format = $self->default_format unless ( defined $format && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $format and $format ne ""
MC/DC0%0/2
defined $format and $format ne ""
defined $format
$format ne ""
Truth table0%0/3
A and B
A= defined $formatB= $format ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | $format ne '' ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->request_format($format); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $ua = LWP::UserAgent->new(env_proxy => 1); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $ua->agent(ref($self) ."/$MODVERSION"); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->ua($ua); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->{'_authentication'} = []; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | # from Bio::DB::RandomAccessI | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =head2 get_Seq_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | Title : get_Seq_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 150 | Usage : $seq = $db->get_Seq_by_id('ROA1_HUMAN') | ||||||||||||||||||||||||||||||||||||||||||
| 151 | Function: Gets a Bio::Seq object by its name | ||||||||||||||||||||||||||||||||||||||||||
| 152 | Returns : a Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Args : the id (as a string) of a sequence | ||||||||||||||||||||||||||||||||||||||||||
| 154 | Throws : "id does not exist" exception | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub get_Seq_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_id: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my ($self,$seqid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->_sleep; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $seqio = $self->get_Stream_by_id([$seqid]); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $self->throw("id does not exist") if( !defined $seqio ) ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ($self->can('complexity') && defined $self->complexity && $self->complexity==0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity") and defined $self->complexity
MC/DC0%0/3
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity")
defined $self->complexity
$self->complexity == 0
Truth table0%0/4
A and B and C
A= $self->can("complexity")B= defined $self->complexityC= $self->complexity == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->warn("When complexity is set to 0, use get_Stream_by_id\n". | |||||||||||||||||||||||||||||||||||||||||
| 166 | "Returning Bio::SeqIO object"); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return $seqio; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my @seqs; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | while( my $seq = $seqio->next_seq() ) { push @seqs, $seq; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # Since $seqio will not be used anymore, explicitly close its filehandle | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # or it will cause trouble later on cleanup | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $seqio->close; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $self->throw("id '$seqid' does not exist") unless @seqs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if( wantarray ) { return @seqs } else { return shift @seqs } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =head2 get_Seq_by_acc | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | Title : get_Seq_by_acc | ||||||||||||||||||||||||||||||||||||||||||
| 183 | Usage : $seq = $db->get_Seq_by_acc('X77802'); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | Function: Gets a Bio::Seq object by accession number | ||||||||||||||||||||||||||||||||||||||||||
| 185 | Returns : A Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 186 | Args : accession number (as a string) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | Throws : "acc does not exist" exception | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub get_Seq_by_acc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_acc: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my ($self,$seqid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $self->_sleep; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $seqio = $self->get_Stream_by_acc($seqid); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $self->throw("acc '$seqid' does not exist") if( ! defined $seqio ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($self->can('complexity') && defined $self->complexity && $self->complexity==0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity") and defined $self->complexity
MC/DC0%0/3
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity")
defined $self->complexity
$self->complexity == 0
Truth table0%0/4
A and B and C
A= $self->can("complexity")B= defined $self->complexityC= $self->complexity == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->warn("When complexity is set to 0, use get_Stream_by_acc\n". | |||||||||||||||||||||||||||||||||||||||||
| 198 | "Returning Bio::SeqIO object"); | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return $seqio; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my @seqs; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | while( my $seq = $seqio->next_seq() ) { push @seqs, $seq; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $self->throw("acc $seqid does not exist") unless @seqs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if( wantarray ) { return @seqs } else { return shift @seqs } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =head2 get_Seq_by_gi | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | Title : get_Seq_by_gi | ||||||||||||||||||||||||||||||||||||||||||
| 211 | Usage : $seq = $db->get_Seq_by_gi('405830'); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | Function: Gets a Bio::Seq object by gi number | ||||||||||||||||||||||||||||||||||||||||||
| 213 | Returns : A Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 214 | Args : gi number (as a string) | ||||||||||||||||||||||||||||||||||||||||||
| 215 | Throws : "gi does not exist" exception | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub get_Seq_by_gi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_gi: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my ($self,$seqid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->_sleep; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $seqio = $self->get_Stream_by_gi($seqid); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $self->throw("gi does not exist") if( !defined $seqio ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($self->can('complexity') && defined $self->complexity && $self->complexity==0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity") and defined $self->complexity
MC/DC0%0/3
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity")
defined $self->complexity
$self->complexity == 0
Truth table0%0/4
A and B and C
A= $self->can("complexity")B= defined $self->complexityC= $self->complexity == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->warn("When complexity is set to 0, use get_Stream_by_gi\n". | |||||||||||||||||||||||||||||||||||||||||
| 226 | "Returning Bio::SeqIO object"); | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return $seqio; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my @seqs; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | while( my $seq = $seqio->next_seq() ) { push @seqs, $seq; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $self->throw("gi does not exist") unless @seqs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if( wantarray ) { return @seqs } else { return shift @seqs } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | =head2 get_Seq_by_version | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | Title : get_Seq_by_version | ||||||||||||||||||||||||||||||||||||||||||
| 238 | Usage : $seq = $db->get_Seq_by_version('X77802.1'); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | Function: Gets a Bio::Seq object by sequence version | ||||||||||||||||||||||||||||||||||||||||||
| 240 | Returns : A Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 241 | Args : accession.version (as a string) | ||||||||||||||||||||||||||||||||||||||||||
| 242 | Throws : "acc.version does not exist" exception | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub get_Seq_by_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_version: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ($self,$seqid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self->_sleep; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $seqio = $self->get_Stream_by_version($seqid); | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $self->throw("accession.version does not exist") if( !defined $seqio ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($self->can('complexity') && defined $self->complexity && $self->complexity==0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity") and defined $self->complexity
MC/DC0%0/3
$self->can("complexity") and defined $self->complexity and $self->complexity == 0
$self->can("complexity")
defined $self->complexity
$self->complexity == 0
Truth table0%0/4
A and B and C
A= $self->can("complexity")B= defined $self->complexityC= $self->complexity == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $self->warn("When complexity is set to 0, use get_Stream_by_version\n". | |||||||||||||||||||||||||||||||||||||||||
| 253 | "Returning Bio::SeqIO object"); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return $seqio; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my @seqs; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | while( my $seq = $seqio->next_seq() ) { push @seqs, $seq; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $self->throw("accession.version does not exist") unless @seqs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if( wantarray ) { return @seqs } else { return shift @seqs } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # implementing class must define these | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =head2 get_request | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | Title : get_request | ||||||||||||||||||||||||||||||||||||||||||
| 267 | Usage : my $url = $self->get_request | ||||||||||||||||||||||||||||||||||||||||||
| 268 | Function: returns a HTTP::Request object | ||||||||||||||||||||||||||||||||||||||||||
| 269 | Returns : | ||||||||||||||||||||||||||||||||||||||||||
| 270 | Args : %qualifiers = a hash of qualifiers (ids, format, etc) | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | sub get_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $msg = "Implementing class must define method get_request in class WebDBSeqI"; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $self->throw($msg); | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # class methods | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | =head2 get_Stream_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | Title : get_Stream_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 285 | Usage : $stream = $db->get_Stream_by_id( [$uid1, $uid2] ); | ||||||||||||||||||||||||||||||||||||||||||
| 286 | Function: Gets a series of Seq objects by unique identifiers | ||||||||||||||||||||||||||||||||||||||||||
| 287 | Returns : a Bio::SeqIO stream object | ||||||||||||||||||||||||||||||||||||||||||
| 288 | Args : $ref : a reference to an array of unique identifiers for | ||||||||||||||||||||||||||||||||||||||||||
| 289 | the desired sequence entries | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub get_Stream_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Stream_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my ($self, $ids) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my ($webfmt,$localfmt) = $self->request_format; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return $self->get_seq_stream('-uids' => $ids, '-mode' => 'single', | |||||||||||||||||||||||||||||||||||||||||
| 298 | '-format' => $webfmt); | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | *get_Stream_by_batch = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | Carp::carp('get_Stream_by_batch() is deprecated; use get_Stream_by_id() instead'); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->get_Stream_by_id(@_) | |||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | =head2 get_Stream_by_acc | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | Title : get_Stream_by_acc | ||||||||||||||||||||||||||||||||||||||||||
| 311 | Usage : $seq = $db->get_Stream_by_acc([$acc1, $acc2]); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | Function: Gets a series of Seq objects by accession numbers | ||||||||||||||||||||||||||||||||||||||||||
| 313 | Returns : a Bio::SeqIO stream object | ||||||||||||||||||||||||||||||||||||||||||
| 314 | Args : $ref : a reference to an array of accession numbers for | ||||||||||||||||||||||||||||||||||||||||||
| 315 | the desired sequence entries | ||||||||||||||||||||||||||||||||||||||||||
| 316 | Note : For GenBank, this just calls the same code for get_Stream_by_id() | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub get_Stream_by_acc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Stream_by_acc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my ($self, $ids ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | return $self->get_seq_stream('-uids' => $ids, '-mode' => 'single'); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | =head2 get_Stream_by_gi | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | Title : get_Stream_by_gi | ||||||||||||||||||||||||||||||||||||||||||
| 329 | Usage : $seq = $db->get_Stream_by_gi([$gi1, $gi2]); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | Function: Gets a series of Seq objects by gi numbers | ||||||||||||||||||||||||||||||||||||||||||
| 331 | Returns : a Bio::SeqIO stream object | ||||||||||||||||||||||||||||||||||||||||||
| 332 | Args : $ref : a reference to an array of gi numbers for | ||||||||||||||||||||||||||||||||||||||||||
| 333 | the desired sequence entries | ||||||||||||||||||||||||||||||||||||||||||
| 334 | Note : For GenBank, this just calls the same code for get_Stream_by_id() | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub get_Stream_by_gi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Stream_by_gi: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ($self, $ids ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $self->get_seq_stream('-uids' => $ids, '-mode' => 'gi'); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | =head2 get_Stream_by_version | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | Title : get_Stream_by_version | ||||||||||||||||||||||||||||||||||||||||||
| 346 | Usage : $seq = $db->get_Stream_by_version([$version1, $version2]); | ||||||||||||||||||||||||||||||||||||||||||
| 347 | Function: Gets a series of Seq objects by accession.versions | ||||||||||||||||||||||||||||||||||||||||||
| 348 | Returns : a Bio::SeqIO stream object | ||||||||||||||||||||||||||||||||||||||||||
| 349 | Args : $ref : a reference to an array of accession.version strings for | ||||||||||||||||||||||||||||||||||||||||||
| 350 | the desired sequence entries | ||||||||||||||||||||||||||||||||||||||||||
| 351 | Note : For GenBank, this is implemented in NCBIHelper | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub get_Stream_by_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Stream_by_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my ($self, $ids ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 357 | # $self->throw("Implementing class should define this method!"); | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | return $self->get_seq_stream('-uids' => $ids, '-mode' => 'version'); # how it should work | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | =head2 get_Stream_by_query | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | Title : get_Stream_by_query | ||||||||||||||||||||||||||||||||||||||||||
| 364 | Usage : $stream = $db->get_Stream_by_query($query); | ||||||||||||||||||||||||||||||||||||||||||
| 365 | Function: Gets a series of Seq objects by way of a query string or oject | ||||||||||||||||||||||||||||||||||||||||||
| 366 | Returns : a Bio::SeqIO stream object | ||||||||||||||||||||||||||||||||||||||||||
| 367 | Args : $query : A string that uses the appropriate query language | ||||||||||||||||||||||||||||||||||||||||||
| 368 | for the database or a Bio::DB::QueryI object. It is suggested | ||||||||||||||||||||||||||||||||||||||||||
| 369 | that you create the Bio::DB::Query object first and interrogate | ||||||||||||||||||||||||||||||||||||||||||
| 370 | it for the entry count before you fetch a potentially large stream. | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub get_Stream_by_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_Stream_by_query: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my ($self, $query ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | return $self->get_seq_stream('-query' => $query, '-mode'=>'query'); | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | =head2 default_format | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | Title : default_format | ||||||||||||||||||||||||||||||||||||||||||
| 382 | Usage : my $format = $self->default_format | ||||||||||||||||||||||||||||||||||||||||||
| 383 | Function: Returns default sequence format for this module | ||||||||||||||||||||||||||||||||||||||||||
| 384 | Returns : string | ||||||||||||||||||||||||||||||||||||||||||
| 385 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | sub default_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_format: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return $DEFAULTFORMAT; | |||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | # sorry, but this is hacked in because of BioFetch problems... | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub db { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
db: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $d = $self->{_db}; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $self->{_db} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $d; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | =head2 request_format | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | Title : request_format | ||||||||||||||||||||||||||||||||||||||||||
| 404 | Usage : my ($req_format, $ioformat) = $self->request_format; | ||||||||||||||||||||||||||||||||||||||||||
| 405 | $self->request_format("genbank"); | ||||||||||||||||||||||||||||||||||||||||||
| 406 | $self->request_format("fasta"); | ||||||||||||||||||||||||||||||||||||||||||
| 407 | Function: Get/Set sequence format retrieval. The get-form will normally not | ||||||||||||||||||||||||||||||||||||||||||
| 408 | be used outside of this and derived modules. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | Returns : Array of two strings, the first representing the format for | ||||||||||||||||||||||||||||||||||||||||||
| 410 | retrieval, and the second specifying the corresponding SeqIO format. | ||||||||||||||||||||||||||||||||||||||||||
| 411 | Args : $format = sequence format | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub request_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_format: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $self->{'_format'} = [ $value, $value]; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return @{$self->{'_format'}}; | |||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | =head2 get_seq_stream | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | Title : get_seq_stream | ||||||||||||||||||||||||||||||||||||||||||
| 427 | Usage : my $seqio = $self->get_seq_stream(%qualifiers) | ||||||||||||||||||||||||||||||||||||||||||
| 428 | Function: builds a url and queries a web db | ||||||||||||||||||||||||||||||||||||||||||
| 429 | Returns : a Bio::SeqIO stream capable of producing sequence | ||||||||||||||||||||||||||||||||||||||||||
| 430 | Args : %qualifiers = a hash qualifiers that the implementing class | ||||||||||||||||||||||||||||||||||||||||||
| 431 | will process to make a url suitable for web querying | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub get_seq_stream { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_seq_stream: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my ($self, %qualifiers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my ($rformat, $ioformat) = $self->request_format(); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $seen = 0; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | foreach my $key ( keys %qualifiers ) { | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if( $key =~ /format/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $rformat = $qualifiers{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $seen = 1; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | $qualifiers{'-format'} = $rformat if( !$seen); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ($rformat, $ioformat) = $self->request_format($rformat); | |||||||||||||||||||||||||||||||||||||||||
| 447 | # These parameters are implemented for Bio::DB::GenBank objects only | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if($self->isa('Bio::DB::GenBank')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $self->seq_start() && ($qualifiers{'-seq_start'} = $self->seq_start()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | $self->seq_stop() && ($qualifiers{'-seq_stop'} = $self->seq_stop()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | $self->strand() && ($qualifiers{'-strand'} = $self->strand()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | defined $self->complexity() && ($qualifiers{'-complexity'} = $self->complexity()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $request = $self->get_request(%qualifiers); | |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $request->proxy_authorization_basic($self->authentication) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | if ( $self->authentication); | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->debug("request is ". $request->as_string(). "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | # workaround for MSWin systems | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | $self->retrieval_type('io_string') if $self->retrieval_type =~ /pipeline/ && $^O =~ /^MSWin/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->retrieval_type =~ /pipeline/ and $^O =~ /^MSWin/
MC/DC0%0/2
$self->retrieval_type =~ /pipeline/ and $^O =~ /^MSWin/
$self->retrieval_type =~ /pipeline/
$^O =~ /^MSWin/
Truth table0%0/3
A and B
A= $self->retrieval_type =~ /pipeline/B= $^O =~ /^MSWin/
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ($self->retrieval_type =~ /pipeline/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | # Try to create a stream using POSIX fork-and-pipe facility. | ||||||||||||||||||||||||||||||||||||||||||
| 464 | # this is a *big* win when fetching thousands of sequences from | ||||||||||||||||||||||||||||||||||||||||||
| 465 | # a web database because we can return the first entry while | ||||||||||||||||||||||||||||||||||||||||||
| 466 | # transmission is still in progress. | ||||||||||||||||||||||||||||||||||||||||||
| 467 | # Also, no need to keep sequence in memory or in a temporary file. | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # If this fails (Windows, MacOS 9), we fall back to non-pipelined access. | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | # fork and pipe: _stream_request()=><STREAM> | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my ($result,$stream) = $self->_open_pipe(); | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if (defined $result) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $DB::fork_TTY = File::Spec->devnull; # prevents complaints from debugger | |||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | if (!$result) { # in child process | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $self->_stream_request($request,$stream); | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | POSIX::_exit(0); #prevent END blocks from executing in this forked child | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return Bio::SeqIO->new('-verbose' => $self->verbose, | |||||||||||||||||||||||||||||||||||||||||
| 481 | '-format' => $ioformat, | ||||||||||||||||||||||||||||||||||||||||||
| 482 | '-fh' => $stream); | ||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | $self->retrieval_type('io_string'); | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($self->retrieval_type =~ /temp/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $dir = $self->io->tempdir( CLEANUP => 1); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my ( $fh, $tmpfile) = $self->io()->tempfile( DIR => $dir ); | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $resp = $self->_request($request, $tmpfile); | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if( ! -e $tmpfile || -z $tmpfile || ! $resp->is_success() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not -e $tmpfile or -z $tmpfile or not $resp->is_success
not -e $tmpfile or -z $tmpfile
MC/DC0%0/3
not -e $tmpfile or -z $tmpfile or not $resp->is_success
not -e $tmpfile
-z $tmpfile
not $resp->is_success
Truth table0%0/4
not(A) or B or not(C)
A= not -e $tmpfileB= -z $tmpfileC= not $resp->is_success
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $self->throw("WebDBSeqI Error - check query sequences!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $self->postprocess_data('type' => 'file', | |||||||||||||||||||||||||||||||||||||||||
| 499 | 'location' => $tmpfile); | ||||||||||||||||||||||||||||||||||||||||||
| 500 | # this may get reset when requesting batch mode | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ($rformat,$ioformat) = $self->request_format(); | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if( $self->verbose > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | open my $ERR, '<', $tmpfile or $self->throw("Could not read file '$tmpfile': $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | while(<$ERR>) { $self->debug($_);} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | close $ERR; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | return Bio::SeqIO->new('-verbose' => $self->verbose, | |||||||||||||||||||||||||||||||||||||||||
| 509 | '-format' => $ioformat, | ||||||||||||||||||||||||||||||||||||||||||
| 510 | '-file' => $tmpfile); | ||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if ($self->retrieval_type =~ /io_string/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $resp = $self->_request($request); | |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my $content = $resp->content_ref; | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $self->debug( "content is $$content\n"); | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | if (!$resp->is_success() || length($$content) == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $resp->is_success or length $$content == 0
MC/DC0%0/2
not $resp->is_success or length $$content == 0
not $resp->is_success
length $$content == 0
Truth table0%0/3
not(A) or B
A= not $resp->is_successB= length $$content == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $self->throw("WebDBSeqI Error - check query sequences!\n"); | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ($rformat,$ioformat) = $self->request_format(); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $self->postprocess_data('type'=> 'string', | |||||||||||||||||||||||||||||||||||||||||
| 522 | 'location' => $content); | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $self->debug( "str is $$content\n"); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | return Bio::SeqIO->new('-verbose' => $self->verbose, | |||||||||||||||||||||||||||||||||||||||||
| 525 | '-format' => $ioformat, | ||||||||||||||||||||||||||||||||||||||||||
| 526 | '-fh' => new IO::String($$content)); | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | # if we got here, we don't know how to handle the retrieval type | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->throw("retrieval type " . $self->retrieval_type . | |||||||||||||||||||||||||||||||||||||||||
| 531 | " unsupported\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | =head2 url_base_address | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | Title : url_base_address | ||||||||||||||||||||||||||||||||||||||||||
| 537 | Usage : my $address = $self->url_base_address or | ||||||||||||||||||||||||||||||||||||||||||
| 538 | $self->url_base_address($address) | ||||||||||||||||||||||||||||||||||||||||||
| 539 | Function: Get/Set the base URL for the Web Database | ||||||||||||||||||||||||||||||||||||||||||
| 540 | Returns : Base URL for the Web Database | ||||||||||||||||||||||||||||||||||||||||||
| 541 | Args : $address - URL for the WebDatabase | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | sub url_base_address { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_base_address: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $d = $self->{'_baseaddress'}; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | $self->{'_baseaddress'} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $d; | |||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =head2 proxy | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | Title : proxy | ||||||||||||||||||||||||||||||||||||||||||
| 556 | Usage : $httpproxy = $db->proxy('http') or | ||||||||||||||||||||||||||||||||||||||||||
| 557 | $db->proxy(['http','ftp'], 'http://myproxy' ) | ||||||||||||||||||||||||||||||||||||||||||
| 558 | Function: Get/Set a proxy for use of proxy | ||||||||||||||||||||||||||||||||||||||||||
| 559 | Returns : a string indicating the proxy | ||||||||||||||||||||||||||||||||||||||||||
| 560 | Args : $protocol : an array ref of the protocol(s) to set/get | ||||||||||||||||||||||||||||||||||||||||||
| 561 | $proxyurl : url of the proxy to use for the specified protocol | ||||||||||||||||||||||||||||||||||||||||||
| 562 | $username : username (if proxy requires authentication) | ||||||||||||||||||||||||||||||||||||||||||
| 563 | $password : password (if proxy requires authentication) | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | sub proxy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proxy: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my ($self,$protocol,$proxy,$username,$password) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | return if ( !defined $self->ua || !defined $protocol | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $self->ua and defined $protocol and defined $proxy
defined $self->ua and defined $protocol
MC/DC0%0/3
defined $self->ua and defined $protocol and defined $proxy
defined $self->ua
defined $protocol
defined $proxy
Truth table0%0/4
A and B and C
A= defined $self->uaB= defined $protocolC= defined $proxy
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | || !defined $proxy ); | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | $self->authentication($username, $password) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$username and $password
MC/DC0%0/2
$username and $password
$username
$password
Truth table0%0/3
A and B
A= $usernameB= $password
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | if ($username && $password); | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | return $self->ua->proxy($protocol,$proxy); | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | =head2 authentication | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | Title : authentication | ||||||||||||||||||||||||||||||||||||||||||
| 579 | Usage : $db->authentication($user,$pass) | ||||||||||||||||||||||||||||||||||||||||||
| 580 | Function: Get/Set authentication credentials | ||||||||||||||||||||||||||||||||||||||||||
| 581 | Returns : Array of user/pass | ||||||||||||||||||||||||||||||||||||||||||
| 582 | Args : Array or user/pass | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | sub authentication{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authentication: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my ($self,$u,$p) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | if( defined $u && defined $p ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $u and defined $p
MC/DC0%0/2
defined $u and defined $p
defined $u
defined $p
Truth table0%0/3
A and B
A= defined $uB= defined $p
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->{'_authentication'} = [ $u,$p]; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | return @{$self->{'_authentication'}}; | |||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | =head2 retrieval_type | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | Title : retrieval_type | ||||||||||||||||||||||||||||||||||||||||||
| 600 | Usage : $self->retrieval_type($type); | ||||||||||||||||||||||||||||||||||||||||||
| 601 | my $type = $self->retrieval_type | ||||||||||||||||||||||||||||||||||||||||||
| 602 | Function: Get/Set a proxy for retrieval_type (pipeline, io_string or tempfile) | ||||||||||||||||||||||||||||||||||||||||||
| 603 | Returns : string representing retrieval type | ||||||||||||||||||||||||||||||||||||||||||
| 604 | Args : $value - the value to store | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | This setting affects how the data stream from the remote web server is | ||||||||||||||||||||||||||||||||||||||||||
| 607 | processed and passed to the Bio::SeqIO layer. Three types of retrieval | ||||||||||||||||||||||||||||||||||||||||||
| 608 | types are currently allowed: | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | pipeline Perform a fork in an attempt to begin streaming | ||||||||||||||||||||||||||||||||||||||||||
| 611 | while the data is still downloading from the remote | ||||||||||||||||||||||||||||||||||||||||||
| 612 | server. Disk, memory and speed efficient, but will | ||||||||||||||||||||||||||||||||||||||||||
| 613 | not work on Windows or MacOS 9 platforms. | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | io_string Store downloaded database entry(s) in memory. Can be | ||||||||||||||||||||||||||||||||||||||||||
| 616 | problematic for batch downloads because entire set | ||||||||||||||||||||||||||||||||||||||||||
| 617 | of entries must fit in memory. Alll entries must be | ||||||||||||||||||||||||||||||||||||||||||
| 618 | downloaded before processing can begin. | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | tempfile Store downloaded database entry(s) in a temporary file. | ||||||||||||||||||||||||||||||||||||||||||
| 621 | All entries must be downloaded before processing can | ||||||||||||||||||||||||||||||||||||||||||
| 622 | begin. | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | The default is pipeline, with automatic fallback to io_string if | ||||||||||||||||||||||||||||||||||||||||||
| 625 | pipelining is not available. | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | sub retrieval_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieval_type: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | if( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $value = lc $value; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | if( ! $RETRIEVAL_TYPES{$value} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $self->warn("invalid retrieval type $value must be one of (" . | |||||||||||||||||||||||||||||||||||||||||
| 635 | join(",", keys %RETRIEVAL_TYPES), ")"); | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $value = $DEFAULT_RETRIEVAL_TYPE; | |||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $self->{'_retrieval_type'} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | return $self->{'_retrieval_type'}; | |||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | =head2 url_params | ||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | Title : url_params | ||||||||||||||||||||||||||||||||||||||||||
| 646 | Usage : my $params = $self->url_params or | ||||||||||||||||||||||||||||||||||||||||||
| 647 | $self->url_params($params) | ||||||||||||||||||||||||||||||||||||||||||
| 648 | Function: Get/Set the URL parameters for the Web Database | ||||||||||||||||||||||||||||||||||||||||||
| 649 | Returns : url parameters for Web Database | ||||||||||||||||||||||||||||||||||||||||||
| 650 | Args : $params - parameters to be appended to the URL for the WebDatabase | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | sub url_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url_params: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | if( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $self->{'_urlparams'} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | =head2 ua | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | Title : ua | ||||||||||||||||||||||||||||||||||||||||||
| 664 | Usage : my $ua = $self->ua or | ||||||||||||||||||||||||||||||||||||||||||
| 665 | $self->ua($ua) | ||||||||||||||||||||||||||||||||||||||||||
| 666 | Function: Get/Set a LWP::UserAgent for use | ||||||||||||||||||||||||||||||||||||||||||
| 667 | Returns : reference to LWP::UserAgent Object | ||||||||||||||||||||||||||||||||||||||||||
| 668 | Args : $ua - must be a LWP::UserAgent | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | sub ua { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ua: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | my ($self, $ua) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | if( defined $ua && $ua->isa("LWP::UserAgent") ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ua and $ua->isa("LWP::UserAgent")
MC/DC0%0/2
defined $ua and $ua->isa("LWP::UserAgent")
defined $ua
$ua->isa("LWP::UserAgent")
Truth table0%0/3
A and B
A= defined $uaB= $ua->isa("LWP::UserAgent")
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | $self->{'_ua'} = $ua; | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | return $self->{'_ua'}; | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | =head2 postprocess_data | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | Title : postprocess_data | ||||||||||||||||||||||||||||||||||||||||||
| 683 | Usage : $self->postprocess_data ( 'type' => 'string', | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 'location' => \$datastr); | ||||||||||||||||||||||||||||||||||||||||||
| 685 | Function: process downloaded data before loading into a Bio::SeqIO | ||||||||||||||||||||||||||||||||||||||||||
| 686 | Returns : void | ||||||||||||||||||||||||||||||||||||||||||
| 687 | Args : hash with two keys - 'type' can be 'string' or 'file' | ||||||||||||||||||||||||||||||||||||||||||
| 688 | - 'location' either file location or string | ||||||||||||||||||||||||||||||||||||||||||
| 689 | reference containing data | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | sub postprocess_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
postprocess_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | my ( $self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | # private methods | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my ($self, $url,$tmpfile) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my ($resp); | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | if( defined $tmpfile && $tmpfile ne '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tmpfile and $tmpfile ne ""
MC/DC0%0/2
defined $tmpfile and $tmpfile ne ""
defined $tmpfile
$tmpfile ne ""
Truth table0%0/3
A and B
A= defined $tmpfileB= $tmpfile ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | $resp = $self->ua->request($url, $tmpfile); | |||||||||||||||||||||||||||||||||||||||||
| 704 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | $resp = $self->ua->request($url); | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | if( $resp->is_error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $self->throw("WebDBSeqI Request Error:\n".$resp->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | return $resp; | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | #mod_perl-safe replacement for the open(BLEH,'-|') call. if running | ||||||||||||||||||||||||||||||||||||||||||
| 715 | #under mod_perl, detects it and closes the child's STDIN and STDOUT | ||||||||||||||||||||||||||||||||||||||||||
| 716 | #handles | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | sub _open_pipe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_pipe: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 719 | # is mod_perl running? Which API? | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $mp = $self->mod_perl_api; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | if($mp and ! our $loaded_apache_sp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mp and not our $loaded_apache_sp
MC/DC0%0/2
$mp and not our $loaded_apache_sp
$mp
not our $loaded_apache_sp
Truth table0%0/3
A and not(B)
A= $mpB= not our $loaded_apache_sp
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | my $load_api = ($mp == 1) ? 'use Apache::SubProcess': 'use Apache2::SubProcess'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | eval $load_api; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | $@ and $self->throw("$@\n$load_api module required for running under mod_perl"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | $loaded_apache_sp = 1; | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | my $pipe = IO::Pipe->new(); | |||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | local $SIG{CHLD} = 'IGNORE'; | |||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | defined(my $pid = fork) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | or $self->throw("Couldn't fork: $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | unless($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | #CHILD | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | $pipe->writer(); | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | #if we're running under mod_perl, clean up some things after this fork | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | ▶ | if ($ENV{MOD_PERL} and my $r = eval{Apache->request} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"MOD_PERL"} and my $r = eval {
do {
"Apache"->request
}
}
MC/DC0%0/2
$ENV{"MOD_PERL"} and my $r = eval {
do {
"Apache"->request
}
}
$ENV{"MOD_PERL"}
my $r = eval {
do {
"Apache"->request
}
}
Truth table0%0/3
A and B
A= $ENV{"MOD_PERL"}B= my $r = eval {
do {
"Apache"->request
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | $r->cleanup_for_exec; | |||||||||||||||||||||||||||||||||||||||||
| 741 | #don't read or write the mod_perl parent's tied filehandles | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | close STDIN; close STDOUT; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | setsid() or $self->throw('Could not detach from parent'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 746 | #PARENT | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | $pipe->reader(); | |||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | return ( $pid, $pipe ); | |||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | # send web request to specified filehandle, or stdout, for streaming purposes | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | sub _stream_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stream_request: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | my $request = shift; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | my $dest_fh = shift || \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || \*STDOUT
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | # fork so as to pipe output of fetch process through to | ||||||||||||||||||||||||||||||||||||||||||
| 759 | # postprocess_data method call. | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | my ($child,$fetch) = $self->_open_pipe(); | |||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | if ($child) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | #PARENT | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | local ($/) = "//\n"; # assume genbank/swiss format | |||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | my $records = 0; | |||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | while (my $record = <$fetch>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | $records++; | |||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | $self->postprocess_data('type' => 'string', | |||||||||||||||||||||||||||||||||||||||||
| 770 | 'location' => \$record); | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | print $dest_fh $record; | |||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | $/ = "\n"; # reset to be safe; | |||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | close $dest_fh; #must explicitly close here, because the hard | |||||||||||||||||||||||||||||||||||||||||
| 775 | #exits don't cloes them for us | ||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||
| 777 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 778 | #CHILD | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 780 | my $resp = $self->ua->request($request, | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | sub { print $fetch $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | if( $resp->is_error ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $self->throw("WebDBSeqI Request Error:\n".$resp->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | close $fetch; #must explicitly close here, because the hard exists | |||||||||||||||||||||||||||||||||||||||||
| 787 | #don't close them for us | ||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | POSIX::_exit(0); | |||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | sub io { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
io: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | my ($self,$io) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | if(defined($io) || (! exists($self->{'_io'}))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $io or not exists $self->{"_io"}
MC/DC0%0/2
defined $io or not exists $self->{"_io"}
defined $io
not exists $self->{"_io"}
Truth table0%0/3
A or not(B)
A= defined $ioB= not exists $self->{"_io"}
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | $io = Bio::Root::IO->new() unless $io; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | $self->{'_io'} = $io; | |||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | return $self->{'_io'}; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | =head2 delay | ||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | Title : delay | ||||||||||||||||||||||||||||||||||||||||||
| 806 | Usage : $secs = $self->delay([$secs]) | ||||||||||||||||||||||||||||||||||||||||||
| 807 | Function: get/set number of seconds to delay between fetches | ||||||||||||||||||||||||||||||||||||||||||
| 808 | Returns : number of seconds to delay | ||||||||||||||||||||||||||||||||||||||||||
| 809 | Args : new value | ||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | NOTE: the default is to use the value specified by delay_policy(). | ||||||||||||||||||||||||||||||||||||||||||
| 812 | This can be overridden by calling this method, or by passing the | ||||||||||||||||||||||||||||||||||||||||||
| 813 | -delay argument to new(). | ||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | sub delay { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delay: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | my $d = $self->{'_delay'}; | |||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | $self->{'_delay'} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | $d; | |||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | =head2 delay_policy | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | Title : delay_policy | ||||||||||||||||||||||||||||||||||||||||||
| 827 | Usage : $secs = $self->delay_policy | ||||||||||||||||||||||||||||||||||||||||||
| 828 | Function: return number of seconds to delay between calls to remote db | ||||||||||||||||||||||||||||||||||||||||||
| 829 | Returns : number of seconds to delay | ||||||||||||||||||||||||||||||||||||||||||
| 830 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||
| 832 | NOTE: The default delay policy is 0s. Override in subclasses to | ||||||||||||||||||||||||||||||||||||||||||
| 833 | implement delays. The timer has only second resolution, so the delay | ||||||||||||||||||||||||||||||||||||||||||
| 834 | will actually be +/- 1s. | ||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | ▶ | sub delay_policy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delay_policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | =head2 _sleep | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | Title : _sleep | ||||||||||||||||||||||||||||||||||||||||||
| 846 | Usage : $self->_sleep | ||||||||||||||||||||||||||||||||||||||||||
| 847 | Function: sleep for a number of seconds indicated by the delay policy | ||||||||||||||||||||||||||||||||||||||||||
| 848 | Returns : none | ||||||||||||||||||||||||||||||||||||||||||
| 849 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||
| 851 | NOTE: This method keeps track of the last time it was called and only | ||||||||||||||||||||||||||||||||||||||||||
| 852 | imposes a sleep if it was called more recently than the delay_policy() | ||||||||||||||||||||||||||||||||||||||||||
| 853 | allows. | ||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | ▶ | sub _sleep { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sleep: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | my $last_invocation = $LAST_INVOCATION_TIME; | |||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | if (time - $LAST_INVOCATION_TIME < $self->delay) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | my $delay = $self->delay - (time - $LAST_INVOCATION_TIME); | |||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | warn "sleeping for $delay seconds\n" if $self->verbose > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | sleep $delay; | |||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | $LAST_INVOCATION_TIME = time; | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | =head2 mod_perl_api | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | Title : mod_perl_api | ||||||||||||||||||||||||||||||||||||||||||
| 871 | Usage : $version = self->mod_perl_api | ||||||||||||||||||||||||||||||||||||||||||
| 872 | Function: Returns API version of mod_perl being used based on set env. variables | ||||||||||||||||||||||||||||||||||||||||||
| 873 | Returns : mod_perl API version; if mod_perl isn't loaded, returns 0 | ||||||||||||||||||||||||||||||||||||||||||
| 874 | Args : none | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | ▶ | sub mod_perl_api { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mod_perl_api: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 880 | my $v = $ENV{MOD_PERL} ? | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | ▶ | ( exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} >= 2 ) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} >= 2
MC/DC0%0/2
exists $ENV{"MOD_PERL_API_VERSION"} and $ENV{"MOD_PERL_API_VERSION"} >= 2
exists $ENV{"MOD_PERL_API_VERSION"}
$ENV{"MOD_PERL_API_VERSION"} >= 2
Truth table0%0/3
A and B
A= exists $ENV{"MOD_PERL_API_VERSION"}B= $ENV{"MOD_PERL_API_VERSION"} >= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | 2 : | ||||||||||||||||||||||||||||||||||||||||||
| 883 | 1 | ||||||||||||||||||||||||||||||||||||||||||
| 884 | : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | return $v; | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||