Bio::DB::Taxonomy
entrez
Summary
Bio::DB::Taxonomy::entrez - Taxonomy Entrez driver
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
# Do not use this object directly, rather through the Bio::DB::Taxonomy
# interface
use Bio::DB::Taxonomy;
my $db = new Bio::DB::Taxonomy(-source => 'entrez');
my $taxaid = $db->get_taxaid('Homo sapiens');
Description
A driver for querying NCBI Entrez Taxonomy database.
Methods
Methods description
Title : get_Taxonomy_Node
Usage : my $species = $db->get_Taxonomy_Node(-taxonid => $taxonid)
Function: Get a Bio::Taxonomy::Taxon object
Returns : Bio::Taxonomy::Taxon object(s) [more than one
Args : -taxonid => taxonomy id (to query by taxonid)
OR
-name => string (to query by a taxonomy name: common name,
species, genus, etc)
or just a single value which is the taxid. |
Title : get_taxonid
Usage : my $taxonid = $db->get_taxonid('Homo sapiens');
Function: Searches for a taxonid (typically ncbi_taxon_id)
based on a query string
Returns : Integer ID
Args : Array of Strings representing species/node name |
Title : entrez_url
Usage : $obj->entrez_url($newval)
Function: Get/set entrez URL
Returns : value of entrez url (a scalar)
Args : on set, new value (a scalar or undef, optional) |
Title : entrez_params
Usage : $obj->entrez_params($newval)
Function: Get/set entrez params
Returns : value of entrez_params (a hashref)
Args : on set, new value Hashref |
Methods code
sub _initialize
{ my($self) = shift;
if( ! $XMLTWIG ) {
$self->throw("Need to have installed XML::Twig");
}
$self->SUPER::_initialize(@_);
my ($location,$params) = $self->_rearrange([qw(LOCATION PARAMS)],@_);
$self->entrez_url($location || $EntrezLocation );
if( $params ) {
if( ref($params) !~ /HASH/i ) {
$self->warn("Must have provided a valid HASHref for -params");
$params =\% EntrezParams;
}
} else {
$params =\% EntrezParams;
}
$self->entrez_params($params);
$self->entrez_url($location || $EntrezLocation );} |
sub get_Taxonomy_Node
{ my ($self) = shift;
my %p = $self->entrez_params;
my $taxonid;
if( @_ > 1 ) {
my %params = @_;
if( $params{'-taxonid'} ) {
$taxonid = $params{'-taxonid'};
} elsif( $params{'-name'} ) {
my @taxaids = $self->get_taxonid($params{'-name'});
if( @taxaids > 1 ) {
$self->warn("Got > 1 taxid for ".$params{'-name'}. " only using the first one");
$taxonid = shift @taxaids;
}
} else {
$self->warn("Need to have provided either a -taxonid or -name value to get_Taxonomy_Node");
}
} else {
$taxonid= shift;
}
$p{'id'} = $taxonid;
my $params = join($UrlParamSeparatorValue, map { "$_=".$p{$_} } keys %p);
my $url = sprintf("%s%s?%s",$self->entrez_url,$EntrezSummary,$params);
$self->debug("url is $url\n") if( $self->verbose > 0);
my $response;
eval {
$response = $self->get($url);
};
if( $@ ) {
$self->warn("Can't query website: $@");
return;
}
my $twig = new XML::Twig;
$self->debug( "resp is $response\n") if( $self->verbose > 0);
$twig->parse($response);
my $root = $twig->root;
my $list = $root->first_child('DocSum');
if( ! $list ) {
$self->warn("Could not find any value for $taxonid");
return undef;
}
my ($id) = map { $_->text } $list->children('Id');
my (%item) = map { $_->{'att'}->{'Name'} => $_->text } $list->children('Item');
if( $item{'RANK'} eq 'species') {
my $node = new Bio::Species(-ncbi_taxid => $id,
-common_name => $item{'CommonName'},
-division => $item{'Division'});
my ($genus,$species,$subspecies) = split(' ',$item{'ScientificName'},3);
$node->genus($species);
$node->species($species);
return $node;
} else {
$self->warn(sprintf("can't create a species object for %s (%s) because it isn't a species but is a '%s' instead",$item{'ScientificName'},$item{'CommonName'}, $item{'RANK'}));
}\%
item;} |
sub get_taxonid
{ my ($self,$query) = @_;
my %p = $self->entrez_params;
$query =~ s/\s/\+/g;
$p{'term'} = $query;
my $params = join($UrlParamSeparatorValue, map { "$_=".$p{$_} } keys %p);
my $url = sprintf("%s%s?%s",$self->entrez_url,$EntrezGet,$params);
my $response;
eval {
$response = $self->get($url);
};
if( $@ ) {
$self->warn("Can't query website: $@");
return;
}
$self->debug( "response is $response\n") if( $self->verbose > 0);
my $twig = new XML::Twig;
$twig->parse($response);
my $root = $twig->root;
my $list = $root->first_child('IdList');
my @data = map { $_->text } $list->children('Id');
( wantarray ) ? @data : shift @data;} |
sub entrez_url
{ my $self = shift;
return $self->{'_entrez_url'} = shift if @_;
return $self->{'_entrez_url'};} |
sub entrez_params
{ my $self = shift;
my $f;
if( @_ ) {
$f = $self->{'_entrez_params'} = shift;
} else {
$f = $self->{'_entrez_params'};
}
return %$f;} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/MailList.shtml - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:
http://bugzilla.bioperl.org/
| AUTHOR - Jason Stajich | Top |
Email jason-at-bioperl.org
Additional contributors names and emails here
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Title : new
Usage : my $obj = new Bio::DB::Taxonomy::entrez();
Function: Builds a new Bio::DB::Taxonomy::entrez object
Returns : an instance of Bio::DB::Taxonomy::entrez
Args : -location => URL to Entrez (if you want to override the default)
-params => Hashref of URL params if you want to override the
default
| Some Get/Setter methods | Top |
| Bio::DB::WebBase methods | Top |
Title : proxy_string
Usage : my $proxy_string = $self->proxy_string($protocol)
Function: Get the proxy string (plus user/pass )
Returns : string
Args : protocol ('http' or 'ftp'), default 'http'
Title : proxy
Usage : $httpproxy = $db->proxy('http') or
$db->proxy(['http','ftp'], 'http://myproxy' )
Function: Get/Set a proxy for use of proxy
Returns : a string indicating the proxy
Args : $protocol : an array ref of the protocol(s) to set/get
$proxyurl : url of the proxy to use for the specified protocol
$username : username (if proxy requires authentication)
$password : password (if proxy requires authentication)
Title : authentication
Usage : $db->authentication($user,$pass)
Function: Get/Set authentication credentials
Returns : Array of user/pass
Args : Array or user/pass