EnsEMBL/Utils/Converter/bio_ens.pm untested

filter: Statementstmt 0.0% 0 / 151 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 9 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 282 CC 45 SCAR 38.9
CC
45
Cov
0%
_initialize
132.0
_guess_module
110.0
contig
30.0
CRAP 49.1
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 =head1 AUTHOR
30  
31 Juguang Xiao <juguang@fugu-sg.org>
32  
33 =cut
34  
35 =head1 NAME
36  
37 Bio::EnsEMBL::Utils::Converter::bio_ens
38  
39 =head1 SYNOPISIS
40  
41 You should not use this module directly. Please check out the
42 Bio::EnsEMBL::Utils::Converter module.
43  
44 =head1 DESCRIPTION
45  
46 =head1 METHODS
47  
48 =cut
49  
50 package Bio::EnsEMBL::Utils::Converter::bio_ens;
51 $Bio::EnsEMBL::Utils::Converter::bio_ens::VERSION = '114.0.0_50'; # TRIAL
52 $Bio::EnsEMBL::Utils::Converter::bio_ens::VERSION = '114.0.050';
53 use strict;
54 use vars qw(@ISA);
55 use Bio::EnsEMBL::Analysis;
56 use Bio::EnsEMBL::DBSQL::DBAdaptor;
57 use Bio::EnsEMBL::Utils::Converter;
58 use Scalar::Util qw(weaken);
59 @ISA = qw(Bio::EnsEMBL::Utils::Converter);
60  
61 =head2 new
62  
63 Please see Bio::EnsEMBL::Utils::Converter::new
64  
65 =cut
66  
67 sub new {
68 my ($caller, @args) = @_;
69 my $class = ref($caller) || $caller;
70  
71 if($class eq 'Bio::EnsEMBL::Utils::Converter::bio_ens'){
72 my %params = @args;
73 @params{map{lc $_} keys %params} = values %params;
74 my $module = $class->_guess_module($params{-in}, $params{-out});
75 return undef unless ($class->_load_module($module));
76 return "$module"->new(@args);
77 }else{
78 my $self = $class->SUPER::new(@args);
79 # $self->_initialize(@args);
80 return $self;
81 }
82 }
83  
84 sub _initialize {
85 my ($self, @args) = @_;
86 $self->SUPER::_initialize(@args);
87
88 my ($dbadaptor,
89 $dbdriver, $dbhost, $dbport, $dbuser, $dbpass, $dbname,
90 $analysis, $analysis_dbid, $analysis_logic_name,
91 $contig, $contig_dbid, $contig_name,
92 $translation_id) =
93
94 $self->_rearrange([qw(DBADAPTOR
95 DBDRIVER DBHOST DBPORT DBUSER DBPASS DBNAME
96 ANALYSIS ANALYSIS_DBID ANALYSIS_LOGIC_NAME
97 CONTIG CONTIG_DBID CONTIG_NAME
98 TRANSLATION_ID)], @args);
99  
100
101 if(defined $dbadaptor){
102 $self->dbadaptor($dbadaptor);
103 }elsif(defined $dbname){
104 $self->ensembl_db(@args);
105 }else{
106 # No db information.
107 }
108
109 if(defined $analysis){
110 $self->analysis($analysis);
111 # then ignore the analysis_dbid and analysis_logic_name
112 }elsif(defined $analysis_dbid){
113 $self->analysis_dbID($analysis_dbid);
114 }elsif(defined $analysis_logic_name){
115 $self->analysis_logic_name($analysis_logic_name);
116 }else{
117 # No analysis information offered
118 }
119
120 if(defined $contig){
121 ($contig) = ref($contig) eq 'ARRAY' ? @{$contig} : $contig;
122 $self->contig($contig);
123 }elsif(defined $contig_dbid){
124 $self->contig_dbID($contig_dbid);
125 }elsif(defined $contig_name){
126 $self->contig_name($contig_name);
127 }else{
128 # No contig information
129 }
130  
131 if(defined $translation_id){
132 $self->translation_id($translation_id);
133 }
134 }
135  
136  
137 sub _guess_module {
138 my ($self, $in, $out) = @_;
139 my $tail;
140 if($in eq 'Bio::Search::HSP::GenericHSP'){
141 $tail = 'bio_ens_hsp';
142 }elsif($in eq 'Bio::SeqFeature::Generic'){
143 $tail = 'bio_ens_seqFeature';
144 }elsif($in eq 'Bio::SeqFeature::FeaturePair'){
145 $tail = 'bio_ens_featurePair';
146 }elsif($in eq 'Bio::Pipeline::Analysis'){
147 $tail = 'bio_ens_analysis';
148 }elsif($in eq 'Bio::Tools::Prediction::Gene'){
149 $tail = 'bio_ens_predictionGene';
150 }elsif($in eq 'Bio::Tools::Prediction::Exon'){
151 $tail = 'bio_ens_predictionExon';
152 }elsif($in eq 'Bio::SeqFeature::Gene::GeneStructure'){
153 $tail = 'bio_ens_gene';
154 }elsif($in eq 'Bio::SeqFeature::Gene::Transcript'){
155 $tail = 'bio_ens_transcript';
156 }elsif($in eq 'Bio::SeqFeature::Gene::Exon'){
157 $tail = 'bio_ens_exon';
158 }else{
159 $self->throw("[$in] to [$out], not supported");
160 }
161 return "Bio::EnsEMBL::Utils::Converter::$tail";
162 }
163  
164  
165 =head2 analysis
166  
167 Title : analysis
168 Usage : $self->analysis
169 Function: get and set for analysis
170 Return : L<Bio::EnsEMBL::Analysis>
171 Args : L<Bio::EnsEMBL::Analysis>
172  
173 =cut
174  
175 sub analysis {
176 my ($self, $arg) = @_;
177 if(defined($arg)){
178 # convert the analysis, if it's not Bio::Pipeline::Analysis
179 if($arg->isa('Bio::Pipeline::Analysis')){
180 my $converter_for_analysis = new Bio::EnsEMBL::Utils::Converter(
181 -in => 'Bio::Pipeline::Analysis',
182 -out => 'Bio::EnsEMBL::Analysis'
183 );
184 ($arg) = @{ $converter_for_analysis->convert([$arg]) };
185 }
186  
187 $self->throws("A Bio::EnsEMBL::Analysis object expected.")
188 unless($arg->isa('Bio::EnsEMBL::Analysis'));
189 $self->{_analysis} = $arg;
190 $self->{_analysis_dbid} = $arg->dbID;
191 $self->{_analysis_logic_name} = $arg->logic_name;
192 }
193 return $self->{_analysis};
194 }
195  
196  
197 =head2 contig
198  
199 Title : contig
200 Usage : $self->contig
201 Function: get and set for contig
202 Return :
203 Args :
204  
205 =cut
206  
207 sub contig {
208 my ($self, $arg) = @_;
209 if(defined($arg)){
210 if($arg->isa('Bio::EnsEMBL::RawContig')){
211 $self->{_contig_dbid} = $arg->dbID;
212 $self->{_contig_name} = $arg->name;
213 }elsif($arg->isa('Bio::EnsEMBL::Slice')){
214 $self->{_slice_dbid} = $arg->dbID;
215 }elsif($arg->isa('Bio::PrimarySeqI')){
216 ;
217 }else{
218 $self->throw("a Bio::EnsEMBL::RawContig needed");
219 }
220 $self->{_contig} = $arg;
221
222 }
223 return $self->{_contig};
224 }
225
226 =head2 dbadaptor
227  
228 Title : dbadaptor
229 Usage : $self->dbadaptor
230 Function: get and set for dbadaptor
231 Return : L<Bio::EnsEMBL::DBSQL::DBAdaptor>
232 Args : L<Bio::EnsEMBL::DBSQL::DBAdaptor>
233  
234 =cut
235  
236 sub dbadaptor {
237 my ($self, $arg) = @_;
238 if(defined($arg)){
239 $self->throws("A Bio::EnsEMBL::DBSQL::DBAdaptor object expected.") unless(defined $arg);
240 weaken($self->{_dbadaptor} = $arg);
241 }
242 return $self->{_dbadaptor};
243 }
244  
245 =head2 ensembl_db
246  
247 Title : ensembl_db
248 Usage :
249 Function:
250 Return :
251 Args :
252  
253 =cut
254  
255 sub ensembl_db {
256 my ($self, @args) = @_;
257
258 my ($dbdriver, $dbhost, $dbport, $dbuser, $dbpass, $dbname) = $self->_rearrange(
259 [qw(DBDRIVER DBHOST DBPORT DBUSER DBPASS DBNAME)], @args);
260  
261 my $dbadaptor = new Bio::EnsEMBL::DBSQL::DBAdaptor(
262 -driver => $dbdriver,
263 -host => $dbhost,
264 -port => $dbport,
265 -user => $dbuser,
266 -pass => $dbpass,
267 -dbname => $dbname
268 );
269 $self->dbadaptor($dbadaptor);
270 }
271  
272 =head2 analysis_dbID
273  
274 Title : analysis_dbID
275 Usage :
276 Function:
277 Return :
278 Args :
279  
280 =cut
281  
282 sub analysis_dbID {
283 my ($self, $arg) = @_;
284  
285 if(defined $arg){
286 my $analysis;
287 eval{
288 $analysis = $self->dbadaptor->get_AnalysisAdaptor->fetch_by_dbID($arg);
289 };
290 $self->throw("Failed during fetching analysis by dbID\n$@") if($@);
291 $self->analysis($analysis);
292 }
293 $self->{_analysis_dbid};
294 }
295  
296  
297 =head2 analysis_logic_name
298  
299 Title : analysis_logic_name
300 Usage :
301 Function:
302 Return :
303 Args :
304  
305 =cut
306  
307 sub analysis_logic_name {
308 my ($self, $arg) = @_;
309
310 return $self->{_analysis_logic_name} unless(defined $arg);
311 my $analysis;
312 eval{
313 $analysis =
314 $self->dbadaptor->get_AnalysisAdaptor->fetch_by_logic_name($arg);
315 };
316 $self->throw("Not found analysis with logic name as \[$arg\]\n$@") if($@);
317  
318 $self->analysis($analysis);
319 return $self->{_analysis_logic_name};
320 }
321  
322 =head2 contig_dbID
323  
324 Title : contig_dbID
325 Usage : $self->contig_dbID
326 Function: get and set for contig_dbID
327 Return :
328 Args :
329  
330 =cut
331  
332 sub contig_dbID {
333 my ($self, $arg) = @_;
334 if(defined($arg)){
335 my $contig;
336 eval{
337 $contig =
338 $self->dbadaptor->get_RawContigAdaptor->fetch_by_dbID($arg);
339 };
340 $self->throw("Failed during fetching contig by dbID\n$@") if($@);
341 $self->contig($contig);
342 }
343 return $self->{_contig_dbid};
344 }
345  
346 =head2 contig_name
347 Title : contig_name
348 Usage : $self->contig_name
349 Function: get and set for contig_name
350 Return :
351 Args :
352 =cut
353  
354 sub contig_name {
355 my ($self, $arg) = @_;
356 if(defined($arg)){
357 my $contig;
358 eval{
359 $contig =
360 $self->dbadaptor->get_RawContigAdaptor->fetch_by_name($arg);
361 };
362 $self->throw("Failed during fetching contig by dbID\n$@") if($@);
363 $self->contig($contig);
364 }
365 return $self->{_contig_name};
366 }
367  
368 =head2 slice_dbID
369 Title : slice
370 Usage : $self->slice
371 Function: get and set for slice
372 Return : L<Bio::EnsEMBL::Slice>
373 Args : L<Bio::EnsEMBL::Slice>
374 =cut
375  
376 sub slice_dbID {
377 my ($self, $arg) = @_;
378 if(defined($arg)){
379 my $slice;
380 $self->throw("undefined dbadpator") unless defined $self->dbadpaotr;
381  
382 eval{
383 my $sliceAdaptor = $self->dbadaptor->get_SliceAdaptor;
384 $slice = $sliceAdaptor->fetch_by_dbID($arg);
385 };
386
387 $self->throw("Failed to fetch slice by dbID\n$@") if($@);
388 $self->contig($slice);
389 }
390 }
391  
392 =head2 slice_chr_start_end
393 Title : slice_chr_start_end
394 Usage : my $slice = $self->slice_chr_start_end($chr, $start, $end);
395 Function: get and set for slice_chr_start_end
396 Return :
397 Args :
398 =cut
399  
400 sub slice_chr_start_end {
401 my ($self, $chr, $start, $end) = @_;
402 if(defined($chr) && defined($start) && defined($end)){
403 my $slice;
404 eval{
405 my $sliceAdaptor = $self->dbadaptor->get_SliceAdaptor;
406 $slice = $sliceAdaptor->fetch_by_chr_start_end($chr, $start, $end);
407 };
408 $self->throw("Failed to fetch slice by chr start end\n$@") if($@);
409 $self->contig($slice);
410 }
411 }
412
413 sub translation_id {
414 my ($self, $arg) = @_;
415 return $self->{_translation_id} = $arg if(defined($arg));
416 return $self->{_translation_id};
417 }
418 1;