| Bio-Das-ProServer documentation | Contained in the Bio-Das-ProServer distribution. |
Bio::Das::ProServer::SourceAdaptor::Transport::ensembl
$LastChangedRevision: 535 $
A transport for using the Registry to retrieve Ensembl data.
This class is a Transport that provides an interface to the Ensembl API. It uses the Ensembl Resistry to determine the location of the appropriate databases, and can be used in a species specific or cross-species manner. The main advantage of using this Transport is that the registry automatically provides access to the latest data available to the installed API.
$oTransport->init(); Loads the registry from the Ensembl database, and applies a custom database override if specified.
$oAdaptor = $oTransport->adaptor();
$oAdaptor = $oTransport->adaptor('human', 'core');
Arguments:
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
L<Bio::EnsEMBL::DBSQL::DBAdaptor>
$oAdaptor = $oTransport->slice_adaptor();
$oAdaptor = $oTransport->slice_adaptor('human', 'core');
Arguments:
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
L<Bio::EnsEMBL::DBSQL::SliceAdaptor>
$oAdaptor = $oTransport->gene_adaptor();
$oAdaptor = $oTransport->gene_adaptor('human', 'core');
Arguments:
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
L<Bio::EnsEMBL::DBSQL::GeneAdaptor>
$oSlice = $oTransport->chromosome_by_region('X');
$oSlice = $oTransport->chromosome_by_region('X', 123453, 132424);
$oSlice = $oTransport->chromosome_by_region('X', 123453, 132424, 'human', 'core');
Arguments:
chromosome # (required)
start (optional)
end (optional)
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
L<Bio::EnsEMBL::Slice>
$aSlices = $oTransport->chromosomes();
$aSlices = $oTransport->chromosomes('human', 'core');
Arguments:
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
listref of L<Bio::EnsEMBL::Slice> objects
$oGene = $oTransport->gene_by_id('ENSG00000139618'); # BRCA2
$oGene = $oTransport->gene_by_id('ENSG00000139618', 'human', 'core');
Arguments:
gene stable ID (required)
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
L<Bio::EnsEMBL::Gene>
$aGenes = $oTransport->genes();
$aGenes = $oTransport->genes('human', 'core');
Arguments:
species (optional, default configured in INI or 'human')
database group (optional, default configured in INI or 'core')
Returns:
listref of L<Bio::EnsEMBL::Gene> objects
$sVersion = $oTransport->version();
$sVersion = $oTransport->version();
$oTransport->disconnect();
Configured as part of each source's ProServer 2 INI file.
The transport will automatically load database connection settings from
the Ensembl Registry at ensembldb.ensembl.org. To skip this, set the
'skip_registry' INI property.
A specific database may also be overridden using these INI properties:
dbname
host (defaults to localhost)
port (defaults to 3306)
username (defaults to ensro)
password
The 'default database' used in the transport's data access methods may be
configured using these INI properties:
species (defaults to human)
group (defaults to core)
None reported
None reported
Andy Jenkinson <andy.jenkinson@ebi.ac.uk>
Copyright (c) 2007 EMBL-EBI
| Bio-Das-ProServer documentation | Contained in the Bio-Das-ProServer distribution. |
######### # Author: aj # Maintainer: $Author: andyjenkinson $ # Created: 2006 # Last Modified: $Date: 2008-10-17 16:51:57 +0100 (Fri, 17 Oct 2008) $ # Id: $Id: ensembl.pm 535 2008-10-17 15:51:57Z andyjenkinson $ # Source: $Source$ # $HeadURL: https://proserver.svn.sf.net/svnroot/proserver/trunk/lib/Bio/Das/ProServer/SourceAdaptor/Transport/ensembl.pm $ # package Bio::Das::ProServer::SourceAdaptor::Transport::ensembl; use strict; use warnings; use Carp; use Bio::EnsEMBL::Registry; use base qw(Bio::Das::ProServer::SourceAdaptor::Transport::generic); our $VERSION = do { my ($v) = (q$Revision: 535 $ =~ /\d+/mxg); $v; }; sub init { my ($self) = @_; $self->{'_species'} = $self->config->{'species'}; $self->{'_group'} = $self->config->{'group'}; $self->_apply_override; $self->_load_registry; return; } sub _load_registry { my ($self) = @_; if (!$self->config->{'skip_registry'}) { Bio::EnsEMBL::Registry->load_registry_from_db( -host => 'ensembldb.ensembl.org', -user => 'anonymous', -verbose => $self->{'debug'} ); } Bio::EnsEMBL::Registry->set_disconnect_when_inactive(); return; } sub _apply_override { my ($self) = @_; my $dbname = $self->config->{'dbname'}; if ($dbname) { my ($species, $group) = $dbname =~ m/([a-z_]+)_([a-z]+)_\d+/mx; if ($species eq 'ensembl') { $species = 'multi'; } $self->{'_species'} ||= $species; $self->{'_group'} ||= $group; if (!$self->{'_species'} || !$self->{'_group'}) { croak "Unable to parse database species and group: $dbname"; } $self->{'debug'} && carp sprintf "Overriding database with %s (%s,%s)\n", $dbname, $self->{'_species'}, $self->{'_group'}; # This is a map from group names to Ensembl DB adaptors. # Taken from Bio::EnsEMBL::Registry my %group2adaptor = ( 'blast' => 'Bio::EnsEMBL::External::BlastAdaptor', 'compara' => 'Bio::EnsEMBL::Compara::DBSQL::DBAdaptor', 'core' => 'Bio::EnsEMBL::DBSQL::DBAdaptor', 'estgene' => 'Bio::EnsEMBL::DBSQL::DBAdaptor', 'funcgen' => 'Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor', 'haplotype' => 'Bio::EnsEMBL::ExternalData::Haplotype::DBAdaptor', 'hive' => 'Bio::EnsEMBL::Hive::DBSQL::DBAdaptor', 'lite' => 'Bio::EnsEMBL::Lite::DBAdaptor', 'otherfeatures' => 'Bio::EnsEMBL::DBSQL::DBAdaptor', 'pipeline' => 'Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor', 'snp' => 'Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor', 'variation' => 'Bio::EnsEMBL::Variation::DBSQL::DBAdaptor', 'vega' => 'Bio::EnsEMBL::DBSQL::DBAdaptor', ); my $adaptorclass = $group2adaptor{ $self->{'_group'} } || croak 'Unknown database group: '.$self->{'_group'}; # Creating a new connection will add it to the registry. require $adaptorclass; $adaptorclass->new( -host => $self->config->{'host'} || 'localhost', -port => $self->config->{'port'} || '3306', -user => $self->config->{'username'} || 'ensro', -pass => $self->config->{'password'}, -dbname => $dbname, -species => $self->{'_species'}, -group => $self->{'_group'}, ); } return; } sub adaptor { my ($self, $species, $group) = @_; $species ||= $self->{'_species'} || 'human'; $group ||= $self->{'_group'} || 'core'; my $dba = Bio::EnsEMBL::Registry->get_DBAdaptor( $species, $group ); $self->{'debug'} && carp "Got adaptor for $species / $group (".$dba->dbc->dbname.")\n"; return $dba; } sub gene_adaptor { my ($self, $species, $group) = @_; return $self->adaptor($species, $group)->get_GeneAdaptor(); } sub slice_adaptor { my ($self, $species, $group) = @_; return $self->adaptor($species, $group)->get_SliceAdaptor(); } sub chromosome_by_region { ## no critic my ($self, $chr, $start, $end, $species, $group) = @_; return $self->slice_adaptor($species, $group)->fetch_by_region('chromosome', $chr, $start, $end); } sub chromosomes { my ($self, $species, $group) = @_; return $self->slice_adaptor($species, $group)->fetch_all('chromosome'); } sub gene_by_id { my ($self, $id, $species, $group) = @_; return $self->gene_adaptor($species, $group)->fetch_by_stable_id($id); } sub genes { my ($self, $species, $group) = @_; return $self->gene_adaptor($species, $group)->fetch_all(); } sub version { my ($self) = @_; return Bio::EnsEMBL::Registry->software_version(); } sub last_modified { my ($self) = @_; my $dbc = $self->adaptor()->dbc(); my $sth = $dbc->prepare(q(SHOW TABLE STATUS)); $sth->execute(); my $server_text = [sort { $b cmp $a } ## no critic keys %{ $sth->fetchall_hashref('Update_time') } ]->[0]; # server local time $sth->finish(); $sth = $dbc->prepare(q(SELECT UNIX_TIMESTAMP(?) as 'unix')); $sth->execute($server_text); # sec since epoch my $server_unix = $sth->fetchrow_arrayref()->[0]; $sth->finish(); return $server_unix; } sub disconnect { my $self = shift; Bio::EnsEMBL::Registry->disconnect_all(); $self->{'debug'} and carp "$self performed disconnect\n"; return; } 1; __END__