Graph/HitWrapper.pm untested

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 26 Podpod 0.0% 0 / 20 totaltotal 0.0% 0 / 152 CC 4 SCAR 12.0
CC
4
Cov
0%
getStrandTypeCount
12.0
sortHSPs
6.0
BEGIN
2.0
CRAP 3.3
1 package Bio::GMOD::Blast::Graph::HitWrapper;
2 BEGIN {
3 $Bio::GMOD::Blast::Graph::HitWrapper::AUTHORITY = 'cpan:RBUELS';
4 }
5 BEGIN {
6 $Bio::GMOD::Blast::Graph::HitWrapper::VERSION = '0.06';
7 }
8 #####################################################################
9 #
10 # Cared for by Shuai Weng <shuai@genome.stanford.edu>
11 #
12 # Originally created by John Slenk <jces@genome.stanford.edu>
13 #
14 # You may distribute this module under the same terms as perl itself
15 #-----------------------------------------------------------------
16  
17 use Bio::GMOD::Blast::Graph::BaseObj;
18 use Bio::GMOD::Blast::Graph::MyUtils;
19 use Bio::GMOD::Blast::Graph::MyDebug qw( assert dmsg );
20 use Bio::GMOD::Blast::Graph::BucketSet;
21 use Bio::GMOD::Blast::Graph::IntSpan;
22 use Bio::GMOD::Blast::Graph::ScientificNotation;
23  
24 @ISA = qw( Bio::GMOD::Blast::Graph::BaseObj );
25  
26 ##################################################################
27 my $kHit
28 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "hit" );
29 my $kForwardHSPs
30 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "forward", "hsps" );
31 my $kReverseHSPs
32 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "reverse", "hsps" );
33 my $kSortedP
34 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "sorted", "predicate" );
35 my $kLineCount
36 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "line", "count" );
37 my $kForwardBucketSet
38 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "forward", "bucket", "set" );
39 my $kReverseBucketSet
40 = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "reverse", "bucket", "set" );
41  
42 #################################################################
43 #
44 # instance stuff.
45 #
46  
47 #################################################################
48 sub init {
49 #################################################################
50 my( $self, $hit ) = @_;
51  
52 $self->{ $kHit } = $hit;
53 $self->{ $kForwardHSPs } = new Bio::GMOD::Blast::Graph::List();
54 $self->{ $kReverseHSPs } = new Bio::GMOD::Blast::Graph::List();
55  
56 $self->{ $kSortedP } = 0;
57 $self->sortHSPs();
58  
59 $self->{ $kForwardBucketSet } = new Bio::GMOD::Blast::Graph::BucketSet();
60 $self->{ $kReverseBucketSet } = new Bio::GMOD::Blast::Graph::BucketSet();
61 $self->calculateHSPLineCount();
62 }
63  
64 #################################################################
65 sub toString {
66 #################################################################
67 my( $self ) = shift;
68 my( $str );
69  
70 $str = Bio::GMOD::Blast::Graph::MyUtils::makeDumpString($self,
71 $self->getName(),
72 $self->getP(),
73 $self->getScore());
74  
75 return( $str );
76 }
77  
78 #################################################################
79 sub getForwardBucketSet {
80 #################################################################
81 my( $self ) = shift;
82 return( $self->{ $kForwardBucketSet } );
83 }
84  
85 #################################################################
86 sub getReverseBucketSet {
87 #################################################################
88 my( $self ) = shift;
89  
90 return( $self->{ $kReverseBucketSet } );
91  
92 }
93  
94 #################################################################
95 sub getHit {
96 #################################################################
97 my( $self ) = shift;
98  
99 return( $self->{ $kHit } );
100  
101 }
102  
103 #################################################################
104 sub getForwardHSPs {
105 #################################################################
106 my( $self ) = shift;
107  
108 return( $self->{ $kForwardHSPs } );
109  
110 }
111  
112 #################################################################
113 sub getReverseHSPs {
114 #################################################################
115 my( $self ) = shift;
116  
117 return( $self->{ $kReverseHSPs } );
118 }
119  
120 #################################################################
121 sub getStrandTypeCount {
122 #################################################################
123 my( $self ) = shift;
124  
125 my( $list );
126 my( $count ) = 0;
127  
128 $list = $self->getForwardHSPs();
129  
130 if( $list->getCount() > 0 )
131 {
132 $count++;
133 }
134  
135 $list = $self->getReverseRef();
136 if( $list->getCount() > 0 )
137 {
138 $count++;
139 }
140  
141 return( $count )
142 }
143  
144 #################################################################
145 sub sortHSPs {
146 #################################################################
147 my( $self ) = shift;
148  
149 my $hit = $self->getHit();
150  
151 my $fwd = $self->getForwardHSPs();
152 my $rev = $self->getReverseHSPs();
153  
154 foreach my $hsp ($hit->hsps() ) {
155  
156 if( $hsp->strand > 0 ) {
157 $fwd->addElement( $hsp );
158 }
159 else {
160 $rev->addElement( $hsp );
161 }
162 }
163  
164 }
165  
166 #################################################################
167 sub getP {
168 #################################################################
169 my( $self ) = shift;
170  
171 return $self->getHit()->significance;
172  
173 }
174  
175 ##################################################################
176 sub getPExponent {
177 ##################################################################
178  
179 my( $self ) = shift;
180  
181 my $p = $self->getP();
182  
183 my $exp = Bio::GMOD::Blast::Graph::ScientificNotation::getExponent( $p );
184  
185 #dmsg( "getPExponent: $p $exp" );
186  
187 return( $exp );
188 }
189  
190  
191 ########################################################################
192 sub getScore {
193 ########################################################################
194 my( $self ) = shift;
195  
196 return $self->getHit()->raw_score();
197  
198 }
199  
200 ########################################################################
201 sub getName {
202 ########################################################################
203 my( $self ) = shift;
204  
205 my $name = $self->getHit()->name();
206  
207 $name =~ s/^.+[:\|](.+)$/$1/;
208 $name =~ s/^(.+)\|$/$1/;
209  
210 return $name;
211  
212 }
213  
214 ########################################################################
215 sub getDescription {
216 ########################################################################
217 my( $self ) = shift;
218  
219 return( $self->getHit()->description() );
220  
221 }
222  
223 ########################################################################
224 sub getGraphAnnotation {
225 ########################################################################
226 my( $self ) = shift;
227  
228 return( $self->getName() . ' ' . $self->getP() );
229  
230 }
231  
232 ########################################################################
233 sub calculateHSPLineCount {
234 ########################################################################
235 my( $self ) = shift;
236  
237 #dmsg( "calculateHSPLineCount(): hit = " . $self->getHit()->name() );
238  
239 $self->addHSPsRef( $self->getForwardHSPs(), $self->getForwardBucketSet() );
240 $self->addHSPsRef( $self->getReverseHSPs(), $self->getReverseBucketSet() );
241  
242 $self->{ $kLineCount } =
243 $self->getForwardBucketSet()->getCount() +
244 $self->getReverseBucketSet()->getCount();
245 }
246  
247 ########################################################################
248 sub getHSPLineCount {
249 ########################################################################
250 my( $self ) = shift;
251  
252 return( $self->{ $kLineCount } );
253  
254 }
255  
256 ########################################################################
257 sub addHSPsRef {
258 ########################################################################
259 my( $self, $list, $bset ) = @_;
260  
261  
262 # the list could be empty (we don't
263 # always have both forward and reverse hsps).
264  
265 #dmsg( "addHSPsRef(): bset = $bset, count = " . $list->getCount() );
266  
267 foreach my $hsp ( @{ $list->getElementsRef() } ) {
268 my $start = $hsp->start;
269 my $end = $hsp->end;
270 my $region = new Bio::GMOD::Blast::Graph::IntSpan "$start-$end";
271 #dmsg( "addHSPsRef(): hsp = ", $hsp->name(), $hsp, $region->run_list() );
272 $bset->addRegion( $region );
273 }
274 }
275  
276 #######################################################################
277 1;
278 #######################################################################
279  
280  
281 __END__