3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
43 The
ConfigRegistry will
"Register" a set of adaptors based on the type
44 of database that is being loaded.
50 package Bio::EnsEMBL::Utils::ConfigRegistry;
56 my $reg =
"Bio::EnsEMBL::Registry";
70 # At some point we hope to set the group in the DBadaptor, hence this
71 # long check etc. should be simpler.
73 if ( $dba->isa(
'Bio::EnsEMBL::Compara::DBSQL::DBAdaptor') ) {
74 if ( !defined( $dba->group() ) ) {
75 $dba->group(
'compara');
78 } elsif ( $dba->isa(
'Bio::EnsEMBL::Lite::DBAdaptor') ) {
79 if ( !defined( $dba->group() ) ) {
82 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_lite;
83 } elsif ( $dba->isa(
'Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor') ) {
84 if ( !defined( $dba->group() ) ) {
85 $dba->group(
'pipeline');
88 } elsif ( $dba->isa(
'Bio::EnsEMBL::Hive::DBSQL::DBAdaptor') ) {
89 if ( !defined( $dba->group() ) ) {
93 } elsif ( $dba->isa(
'Bio::EnsEMBL::Variation::DBSQL::DBAdaptor') ) {
94 if ( !defined( $dba->group() ) ) {
95 $dba->group(
'variation');
98 } elsif ( $dba->isa(
'Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor') ) {
99 if ( !defined( $dba->group() ) ) {
100 $dba->group(
'funcgen');
104 } elsif ( $dba->isa(
'Bio::EnsEMBL::DBSQL::OntologyDBAdaptor') || $dba->isa(
'Bio::Ensembl::DBSQL::OntologyTermAdaptor') ) {
105 if ( !defined( $dba->group() ) ) {
106 $dba->group(
'ontology');
109 } elsif ( $dba->isa(
'Bio::EnsEMBL::DBSQL::DBAdaptor') ) {
110 #vega uses the core DBAdaptor so test if vega is in the dbname
111 if ( !defined( $dba->group() ) ) {
115 if ( $dba->group eq
"estgene" ) {
117 } elsif ( $dba->group eq
"otherfeatures" ) {
120 } elsif ( $dba->group eq
"rnaseq" ) {
123 } elsif ( $dba->group eq
'vega' || $dba->group eq
'vega_update' ) {
130 # none standard DBA adaptor
131 if ( !defined( $dba->group() ) ) {
132 $dba->group(
'none_standard');
136 # throw("Unknown DBAdaptor type $dba\n");
139 #Run the pre-hook if one was defined
140 $pre_hook->($dba)
if $pre_hook;
142 # return if the connection and species, group are the same
144 if ( defined( $dba->species ) ) {
145 my $db_reg = $reg->get_DBAdaptor( $dba->species, $dba->group, 1 );
146 if ( defined($db_reg) ) {
147 if ( $dba->dbc->equals( $db_reg->dbc ) ) {
return $db_reg }
150 sprintf(
'WARN: Species (%s) and group (%s) '
151 .
'same for two seperate databases',
152 $dba->species(), $dba->group() );
154 warn
"${msg}\nModify species name for one of these\n";
156 find_unique_species( $dba->species, $dba->group ) );
159 }
else { # no species
162 @{ $reg->get_all_DBAdaptors_by_connection( $dba->dbc ) };
164 foreach my $db_adaptor (@db_reg) {
165 if ( $db_adaptor->group eq $dba->group ) {
166 # found same db connection and group
171 $dba->species( find_unique_species(
"DEFAULT", $dba->group ) );
172 if ( $dba->species ne
"DEFAULT" ) {
173 warn
"WARN: For multiple species "
174 .
"use species attribute in DBAdaptor->new()\n";
181 #call the loading subroutine. (add the adaptors to the DBAdaptor)
182 &{$config_sub}($dba);
185 } ## end sub gen_load
189 sub find_unique_species {
190 my ( $species, $group ) = @_;
192 $reg->add_alias( $species, $species );
199 if ( !defined( $reg->get_DBAdaptor( $species, $group ) ) ) {
206 # set needed self alias
207 $reg->add_alias( $species . $i, $species . $i );
209 if ( !defined( $reg->get_DBAdaptor( $species . $i, $group ) ) ) {
219 } ## end sub find_unique_species
226 my %pairs = %{ $dba->get_available_adaptors() };
228 while ( my ( $key, $value ) = each(%pairs) ) {
234 sub load_and_attach_dnadb_to_core {
238 $reg->add_DNAAdaptor( $dba->species(), $dba->group(), $dba->species(),
244 Arg [1] : DBAdaptor with DBConnection already attached
245 Returntype : DBAdaptor
248 sub load_core { load_adaptors(@_) }
252 # 1) core. no need to add dnadb
253 # 2) not core add dnadb
258 Arg [1] : DBAdaptor with DBConnection already attached
259 Returntype : DBAdaptor
262 sub load_compara { load_adaptors(@_) }
265 Arg [1] : DBAdaptor with DBConnection already attached
266 Returntype : DBAdaptor
269 sub load_hive { load_adaptors(@_) }
272 Arg [1] : DBAdaptor with DBConnection already attached
273 Returntype : DBAdaptor
276 sub load_pipeline { load_adaptors(@_) }
279 Arg [1] : DBAdaptor with DBConnection already attached
280 Returntype : DBAdaptor
283 sub load_SNP { load_adaptors(@_) }
285 sub load_haplotype { load_adaptors(@_) }
287 sub load_ontology { load_adaptors(@_) }
290 # these that need to attach to the core to get the sequence data
292 sub load_estgene { load_and_attach_dnadb_to_core(@_) }
294 sub load_variation { load_and_attach_dnadb_to_core(@_) }
296 sub load_funcgen { load_and_attach_dnadb_to_core(@_) }
298 =head2 load_otherfeatures
299 Arg [1] : DBAdaptor with DBConnection alredy attached
300 Returntype : DBAdaptor
304 sub load_otherfeatures { load_and_attach_dnadb_to_core(@_) }
306 sub load_rnaseq { load_and_attach_dnadb_to_core(@_) }
309 Arg [1] : DBAdaptor with DBConnection already attached
310 Returntype : DBAdaptor
313 sub load_vega { load_and_attach_dnadb_to_core(@_) }
317 my ( $class, @args ) = @_;
319 my ( $species, $aliases ) = rearrange( [qw(SPECIES ALIAS)], @args );
321 # Make sure it exists itself
324 if ( defined($aliases) ) {
325 foreach my $ali (@$aliases) {
331 # WARNING: "CONVENIENCE METHOD" for retriving the species name when one was
332 # not set. Regulation DB requirement
333 sub pre_funcgen_hook {
335 if(! $dba->species() ) {
337 my $name = $dba->dbc()->sql_helper()->execute_single_result(
338 -SQL =>
'select meta_value from meta where meta_key =?',
339 -PARAMS => [
'species.production_name'],
341 $dba->dbc()->disconnect_if_idle();
342 $dba->species($name);
348 # overwrite/load new types. Done this way to enable no changes to CVS for
349 # external users. External users should add there own "GROUPS" in the file
353 eval{ require Bio::EnsEMBL::Utils::User_defined_load };