Bio/SearchIO/wise.pm

filter: Statementstmt 76.6% 118 / 154 Branchbran 55.5% 30 / 54 Conditioncond 33.3% 4 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 70.0% 14 / 20 Podpod 92.8% 13 / 14 totaltotal 69.3% 181 / 261 CC 35 SCAR 22.6
CC
35
Cov
69%
within_element
42.0
next_result
9.5
_initialize
7.7
CRAP 9.5
« Bio/Tools/Signalp/ExtendedSignalp.pm ↑ Summary Bio/SearchIO.pm »
1 #
2 # BioPerl module for Bio::SearchIO::wise
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
7 #
8 # Copyright Jason Stajich
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SearchIO::wise - Parsing of wise output as alignments
17  
18 =head1 SYNOPSIS
19  
20 use Bio::SearchIO;
21 my $parser = Bio::SearchIO->new(-file => 'file.genewise',
22 -format => 'wise',
23 -wisetype=> 'genewise');
24  
25 while( my $result = $parser->next_result ) {}
26  
27 =head1 DESCRIPTION
28  
29 This object parsers Wise output using Bio::Tools::Genewise or
30 Bio::Tools::Genomewise as a helper.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
53  
54 =head2 Reporting Bugs
55  
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via
58 the web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Jason Stajich
63  
64 Email jason-at-bioperl-dot-org
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
70  
71 =cut
72  
73  
74 # Let the code begin...
75  
76  
77 package Bio::SearchIO::wise;
78 2 $Bio::SearchIO::wise::VERSION = '1.7.8';
79 2 ▶use vars qw(%MAPPING %MODEMAP $DEFAULT_WRITER_CLASS);
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 # Object preamble - inherits from Bio::Root::Root
83  
84 2 ▶use base qw(Bio::SearchIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 2 %MODEMAP = ('WiseOutput' => 'result',
87 'Hit' => 'hit',
88 'Hsp' => 'hsp'
89 );
90 2 %MAPPING =
91 (
92 'Hsp_query-from'=> 'HSP-query_start',
93 'Hsp_query-to' => 'HSP-query_end',
94 'Hsp_hit-from' => 'HSP-hit_start',
95 'Hsp_hit-to' => 'HSP-hit_end',
96 'Hsp_qseq' => 'HSP-query_seq',
97 'Hsp_hseq' => 'HSP-hit_seq',
98 'Hsp_midline' => 'HSP-homology_seq',
99 'Hsp_score' => 'HSP-score',
100 'Hsp_qlength' => 'HSP-query_length',
101 'Hsp_hlength' => 'HSP-hit_length',
102 'Hsp_align-len' => 'HSP-hsp_length',
103 'Hsp_positive' => 'HSP-conserved',
104 'Hsp_identity' => 'HSP-identical',
105 #'Hsp_gaps' => 'HSP-hsp_gaps',
106 #'Hsp_hitgaps' => 'HSP-hit_gaps',
107 #'Hsp_querygaps' => 'HSP-query_gaps',
108
109 'Hit_id' => 'HIT-name',
110 # 'Hit_desc' => 'HIT-description',
111 # 'Hit_len' => 'HIT-length',
112 'Hit_score' => 'HIT-score',
113  
114 'WiseOutput_program' => 'RESULT-algorithm_name',
115 'WiseOutput_query-def' => 'RESULT-query_name',
116 'WiseOutput_query-desc'=> 'RESULT-query_description',
117 'WiseOutput_query-len' => 'RESULT-query_length',
118 );
119  
120 2 $DEFAULT_WRITER_CLASS = 'Bio::SearchIO::Writer::HitTableWriter';
121  
122  
123 2 ▶use Bio::Tools::Genewise;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 2 ▶use Bio::Tools::Genomewise;
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 =head2 new
127  
128 Title : new
129 Usage : my $obj = Bio::SearchIO::wise->new();
130 Function: Builds a new Bio::SearchIO::wise object
131 Returns : an instance of Bio::SearchIO::wise
132 Args : -wise => a Bio::Tools::Genewise or Bio::Tools::Genomewise object
133  
134  
135 =cut
136  
137 1 ▶sub _initialize {
Subroutine _initialize: called CC=7 SCAR=20.4
138 1 my ($self,@args) = @_;
139 1 my ( $wisetype, $file,$fh ) =
140 $self->_rearrange([qw(WISETYPE FILE FH)], @args);
141 1 my @newargs;
142 1 ▶ while( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 3 1 4
143 3 my $a = shift @args;
144 3 ▶ if( $a =~ /FILE|FH/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a =~ /FILE|FH/i) 1 2 3
145 1 shift @args;
146 1 next;
147 }
148 2 push @newargs, $a, shift @args;
149 }
150 1 $self->SUPER::_initialize(@newargs);
151  
152 # Optimization: caching the EventHandler
153 # since it's use a lot during the parse.
154 1 $self->{'_handler_cache'} = $self->_eventHandler;
155  
156 1 $self->wisetype($wisetype);
157 1 my @ioargs;
158 1 ▶ if( $fh ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fh) { } 0 1 1
elsif ($file) { } 1 0 1
159 0 push @ioargs, ('-fh' => $fh);
160 } elsif( $file ) {
161 1 push @ioargs, ('-file' => $file);
162 }
163  
164 1 ▶ if( $wisetype =~ /genewise/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wisetype =~ /genewise/i) { } 1 0 1
elsif ($wisetype =~ /genomewise/i) { } 0 0 0
165 1 $self->wise(Bio::Tools::Genewise->new(@ioargs));
166 } elsif( $wisetype =~ /genomewise/i ) {
167 0 $self->wise(Bio::Tools::Genomewise->new(@ioargs));
168 } else {
169 0 $self->throw("Must supply a -wisetype to ".ref($self)." which is one of 'genomewise' 'genewise'\n");
170 }
171 1 return $self;
172 }
173  
174  
175 =head2 next_result
176  
177 Title : next_result
178 Usage : my $hit = $searchio->next_result;
179 Function: Returns the next Result from a search
180 Returns : Bio::Search::Result::ResultI object
181 Args : none
182  
183 =cut
184  
185 1 ▶sub next_result{
Subroutine next_result: called CC=9 SCAR=22.5
Pod documented
186 1 my ($self) = @_;
187 1 local $/ = "\n";
188 1 local $_;
189  
190 1 ▶ return unless $self->wise;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->wise 0 1 1
191 1 my $prediction = $self->wise->next_prediction;
192 1 ▶ return unless $prediction;
Branch: 1 branch
BranchTrueFalseTotal
unless $prediction 0 1 1
193 1 $self->{'_reporttype'} = uc $self->wisetype;
194 1 $self->start_element({'Name' => 'WiseOutput'});
195 1 $self->element({'Name' => 'WiseOutput_program',
196 'Data' => $self->wisetype});
197 1 $self->element({'Name' => 'WiseOutput_query-def',
198 'Data' => $self->wise->_prot_id});
199 1 my @transcripts = $prediction->transcripts;
200  
201 1 foreach my $transcript ( @transcripts ) {
202 1 my @exons = $transcript->exons;
203 1 my $protid;
204 1 $self->start_element({'Name' => 'Hit'});
205
206 1 ▶ if( $exons[0]->has_tag('supporting_feature') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exons[0]->has_tag("supporting_feature")) 1 0 1
207 1 my ($supporting_feature) = $exons[0]->get_tag_values('supporting_feature');
208 1 $protid = $supporting_feature->feature2->seq_id;
209 1 $self->element({'Name' => 'Hit_id',
210 'Data' => $self->wise->_target_id});
211 }
212 1 $self->element({'Name' => 'Hit_score',
213 'Data' => $self->wise->_score});
214 1 foreach my $exon ( @exons ) {
215 18 $self->start_element({'Name' => 'Hsp'});
216 18 ▶ if( $exon->strand < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exon->strand < 0) { } 0 18 18
217 0 $self->element({'Name' => 'Hsp_query-from',
218 'Data' => $exon->end});
219 0 $self->element({'Name' => 'Hsp_query-to',
220 'Data' => $exon->start});
221 } else {
222 18 $self->element({'Name' => 'Hsp_query-from',
223 'Data' => $exon->start});
224 18 $self->element({'Name' => 'Hsp_query-to',
225 'Data' => $exon->end});
226 }
227 18 $self->element({'Name' => 'Hsp_score',
228 'Data' => $self->wise->_score});
229 18 ▶ if( $exon->has_tag('supporting_feature') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exon->has_tag("supporting_feature")) 18 0 18
230 18 my ($sf) = $exon->get_tag_values('supporting_feature');
231 18 my $protein = $sf->feature2;
232 18 ▶ if( $protein->strand < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protein->strand < 0) { } 0 18 18
233 0 $self->element({'Name' => 'Hsp_hit-from',
234 'Data' => $protein->end});
235 0 $self->element({'Name' => 'Hsp_hit-to',
236 'Data' => $protein->start});
237 } else {
238 18 $self->element({'Name' => 'Hsp_hit-from',
239 'Data' => $protein->start});
240 18 $self->element({'Name' => 'Hsp_hit-to',
241 'Data' => $protein->end});
242 }
243 }
244 18 $self->element({'Name' => 'Hsp_identity',
245 'Data' => 0});
246 18 $self->element({'Name' => 'Hsp_positive',
247 'Data' => 0});
248 18 $self->end_element({'Name' => 'Hsp'});
249 }
250 1 $self->end_element({'Name' => 'Hit'});
251 }
252 1 $self->end_element({'Name' => 'WiseOutput'});
253 1 return $self->end_document();
254 }
255  
256 =head2 start_element
257  
258 Title : start_element
259 Usage : $eventgenerator->start_element
260 Function: Handles a start element event
261 Returns : none
262 Args : hashref with at least 2 keys 'Data' and 'Name'
263  
264  
265 =cut
266  
267 150 ▶sub start_element{
Subroutine start_element: called CC=4 SCAR=13.9
Pod documented
268 150 my ($self,$data) = @_;
269 # we currently don't care about attributes
270 150 my $nm = $data->{'Name'};
271 150 my $type = $MODEMAP{$nm};
272  
273 150 ▶ if( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 20 130 150
274 20 ▶ if( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 20 0 20
275 20 my $func = sprintf("start_%s",lc $type);
276 20 $self->_eventHandler->$func($data->{'Attributes'});
277 }
278 20 unshift @{$self->{'_elements'}}, $type;
279  
280 20 ▶ if($type eq 'result') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "result") 1 19 20
281 1 $self->{'_values'} = {};
282 1 $self->{'_result'}= undef;
283 }
284 }
285  
286 }
287  
288 =head2 end_element
289  
290 Title : start_element
291 Usage : $eventgenerator->end_element
292 Function: Handles an end element event
293 Returns : none
294 Args : hashref with at least 2 keys 'Data' and 'Name'
295  
296  
297 =cut
298  
299 150 ▶sub end_element {
Subroutine end_element: called CC=7 SCAR=20.2
Pod documented
300 150 my ($self,$data) = @_;
301 150 my $nm = $data->{'Name'};
302 150 my $type = $MODEMAP{$nm};
303 150 my $rc;
304  
305 150 ▶ if( $type = $MODEMAP{$nm} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type = $Bio::SearchIO::wise::MODEMAP{$nm}) { } 20 130 150
elsif ($Bio::SearchIO::wise::MAPPING{$nm}) { } 130 0 130
306 20 ▶ if( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 20 0 20
307 20 my $func = sprintf("end_%s",lc $type);
308 $rc = $self->_eventHandler->$func($self->{'_reporttype'},
309 20 $self->{'_values'});
310 }
311 20 shift @{$self->{'_elements'}};
312  
313 } elsif( $MAPPING{$nm} ) {
314  
315 130 ▶ if ( ref($MAPPING{$nm}) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::SearchIO::wise::MAPPING{$nm}) =~ /hash/i) { } 0 130 130
316 0 my $key = (keys %{$MAPPING{$nm}})[0];
317 0 $self->{'_values'}->{$key}->{$MAPPING{$nm}->{$key}} = $self->{'_last_data'};
318 } else {
319 130 $self->{'_values'}->{$MAPPING{$nm}} = $self->{'_last_data'};
320 }
321 } else {
322 0 $self->debug( "unknown nm $nm, ignoring\n");
323 }
324 150 $self->{'_last_data'} = ''; # remove read data if we are at
325 # end of an element
326 150 ▶ $self->{'_result'} = $rc if( defined $type && $type eq 'result' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type eq "result" 1 149 150
Condition100%3/3
defined $type and $type eq "result"
!ll&&!rl&&r
130191
MC/DC100%2/2
defined $type and $type eq "result"
defined $type $type eq "result"
Truth table100%3/3
A and B
A= defined $typeB= $type eq "result"
ABresult
0X0
100
111
327 150 return $rc;
328 }
329  
330 =head2 element
331  
332 Title : element
333 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
334 Function: Convience method that calls start_element, characters, end_element
335 Returns : none
336 Args : Hash ref with the keys 'Name' and 'Data'
337  
338  
339 =cut
340  
341 130 ▶sub element{
Subroutine element: called CC=1 SCAR=0.0
Pod documented
342 130 my ($self,$data) = @_;
343 130 $self->start_element($data);
344 130 $self->characters($data);
345 130 $self->end_element($data);
346 }
347  
348 =head2 characters
349  
350 Title : characters
351 Usage : $eventgenerator->characters($str)
352 Function: Send a character events
353 Returns : none
354 Args : string
355  
356  
357 =cut
358  
359 130 ▶sub characters{
Subroutine characters: called CC=3 SCAR=12.5
Pod documented
360 130 my ($self,$data) = @_;
361  
362 130 ▶ return unless ( defined $data->{'Data'} && $data->{'Data'} !~ /^\s+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/ 0 130 130
Condition33%1/3
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/
!ll&&!rl&&r
00130
MC/DC0%0/2
defined $data->{"Data"} and not $data->{"Data"} =~ /^\s+$/
defined $data->{"Data"} not $data->{"Data"} =~ /^\s+$/
Truth table33%1/3
A and not(B)
A= defined $data->{"Data"}B= not $data->{"Data"} =~ /^\s+$/
ABresult
0X0
100
111
363  
364 130 $self->{'_last_data'} = $data->{'Data'};
365 }
366  
367 =head2 within_element
368  
369 Title : within_element
370 Usage : if( $eventgenerator->within_element($element) ) {}
371 Function: Test if we are within a particular element
372 This is different than 'in' because within can be tested
373 for a whole block.
374 Returns : boolean
375 Args : string element name
376  
377  
378 =cut
379  
380 0 ▶sub within_element{
Subroutine within_element: not called CC=6 SCAR=37.4
Pod documented
381 0 my ($self,$name) = @_;
382 return 0 if ( ! defined $name &&
383 ! defined $self->{'_elements'} ||
384 0 ▶ scalar @{$self->{'_elements'}} == 0) ;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name || defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0 0 0 0
Condition0%0/6
not defined $name || defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
l!l&&r!l&&!r
000
defined $name || defined $self->{'_elements'}
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $name || defined $self->{"_elements"} or scalar @{$self->{"_elements"};} == 0
defined $name defined $self->{'_elements'} scalar @{$self->{"_elements"};} == 0
Truth table0%0/5
not(A || B) or C
A= defined $nameB= defined $self->{'_elements'}C= scalar @{$self->{"_elements"};} == 0
ABCresult
00X1
1X11
0111
1X00
0100
385 0 foreach ( @{$self->{'_elements'}} ) {
386 0 ▶ if( $_ eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $name) 0 0 0
387 0 return 1;
388 }
389 }
390 0 return 0;
391 }
392  
393  
394 =head2 in_element
395  
396 Title : in_element
397 Usage : if( $eventgenerator->in_element($element) ) {}
398 Function: Test if we are in a particular element
399 This is different than 'in' because within can be tested
400 for a whole block.
401 Returns : boolean
402 Args : string element name
403  
404  
405 =cut
406  
407 0 ▶sub in_element{
Subroutine in_element: not called CC=2 SCAR=17.9
Pod documented
408 0 my ($self,$name) = @_;
409 0 ▶ return 0 if ! defined $self->{'_elements'}->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_elements"}[0] 0 0 0
410 0 return ( $self->{'_elements'}->[0] eq $name)
411 }
412  
413 =head2 start_document
414  
415 Title : start_document
416 Usage : $eventgenerator->start_document
417 Function: Handle a start document event
418 Returns : none
419 Args : none
420  
421  
422 =cut
423  
424 0 ▶sub start_document{
Subroutine start_document: not called CC=1 SCAR=6.9
Pod documented
425 0 my ($self) = @_;
426 0 $self->{'_lasttype'} = '';
427 0 $self->{'_values'} = {};
428 0 $self->{'_result'}= undef;
429 0 $self->{'_elements'} = [];
430 0 $self->{'_reporttype'} = 'exonerate';
431 }
432  
433  
434 =head2 end_document
435  
436 Title : end_document
437 Usage : $eventgenerator->end_document
438 Function: Handles an end document event
439 Returns : Bio::Search::Result::ResultI object
440 Args : none
441  
442  
443 =cut
444  
445 1 ▶sub end_document{
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
446 1 my ($self,@args) = @_;
447 1 return $self->{'_result'};
448 }
449  
450  
451 0 ▶sub write_result {
Subroutine write_result: not called CC=2 SCAR=17.9
Pod documented
452 0 my ($self, $blast, @args) = @_;
453  
454 0 ▶ if( not defined($self->writer) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->writer) 0 0 0
455 0 $self->warn("Writer not defined. Using a $DEFAULT_WRITER_CLASS");
456 0 $self->writer( $DEFAULT_WRITER_CLASS->new() );
457 }
458 0 $self->SUPER::write_result( $blast, @args );
459 }
460  
461 0 ▶sub result_count {
Subroutine result_count: not called CC=1 SCAR=6.9
Pod documented
462 0 my $self = shift;
463 0 return $self->{'_result_count'};
464 }
465  
466 0 ▶sub report_count { shift->result_count }
Subroutine report_count: not called CC=1 SCAR=6.9
Pod undocumented
467  
468  
469 =head2 wise
470  
471 Title : wise
472 Usage : $obj->wise($newval)
473 Function: Get/Set the Wise object parser
474 Returns : value of wise (a scalar)
475 Args : on set, new value (a scalar or undef, optional)
476  
477  
478 =cut
479  
480 24 ▶sub wise{
Subroutine wise: called CC=2 SCAR=6.9
Pod documented
481 24 my $self = shift;
482 24 ▶ return $self->{'wise'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 23 24
483 23 return $self->{'wise'};
484 }
485  
486 =head2 wisetype
487  
488 Title : wisetype
489 Usage : $obj->wisetype($newval)
490 Function: Wise program type
491 Returns : value of wisetype (a scalar)
492 Args : on set, new value (a scalar or undef, optional)
493  
494  
495 =cut
496  
497 3 ▶sub wisetype{
Subroutine wisetype: called CC=2 SCAR=6.9
Pod documented
498 3 my $self = shift;
499  
500 3 ▶ return $self->{'wisetype'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 2 3
501 2 return $self->{'wisetype'};
502 }
503  
504 2 1;
« Bio/Tools/Signalp/ExtendedSignalp.pm ↑ Summary Bio/SearchIO.pm »