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
31 Juguang Xiao <juguang@tll.org.sg>
42 -in =>
'Bio::SeqFeature::Generic',
43 -out =>
'Bio::EnsEMBL::SimpleFeature'
46 my ( $fearture1, $feature2 );
47 my $ens_simple_features =
48 $converter->convert( [ $feature1, $feature2 ] );
49 my @ens_simple_features = @{$ens_simple_features};
53 Module to converter the business objects between
EnsEMBL and any other
54 projects, currently BioPerl.
56 What the ready conversions are,
61 Bio::Tools::Prediction::Gene -> Bio::EnsEMBL::PredictionTranscript
62 Bio::Tools::Prediction::Exon -> Bio::EnsEMBL::Exon
63 Bio::Pipeline::Analysis -> Bio::EnsEMBL::Analysis
70 package Bio::EnsEMBL::Utils::Converter;
78 my $converter = Bio::EnsEMBL::Utils::Converter->new(
79 -in => 'Bio::SeqFeature::Generic
',
83 Function: constructor for converter object
84 Returns : L<Bio::EnsEMBL::Utils::Converter>
86 in - the module name of the input.
87 out - the module name of the output.
88 analysis - a Bio::EnsEMBL::Analysis object, if converting other objects to EnsEMBL features.
89 contig - a Bio::EnsEMBL::RawContig object, if converting other objects to EnsEMBL features.
94 my ($caller, @args) = @_;
95 my $class = ref($caller) || $caller;
97 if($class =~ /Bio::EnsEMBL::Utils::Converter::(\S+)/){
98 my $self = $class->SUPER::new(@args);
99 $self->_initialize(@args);
103 @params{map {lc $_} keys %params} = values %params;
104 my $module = $class->_guess_module($params{-in}, $params{-out});
106 return undef unless($class->_load_module($module));
107 return "$module"->new(@args);
111 # This would be invoked by sub-module's _initialize.
114 my ($self, @args) = @_;
116 my ($in, $out) = $self->_rearrange([qw(IN OUT)], @args);
124 Usage : $module = $class->_guess_module(
125 'Bio::EnsEMBL::SimpleFeature',
126 'Bio::EnsEMBL::Generic'
132 my ($self, $in, $out) = @_;
134 $self->throw(
"Cannot convert between EnsEMBL objects.\n[$in] to [$out]");
136 return 'Bio::EnsEMBL::Utils::Converter::ens_bio';
138 return 'Bio::EnsEMBL::Utils::Converter::bio_ens';
140 $self->throw(
"Cannot convert between non-EnsEMBL objects.\n[$in] to [$out]");
147 Usage : my $array_ref = $converter->convert(\@input);
148 Function: does the actual conversion
149 Returns : an array ref of converted objects
150 Args : an array ref of converting objects
155 my ($self, $input) = @_;
157 $input || $self->throw(
"Need a ref of array of input objects to convert");
159 my $output_module = $self->out;
160 $self->throw(
"Cannot load [$output_module] perl module")
161 unless $self->_load_module($output_module);
163 unless(ref($input) eq
'ARRAY'){
164 $self->warn(
"The input is supposed to be an array ref");
165 return $self->_convert_single($input);
170 push(@output, $self->_convert_single($_));
177 shift->throw(
"Not implemented. Please check the instance subclass");
180 foreach my $field (qw(in out)){
181 my $slot=__PACKAGE__ .
"::$field";
182 no strict
'refs'; ## no critic
185 $self->{$slot}=shift
if @_;
186 return $self->{$slot};
192 This method is copied from Bio::Root::Root
197 my ($self, $name) = @_;
198 my ($module, $load, $m);
199 $module =
"_<$name.pm";
200 return 1
if $main::{$module};
202 # untaint operation for safe web-based running (modified after a fix
203 # a fix by Lincoln) HL
204 if ($name !~ /^([\w:]+)$/) {
205 $self->throw(
"$name is an illegal perl package name");
209 my $io = Bio::Root::IO->new();
210 # catfile comes from IO
211 $load = $io->catfile((split(/::/,$load)));
216 $self->throw(
"Failed to load module $name. ".$@);