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