EnsEMBL/Utils/Converter/bio_ens_hsp.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 95 CC 8 SCAR 23.9
CC
8
Cov
0%
_convert_single
20.0
_convert_single_to_alignFeature
20.0
_bio_ens_seqFeature_converter
6.0
CRAP 10.9
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 =cut
30  
31  
32 package Bio::EnsEMBL::Utils::Converter::bio_ens_hsp;
33 $Bio::EnsEMBL::Utils::Converter::bio_ens_hsp::VERSION = '114.0.0';
34 use strict;
35 use vars qw(@ISA);
36 use Bio::EnsEMBL::Utils::Converter::bio_ens;
37 use Bio::EnsEMBL::ProteinFeature;
38  
39 @ISA = qw(Bio::EnsEMBL::Utils::Converter::bio_ens);
40  
41 sub _initialize {
42 my ($self, @args) = @_;
43 $self->SUPER::_initialize(@args);
44  
45 # After super initialized, analysis and contig are ready.
46 my $bio_ens_seqFeature_converter = new Bio::EnsEMBL::Utils::Converter(
47 -in => 'Bio::SeqFeature::Generic',
48 -out => 'Bio::EnsEMBL::SeqFeature',
49 -analysis => $self->analysis,
50 -contig => $self->contig
51 );
52 $self->_bio_ens_seqFeature_converter($bio_ens_seqFeature_converter);
53  
54 }
55  
56 sub _convert_single {
57 my ($self, $hsp) = @_;
58  
59 unless(ref($hsp) && $hsp->isa('Bio::Search::HSP::GenericHSP')){
60 $self->throw("a GenericHSP object needed");
61 }
62
63 my $in = $self->in;
64 my $out = $self->out;
65  
66 if($out =~ /^Bio::EnsEMBL::ProteinFeature$/){
67 return $self->_convert_single_to_proteinFeature($hsp);
68 }elsif($out =~/^Bio::EnsEMBL::(DnaDna|DnaPep|PepDna)AlignFeature/){
69 return $self->_convert_single_to_alignFeature($hsp);
70 }else{
71 $self->throw("[$in]->[$out], not implemented");
72 }
73 }
74  
75 sub _convert_single_to_featurePair {
76 my ($self, $hsp) = @_;
77
78 my $bio_ens_seqFeature_converter = $self->_bio_ens_seqFeature_converter;
79 my $ens_feature1 = $bio_ens_seqFeature_converter->_convert_single(
80 $hsp->feature1);
81 my $ens_feature2 = $bio_ens_seqFeature_converter->_convert_single(
82 $hsp->feature2);
83  
84 $ens_feature1->p_value($hsp->evalue);
85 $ens_feature1->score($hsp->score);
86 $ens_feature1->percent_id($hsp->percent_identity);
87 $ens_feature2->p_value($hsp->evalue);
88 $ens_feature2->score($hsp->score);
89 $ens_feature2->percent_id($hsp->percent_identity);
90  
91 my $featurePair = Bio::EnsEMBL::FeaturePair->new(
92 -feature1 => $ens_feature1,
93 -feature2 => $ens_feature2
94 );
95  
96 return $featurePair;
97 }
98  
99 sub _convert_single_to_proteinFeature {
100 my ($self, $hsp) = @_;
101
102 my $ens_featurePair = $self->_convert_single_to_featurePair($hsp);
103 my $ens_proteinFeature = Bio::EnsEMBL::ProteinFeature->new(
104 -feature1 => $ens_featurePair->feature1,
105 -feature2 => $ens_featurePair->feature2
106 );
107 $ens_proteinFeature->seqname($self->translation_id);
108 return $ens_proteinFeature;
109 }
110  
111 sub _convert_single_to_alignFeature {
112 my ($self, $hsp) = @_;
113 my $ens_featurePair = $self->_convert_single_to_featurePair($hsp);
114 my $cigar_string = $hsp->cigar_string;
115 my @args = (
116 -feature1 => $ens_featurePair->feature1,
117 -feature2 => $ens_featurePair->feature2,
118 -cigar_string => $hsp->cigar_string
119 );
120 my $contig = $self->contig;
121 # choose the AlignFeature based on the blast program
122 my $program = $hsp->algorithm;
123  
124 $self->throw("HSP does not have algorithm value") unless(defined($program));
125 my $align_feature;
126 if($program =~ /blastn/i){
127 $align_feature = new Bio::EnsEMBL::DnaDnaAlignFeature(@args);
128 # $align_feature->attach_seq($contig);
129 }elsif($program =~ /blastx/i){
130 $align_feature = new Bio::EnsEMBL::DnaPepAlignFeature(@args);
131 # $align_feature->attach_seq($contig);
132 }else{
133 $self->throw("\[$program\] is not supported yet");
134 }
135 return $align_feature;
136 }
137  
138 sub _bio_ens_seqFeature_converter {
139 my ($self) = shift ;
140 return $self->{_bio_ens_seqFeature_converter} = shift if(@_);
141 return $self->{_bio_ens_seqFeature_converter};
142 }
143 1;