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@fugu-sg.org>
41 You should not use
this module directly. Please check out the
50 package Bio::EnsEMBL::Utils::Converter::bio_ens;
57 use Scalar::Util qw(weaken);
67 my ($caller, @args) = @_;
68 my $class = ref($caller) || $caller;
70 if($class eq
'Bio::EnsEMBL::Utils::Converter::bio_ens'){
72 @params{
map{lc $_} keys %params} = values %params;
73 my $module = $class->_guess_module($params{-in}, $params{-out});
74 return undef unless ($class->_load_module($module));
75 return "$module"->new(@args);
77 my $self = $class->SUPER::new(@args);
78 # $self->_initialize(@args);
84 my ($self, @args) = @_;
85 $self->SUPER::_initialize(@args);
88 $dbdriver, $dbhost, $dbport, $dbuser, $dbpass, $dbname,
89 $analysis, $analysis_dbid, $analysis_logic_name,
90 $contig, $contig_dbid, $contig_name,
93 $self->_rearrange([qw(DBADAPTOR
94 DBDRIVER DBHOST DBPORT DBUSER DBPASS DBNAME
95 ANALYSIS ANALYSIS_DBID ANALYSIS_LOGIC_NAME
96 CONTIG CONTIG_DBID CONTIG_NAME
97 TRANSLATION_ID)], @args);
100 if(defined $dbadaptor){
101 $self->dbadaptor($dbadaptor);
102 }elsif(defined $dbname){
103 $self->ensembl_db(@args);
108 if(defined $analysis){
109 $self->analysis($analysis);
110 # then ignore the analysis_dbid and analysis_logic_name
111 }elsif(defined $analysis_dbid){
112 $self->analysis_dbID($analysis_dbid);
113 }elsif(defined $analysis_logic_name){
114 $self->analysis_logic_name($analysis_logic_name);
116 # No analysis information offered
120 ($contig) = ref($contig) eq
'ARRAY' ? @{$contig} : $contig;
121 $self->contig($contig);
122 }elsif(defined $contig_dbid){
123 $self->contig_dbID($contig_dbid);
124 }elsif(defined $contig_name){
125 $self->contig_name($contig_name);
127 # No contig information
130 if(defined $translation_id){
131 $self->translation_id($translation_id);
137 my ($self, $in, $out) = @_;
139 if($in eq
'Bio::Search::HSP::GenericHSP'){
140 $tail =
'bio_ens_hsp';
141 }elsif($in eq
'Bio::SeqFeature::Generic'){
142 $tail =
'bio_ens_seqFeature';
143 }elsif($in eq
'Bio::SeqFeature::FeaturePair'){
144 $tail =
'bio_ens_featurePair';
145 }elsif($in eq
'Bio::Pipeline::Analysis'){
146 $tail =
'bio_ens_analysis';
147 }elsif($in eq
'Bio::Tools::Prediction::Gene'){
148 $tail =
'bio_ens_predictionGene';
149 }elsif($in eq
'Bio::Tools::Prediction::Exon'){
150 $tail =
'bio_ens_predictionExon';
151 }elsif($in eq
'Bio::SeqFeature::Gene::GeneStructure'){
152 $tail =
'bio_ens_gene';
153 }elsif($in eq
'Bio::SeqFeature::Gene::Transcript'){
154 $tail =
'bio_ens_transcript';
155 }elsif($in eq
'Bio::SeqFeature::Gene::Exon'){
156 $tail =
'bio_ens_exon';
158 $self->throw(
"[$in] to [$out], not supported");
160 return "Bio::EnsEMBL::Utils::Converter::$tail";
167 Usage : $self->analysis
168 Function: get and set
for analysis
169 Return : L<Bio::EnsEMBL::Analysis>
170 Args : L<Bio::EnsEMBL::Analysis>
175 my ($self, $arg) = @_;
177 # convert the analysis, if it's not Bio::Pipeline::Analysis
178 if($arg->isa(
'Bio::Pipeline::Analysis')){
180 -in =>
'Bio::Pipeline::Analysis',
181 -out =>
'Bio::EnsEMBL::Analysis'
183 ($arg) = @{ $converter_for_analysis->convert([$arg]) };
186 $self->throws(
"A Bio::EnsEMBL::Analysis object expected.")
187 unless($arg->isa(
'Bio::EnsEMBL::Analysis'));
188 $self->{_analysis} = $arg;
189 $self->{_analysis_dbid} = $arg->dbID;
190 $self->{_analysis_logic_name} = $arg->logic_name;
192 return $self->{_analysis};
199 Usage : $self->contig
200 Function: get and set
for contig
207 my ($self, $arg) = @_;
209 if($arg->isa(
'Bio::EnsEMBL::RawContig')){
210 $self->{_contig_dbid} = $arg->dbID;
211 $self->{_contig_name} = $arg->name;
212 }elsif($arg->isa(
'Bio::EnsEMBL::Slice')){
213 $self->{_slice_dbid} = $arg->dbID;
214 }elsif($arg->isa(
'Bio::PrimarySeqI')){
217 $self->throw(
"a Bio::EnsEMBL::RawContig needed");
219 $self->{_contig} = $arg;
222 return $self->{_contig};
228 Usage : $self->dbadaptor
229 Function: get and set
for dbadaptor
230 Return : L<Bio::EnsEMBL::DBSQL::DBAdaptor>
231 Args : L<Bio::EnsEMBL::DBSQL::DBAdaptor>
236 my ($self, $arg) = @_;
238 $self->throws(
"A Bio::EnsEMBL::DBSQL::DBAdaptor object expected.") unless(defined $arg);
239 weaken($self->{_dbadaptor} = $arg);
241 return $self->{_dbadaptor};
255 my ($self, @args) = @_;
257 my ($dbdriver, $dbhost, $dbport, $dbuser, $dbpass, $dbname) = $self->_rearrange(
258 [qw(DBDRIVER DBHOST DBPORT DBUSER DBPASS DBNAME)], @args);
261 -driver => $dbdriver,
268 $self->dbadaptor($dbadaptor);
273 Title : analysis_dbID
282 my ($self, $arg) = @_;
287 $analysis = $self->dbadaptor->get_AnalysisAdaptor->fetch_by_dbID($arg);
289 $self->throw(
"Failed during fetching analysis by dbID\n$@")
if($@);
290 $self->analysis($analysis);
292 $self->{_analysis_dbid};
296 =head2 analysis_logic_name
298 Title : analysis_logic_name
306 sub analysis_logic_name {
307 my ($self, $arg) = @_;
309 return $self->{_analysis_logic_name} unless(defined $arg);
313 $self->dbadaptor->get_AnalysisAdaptor->fetch_by_logic_name($arg);
315 $self->throw(
"Not found analysis with logic name as \[$arg\]\n$@")
if($@);
317 $self->analysis($analysis);
318 return $self->{_analysis_logic_name};
324 Usage : $self->contig_dbID
325 Function: get and set
for contig_dbID
332 my ($self, $arg) = @_;
337 $self->dbadaptor->get_RawContigAdaptor->fetch_by_dbID($arg);
339 $self->throw(
"Failed during fetching contig by dbID\n$@")
if($@);
340 $self->contig($contig);
342 return $self->{_contig_dbid};
347 Usage : $self->contig_name
348 Function: get and set
for contig_name
354 my ($self, $arg) = @_;
359 $self->dbadaptor->get_RawContigAdaptor->fetch_by_name($arg);
361 $self->throw(
"Failed during fetching contig by dbID\n$@")
if($@);
362 $self->contig($contig);
364 return $self->{_contig_name};
370 Function: get and set
for slice
371 Return : L<Bio::EnsEMBL::Slice>
372 Args : L<Bio::EnsEMBL::Slice>
376 my ($self, $arg) = @_;
379 $self->throw(
"undefined dbadpator") unless defined $self->dbadpaotr;
382 my $sliceAdaptor = $self->dbadaptor->get_SliceAdaptor;
383 $slice = $sliceAdaptor->fetch_by_dbID($arg);
386 $self->throw(
"Failed to fetch slice by dbID\n$@")
if($@);
387 $self->contig($slice);
391 =head2 slice_chr_start_end
392 Title : slice_chr_start_end
393 Usage : my $slice = $self->slice_chr_start_end($chr, $start, $end);
394 Function: get and set
for slice_chr_start_end
399 sub slice_chr_start_end {
400 my ($self, $chr, $start, $end) = @_;
401 if(defined($chr) && defined($start) && defined($end)){
404 my $sliceAdaptor = $self->dbadaptor->get_SliceAdaptor;
405 $slice = $sliceAdaptor->fetch_by_chr_start_end($chr, $start, $end);
407 $self->throw(
"Failed to fetch slice by chr start end\n$@")
if($@);
408 $self->contig($slice);
413 my ($self, $arg) = @_;
414 return $self->{_translation_id} = $arg
if(defined($arg));
415 return $self->{_translation_id};