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
37 # load all available adaptors of the given type for the species
43 # only load adaptors from the given groups of the given type for the species
47 -groups => [
'core',
'otherfeatures']
52 The
MergedAdaptor object is merely a list of adaptors. AUTOLOAD is used
53 to call a subroutine on each adaptor and merge the results. This
object structure
54 allows you to treat a set of adaptors as a logical single entity. The end result
55 is that disparate database source data sets are accessible through a single
58 This code will convert single
object return calls into ArrayRef returning calls
59 and so is only safe to use with the C<fetch_all_XXX> or C<get_all_XXX> methods.
66 package Bio::EnsEMBL::DBSQL::MergedAdaptor;
75 my $registry =
"Bio::EnsEMBL::Registry";
80 Arg [SPECIES]: String species name to get adaptors
for
81 Arg [TYPE] : String type to get adaptors
for
82 Arg [GROUPS] : (optional) ArrayRef of groups to load
84 -species=>
'human', -type =>
'Population', -groups => [
'Sanger',
'Ensembl']);
86 -species=>
'human', -type =>
'Population');
89 Exceptions :
throws if species or type not specified
97 my ($class, @args) = @_;
98 $class = ref($class) || $class;
99 my $self = bless({}, $class);
100 my ($species, $type, $groups) = rearrange([qw(SPECIES TYPE GROUPS)], @args);
102 if(!defined($species)|| !defined($type)){
103 throw "-SPECIES and -TYPE must be specified";
105 $self->_populate_adaptors($species, $type, $groups);
109 =head2 _populate_adaptors
111 Arg [1] : String species name to get adaptors
for
112 Arg [2] : String type to get adaptors
for
113 Arg [3] : (optional) ArrayRef of groups to load
114 Description : Auto-populates the current
MergedAdaptor with the
115 adaptors linked to
this species, type and optional set of groups
121 sub _populate_adaptors {
122 my ($self, $species, $type, $groups) = @_;
124 assert_ref($groups,
'ARRAY',
'-GROUPS');
125 my @adaptors =
map { $registry->get_adaptor($species, $_, $type) } @{$groups};
126 $self->add_list(@adaptors);
129 my $adaptors = $registry->get_all_adaptors(-SPECIES => $species, -TYPE => $type);
130 $self->add_list(@{$adaptors});
137 Arg [n] : Adaptors to add into
this instance
138 Description : Adds the given adaptors to the
internal adaptor list
143 my ($self, @adaptors) = @_;
144 push(@{$self->{adaptors}}, @adaptors);
150 Arg [1] : Adaptor to add into
this instance
151 Description : Adds the given adaptor to the
internal adaptor list. For
152 multiple adaptor addition use C<add_list()>.
157 my ($self, $adaptor) = @_;
158 $self->add_list($adaptor);
164 Arg [1] : String method name to be called
165 Description : Implementation of UNIVERSAL::can(). We loop through the
166 available adaptors and
return true if any will respond
167 to the given method name
168 Returntype : Boolean indicating
if any delegating
object will respond to
this method
173 my ($self, $method) = @_;
174 foreach my $adaptor (@{$self->{adaptors}}) {
175 return 1
if $adaptor->can($method);
183 Arg [1] : String method name to be called
184 Description : Implementation of UNIVERSAL::isa(). We loop through the
185 available adaptors and
return true if any inherited from
187 Returntype : Boolean indicating
if any delegating
object inherits from the given
class
192 my ($self, $isa) = @_;
193 foreach my $adaptor (@{$self->{adaptors}}) {
194 return 1
if $adaptor->isa($isa);
199 use vars
'$AUTOLOAD';
203 Description : Internal
override of AUTLOAD. The code will detect the requested
204 method, loop through all available adaptors and will
205 Returntype : Boolean indicating
if any delegating
object inherits from the given
class
210 my ($self, @args) = @_;
213 #Detect required method
214 $AUTOLOAD =~ /^.*::(\w+)+$/ ;
217 foreach my $adaptor (@{$self->{adaptors}}) {
219 if(my $method_ref = $adaptor->can($sub)) {
220 my $ref = $method_ref->($adaptor, @args);
221 push(@
return, @{wrap_array($ref)});
224 warning(
"In Merged Adaptor $adaptor cannot call sub $sub");