0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 =head1 NAME
|
|
22
|
|
23 Bio::EnsEMBL::Utils::ConfigRegistry;
|
|
24
|
|
25 =head1 SYNOPSIS
|
|
26
|
|
27
|
|
28 Bio::EnsEMBL::Utils::ConfigRegistry->load_core($dba);
|
|
29
|
|
30
|
|
31 =head1 DESCRIPTION
|
|
32
|
|
33 The ConfigRegistry will "Register" a set of adaptors based on the type
|
|
34 of database that is being loaded.
|
|
35
|
|
36 =head1 METHODS
|
|
37
|
|
38 =cut
|
|
39
|
|
40 package Bio::EnsEMBL::Utils::ConfigRegistry;
|
|
41
|
|
42 use strict;
|
|
43 use warnings;
|
|
44
|
|
45 use Bio::EnsEMBL::Registry;
|
|
46 my $reg = "Bio::EnsEMBL::Registry";
|
|
47 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
|
|
48 use Bio::EnsEMBL::DBSQL::DBConnection;
|
|
49 use Bio::EnsEMBL::DBSQL::DBAdaptor;
|
|
50
|
|
51 use Bio::EnsEMBL::Utils::Exception qw(warning throw deprecate stack_trace_dump);
|
|
52
|
|
53
|
|
54
|
|
55 sub gen_load {
|
|
56 my ($dba) = @_;
|
|
57 my $config_sub;
|
|
58
|
|
59 # At some point we hope to set the group in the DBadaptor, hence this
|
|
60 # long check etc. should be simpler.
|
|
61
|
|
62 if ( $dba->isa('Bio::EnsEMBL::Compara::DBSQL::DBAdaptor') ) {
|
|
63 if ( !defined( $dba->group() ) ) {
|
|
64 $dba->group('compara');
|
|
65 }
|
|
66 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_compara;
|
|
67 } elsif ( $dba->isa('Bio::EnsEMBL::Lite::DBAdaptor') ) {
|
|
68 if ( !defined( $dba->group() ) ) {
|
|
69 $dba->group('lite');
|
|
70 }
|
|
71 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_lite;
|
|
72 } elsif ( $dba->isa('Bio::EnsEMBL::External::BlastAdaptor') ) {
|
|
73 if ( !defined( $dba->group() ) ) {
|
|
74 $dba->group('blast');
|
|
75 }
|
|
76 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_blast;
|
|
77 } elsif ( $dba->isa('Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor') )
|
|
78 {
|
|
79 if ( !defined( $dba->group() ) ) {
|
|
80 $dba->group('SNP');
|
|
81 }
|
|
82 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_SNP;
|
|
83 } elsif ( $dba->isa('Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor') ) {
|
|
84 if ( !defined( $dba->group() ) ) {
|
|
85 $dba->group('pipeline');
|
|
86 }
|
|
87 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_pipeline;
|
|
88 } elsif ( $dba->isa('Bio::EnsEMBL::Hive::DBSQL::DBAdaptor') ) {
|
|
89 if ( !defined( $dba->group() ) ) {
|
|
90 $dba->group('hive');
|
|
91 }
|
|
92 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_hive;
|
|
93 } elsif (
|
|
94 $dba->isa('Bio::EnsEMBL::ExternalData::Haplotype::DBAdaptor') )
|
|
95 {
|
|
96 if ( !defined( $dba->group() ) ) {
|
|
97 $dba->group('haplotype');
|
|
98 }
|
|
99 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_haplotype;
|
|
100 } elsif ( $dba->isa('Bio::EnsEMBL::Variation::DBSQL::DBAdaptor') ) {
|
|
101 if ( !defined( $dba->group() ) ) {
|
|
102 $dba->group('variation');
|
|
103 }
|
|
104 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_variation;
|
|
105 } elsif ( $dba->isa('Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor') ) {
|
|
106 if ( !defined( $dba->group() ) ) {
|
|
107 $dba->group('funcgen');
|
|
108 }
|
|
109 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_funcgen;
|
|
110 } elsif ( $dba->isa('Bio::Ensembl::DBSQL::OntologyTermAdaptor') ) {
|
|
111 if ( !defined( $dba->group() ) ) {
|
|
112 $dba->group('ontology');
|
|
113 }
|
|
114 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_ontology;
|
|
115 } elsif ( $dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor') ) {
|
|
116 #vega uses the core DBAdaptor so test if vega is in the dbname
|
|
117 if ( !defined( $dba->group() ) ) {
|
|
118 $dba->group('core');
|
|
119 }
|
|
120
|
|
121 if ( $dba->group eq "estgene" ) {
|
|
122 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_estgene;
|
|
123 } elsif ( $dba->group eq "otherfeatures" ) {
|
|
124 $config_sub =
|
|
125 \&Bio::EnsEMBL::Utils::ConfigRegistry::load_otherfeatures;
|
|
126 } elsif ( $dba->group eq 'vega' || $dba->group eq 'vega_update' ) {
|
|
127 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_vega;
|
|
128 } else {
|
|
129 $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_core;
|
|
130 }
|
|
131
|
|
132 } else {
|
|
133 # none standard DBA adaptor
|
|
134 if ( !defined( $dba->group() ) ) {
|
|
135 $dba->group('none_standard');
|
|
136 }
|
|
137 $config_sub =
|
|
138 \&Bio::EnsEMBL::Utils::ConfigRegistry::load_and_attach_dnadb_to_core;
|
|
139 # throw("Unknown DBAdaptor type $dba\n");
|
|
140 }
|
|
141
|
|
142 # return if the connection and species, group are the same
|
|
143
|
|
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 }
|
|
148 else {
|
|
149 my $msg =
|
|
150 sprintf( 'WARN: Species (%s) and group (%s) '
|
|
151 . 'same for two seperate databases',
|
|
152 $dba->species(), $dba->group() );
|
|
153
|
|
154 warn "${msg}\nModify species name for one of these\n";
|
|
155 $dba->species(
|
|
156 find_unique_species( $dba->species, $dba->group ) );
|
|
157 }
|
|
158 }
|
|
159 } else { # no species
|
|
160
|
|
161 my @db_reg =
|
|
162 @{ $reg->get_all_DBAdaptors_by_connection( $dba->dbc ) };
|
|
163
|
|
164 foreach my $db_adaptor (@db_reg) {
|
|
165 if ( $db_adaptor->group eq $dba->group ) {
|
|
166 # found same db connection and group
|
|
167 return $db_adaptor;
|
|
168 }
|
|
169 }
|
|
170
|
|
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";
|
|
175 }
|
|
176 }
|
|
177
|
|
178 Bio::EnsEMBL::Registry->add_DBAdaptor( $dba->species(), $dba->group(),
|
|
179 $dba );
|
|
180
|
|
181 #call the loading subroutine. (add the adaptors to the DBAdaptor)
|
|
182 &{$config_sub}($dba);
|
|
183
|
|
184 return $dba;
|
|
185 } ## end sub gen_load
|
|
186
|
|
187
|
|
188
|
|
189 sub find_unique_species {
|
|
190 my ( $species, $group ) = @_;
|
|
191
|
|
192 $reg->add_alias( $species, $species );
|
|
193
|
|
194 my $i = 0;
|
|
195 my $free = 0;
|
|
196
|
|
197 while ( !$free ) {
|
|
198 if ( $i == 0 ) {
|
|
199 if ( !defined( $reg->get_DBAdaptor( $species, $group ) ) ) {
|
|
200 $free = 1;
|
|
201 $i = "";
|
|
202 } else {
|
|
203 $i = 1;
|
|
204 }
|
|
205 } else {
|
|
206 # set needed self alias
|
|
207 $reg->add_alias( $species . $i, $species . $i );
|
|
208
|
|
209 if ( !defined( $reg->get_DBAdaptor( $species . $i, $group ) ) ) {
|
|
210 $free = 1;
|
|
211 } else {
|
|
212 $i++;
|
|
213 }
|
|
214 }
|
|
215 }
|
|
216
|
|
217 $species .= $i;
|
|
218 return ($species);
|
|
219 } ## end sub find_unique_species
|
|
220
|
|
221
|
|
222
|
|
223 sub load_adaptors {
|
|
224 my ($dba) = @_;
|
|
225
|
|
226 my %pairs = %{ $dba->get_available_adaptors() };
|
|
227
|
|
228 while ( my ( $key, $value ) = each(%pairs) ) {
|
|
229 Bio::EnsEMBL::Registry->add_adaptor( $dba->species(), $dba->group(),
|
|
230 $key, $value );
|
|
231 }
|
|
232 }
|
|
233
|
|
234 sub load_and_attach_dnadb_to_core {
|
|
235 my ($dba) = @_;
|
|
236
|
|
237 load_adaptors($dba);
|
|
238 $reg->add_DNAAdaptor( $dba->species(), $dba->group(), $dba->species(),
|
|
239 'core' );
|
|
240 }
|
|
241
|
|
242
|
|
243 =head2 load_core
|
|
244 Arg [1] : DBAdaptor with DBConnection already attached
|
|
245 Returntype : DBAdaptor
|
|
246 Exceptions : none
|
|
247 =cut
|
|
248 sub load_core { load_adaptors(@_) }
|
|
249
|
|
250
|
|
251 #
|
|
252 # 1) core. no need to add dnadb
|
|
253 # 2) not core add dnadb
|
|
254 # 3)
|
|
255 #
|
|
256
|
|
257 =head2 load_compara
|
|
258 Arg [1] : DBAdaptor with DBConnection already attached
|
|
259 Returntype : DBAdaptor
|
|
260 Exceptions : none
|
|
261 =cut
|
|
262 sub load_compara { load_adaptors(@_) }
|
|
263
|
|
264 =head2 load_hive
|
|
265 Arg [1] : DBAdaptor with DBConnection already attached
|
|
266 Returntype : DBAdaptor
|
|
267 Exceptions : none
|
|
268 =cut
|
|
269 sub load_hive { load_adaptors(@_) }
|
|
270
|
|
271 =head2 load_pipeline
|
|
272 Arg [1] : DBAdaptor with DBConnection already attached
|
|
273 Returntype : DBAdaptor
|
|
274 Exceptions : none
|
|
275 =cut
|
|
276 sub load_pipeline { load_adaptors(@_) }
|
|
277
|
|
278 =head2 load_SNP
|
|
279 Arg [1] : DBAdaptor with DBConnection already attached
|
|
280 Returntype : DBAdaptor
|
|
281 Exceptions : none
|
|
282 =cut
|
|
283 sub load_SNP { load_adaptors(@_) }
|
|
284
|
|
285 sub load_haplotype { load_adaptors(@_) }
|
|
286
|
|
287 sub load_ontology { load_adaptors(@_) }
|
|
288
|
|
289
|
|
290 # these that need to attach to the core to get the sequence data
|
|
291
|
|
292 sub load_estgene { load_and_attach_dnadb_to_core(@_) }
|
|
293
|
|
294 sub load_variation { load_and_attach_dnadb_to_core(@_) }
|
|
295
|
|
296 sub load_funcgen { load_and_attach_dnadb_to_core(@_) }
|
|
297
|
|
298 =head2 load_otherfeatures
|
|
299 Arg [1] : DBAdaptor with DBConnection alredy attached
|
|
300 Returntype : DBAdaptor
|
|
301 Exceptions : none
|
|
302
|
|
303 =cut
|
|
304 sub load_otherfeatures { load_and_attach_dnadb_to_core(@_) }
|
|
305
|
|
306 =head2 load_vega
|
|
307 Arg [1] : DBAdaptor with DBConnection already attached
|
|
308 Returntype : DBAdaptor
|
|
309 Exceptions : none
|
|
310 =cut
|
|
311 sub load_vega { load_and_attach_dnadb_to_core(@_) }
|
|
312
|
|
313
|
|
314 sub add_alias {
|
|
315 my ( $class, @args ) = @_;
|
|
316
|
|
317 my ( $species, $aliases ) = rearrange( [qw(SPECIES ALIAS)], @args );
|
|
318
|
|
319 # Make sure it exists itself
|
|
320 Bio::EnsEMBL::Registry->add_alias( $species, $species );
|
|
321
|
|
322 if ( defined($aliases) ) {
|
|
323 foreach my $ali (@$aliases) {
|
|
324 Bio::EnsEMBL::Registry->add_alias( $species, $ali );
|
|
325 }
|
|
326 }
|
|
327 }
|
|
328
|
|
329 #
|
|
330 # overwrite/load new types. Done this way to enable no changes to CVS for
|
|
331 # external users. External users should add there own "GROUPS" in the file
|
|
332 # User_defined_load.
|
|
333 #
|
|
334
|
|
335 eval{ require Bio::EnsEMBL::Utils::User_defined_load };
|
|
336
|
|
337 1;
|