Bio/SearchIO/axt.pm

filter: Statementstmt 84.4% 130 / 154 Branchbran 60.4% 29 / 48 Conditioncond 46.6% 7 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 85.7% 18 / 21 Podpod 91.6% 11 / 12 totaltotal 76.0% 197 / 259 CC 31 SCAR 22.9
CC
31
Cov
76%
within_element
42.0
next_result
11.9
characters
6.8
CRAP 9.9
« Bio/SeqFeature/Gene/Transcript.pm ↑ Summary Bio/Ontology/TermI.pm »
1 #
2 # BioPerl module for Bio::SearchIO::axt
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl.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::axt - a parser for axt format reports
17  
18 =head1 SYNOPSIS
19  
20 use Bio::SearchIO;
21 my $parser = Bio::SearchIO->new(-format => 'axt',
22 -file => 't/data/report.blastz');
23 while( my $result = $parser->next_result ) {
24 while( my $hit = $result->next_hit ) {
25 while( my $hsp = $hit->next_hsp ) {
26 }
27 }
28 }
29  
30 =head1 DESCRIPTION
31  
32 This is a parser and event-generator for AXT format reports. BLASTZ
33 reports (Schwartz et al,(2003) Genome Research, 13:103-107) are normally
34 in LAV format but are commonly post-processed to AXT format; many precomputed
35 BLASTZ reports, such as those found in the UCSC Genome
36 Browser, are in AXT format. This parser will also parse any
37 AXT format produced from any lav report and directly out of BLAT.
38  
39 =head1 FEEDBACK
40  
41 =head2 Mailing Lists
42  
43 User feedback is an integral part of the evolution of this and other
44 Bioperl modules. Send your comments and suggestions preferably to
45 the Bioperl mailing list. Your participation is much appreciated.
46  
47 bioperl-l@bioperl.org - General discussion
48 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
49  
50 =head2 Support
51  
52 Please direct usage questions or support issues to the mailing list:
53  
54 I<bioperl-l@bioperl.org>
55  
56 rather than to the module maintainer directly. Many experienced and
57 reponsive experts will be able look at the problem and quickly
58 address it. Please include a thorough description of the problem
59 with code and data examples if at all possible.
60  
61 =head2 Reporting Bugs
62  
63 Report bugs to the Bioperl bug tracking system to help us keep track
64 of the bugs and their resolution. Bug reports can be submitted via the
65 web:
66  
67 https://github.com/bioperl/bioperl-live/issues
68  
69 =head1 AUTHOR - Jason Stajich
70  
71 Email jason-at-bioperl.org
72  
73 =head1 APPENDIX
74  
75 The rest of the documentation details each of the object methods.
76 Internal methods are usually preceded with a _
77  
78 =cut
79  
80  
81 # Let the code begin...
82  
83  
84 package Bio::SearchIO::axt;
85 2 $Bio::SearchIO::axt::VERSION = '1.7.8';
86 2 ▶use vars qw(%MODEMAP %MAPPING @STATES $GAPCHAR);
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 ▶use Bio::Search::Result::ResultFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 2 ▶use Bio::Search::HSP::HSPFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 2 ▶use base qw(Bio::SearchIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
96 # mapping of NCBI Blast terms to Bioperl hash keys
97 2 %MODEMAP = ('AXTOutput' => 'result',
98 'Hit' => 'hit',
99 'Hsp' => 'hsp'
100 );
101 2 $GAPCHAR = '-';
102 2 %MAPPING =
103 (
104 'Hsp_score' => 'HSP-score',
105 'Hsp_query-from' => 'HSP-query_start',
106 'Hsp_query-to' => 'HSP-query_end',
107 'Hsp_hit-from' => 'HSP-hit_start',
108 'Hsp_hit-to' => 'HSP-hit_end',
109 'Hsp_positive' => 'HSP-conserved',
110 'Hsp_identity' => 'HSP-identical',
111 'Hsp_gaps' => 'HSP-hsp_gaps',
112 'Hsp_hitgaps' => 'HSP-hit_gaps',
113 'Hsp_querygaps' => 'HSP-query_gaps',
114 'Hsp_qseq' => 'HSP-query_seq',
115 'Hsp_hseq' => 'HSP-hit_seq',
116 'Hsp_midline' => 'HSP-homology_seq', # ignoring this for now
117 'Hsp_align-len' => 'HSP-hsp_length',
118
119 'Hit_id' => 'HIT-name',
120 'AXTOutput_query-def'=> 'RESULT-query_name',
121 );
122 }
123  
124 =head2 new
125  
126 Title : new
127 Usage : my $obj = Bio::SearchIO::axt->new();
128 Function: Builds a new Bio::SearchIO::axt object
129 Returns : an instance of Bio::SearchIO::axt
130 Args :
131  
132  
133 =cut
134  
135 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
136 1 my($class,@args) = @_;
137 1 my $self = $class->SUPER::new(@args);
138 1 return $self;
139 }
140  
141 =head2 next_result
142  
143 Title : next_result
144 Usage : my $hit = $searchio->next_result;
145 Function: Returns the next Result from a search
146 Returns : Bio::Search::Result::ResultI object
147 Args : none
148  
149 =cut
150  
151 1 ▶sub next_result{
Subroutine next_result: called CC=11 SCAR=24.7
Pod documented
152 1 my ($self) = @_;
153 1 local $/ = "\n";
154 1 local $_;
155  
156 1 my ($curquery,$curhit);
157 1 $self->start_document();
158 1 my @hit_signifs;
159 1 ▶ while( defined ($_ = $self->_readline )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 3 1 4
160 3 ▶ next if (/^\s+$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^\s+$/ 1 2 3
161 2 ▶ if( m/^(\d+)\s+ # alignment number - we'll throw this away anyways
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d+)\s+ # alignment number - we'll throw this away anyways (\S+)\s+ # Query name (\d+)\s+(\d+)\s+ # Query start Query end (always + strand, 0 based) (\S+)\s+ # Hit name (\d+)\s+(\d+)\s+ # Hit start Hit end (0 based) ([\-\+])\s+ # Hit strand ([\d\.\-]+)\s+ # Score /ox) 2 0 2
162 (\S+)\s+ # Query name
163 (\d+)\s+(\d+)\s+ # Query start Query end (always + strand, 0 based)
164 (\S+)\s+ # Hit name
165 (\d+)\s+(\d+)\s+ # Hit start Hit end (0 based)
166 ([\-\+])\s+ # Hit strand
167 ([\d\.\-]+)\s+ # Score
168 /ox ) {
169 2 my ($alnnum, $qname,$qstart,$qend, $hname,
170 $hstart,$hend,$hstrand, $score) = ($1,$2,$3,$4,$5,
171 $6,$7,$8,$9);
172 2 $self->{'_reporttype'} = 'AXT';
173 # Jim's code is 0 based
174 # yes, but axt format is one-based, see bug 3145 - cjfields 10-11-10
175 #$qstart++; $qend++; $hstart++; $hend++;
176 2 ▶ if( defined $curquery && $curquery ne $qname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curquery and $curquery ne $qname) 0 2 2
Condition66%2/3
defined $curquery and $curquery ne $qname
!ll&&!rl&&r
110
MC/DC0%0/2
defined $curquery and $curquery ne $qname
defined $curquery $curquery ne $qname
Truth table66%2/3
A and B
A= defined $curqueryB= $curquery ne $qname
ABresult
0X0
100
111
177 0 $self->end_element({'Name' => 'Hit'});
178 0 $self->_pushback($_);
179 0 $self->end_element({'Name' => 'AXTOutput'});
180 0 return $self->end_document();
181 }
182
183 2 ▶ if( defined $curhit &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $curhit and $curhit ne $hname) { } 0 2 2
elsif (not defined $curquery) { } 1 1 2
Condition66%2/3
defined $curhit and $curhit ne $hname
!ll&&!rl&&r
110
MC/DC0%0/2
defined $curhit and $curhit ne $hname
defined $curhit $curhit ne $hname
Truth table66%2/3
A and B
A= defined $curhitB= $curhit ne $hname
ABresult
0X0
100
111
184 $curhit ne $hname) {
185 # slight duplication here -- keep these in SYNC
186 0 $self->end_element({'Name' => 'Hit'});
187 0 $self->start_element({'Name' => 'Hit'});
188 0 $self->element({'Name' => 'Hit_id',
189 'Data' => $hname});
190 } elsif ( ! defined $curquery ) {
191 1 $self->start_element({'Name' => 'AXTOutput'});
192 1 $self->{'_result_count'}++;
193 1 $self->element({'Name' => 'AXTOutput_query-def',
194 'Data' => $qname });
195
196 1 $self->start_element({'Name' => 'Hit'});
197 1 $self->element({'Name' => 'Hit_id',
198 'Data' => $hname});
199 }
200 2 $self->start_element({'Name' => 'Hsp'});
201 2 my $queryalign = $self->_readline;
202 2 my $hitalign = $self->_readline;
203 2 chomp($queryalign);
204 2 chomp($hitalign);
205 2 my $alnlen = length($queryalign);
206 2 my $qgapnum = ( $queryalign =~ s/\Q$GAPCHAR/$GAPCHAR/g);
207 2 my $hgapnum = ( $hitalign =~ s/\Q$GAPCHAR/$GAPCHAR/g);
208 2 my $totalgaps = ($qgapnum + $hgapnum);
209
210 2 ▶ if( $hstrand eq '-' ) { # strand gets inferred by start/end
Branch: 1 branch
BranchTrueFalseTotal
if ($hstrand eq "-") 2 0 2
211 2 ($hstart,$hend) = ($hend,$hstart);
212 }
213 2 $self->element({'Name' => 'Hsp_score',
214 'Data' => $score});
215 2 $self->element({'Name' => 'Hsp_query-from',
216 'Data' => $qstart});
217 2 $self->element({'Name' => 'Hsp_query-to',
218 'Data' => $qend});
219 2 $self->element({'Name' => 'Hsp_hit-from',
220 'Data' => $hstart});
221 2 $self->element({'Name' => 'Hsp_hit-to',
222 'Data' => $hend});
223 2 $self->element({'Name' => 'Hsp_gaps',
224 'Data' => $qgapnum + $hgapnum});
225 2 $self->element({'Name' => 'Hsp_querygaps',
226 'Data' => $qgapnum});
227 2 $self->element({'Name' => 'Hsp_hitgaps',
228 'Data' => $hgapnum});
229
230 2 $self->element({'Name' => 'Hsp_identity',
231 'Data' => $alnlen - $totalgaps});
232 2 $self->element({'Name' => 'Hsp_positive',
233 'Data' => $alnlen - $totalgaps});
234 2 $self->element({'Name' => 'Hsp_qseq',
235 'Data' => $queryalign});
236 2 $self->element({'Name' => 'Hsp_hseq',
237 'Data' => $hitalign});
238
239 2 $self->end_element({'Name' => 'Hsp'});
240 2 $curquery = $qname;
241 2 $curhit = $hname;
242 }
243 }
244 # fence post
245 1 ▶ if( defined $curquery ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curquery) 1 0 1
246 1 $self->end_element({'Name' => 'Hit'});
247 1 $self->end_element({'Name' => 'AXTOutput'});
248 1 return $self->end_document();
249 }
250 0 return;
251 }
252  
253 1 ▶sub _initialize {
Subroutine _initialize: called CC=1 SCAR=0.0
254 1 my ($self,@args) = @_;
255 1 $self->SUPER::_initialize(@args);
256 1 $self->_eventHandler->register_factory('result', Bio::Search::Result::ResultFactory->new(-type => 'Bio::Search::Result::GenericResult'));
257  
258 1 $self->_eventHandler->register_factory('hsp', Bio::Search::HSP::HSPFactory->new(-type => 'Bio::Search::HSP::GenericHSP'));
259 }
260  
261  
262 =head2 start_element
263  
264 Title : start_element
265 Usage : $eventgenerator->start_element
266 Function: Handles a start element event
267 Returns : none
268 Args : hashref with at least 2 keys 'Data' and 'Name'
269  
270  
271 =cut
272  
273 30 ▶sub start_element{
Subroutine start_element: called CC=4 SCAR=13.9
Pod documented
274 30 my ($self,$data) = @_;
275 # we currently don't care about attributes
276 30 my $nm = $data->{'Name'};
277 30 ▶ if( my $type = $MODEMAP{$nm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $Bio::SearchIO::axt::MODEMAP{$nm}) 4 26 30
278 4 $self->_mode($type);
279 4 ▶ if( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 4 0 4
280 4 my $func = sprintf("start_%s",lc $type);
281 4 $self->_eventHandler->$func($data->{'Attributes'});
282 }
283 4 unshift @{$self->{'_elements'}}, $type;
284 }
285 30 ▶ if($nm eq 'AXTOutput') {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm eq "AXTOutput") 1 29 30
286 1 $self->{'_values'} = {};
287 1 $self->{'_result'}= undef;
288 1 $self->{'_mode'} = '';
289 }
290  
291 }
292  
293 =head2 end_element
294  
295 Title : start_element
296 Usage : $eventgenerator->end_element
297 Function: Handles an end element event
298 Returns : none
299 Args : hashref with at least 2 keys 'Data' and 'Name'
300  
301  
302 =cut
303  
304 30 ▶sub end_element {
Subroutine end_element: called CC=6 SCAR=18.8
Pod documented
305 30 my ($self,$data) = @_;
306 30 my $nm = $data->{'Name'};
307 30 my $rc;
308 # Hsp are sort of weird, in that they end when another
309 # object begins so have to detect this in end_element for now
310
311 30 ▶ if( my $type = $MODEMAP{$nm} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $type = $Bio::SearchIO::axt::MODEMAP{$nm}) { } 4 26 30
elsif ($Bio::SearchIO::axt::MAPPING{$nm}) { } 26 0 26
312 4 ▶ if( $self->_eventHandler->will_handle($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eventHandler->will_handle($type)) 4 0 4
313 4 my $func = sprintf("end_%s",lc $type);
314 $rc = $self->_eventHandler->$func($self->{'_reporttype'},
315 4 $self->{'_values'});
316 }
317 4 shift @{$self->{'_elements'}};
318  
319 } elsif( $MAPPING{$nm} ) {
320 26 ▶ if ( ref($MAPPING{$nm}) =~ /hash/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Bio::SearchIO::axt::MAPPING{$nm}) =~ /hash/i) { } 0 26 26
321 0 my $key = (keys %{$MAPPING{$nm}})[0];
322 0 $self->{'_values'}->{$key}->{$MAPPING{$nm}->{$key}} = $self->{'_last_data'};
323 } else {
324 26 $self->{'_values'}->{$MAPPING{$nm}} = $self->{'_last_data'};
325 }
326 } else {
327 0 $self->warn( "unknown nm $nm ignoring\n");
328 }
329 30 $self->{'_last_data'} = ''; # remove read data if we are at
330 # end of an element
331 30 ▶ $self->{'_result'} = $rc if( $nm eq 'AXTOutput' );
Branch: 1 branch
BranchTrueFalseTotal
if $nm eq "AXTOutput" 1 29 30
332 30 return $rc;
333  
334 }
335  
336 =head2 element
337  
338 Title : element
339 Usage : $eventhandler->element({'Name' => $name, 'Data' => $str});
340 Function: Convience method that calls start_element, characters, end_element
341 Returns : none
342 Args : Hash ref with the keys 'Name' and 'Data'
343  
344  
345 =cut
346  
347 26 ▶sub element{
Subroutine element: called CC=1 SCAR=0.0
Pod documented
348 26 my ($self,$data) = @_;
349 26 $self->start_element($data);
350 26 $self->characters($data);
351 26 $self->end_element($data);
352 }
353  
354  
355 =head2 characters
356  
357 Title : characters
358 Usage : $eventgenerator->characters($str)
359 Function: Send a character events
360 Returns : none
361 Args : string
362  
363  
364 =cut
365  
366 26 ▶sub characters{
Subroutine characters: called CC=6 SCAR=19.1
Pod documented
367 26 my ($self,$data) = @_;
368  
369 26 ▶ return unless ( defined $data->{'Data'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{"Data"} 0 26 26
370 26 ▶ if( $data->{'Data'} =~ /^\s+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"Data"} =~ /^\s+$/) 0 26 26
371 0 ▶ return unless $data->{'Name'} =~ /Hsp\_(midline|qseq|hseq)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data->{"Name"} =~ /Hsp\_(midline|qseq|hseq)/ 0 0 0
372 }
373  
374 26 ▶ if( $self->in_element('hsp') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/) 4 22 26
Condition100%3/3
$self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
!ll&&!rl&&r
2204
MC/DC100%2/2
$self->in_element("hsp") and $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
$self->in_element("hsp") $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
Truth table100%3/3
A and B
A= $self->in_element("hsp")B= $data->{"Name"} =~ /Hsp\_(qseq|hseq|midline)/
ABresult
0X0
100
111
375 $data->{'Name'} =~ /Hsp\_(qseq|hseq|midline)/ ) {
376
377 4 $self->{'_last_hspdata'}->{$data->{'Name'}} .= $data->{'Data'};
378 }
379
380 26 $self->{'_last_data'} = $data->{'Data'};
381 }
382  
383 =head2 _mode
384  
385 Title : _mode
386 Usage : $obj->_mode($newval)
387 Function:
388 Example :
389 Returns : value of _mode
390 Args : newvalue (optional)
391  
392  
393 =cut
394  
395 4 ▶sub _mode{
Subroutine _mode: called CC=2 SCAR=7.0
396 4 my ($self,$value) = @_;
397 4 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 4 0 4
398 4 $self->{'_mode'} = $value;
399 }
400 4 return $self->{'_mode'};
401 }
402  
403 =head2 within_element
404  
405 Title : within_element
406 Usage : if( $eventgenerator->within_element($element) ) {}
407 Function: Test if we are within a particular element
408 This is different than 'in' because within can be tested
409 for a whole block.
410 Returns : boolean
411 Args : string element name
412  
413  
414 =cut
415  
416 0 ▶sub within_element{
Subroutine within_element: not called CC=6 SCAR=37.4
Pod documented
417 0 my ($self,$name) = @_;
418 return 0 if ( ! defined $name &&
419 ! defined $self->{'_elements'} ||
420 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
421 0 foreach ( @{$self->{'_elements'}} ) {
422 0 ▶ if( $_ eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $name) 0 0 0
423 0 return 1;
424 }
425 }
426 0 return 0;
427 }
428  
429 =head2 in_element
430  
431 Title : in_element
432 Usage : if( $eventgenerator->in_element($element) ) {}
433 Function: Test if we are in a particular element
434 This is different than 'in' because within can be tested
435 for a whole block.
436 Returns : boolean
437 Args : string element name
438  
439  
440 =cut
441  
442 26 ▶sub in_element{
Subroutine in_element: called CC=2 SCAR=7.1
Pod documented
443 26 my ($self,$name) = @_;
444 26 ▶ return 0 if ! defined $self->{'_elements'}->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_elements"}[0] 0 26 26
445 26 return ( $self->{'_elements'}->[0] eq $name)
446 }
447  
448  
449 =head2 start_document
450  
451 Title : start_document
452 Usage : $eventgenerator->start_document
453 Function: Handles a start document event
454 Returns : none
455 Args : none
456  
457  
458 =cut
459  
460 1 ▶sub start_document{
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
461 1 my ($self) = @_;
462 1 $self->{'_lasttype'} = '';
463 1 $self->{'_values'} = {};
464 1 $self->{'_result'}= undef;
465 1 $self->{'_mode'} = '';
466 1 $self->{'_elements'} = [];
467 }
468  
469  
470 =head2 end_document
471  
472 Title : end_document
473 Usage : $eventgenerator->end_document
474 Function: Handles an end document event
475 Returns : Bio::Search::Result::ResultI object
476 Args : none
477  
478  
479 =cut
480  
481 1 ▶sub end_document{
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
482 1 my ($self,@args) = @_;
483 1 return $self->{'_result'};
484 }
485  
486 =head2 result_count
487  
488 Title : result_count
489 Usage : my $count = $searchio->result_count
490 Function: Returns the number of results we have processed
491 Returns : integer
492 Args : none
493  
494  
495 =cut
496  
497 0 ▶sub result_count {
Subroutine result_count: not called CC=1 SCAR=6.9
Pod documented
498 0 my $self = shift;
499 0 return $self->{'_result_count'};
500 }
501  
502 0 ▶sub report_count { shift->result_count }
Subroutine report_count: not called CC=1 SCAR=6.9
Pod undocumented
503  
504  
505  
506 2 1;
507  
« Bio/SeqFeature/Gene/Transcript.pm ↑ Summary Bio/Ontology/TermI.pm »