File Coverage

blib/lib/Bio/FastParsers/Blast/Xml.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 32 33 96.9


line stmt bran cond sub pod time code
1             package Bio::FastParsers::Blast::Xml;
2             # ABSTRACT: Front-end class for XML BLAST parser
3             $Bio::FastParsers::Blast::Xml::VERSION = '0.201110';
4 7     7   53 use Moose;
  7         16  
  7         58  
5 7     7   49635 use namespace::autoclean;
  7         23  
  7         73  
6              
7 7     7   750 use Carp;
  7         17  
  7         549  
8 7     7   4629 use XML::Bare;
  7         58096  
  7         404  
9              
10             extends 'Bio::FastParsers::Base';
11              
12 7     7   61 use aliased 'Bio::FastParsers::Blast::Xml::BlastOutput';
  7         38  
  7         54  
13              
14             # TODO: check behavior with single iterations, hits or hsps
15              
16             # public attributes (some inherited)
17              
18              
19              
20             has 'blast_output' => (
21             is => 'ro',
22             isa => 'Maybe[Bio::FastParsers::Blast::Xml::BlastOutput]',
23             init_arg => undef,
24             lazy => 1,
25             builder => '_build_blast_output',
26             );
27              
28             ## no critic (ProhibitUnusedPrivateSubroutines)
29              
30             sub _build_blast_output {
31 7     7   20 my $self = shift;
32              
33 7         221 my $file = $self->file;
34 7 50       102 my $xb = XML::Bare->new( file => $file )
35             or croak "Can't open '$file' for reading: $!";
36              
37 7         8566 my $bo = $xb->parse->{'BlastOutput'};
38 7 100       16734 unless ($bo) {
39 1         6 carp "Warning: '$file' unexpectedly empty; returning no BlastOutput!";
40 1         521 return;
41             }
42              
43 6         371 return BlastOutput->new( _root => $bo );
44             }
45              
46             ## use critic
47              
48              
49             __PACKAGE__->meta->make_immutable;
50             1;
51              
52             __END__
53              
54             =pod
55              
56             =head1 NAME
57              
58             Bio::FastParsers::Blast::Xml - Front-end class for XML BLAST parser
59              
60             =head1 VERSION
61              
62             version 0.201110
63              
64             =head1 SYNOPSIS
65              
66             use aliased 'Bio::FastParsers::Blast::Xml';
67              
68             # open and parse BLAST report in XML format
69             my $infile = 'test/blastp.xml';
70             my $report = Xml->new( file => $infile );
71              
72             # get main container
73             my $bo = $report->blast_output;
74              
75             # examine report content
76             say $bo->program; # blastp
77             say $bo->version; # BLASTP 2.2.25+
78             say $bo->db; # mcl-db-22species
79              
80             # get evalue threshold...
81             say $bo->parameters->expect; # 10
82              
83             # ...or equivalently
84             my $param = $bo->parameters;
85             say $param->expect; # 10
86             say $param->matrix; # BLOSUM62
87              
88             # get the number of iterations (= queries)
89             say $bo->count_iterations; # 3
90              
91             # loop through iterations (or queries), hits and hsps
92             # this is extremely fast because no data is moved around
93             for my $iter ($bo->all_iterations) {
94             say $iter->count_hits; # always available!
95             for my $hit ($iter->all_hits) {
96             for my $hsp ($hit->all_hsps) {
97             # ...
98             }
99             }
100             }
101              
102             # ...or nearly equivalently (still ultra-fast)
103             # here the container is altered by each iterator call
104             while (my $iter = $bo->next_iteration) {
105             say $iter->count_hits; # here too!
106             while (my $hit = $iter->next_hit) {
107             while (my $hsp = $hit->next_hsp) {
108             # ...
109             }
110             }
111             say $iter->count_hits; # 0 (exhausted)
112             }
113              
114             =head1 DESCRIPTION
115              
116             This module implements a parser for the XML output format of the BLAST program
117             (e.g., C<-outfmt 5>). It provides methods for iterating over and querying all
118             elements of the XML tree. The hierarchy is as follows:
119              
120             =over
121              
122             =item L<Bio::FastParsers::Blast::Xml>
123              
124             =item L<Bio::FastParsers::Blast::Xml::BlastOutput>
125              
126             =item L<Bio::FastParsers::Blast::Xml::Statistics>
127              
128             =item L<Bio::FastParsers::Blast::Xml::Parameters>
129              
130             =item L<Bio::FastParsers::Blast::Xml::Iteration>'s
131              
132             =item L<Bio::FastParsers::Blast::Xml::Hit>'s
133              
134             =item L<Bio::FastParsers::Blast::Xml::Hsp>'s
135              
136             =back
137              
138             Documentation is autogenerated.
139              
140             =head1 ATTRIBUTES
141              
142             =head2 file
143              
144             Path to BLAST report file in XML format to be parsed
145              
146             =head2 blast_output
147              
148             L<Bio::FastParsers::Blast::Xml::BlastOutput> composed object
149              
150             =head1 AUTHOR
151              
152             Denis BAURAIN <denis.baurain@uliege.be>
153              
154             =head1 COPYRIGHT AND LICENSE
155              
156             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
157              
158             This is free software; you can redistribute it and/or modify it under
159             the same terms as the Perl 5 programming language system itself.
160              
161             =cut