EnsEMBL/Utils/Converter/bio_ens_hsp.pm untested

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