Bio::Das::ProServer::SourceAdaptor::Transport::ensembl - Bio::Das::ProServer::SourceAdaptor::Transport::ensembl documentation


Bio-Das-ProServer documentation Contained in the Bio-Das-ProServer distribution.

Index


Code Index:

NAME

Top

Bio::Das::ProServer::SourceAdaptor::Transport::ensembl

VERSION

Top

$LastChangedRevision: 535 $

SYNOPSIS

Top

A transport for using the Registry to retrieve Ensembl data.

DESCRIPTION

Top

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.

SUBROUTINES/METHODS

Top

init - Post-construction initialisation.

  $oTransport->init();

  Loads the registry from the Ensembl database, and applies a custom database
  override if specified.

adaptor - Gets an Ensembl adaptor.

  $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>

slice_adaptor - Gets an Ensembl slice adaptor.

  $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>

gene_adaptor - Gets an Ensembl gene adaptor.

  $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>

chromosome_by_region - Gets a chromosome slice.

  $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>

chromosomes - Gets all chromosomes.

  $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

gene_by_id - Gets a gene.

  $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>

genes - Gets all genes.

  $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

version - Gets the Ensembl API's release number.

  $sVersion = $oTransport->version();

last_modified - Gets a last modified date from the database.

  $sVersion = $oTransport->version();

disconnect - ProServer hook to disconnect all connected databases.

  $oTransport->disconnect();

CONFIGURATION AND ENVIRONMENT

Top

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)

DIAGNOSTICS

Top

CONFIGURATION AND ENVIRONMENT

Top

DEPENDENCIES

Top

Carp
Bio::Das::ProServer::SourceAdaptor::Transport::generic
Ensembl core API
Additional Ensembl APIs if used

INCOMPATIBILITIES

Top

None reported

BUGS AND LIMITATIONS

Top

None reported

REFERENCES

Top

http://www.ensembl.org/info/software/Pdoc/ensembl/ Ensembl API

AUTHOR

Top

Andy Jenkinson <andy.jenkinson@ebi.ac.uk>

LICENSE AND COPYRIGHT

Top


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__