Bio::DB DBFetch
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::DB::DBFetch - Database object for retrieving using the dbfetch script
Package variables
No package variables defined.
Included modules
HTTP::Request::Common
Inherit
Bio::DB::WebDBSeqI
Synopsis
  #do not use this module directly
Description
Allows the dynamic retrieval of entries from databases using the
dbfetch script at EBI:
http:EEwww.ebi.ac.ukEcgi-binEdbfetch.
In order to make changes transparent we have host type (currently only
ebi) and location (defaults to ebi) separated out. This allows later
additions of more servers in different geographical locations.
This is a superclass which is called by instantiable subclasses with
correct parameters.
Methods
BEGIN Code
get_requestDescriptionCode
postprocess_dataDescriptionCode
default_formatDescriptionCode
get_Stream_by_idDescriptionCode
get_Seq_by_versionDescriptionCode
request_formatDescriptionCode
servertypeDescriptionCode
hostlocationDescriptionCode
location_urlDescriptionCode
hostsDescriptionCode
formatmapDescriptionCode
Methods description
get_requestcode    nextTop
 Title   : get_request
Usage : my $url = $self->get_request
Function: returns a HTTP::Request object
Returns :
Args : %qualifiers = a hash of qualifiers (ids, format, etc)
postprocess_datacodeprevnextTop
 Title   : postprocess_data
Usage : $self->postprocess_data ( 'type' => 'string',
'location' => \$datastr);
Function: process downloaded data before loading into a Bio::SeqIO
Returns : void
Args : hash with two keys - 'type' can be 'string' or 'file'
- 'location' either file location or string
reference containing data
default_formatcodeprevnextTop
 Title   : default_format
Usage : my $format = $self->default_format
Function: Returns default sequence format for this module
Returns : string
Args : none
get_Stream_by_idcodeprevnextTop
  Title   : get_Stream_by_id
Usage : $seq = $db->get_Stream_by_id($ref);
Function: Retrieves Seq objects from the server 'en masse', rather than one
at a time. For large numbers of sequences, this is far superior
than get_Stream_by_[id/acc]().
Example :
Returns : a Bio::SeqIO stream object
Args : $ref : either an array reference, a filename, or a filehandle
from which to get the list of unique ids/accession numbers.
NOTE: for backward compatibility, this method is also called
get_Stream_by_batch.
get_Seq_by_versioncodeprevnextTop
 Title   : get_Seq_by_version
Usage : $seq = $db->get_Seq_by_version('X77802.1');
Function: Gets a Bio::Seq object by accession number
Returns : A Bio::Seq object
Args : version number (as a string)
Throws : "version does not exist" exception
request_formatcodeprevnextTop
 Title   : request_format
Usage : my ($req_format, $ioformat) = $self->request_format;
$self->request_format("genbank");
$self->request_format("fasta");
Function: Get/Set sequence format retrieval. The get-form will normally not
be used outside of this and derived modules.
Returns : Array of two strings, the first representing the format for
retrieval, and the second specifying the corresponding SeqIO format.
Args : $format = sequence format
servertypecodeprevnextTop
 Title   : servertype
Usage : my $servertype = $self->servertype
$self->servertype($servertype);
Function: Get/Set server type
Returns : string
Args : server type string [optional]
hostlocationcodeprevnextTop
 Title   : hostlocation
Usage : my $location = $self->hostlocation()
$self->hostlocation($location)
Function: Set/Get Hostlocation
Returns : string representing hostlocation
Args : string specifying hostlocation [optional]
location_urlcodeprevnextTop
 Title   : location
Usage : my $url = $self->location_url()
Function: Get host url
Returns : string representing url
Args : none
hostscodeprevnextTop
 Title   : hosts
Usage :
Function: get/set for host hash
Returns :
Args : optional hash
formatmapcodeprevnextTop
 Title   : formatmap
Usage :
Function: get/set for format hash
Returns :
Args : optional hash
Methods code
BEGINTop
BEGIN {
 	    # global vars
$DEFAULTSERVERTYPE = 'dbfetch'; $DEFAULTLOCATION = 'ebi';
}
get_requestdescriptionprevnextTop
sub get_request {
	my ($self, @qualifiers) = @_;
	my ($uids, $format) = $self->_rearrange([qw(UIDS FORMAT)],
														 @qualifiers);

	$self->throw("Must specify a value for UIDs to fetch")
	  unless defined $uids;
	my $tmp;
	my $format_string = '';
	$format ||= $self->default_format;
	($format, $tmp) = $self->request_format($format);
	$format_string = "&format=$format"; 
	my $url = $self->location_url();
	my $uid;
	if( ref($uids) =~ /ARRAY/i ) {
		$uid = join (',', @$uids);
		$self->warn ('The server will accept maximum of 50 entries in a request. The rest are ignored.')
		  if scalar @$uids >50;
	} else {
		$uid = $uids;
	}

	return GET $url. $format_string. '&id='. $uid;
}
postprocess_datadescriptionprevnextTop
sub postprocess_data {
  my ($self, %args) = @_;
  if ($args{type} eq 'string') {
    ${$args{location}} =~ s/^\s+//;  # get rid of leading whitespace
} elsif ($args{type} eq 'file') { my $F; open $F,"<", $args{location} or $self->throw("Cannot open $args{location}: $!"); my @data = <$F>; for (@data) { last unless /^\s+$/; shift @data; } open $F,">", $args{location} or $self->throw("Cannot write to $args{location}: $!"); print $F @data; close $F; }
}
default_formatdescriptionprevnextTop
sub default_format {
    my ($self) = @_;
    return $self->{'_default_format'};
}
get_Stream_by_iddescriptionprevnextTop
sub get_Stream_by_id {
    my ($self, $ids) = @_;
    return $self->get_seq_stream('-uids' => $ids, '-mode' => 'batch');
}
get_Seq_by_versiondescriptionprevnextTop
sub get_Seq_by_version {
   my ($self,$seqid) = @_;
   my $seqio = $self->get_Stream_by_acc([$seqid]);
   $self->throw("version does not exist") if( !defined $seqio );
   return $seqio->next_seq();
}
request_formatdescriptionprevnextTop
sub request_format {
    my ($self, $value) = @_;
    if( defined $value ) {
	$value = lc $value;
	$self->{'_format'} = $value;
	return ($value, $value);
    }
    $value = $self->{'_format'};
    if( $value and defined $self->formatmap->{$value} ) {
	return ($value, $self->formatmap->{$value});
    } else {
	# Try to fall back to a default.
return ($self->default_format, $self->default_format ); }
}
servertypedescriptionprevnextTop
sub servertype {
    my ($self, $servertype) = @_;
    if( defined $servertype && $servertype ne '') {		
	 $self->throw("You gave an invalid server type ($servertype)".
			  " - available types are ".
			  keys %{$self->hosts}) unless( $self->hosts->{$servertype} );
	 $self->{'_servertype'} = $servertype;
    }
    $self->{'_servertype'} = $DEFAULTSERVERTYPE unless $self->{'_servertype'};
    return $self->{'_servertype'};
}
hostlocationdescriptionprevnextTop
sub hostlocation {
    my ($self, $location ) = @_;
    my $servertype = $self->servertype;
    $self->throw("Must have a valid servertype defined not $servertype")
	unless defined $servertype; 
    my %hosts = %{$self->hosts->{$servertype}->{'hosts'}};
    if( defined $location && $location ne '' ) {
    $location = lc $location;
	if( ! $hosts{$location} ) {
	    $self->throw("Must specify a known host, not $location,".
			 " possible values (".
			 join(",", sort keys %hosts ). ")");
	}
	$self->{'_hostlocation'} = $location;
    }
    $self->{'_hostlocation'} = $DEFAULTLOCATION unless $self->{'_hostlocation'};
    return $self->{'_hostlocation'};
}
location_urldescriptionprevnextTop
sub location_url {
    my ($self) = @_;
    my $servertype = $self->servertype();
    my $location = $self->hostlocation();
    if( ! defined $location || !defined $servertype )  {	
	$self->throw("must have a valid hostlocation and servertype set before calling location_url");
    }
    return sprintf($self->hosts->{$servertype}->{'baseurl'},
		   $self->hosts->{$servertype}->{'hosts'}->{$location});
}
hostsdescriptionprevnextTop
sub hosts {
    my ($self, $value) = @_;
    if (defined $value) {
	$self->{'_hosts'} = $value;
    }
    unless (exists $self->{'_hosts'}) {
	return ('');
    } else {
	return $self->{'_hosts'};
    }
}
formatmapdescriptionprevnextTop
sub formatmap {
    my ($self, $value) = @_;
    if (defined $value) {
	$self->{'_formatmap'} = $value;
    }
    unless (exists $self->{'_formatmap'}) {
	return ('');
    } else {
	return $self->{'_formatmap'};
    }
}		


1;
__END__
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
  bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support Top
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
  https://redmine.open-bio.org/projects/bioperl/
AUTHOR - Heikki LehvaslaihoTop
Email Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
APPENDIXTop
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
Routines from Bio::DB::WebDBSeqITop
Bio::DB::DBFetch specific routinesTop
Bio::DB::DBFetch routinesTop
These methods allow subclasses to pass parameters.