Skip to content
Snippets Groups Projects
Commit 72c963af authored by Monika Komorowska's avatar Monika Komorowska
Browse files

load_registry_from_db - load the stable ids lookup database if found;...

load_registry_from_db - load the stable ids lookup database if found; get_species_and_object_type - use the stable id lookup database if found
parent 837d452a
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,7 @@ my %group2adaptor = (
'otherfeatures' => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
'pipeline' => 'Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor',
'snp' => 'Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor',
'stable_ids' => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
'variation' => 'Bio::EnsEMBL::Variation::DBSQL::DBAdaptor',
'vega' => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
'vega_update' => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
......@@ -1557,6 +1558,9 @@ sub load_registry_from_db {
my $ontology_db;
my $ontology_version;
my $stable_ids_db;
my $stable_ids_version;
$user ||= "ensro";
if ( !defined($port) ) {
$port = 3306;
......@@ -1621,6 +1625,12 @@ sub load_registry_from_db {
$ontology_db = $db;
$ontology_version = $1;
}
} elsif ( $db =~ /^ensembl(?:genomes)?_stable_ids_(?:\d+_)?(\d+)/x ) {
if ( $1 eq $software_version ) {
$stable_ids_db = $db;
$stable_ids_version = $1;
}
} elsif (
$db =~ /^([a-z]+_[a-z0-9]+(?:_[a-z0-9]+)? # species name e.g. homo_sapiens or canis_lupus_familiaris
_
......@@ -2090,6 +2100,26 @@ sub load_registry_from_db {
print("No ontology database found\n");
}
if ( defined($stable_ids_db) && $stable_ids_version != 0 ) {
my $dba =
Bio::EnsEMBL::DBSQL::DBAdaptor->new(
'-species' => 'multi' . $species_suffix,
'-group' => 'stable_ids',
'-host' => $host,
'-port' => $port,
'-user' => $user,
'-pass' => $pass,
'-dbname' => $stable_ids_db, );
if ($verbose) {
printf( "%s loaded\n", $stable_ids_db );
}
}
Bio::EnsEMBL::Utils::ConfigRegistry->add_alias(
-species => 'multi'.$species_suffix,
-alias => ['compara'.$species_suffix] );
......@@ -2098,6 +2128,11 @@ sub load_registry_from_db {
-species => 'multi'.$species_suffix,
-alias => ['ontology'.$species_suffix] );
Bio::EnsEMBL::Utils::ConfigRegistry->add_alias(
-species => 'multi'.$species_suffix,
-alias => ['stable_ids'.$species_suffix] );
Bio::EnsEMBL::Utils::ConfigRegistry->add_alias(
-species => 'Ancestral sequences'.$species_suffix,
-alias => ['ancestral_sequences'.$species_suffix] );
......@@ -2560,6 +2595,8 @@ sub version_check {
$database_version = $1;
} elsif ( $dba->dbc()->dbname() =~ /ensembl_ontology_(\d+)/x ) {
$database_version = $1;
} elsif ( $dba->dbc()->dbname() =~ /ensembl_stable_ids_(\d+)/x ) {
$database_version = $1;
} else {
warn(
sprintf(
......@@ -2596,15 +2633,18 @@ sub version_check {
translation, or exon etc.), and database type for a
stable ID.
NOTE: No validation is done to see if the stable ID
actually exists.
Arg [1] : String stable_id
The stable ID to find species and object type for.
Arg [2] : String known_type (optional)
The type of the stable ID, if it is known.
Arg [3] : String known_species (optional)
The species, if known
Arg [4] : String known_db_type (optional)
The database type, if known
Example : my $stable_id = 'ENST00000326632';
my ( $species, $object_type, $db_type ) =
......@@ -2626,28 +2666,28 @@ sub version_check {
=cut
my %stable_id_stmts = (
"gene" => 'SELECT m.meta_value '
gene => 'SELECT m.meta_value '
. 'FROM %1$s.gene '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
. 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
"transcript" => 'SELECT m.meta_value '
transcript => 'SELECT m.meta_value '
. 'FROM %1$s.transcript '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
. 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
"exon" => 'SELECT m.meta_value '
exon => 'SELECT m.meta_value '
. 'FROM %1$s.exon '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
. 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
"translation" => 'SELECT m.meta_value '
translation => 'SELECT m.meta_value '
. 'FROM %1$s.translation tl '
. 'JOIN %1$s.transcript USING (transcript_id) '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
......@@ -2655,59 +2695,102 @@ my %stable_id_stmts = (
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE tl.stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
"operon" => 'SELECT m.meta_value '
operon => 'SELECT m.meta_value '
. 'FROM %1$s.operon '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
. 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
"operontranscript" => 'SELECT m.meta_value '
operontranscript => 'SELECT m.meta_value '
. 'FROM %1$s.operon_transcript '
. 'JOIN %1$s.seq_region USING (seq_region_id) '
. 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE stable_id = ? '
. 'AND m.meta_key = "species.production_name"',
);
sub get_species_and_object_type {
my ($self, $stable_id, $known_type) = @_;
my ($self, $stable_id, $known_type, $known_species, $known_db_type) = @_;
#get the stable_id lookup database adaptor
my $stable_ids_dba = $self->get_DBAdaptor("multi", "stable_ids");
if ($stable_ids_dba) {
my $statement = 'SELECT name, object_type, db_type FROM stable_id_lookup join species using(species_id) WHERE stable_id = ?';
if ($known_species) {
$statement .= ' AND name = ?';
}
if ($known_db_type) {
$statement .= ' AND db_type = ?';
}
if ($known_type) {
$statement .= ' AND object_type = ?';
}
my $sth = $stable_ids_dba->dbc()->prepare($statement);
$sth->bind_param(1, $stable_id, SQL_VARCHAR);
my $param_count = 1;
if ($known_species) {
$param_count++;
$sth->bind_param($param_count, $known_species, SQL_VARCHAR);
}
if ($known_db_type) {
$param_count++;
$sth->bind_param($param_count, $known_db_type, SQL_VARCHAR);
}
if ($known_type) {
$param_count++;
$sth->bind_param($param_count, $known_type, SQL_VARCHAR);
}
$sth->execute();
my ($species, $type, $db_type) = $sth->fetchrow_array();
return ($species ,$type, $db_type);
if (defined $known_type && !exists $stable_id_stmts{lc $known_type}) {
warn "Got invalid known_type '$known_type'";
return;
}
} else {
my @types = defined $known_type ? ($known_type) : ('Gene', 'Transcript', 'Translation', 'Exon', 'Operon', 'OperonTranscript');
my $dbc;
my $dbh;
if (defined $known_type && !exists $stable_id_stmts{lc $known_type}) {
return;
}
foreach my $dba (
sort { $a->dbc->host cmp $b->dbc->host || $a->dbc->port <=> $b->dbc->port }
@{$self->get_all_DBAdaptors( '-group' => 'Core' )}
) {
unless (defined $dbc && $dbc->host eq $dba->dbc->host && $dbc->port eq $dba->dbc->port) {
$dbc = $dba->dbc;
$dbh = $dbc->db_handle;
}
my @types = defined $known_type ? ($known_type) : ('Gene', 'Transcript', 'Translation', 'Exon', 'Operon', 'OperonTranscript');
if ($known_db_type && $known_db_type ne 'core' && $known_db_type ne 'Core' ) {
return;
}
my %get_adaptors_args;
$get_adaptors_args{'-group'} = 'Core';
if ($known_species) {
$get_adaptors_args{'-species'} = $known_species;
}
foreach my $type (@types) {
my $statement = sprintf $stable_id_stmts{lc $type}, $dba->dbc->dbname;
my @dbas = sort { $a->dbc->host cmp $b->dbc->host || $a->dbc->port <=> $b->dbc->port }
@{$self->get_all_DBAdaptors(%get_adaptors_args)};
foreach my $dba (@dbas) {
foreach my $type (@types) {
my $statement = sprintf $stable_id_stmts{lc $type}, $dba->dbc->dbname;
my $sth = $dbh->prepare($statement);
my $sth = $dba->dbc()->prepare($statement);
$sth->bind_param(1, $stable_id, SQL_VARCHAR);
$sth->execute;
$sth->bind_param(1, $stable_id, SQL_VARCHAR);
$sth->execute;
my $species = $sth->fetchall_arrayref->[0][0];
my $species = $sth->fetchall_arrayref->[0][0];
$sth->finish;
$sth->finish;
return ($species, $type, 'Core') if defined $species;
}
return ($species, $type, 'Core') if defined $species;
}
} ## end foreach my $dba ( sort { $a...})
} ## end foreach my $dba ( sort { $a...})
}
return;
} ## end sub get_species_and_object_type
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment