comparison variant_effect_predictor/Bio/EnsEMBL/DBSQL/MergedAdaptor.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1f6dce3d34e0
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::DBSQL::MergedAdaptor
24
25 =head1 SYNOPSIS
26
27 $merged_adaptor = new Bio::EnsEMBL::DBSQL::MergedAdaptor(
28 -species => "human",
29 -type => "Population"
30 );
31
32 =head1 DESCRIPTION
33
34 The MergedAdaptor object is merely a list of adaptors. AUTOLOAD is used
35 to call a subroutine on each adaptor and merge the results.
36
37 =head1 METHODS
38
39 =cut
40
41
42 package Bio::EnsEMBL::DBSQL::MergedAdaptor;
43
44
45 use vars qw(@ISA);
46 use strict;
47
48 use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
49 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
50 use Bio::EnsEMBL::Registry;
51 my $reg = "Bio::EnsEMBL::Registry";
52
53
54 =head2 new
55
56 Arg [SPECIES]: (optional) string
57 species name to get adaptors for
58 Arg [TYPE] : (optional) string
59 type to get adaptors for
60 Arg [GROUPS] : (optional) ref to list
61 Example : $MergedAdaptor = new
62 : Bio::EnsEMBL::DBSQL::MergedAdaptor(-species=> 'human', -type =>'Population', -groups => ['Sanger','Ensembl']);
63
64 Description: Creates a new MergedAdaptor
65 Returntype : Bio::EnsEMBL::DBSQL::MergedAdaptor
66 Exceptions : throws if species or type not specified
67 Caller : general
68 Status : At Risk
69 : Under development
70
71 =cut
72
73 sub new {
74 my ($class,@args) = @_;
75
76 my $self ={};
77 bless $self,$class;
78
79 my ($species, $type, $groups) =
80 rearrange([qw(SPECIES TYPE GROUPS)], @args);
81
82 if(!defined($species)|| !defined($type)){
83 die "Species and Type must be specified\n";
84 }
85
86 my @adaps;
87 if (!defined ($groups)){
88 #get all adaptors for that species and type
89 @adaps = @{$reg->get_all_adaptors(-species => $species, -type => $type)};
90 }
91 else{
92 #get only specified adaptors for the particular groups
93 foreach my $group (@{$groups}){
94 push @adaps, $reg->get_adaptor($species,$group,$type);
95 }
96 }
97
98 my @list =();
99 push(@list,@adaps);
100 $self->{'list'}= \@list;
101
102 return $self;
103 }
104
105 =head2 add_list
106
107 Example : $MergedAdaptor->add_list(@adaptors);
108 Description: adds a list of adaptors to the Merged adaptor list.
109 Returntype : none
110 Exceptions : none
111 Status : At Risk
112 : Under development
113
114 =cut
115
116 sub add_list{
117 my ($self, @arr) = @_;
118
119 foreach my $adap (@arr){
120 $self->add_adaptor($adap);
121 }
122 }
123
124 =head2 add_adaptor
125
126 Example : $MergedAdaptor->add_adaptor(@adaptors);
127 Description: adds an adaptor to the Merged adaptor list.
128 Returntype : none
129 Exceptions : none
130 Status : At Risk
131 : Under development
132
133 =cut
134
135 sub add_adaptor{
136 my ($self,$adaptor)=@_;
137
138 if(!defined ($self->{'list'})){
139 my @list =();
140 push(@list,$adaptor);
141 $self->{'list'}= \@list;
142 }
143 else{
144 push(@{$self->{'list'}},$adaptor);
145 }
146 }
147
148
149 sub printit{
150 my ($self)=@_;
151
152 foreach my $adaptor (@{$self->{'list'}}){
153 print "printit $adaptor\t".$adaptor->db->group()."\n";
154 }
155 }
156
157
158 use vars '$AUTOLOAD';
159
160 sub AUTOLOAD {
161 my ($self,@args) = @_;
162 my @array_return=();
163 my $ref_return = undef;
164 $AUTOLOAD =~ /^.*::(\w+)+$/ ;
165
166 my $sub = $1;
167
168 foreach my $adaptor (@{$self->{'list'}}) {
169 my $ref;
170 if($adaptor->can($sub)){
171 $ref = $adaptor->$sub(@args);
172 if( ref($ref) eq 'ARRAY' ) {
173 push @array_return, @{$ref};
174 } else {
175 push @array_return, $ref;
176 }
177 }
178 else{ # end of can
179 warn("In Merged Adaptor $adaptor cannot call sub $sub");
180 }
181 }
182 return \@array_return;
183 }
184
185 sub DESTROY{
186 }
187
188 1;