| 1 | package Bio::FastParsers::Blast::Xml; | ||||||||||
| 2 | # ABSTRACT: Front-end class for XML BLAST parser | ||||||||||
| 3 | # CONTRIBUTOR: Aymeric NAOME <aymeric.naome@gmail.com> | ||||||||||
| 4 | 7 | $Bio::FastParsers::Blast::Xml::VERSION = '0.213510'; | |||||||||
| 5 | 7 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 7 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 7 | ▶ | use XML::Bare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 7 | extends 'Bio::FastParsers::Base'; | |||||||||
| 12 | |||||||||||
| 13 | 7 | ▶ | use aliased 'Bio::FastParsers::Blast::Xml::BlastOutput'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | # TODO: check behavior with single iterations, hits or hsps | ||||||||||
| 16 | |||||||||||
| 17 | # public attributes (some inherited) | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 7 | 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_blast_output: called CC=3 SCAR=11.0
| |||||||||||
| 33 | |||||||||||
| 34 | 7 | my $file = $self->file; | |||||||||
| 35 | 7 | ▶ | my $xb = XML::Bare->new( file => $file ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | or croak "Can't open '$file' for reading: $!"; | ||||||||||
| 37 | |||||||||||
| 38 | 7 | my $bo = $xb->parse->{'BlastOutput'}; | |||||||||
| 39 | 7 | ▶ | unless ($bo) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | carp "Warning: '$file' unexpectedly empty; returning no BlastOutput!"; | |||||||||
| 41 | 1 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 6 | return BlastOutput->new( _root => $bo, _parent => undef); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | ## use critic | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||
| 51 | 7 | 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 | ||||||||||