EnsEMBL/Utils/Converter/bio_ens_featurePair.pm untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 124 CC 8 SCAR 25.3
CC
8
Cov
0%
_convert_single
30.0
_convert_single_to_repeatFeature
20.0
_initialize
2.0
CRAP 12.6
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@tll.org.sg>
32  
33 =cut
34  
35 =head1 NAME
36  
37 Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair
38  
39 =head1 SYNOPISIS
40  
41 =head1 DESCRIPTION
42  
43 =head1 METHODS
44  
45 =cut
46  
47 package Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair;
48 $Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair::VERSION = '114.0.0_50'; # TRIAL
49 $Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair::VERSION = '114.0.050';
50 use strict;
51 use vars qw(@ISA);
52  
53 use Bio::EnsEMBL::FeaturePair;
54 use Bio::EnsEMBL::RepeatConsensus;
55 use Bio::EnsEMBL::ProteinFeature;
56 use Bio::EnsEMBL::Utils::Converter;
57 use Bio::EnsEMBL::Utils::Converter::bio_ens;
58 @ISA = qw(Bio::EnsEMBL::Utils::Converter::bio_ens);
59  
60 sub _initialize {
61 my ($self, @args) = @_;
62 $self->SUPER::_initialize(@args);
63 my ($translation_id) = $self->_rearrange([qw(TRANSLATION_ID)], @args);
64 $self->translation_id($translation_id);
65
66 # internal converter for seqFeature
67 $self->{_bio_ens_seqFeature} = new Bio::EnsEMBL::Utils::Converter (
68 -in => 'Bio::SeqFeature::Generic',
69 -out => 'Bio::EnsEMBL::SeqFeature',
70 );
71 }
72  
73 sub _convert_single {
74 my ($self, $pair) = @_;
75 unless($pair && $pair->isa('Bio::SeqFeature::FeaturePair')){
76 $self->throw('a Bio::SeqFeature::FeaturePair object needed');
77 }
78
79 if($self->out eq 'Bio::EnsEMBL::RepeatFeature'){
80 return $self->_convert_single_to_repeatFeature($pair);
81 }elsif($self->out eq 'Bio::EnsEMBL::FeaturePair'){
82 return $self->_convert_single_to_featurePair($pair);
83 }elsif($self->out eq 'Bio::EnsEMBL::ProteinFeature'){
84 return $self->_convert_single_to_proteinFeature($pair);
85 }else{
86 my $output_module = $self->out;
87 $self->throw("Cannot covert to [$output_module]");
88 }
89 }
90  
91 sub _convert_single_to_featurePair {
92 my ($self, $pair) = @_;
93 my $feature1 = $pair->feature1;
94 my $feature2 = $pair->feature2;
95 $self->{_bio_ens_seqFeature}->contig($self->contig);
96 $self->{_bio_ens_seqFeature}->analysis($self->analysis);
97 my $ens_f1 = $self->{_bio_ens_seqFeature}->_convert_single($feature1);
98 my $ens_f2 = $self->{_bio_ens_seqFeature}->_convert_single($feature2);
99 my $ens_fp = Bio::EnsEMBL::FeaturePair->new(
100 -feature1 => $ens_f1,
101 -feature2 => $ens_f2
102 );
103 return $ens_fp;
104 }
105  
106 sub _convert_single_to_proteinFeature {
107 my ($self, $pair) = @_;
108 my $featurePair = $self->_convert_single_to_featurePair($pair);
109 my $proteinFeature = Bio::EnsEMBL::ProteinFeature->new(
110 -feature1 => $featurePair->feature1,
111 -feature2 => $featurePair->feature2
112 );
113 $proteinFeature->seqname($self->translation_id);
114 return $proteinFeature;
115 }
116  
117 sub _convert_single_to_repeatFeature {
118 my ($self, $pair) = @_;
119 my $feature1 = $pair->feature1;
120 my $feature2 = $pair->feature2;
121 my $ens_repeatfeature = new Bio::EnsEMBL::RepeatFeature(
122 -seqname => $feature1->seq_id,
123 -start => $feature1->start,
124 -end => $feature1->end,
125 -strand => $feature1->strand,
126 -source_tag => $feature1->source_tag,
127 );
128
129 my ($h_start, $h_end);
130 if($feature1->strand == 1){
131 $h_start = $feature2->start;
132 $h_end = $feature2->end;
133 }elsif($feature1->strand == -1){
134 $h_start = $feature2->end;
135 $h_end = $feature2->start;
136 }else{
137 $self->throw("strand cannot be outside of (1, -1)");
138 }
139  
140 $ens_repeatfeature->hstart($h_start);
141 $ens_repeatfeature->hend($h_end);
142 my $repeat_name = $feature2->seq_id;
143 my $repeat_class = $feature1->primary_tag;
144 $repeat_class ||= $feature2->primary_tag;
145 $repeat_class ||= "not sure";
146 my $ens_repeat_consensus =
147 $self->_create_consensus($repeat_name, $repeat_class);
148 $ens_repeatfeature->repeat_consensus($ens_repeat_consensus);
149
150 my($contig) = ref ($self->contig) eq 'ARRAY' ? @{$self->contig} : $self->contig;
151  
152 $ens_repeatfeature->attach_seq($contig);
153 $ens_repeatfeature->analysis($self->analysis);
154 return $ens_repeatfeature;
155 }
156  
157 sub _create_consensus{
158 my ($self, $repeat_name, $repeat_class) = @_;
159 my $consensus = new Bio::EnsEMBL::RepeatConsensus;
160 $consensus->name($repeat_name);
161 $consensus->repeat_class($repeat_class);
162 return $consensus;
163 }
164  
165 1;