my
$reg
=
"Bio::EnsEMBL::Registry"
;
sub
gen_load {
my
(
$dba
) =
@_
;
my
$pre_hook
;
my
$config_sub
;
if
(
$dba
->isa(
'Bio::EnsEMBL::Compara::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'compara'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_compara
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::Lite::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'lite'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_lite
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'pipeline'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_pipeline
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::Hive::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'hive'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_hive
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::Variation::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'variation'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_variation
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'funcgen'
);
}
$pre_hook
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::pre_funcgen_hook
;
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_funcgen
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::DBSQL::OntologyDBAdaptor'
) ||
$dba
->isa(
'Bio::Ensembl::DBSQL::OntologyTermAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'ontology'
);
}
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_ontology
;
}
elsif
(
$dba
->isa(
'Bio::EnsEMBL::DBSQL::DBAdaptor'
) ) {
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'core'
);
}
if
(
$dba
->group eq
"estgene"
) {
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_estgene
;
}
elsif
(
$dba
->group eq
"otherfeatures"
) {
$config_sub
=
\
&Bio::EnsEMBL::Utils::ConfigRegistry::load_otherfeatures
;
}
elsif
(
$dba
->group eq
"rnaseq"
) {
$config_sub
=
\
&Bio::EnsEMBL::Utils::ConfigRegistry::load_rnaseq
;
}
elsif
(
$dba
->group eq
'vega'
||
$dba
->group eq
'vega_update'
) {
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_vega
;
}
else
{
$config_sub
= \
&Bio::EnsEMBL::Utils::ConfigRegistry::load_core
;
}
}
else
{
if
( !
defined
(
$dba
->group() ) ) {
$dba
->group(
'none_standard'
);
}
$config_sub
=
\
&Bio::EnsEMBL::Utils::ConfigRegistry::load_and_attach_dnadb_to_core
;
}
$pre_hook
->(
$dba
)
if
$pre_hook
;
if
(
defined
(
$dba
->species ) ) {
my
$db_reg
=
$reg
->get_DBAdaptor(
$dba
->species,
$dba
->group, 1 );
if
(
defined
(
$db_reg
) ) {
if
(
$dba
->dbc->equals(
$db_reg
->dbc ) ) {
return
$db_reg
}
else
{
my
$msg
=
sprintf
(
'WARN: Species (%s) and group (%s) '
.
'same for two seperate databases'
,
$dba
->species(),
$dba
->group() );
warn
"${msg}\nModify species name for one of these\n"
;
$dba
->species(
find_unique_species(
$dba
->species,
$dba
->group ) );
}
}
}
else
{
my
@db_reg
=
@{
$reg
->get_all_DBAdaptors_by_connection(
$dba
->dbc ) };
foreach
my
$db_adaptor
(
@db_reg
) {
if
(
$db_adaptor
->group eq
$dba
->group ) {
return
$db_adaptor
;
}
}
$dba
->species( find_unique_species(
"DEFAULT"
,
$dba
->group ) );
if
(
$dba
->species ne
"DEFAULT"
) {
warn
"WARN: For multiple species "
.
"use species attribute in DBAdaptor->new()\n"
;
}
}
Bio::EnsEMBL::Registry->add_DBAdaptor(
$dba
->species(),
$dba
->group(),
$dba
);
&{
$config_sub
}(
$dba
);
return
$dba
;
}
sub
find_unique_species {
my
(
$species
,
$group
) =
@_
;
$reg
->add_alias(
$species
,
$species
);
my
$i
= 0;
my
$free
= 0;
while
( !
$free
) {
if
(
$i
== 0 ) {
if
( !
defined
(
$reg
->get_DBAdaptor(
$species
,
$group
) ) ) {
$free
= 1;
$i
=
""
;
}
else
{
$i
= 1;
}
}
else
{
$reg
->add_alias(
$species
.
$i
,
$species
.
$i
);
if
( !
defined
(
$reg
->get_DBAdaptor(
$species
.
$i
,
$group
) ) ) {
$free
= 1;
}
else
{
$i
++;
}
}
}
$species
.=
$i
;
return
(
$species
);
}
sub
load_adaptors {
my
(
$dba
) =
@_
;
my
%pairs
= %{
$dba
->get_available_adaptors() };
while
(
my
(
$key
,
$value
) =
each
(
%pairs
) ) {
Bio::EnsEMBL::Registry->add_adaptor(
$dba
->species(),
$dba
->group(),
$key
,
$value
);
}
}
sub
load_and_attach_dnadb_to_core {
my
(
$dba
) =
@_
;
load_adaptors(
$dba
);
$reg
->add_DNAAdaptor(
$dba
->species(),
$dba
->group(),
$dba
->species(),
'core'
);
}
sub
load_core { load_adaptors(
@_
) }
sub
load_compara { load_adaptors(
@_
) }
sub
load_hive { load_adaptors(
@_
) }
sub
load_pipeline { load_adaptors(
@_
) }
sub
load_SNP { load_adaptors(
@_
) }
sub
load_haplotype { load_adaptors(
@_
) }
sub
load_ontology { load_adaptors(
@_
) }
sub
load_estgene { load_and_attach_dnadb_to_core(
@_
) }
sub
load_variation { load_and_attach_dnadb_to_core(
@_
) }
sub
load_funcgen { load_and_attach_dnadb_to_core(
@_
) }
sub
load_otherfeatures { load_and_attach_dnadb_to_core(
@_
) }
sub
load_rnaseq { load_and_attach_dnadb_to_core(
@_
) }
sub
load_vega { load_and_attach_dnadb_to_core(
@_
) }
sub
add_alias {
my
(
$class
,
@args
) =
@_
;
my
(
$species
,
$aliases
) = rearrange( [
qw(SPECIES ALIAS)
],
@args
);
Bio::EnsEMBL::Registry->add_alias(
$species
,
$species
);
if
(
defined
(
$aliases
) ) {
foreach
my
$ali
(
@$aliases
) {
Bio::EnsEMBL::Registry->add_alias(
$species
,
$ali
);
}
}
}
sub
pre_funcgen_hook {
my
(
$dba
) =
@_
;
if
(!
$dba
->species() ) {
warn
"Setting name"
;
my
$name
=
$dba
->dbc()->sql_helper()->execute_single_result(
-SQL
=>
'select meta_value from meta where meta_key =?'
,
-PARAMS
=> [
'species.production_name'
],
);
$dba
->dbc()->disconnect_if_idle();
$dba
->species(
$name
);
}
return
;
}
1;