Bio-DB-NCBIHelper
view release on metacpan or search on metacpan
lib/Bio/DB/NCBIHelper.pm view on Meta::CPAN
$stop !~ /^\d+$/;
$self->{'_seq_stop'} = $stop;
}
return $self->{'_seq_stop'};
}
=head2 email
Title : email
Usage : $db->email('foo@bar.edu')
Function: get/set email value
Returns : email (string) or undef
Args : string with a valid email address; note we do not vallidate this
currently!
Throws : if arg is not an integer or falls outside of noted range above
Note : This is required if you wish to speed up mulltiple requests faster
than 4s per request.
=cut
sub email {
my ( $self, $email ) = @_;
if ( defined $email ) {
# TODO: validate email?
$self->{'_email'} = $email;
}
return $self->{'_email'};
}
=head2 Bio::DB::WebDBSeqI methods
Overriding WebDBSeqI method to help newbies to retrieve sequences
=head2 get_Stream_by_acc
Title : get_Stream_by_acc
Usage : $seq = $db->get_Stream_by_acc([$acc1, $acc2]);
Function: gets a series of Seq objects by accession numbers
Returns : a Bio::SeqIO stream object
Args : $ref : a reference to an array of accession numbers for
the desired sequence entries
Note : For GenBank, this just calls the same code for get_Stream_by_id()
=cut
sub get_Stream_by_acc {
my ( $self, $ids ) = @_;
$self->throw("NT_ contigs are whole chromosome files which are not part of regular"
. "database distributions. Go to ftp://ftp.ncbi.nih.gov/genomes/.")
if $ids =~ /NT_/;
return $self->get_seq_stream( '-uids' => $ids, '-mode' => 'single' );
}
=head2 delay_policy
Title : delay_policy
Usage : $secs = $self->delay_policy
Function: NCBI requests a delay of 4 seconds between requests unless email is
provided. This method implements a 4 second delay; use 'delay()' to
override, though understand if no email is provided we are not
responsible for users being IP-blocked by NCBI
Returns : number of seconds to delay
Args : none
=cut
sub delay_policy {
my $self = shift;
return $REQUEST_DELAY;
}
=head2 cookie
Title : cookie
Usage : ($cookie,$querynum) = $db->cookie
Function: return the NCBI query cookie, this information is used by
Bio::DB::GenBank in conjunction with efetch, ripped from
Bio::DB::Query::GenBank
Returns : list of (cookie,querynum)
Args : none
=cut
sub cookie {
my $self = shift;
if (@_) {
$self->{'_cookie'} = shift;
$self->{'_querynum'} = shift;
}
else {
return @{$self}{qw(_cookie _querynum)};
}
}
=head2 _parse_response
Title : _parse_response
Usage : $db->_parse_response($content)
Function: parse out response for cookie, this is a trimmed-down version
of _parse_response from Bio::DB::Query::GenBank
Returns : empty
Args : none
Throws : 'unparseable output exception'
=cut
sub _parse_response {
my $self = shift;
my $content = shift;
if ( my ($warning) = $content =~ m!<ErrorList>(.+)</ErrorList>!s ) {
$self->warn("Warning(s) from GenBank: $warning\n");
}
if ( my ($error) = $content =~ /<OutputMessage>([^<]+)/ ) {
$self->throw("Error from Genbank: $error");
}
my ($cookie) = $content =~ m!<WebEnv>(\S+)</WebEnv>!;
my ($querykey) = $content =~ m!<QueryKey>(\d+)!;
$self->cookie( uri_unescape($cookie), $querykey );
}
=head2 no_redirect
( run in 0.568 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )