BioPerl

 view release on metacpan or  search on metacpan

Bio/DB/Taxonomy/entrez.pm  view on Meta::CPAN

 Args    : on set, new value (a scalar or undef, optional)

=cut

sub entrez_url{
    my $self = shift;

    return $self->{'_entrez_url'} = shift if @_;
    return $self->{'_entrez_url'};
}


=head2 entrez_params

 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

=cut

sub entrez_params{
    my $self = shift;
    my $f;
    if( @_ ) {
        $f = $self->{'_entrez_params'} = shift;
    } else {
        $f = $self->{'_entrez_params'};
    }
    return %$f;
}


=head2 Bio::DB::WebBase methods

=head2 proxy_string

 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'

=head2 proxy

 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)

=head2 authentication

 Title   : authentication
 Usage   : $db->authentication($user,$pass)
 Function: Get/Set authentication credentials
 Returns : Array of user/pass
 Args    : Array or user/pass

=cut


# make a Taxon object from data hash ref
sub _make_taxon {
    my ($self, $data) = @_;

    my $taxon = Bio::Taxon->new();

    my $taxid;
    while (my ($method, $value) = each %{$data}) {
        if ($method eq 'id') {
            $method = 'ncbi_taxid'; # since this is a real ncbi taxid, explicitly set it as one
            $taxid = $value;
        }
        $taxon->$method(ref($value) eq 'ARRAY' ? @{$value} : $value);
    }

    # we can't use -dbh or the db_handle() method ourselves or we'll go
    # infinite on the merge attempt
    $taxon->{'db_handle'} = $self;

    $self->_handle_internal_id($taxon);

    return $taxon;
}


sub _build_url {
    # Given a eutility (esearch.fcgi, efetch.fcgi or esummary.fcgi) and a
    # hashref or parameters, build a url suitable for eutil query
    my ($self, $eutility, $p) = @_;
    my $params = join($UrlParamSeparatorValue, map { $_.'='.$p->{$_} } keys %$p);
    my $url = $self->entrez_url.$eutility.'?'.$params;
    $self->debug("url is $url\n");
    return $url;
}


sub _run_query {
    # Given an eutil url, run the eutil query and parse the response into an
    # XML Twig object
    my ($self, $url) = @_;
    my $response = $self->get($url);
    if ($response->is_success) {
        $response = $response->content;
    }else {
        $self->throw("Can't query website: ".$response->status_line);
    }
    $self->debug("response is $response\n");
    my $twig = XML::Twig->new;
    $twig->parse($response);
    return $twig;
}


1;



( run in 1.621 second using v1.01-cache-2.11-cpan-39bf76dae61 )