| Summary | Included libraries | Package variables | Synopsis | Description | General documentation | Methods |
my $esearch = Bio::DB::EUtilities->new(-eutil => 'esearch',
-db => 'pubmed',
-term => 'hutP',
-usehistory => 'y');
$esearch->get_response; # parse the response, fetch a cookie my $elink = Bio::DB::EUtilities->new(-eutil => 'elink', -db => 'protein', -dbfrom => 'pubmed', -cookie => $esearch->next_cookie, -cmd => 'neighbor_history'); $elink->get_response; # parse the response, fetch the next cookie my $efetch = Bio::DB::EUtilities->new(-cookie => $elink->next_cookie, -retmax => 10, -rettype => 'fasta'); print $efetch->get_response->content;
http://eutils.ncbi.nlm.nih.gov/At this point, Bio::DB::EUtilities uses the EUtilities plugin modules somewhat
my $esearch = Bio::DB::EUtilities->new(-eutil => 'esearch',The default EUtility (when eutil is left out) is 'efetch'. For specifics on
-db => 'pubmed',
-term => 'dihydroorotase',
-usehistory => 'y');
http://eutils.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.htmlAt this time, retrieving the response is accomplished by using the method
my $efetch = Bio::DB::EUtilities->new(-cookie => $elink->next_cookie,Based on this, if one wanted to retrieve sequences or other raw data
-retmax => 10,
-rettype => 'fasta');
print $efetch->get_response->content;
| BEGIN | Code | |
| new | No description | Code |
| _initialize | No description | Code |
| add_cookie | Description | Code |
| next_cookie | Description | Code |
| reset_cookies | Description | Code |
| get_all_cookies | Description | Code |
| get_cookie_count | Description | Code |
| rewind_cookies | Description | Code |
| keep_cookies | Description | Code |
| parse_response | Description | Code |
| get_response | Description | Code |
| get_ids | Description | Code |
| delay_policy | Description | Code |
| get_entrezdbs | Description | Code |
| _add_db_ids | No description | Code |
| _eutil | Description | Code |
| _submit_request | No description | Code |
| _get_params | No description | Code |
| _load_eutil_module | No description | Code |
| _next_cookie_index | No description | Code |
| add_cookie | code | next | Top |
Title : cookie |
| next_cookie | code | prev | next | Top |
Title : next_cookie |
| reset_cookies | code | prev | next | Top |
Title : reset_cookies |
| get_all_cookies | code | prev | next | Top |
Title : get_all_cookies |
| get_cookie_count | code | prev | next | Top |
Title : get_cookie_count |
| rewind_cookies | code | prev | next | Top |
Title : rewind_cookies |
| keep_cookies | code | prev | next | Top |
Title : keep_cookies |
| parse_response | code | prev | next | Top |
Title : parse_response |
| get_response | code | prev | next | Top |
Title : get_response |
| get_ids | code | prev | next | Top |
Title : get_ids |
| delay_policy | code | prev | next | Top |
Title : delay_policy |
| get_entrezdbs | code | prev | next | Top |
Title : get_entrezdbs |
| _eutil | code | prev | next | Top |
Title : _eutil |
| BEGIN | Top |
our @METHODS = qw(rettype usehistory term field tool reldate mindate maxdate datetype retstart retmax sort seq_start seq_stop strand complexity report dbfrom cmd holding version linkname); for my $method (@METHODS) { eval <<END}
sub $method {
my \$self = shift;
return \$self->{'_$method'} = shift if \@_;
return \$self->{'_$method'};
}
END
| new | description | prev | next | Top |
my($class,@args) = @_; if( $class =~ /Bio::DB::EUtilities::(\S+)/ ) { my ($self) = $class->SUPER::new(@args); $self->_initialize(@args); return $self; } else { my %param = @args; @param{ map { lc $_ } keys %param } = values %param; # lowercase keys}
my $eutil = $param{'-eutil'} || 'efetch'; return unless ($class->_load_eutil_module($eutil)); return "Bio::DB::EUtilities::$eutil"->new(@args); }
| _initialize | description | prev | next | Top |
my ($self, @args) = @_; my ( $tool, $ids, $retmode, $verbose, $cookie, $keep_cookies) = $self->_rearrange([qw(TOOL ID RETMODE VERBOSE COOKIE KEEP_COOKIES)], @args); # hard code the base address}
$self->url_base_address($HOSTBASE); $tool ||= $DEFAULT_TOOL; $self->tool($tool); $ids && $self->id($ids); $verbose && $self->verbose($verbose); $retmode && $self->retmode($retmode); $keep_cookies && $self->keep_cookies($keep_cookies); if ($cookie && ref($cookie) =~ m{cookie}i) { $self->db($cookie->database) if !($self->db); $self->add_cookie($cookie); } $self->{'_cookieindex'} = 0; $self->{'_cookiecount'} = 0; $self->{'_authentication'} = [];
| add_cookie | description | prev | next | Top |
my $self = shift; if (@_) { my $cookie = shift; $self->throw("Expecting a Bio::DB::EUtilities::Cookie, got $cookie.") unless $cookie->isa("Bio::DB::EUtilities::Cookie"); push @{$self->{'_cookie'}}, $cookie; } $self->{'_cookiecount'}++;}
| next_cookie | description | prev | next | Top |
my $self = shift; my $index = $self->_next_cookie_index; if ($self->{'_cookie'}) { return $self->{'_cookie'}->[$index]; } else { $self->warn("No cookies left in the jar!"); }}
| reset_cookies | description | prev | next | Top |
my $self = shift; $self->{'_cookie'} = []; $self->{'_cookieindex'} = 0; $self->{'_cookiecount'} = 0;}
| get_all_cookies | description | prev | next | Top |
my $self = shift; return @{ $self->{'_cookie'} } if $self->{'_cookie'} && wantarray; return $self->{'_cookie'}->[0] if $self->{'_cookie'}}
| get_cookie_count | description | prev | next | Top |
my $self = shift; return $self->{'_cookiecount'};}
| rewind_cookies | description | prev | next | Top |
my $self = shift; $self->{'_cookieindex'} = 0;}
| keep_cookies | description | prev | next | Top |
my $self = shift; return $self->{'_keep_cookies'} = shift if @_; return $self->{'_keep_cookies'};}
| parse_response | description | prev | next | Top |
my $self = shift; $self->throw_not_implemented;}
| get_response | description | prev | next | Top |
my $self = shift; $self->_sleep; # institute delay policy}
my $request = $self->_submit_request; if ($self->authentication) { $request->proxy_authorization_basic($self->authentication) } if (!$request->is_success) { $self->throw(ref($self)." Request Error:".$request->as_string); } $self->reset_cookies if !($self->keep_cookies); $self->parse_response($request); # grab cookies and what not
return $request;
| get_ids | description | prev | next | Top |
my $self = shift; my $user_db = shift if @_; if ($self->can('get_all_linksets')) { my $querydb = $self->db; if (!$user_db && ($querydb eq 'all' || $querydb =~ m{,}) ) { $self->throw(q(Multiple databases searched; must use a specific ). q(database as an argument.) ); } my $count = $self->get_linkset_count; if ($count == 0) { $self->throw( q(No linksets!) ); } elsif ($count == 1) { my ($linkset) = $self->get_all_linksets; my ($db) = $user_db ? $user_db : $linkset->get_all_linkdbs; $self->_add_db_ids( scalar( $linkset->get_LinkIds_by_db($db) ) ); } else { $self->throw( q(Multiple linkset objects present; can't use get_ids.). qq(\nUse get_all_linksets/get_databases/get_LinkIds_by_db ). qq(\n$count total linksets )); } } if ($self->{'_db_ids'}) { return @{$self->{'_db_ids'}} if wantarray; return $self->{'_db_ids'}; }}
| delay_policy | description | prev | next | Top |
my $self = shift; return 3;}
| get_entrezdbs | description | prev | next | Top |
my $self = shift; my $info = Bio::DB::EUtilities->new(-eutil => 'einfo'); $info->get_response; # copy list, not ref of list (so einfo obj doesn't stick around)}
my @databases = $info->einfo_dbs; return @databases;
| _add_db_ids | description | prev | next | Top |
my ($self, $ids) = @_; $self->throw ("IDs must be an ARRAY reference") unless ref($ids) =~ m{ARRAY}i; my @ids = @{ $ids}; # deep copy}
$self->{'_db_ids'} =\@ ids;
| _eutil | description | prev | next | Top |
my $self = shift; return $self->{'_eutil'} = shift if @_; return $self->{'_eutil'};}
| _submit_request | description | prev | next | Top |
my $self = shift; my %params = $self->_get_params; my $eutil = $self->_eutil; if ($self->id) { # this is in case multiple id groups are present}
if ($self->can('multi_id') && $self->multi_id) { # multiple id groups if groups are together in an array reference
# ids and arrays are flattened into individual groups
for my $id_group (@{ $self->id }) { if (ref($id_group) eq 'ARRAY') { push @{ $params{'id'} }, (join q(,), @{ $id_group }); } elsif (!ref($id_group)) { push @{ $params{'id'} }, $id_group; } else { $self->throw("Unknown ID type: $id_group"); } } } else { my @ids = @{ $self->id }; $params{'id'} = join ',', @ids; } } my $url = URI->new($HOSTBASE . $CGILOCATION{$eutil}[1]); $url->query_form(%params); $self->debug("The web address:\n".$url->as_string."\n"); if ($CGILOCATION{$eutil}[0] eq 'post') { # epost request
return $self->post($url); } else { # all other requests
return $self->get($url); }
| _get_params | description | prev | next | Top |
my $self = shift; my $cookie = $self->get_all_cookies ? $self->get_all_cookies : 0; my @final; # final parameter list; this changes dep. on presence of cookie}
my $eutil = $self->_eutil; my %params; @final = ($cookie && $cookie->isa("Bio::DB::EUtilities::Cookie")) ? @COOKIE_PARAMS : @PARAMS; # build parameter hash based on final parameter list
for my $method (@final) { if ($self->$method) { $params{$method} = $self->$method; } } if ($cookie) { my ($webenv, $qkey) = @{$cookie->cookie}; $self->debug("WebEnv:$webenv\tQKey:$qkey\n"); ($params{'WebEnv'}, $params{'query_key'}) = ($webenv, $qkey); $params{'dbfrom'} = $cookie->database if $eutil eq 'elink'; } my $db = $self->db; # elink cannot set the db from a cookie (it is actually dbfrom)
$params{'db'} = $db ? $db : ($cookie && $eutil ne 'elink') ? $cookie->database : 'nucleotide'; # einfo db exception (db is optional)
if (!$db && ($eutil eq 'einfo' || $eutil eq 'egquery')) { delete $params{'db'}; } unless (exists $params{'retmode'}) { # set by user
my $format = $CGILOCATION{ $eutil }[2]; # set by eutil
if ($format eq 'dbspec') { # database-specific
$format = $DATABASE{$params{'db'}} ? $DATABASE{$params{'db'}} : 'xml'; # have xml as a fallback
} $params{'retmode'} = $format; } $self->debug("Param: $_\tValue: $params{$_}\n") for keys %params; return %params;
| _load_eutil_module | description | prev | next | Top |
my ($self,$eutil) = @_; my $module = "Bio::DB::EUtilities::" . $eutil; my $ok; eval { $ok = $self->_load_module($module); }; if ( $@ ) { print STDERR <<END}
$self: $eutil cannot be found
Exception $@
For more information about the EUtilities system please see the EUtilities docs.
This includes ways of checking for formats at compile time, not run time
END
; } return $ok;
| _next_cookie_index | description | prev | next | Top |
my $self = shift; return $self->{'_cookieindex'}++;}
| TODO | Top |
| FEEDBACK | Top |
| Mailing Lists | Top |
bioperl-l@lists.open-bio.org - General discussion
http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
| Reporting Bugs | Top |
http://bugzilla.open-bio.org/
| AUTHOR | Top |
| APPENDIX | Top |
| Private methods | Top |