EnsEMBL/DBSQL/MergedAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 116 CC 6 SCAR 13.9
CC
6
Cov
0%
new
6.0
_populate_adaptors
6.0
can
6.0
CRAP 4.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
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
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
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.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBSQL::MergedAdaptor
34  
35 =head1 SYNOPSIS
36  
37 # load all available adaptors of the given type for the species
38 my $merged_adaptor = Bio::EnsEMBL::DBSQL::MergedAdaptor->new(
39 -species => "human",
40 -type => "gene"
41 );
42  
43 # only load adaptors from the given groups of the given type for the species
44 my $merged_adaptor = Bio::EnsEMBL::DBSQL::MergedAdaptor->new(
45 -species => "human",
46 -type => "gene",
47 -groups => ['core','otherfeatures']
48 );
49  
50 =head1 DESCRIPTION
51  
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
56 adaptor call.
57  
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.
60  
61 =head1 METHODS
62  
63 =cut
64  
65  
66 package Bio::EnsEMBL::DBSQL::MergedAdaptor;
67 $Bio::EnsEMBL::DBSQL::MergedAdaptor::VERSION = '114.0.0_50'; # TRIAL
68 $Bio::EnsEMBL::DBSQL::MergedAdaptor::VERSION = '114.0.050';
69 use strict;
70 use warnings;
71  
72 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
73 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
74 use Bio::EnsEMBL::Utils::Scalar qw(wrap_array assert_ref);
75 require Bio::EnsEMBL::Registry;
76 my $registry = "Bio::EnsEMBL::Registry";
77  
78  
79 =head2 new
80  
81 Arg [SPECIES]: String species name to get adaptors for
82 Arg [TYPE] : String type to get adaptors for
83 Arg [GROUPS] : (optional) ArrayRef of groups to load
84 Example : my $adaptor = Bio::EnsEMBL::DBSQL::MergedAdaptor->new(
85 -species=> 'human', -type =>'Population', -groups => ['Sanger','Ensembl']);
86 my $alL_adaptor = Bio::EnsEMBL::DBSQL::MergedAdaptor->new(
87 -species=> 'human', -type =>'Population');
88 Description: Creates a new MergedAdaptor.
89 Returntype : Bio::EnsEMBL::DBSQL::MergedAdaptor
90 Exceptions : throws if species or type not specified
91 Caller : general
92 Status : At Risk
93 : Under development
94  
95 =cut
96  
97 sub new {
98 my ($class, @args) = @_;
99 $class = ref($class) || $class;
100 my $self = bless({}, $class);
101 my ($species, $type, $groups) = rearrange([qw(SPECIES TYPE GROUPS)], @args);
102  
103 if(!defined($species)|| !defined($type)){
104 throw "-SPECIES and -TYPE must be specified";
105 }
106 $self->_populate_adaptors($species, $type, $groups);
107 return $self;
108 }
109  
110 =head2 _populate_adaptors
111  
112 Arg [1] : String species name to get adaptors for
113 Arg [2] : String type to get adaptors for
114 Arg [3] : (optional) ArrayRef of groups to load
115 Description : Auto-populates the current MergedAdaptor with the
116 adaptors linked to this species, type and optional set of groups
117 Caller : general
118 Status : At Risk
119  
120 =cut
121  
122 sub _populate_adaptors {
123 my ($self, $species, $type, $groups) = @_;
124 if($groups) {
125 assert_ref($groups, 'ARRAY', '-GROUPS');
126 my @adaptors = map { $registry->get_adaptor($species, $_, $type) } @{$groups};
127 $self->add_list(@adaptors);
128 }
129 else {
130 my $adaptors = $registry->get_all_adaptors(-SPECIES => $species, -TYPE => $type);
131 $self->add_list(@{$adaptors});
132 }
133 return;
134 }
135  
136 =head2 add_list
137  
138 Arg [n] : Adaptors to add into this instance
139 Description : Adds the given adaptors to the internal adaptor list
140  
141 =cut
142  
143 sub add_list {
144 my ($self, @adaptors) = @_;
145 push(@{$self->{adaptors}}, @adaptors);
146 return;
147 }
148  
149 =head2 add_list
150  
151 Arg [1] : Adaptor to add into this instance
152 Description : Adds the given adaptor to the internal adaptor list. For
153 multiple adaptor addition use C<add_list()>.
154  
155 =cut
156  
157 sub add_adaptor {
158 my ($self, $adaptor) = @_;
159 $self->add_list($adaptor);
160 return;
161 }
162  
163 =head2 can
164  
165 Arg [1] : String method name to be called
166 Description : Implementation of UNIVERSAL::can(). We loop through the
167 available adaptors and return true if any will respond
168 to the given method name
169 Returntype : Boolean indicating if any delegating object will respond to this method
170  
171 =cut
172  
173 sub can {
174 my ($self, $method) = @_;
175 foreach my $adaptor (@{$self->{adaptors}}) {
176 return 1 if $adaptor->can($method);
177 }
178 return 0;
179 }
180  
181  
182 =head2 isa
183  
184 Arg [1] : String method name to be called
185 Description : Implementation of UNIVERSAL::isa(). We loop through the
186 available adaptors and return true if any inherited from
187 the given class
188 Returntype : Boolean indicating if any delegating object inherits from the given class
189  
190 =cut
191  
192 sub isa {
193 my ($self, $isa) = @_;
194 foreach my $adaptor (@{$self->{adaptors}}) {
195 return 1 if $adaptor->isa($isa);
196 }
197 return 0;
198 }
199  
200 use vars '$AUTOLOAD';
201  
202 =head2 AUTOLOAD
203  
204 Description : Internal override of AUTLOAD. The code will detect the requested
205 method, loop through all available adaptors and will
206 Returntype : Boolean indicating if any delegating object inherits from the given class
207  
208 =cut
209  
210 sub AUTOLOAD {
211 my ($self, @args) = @_;
212 my @return;
213  
214 #Detect required method
215 $AUTOLOAD =~ /^.*::(\w+)+$/ ;
216 my $sub = $1;
217  
218 foreach my $adaptor (@{$self->{adaptors}}) {
219 my @local_return;
220 if(my $method_ref = $adaptor->can($sub)) {
221 my $ref = $method_ref->($adaptor, @args);
222 push(@return, @{wrap_array($ref)});
223 }
224 else{
225 warning("In Merged Adaptor $adaptor cannot call sub $sub");
226 }
227 }
228 return \@return;
229 }
230  
231 sub DESTROY {
232  
233 }
234  
235 1;