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