File Coverage

blib/lib/Bio/FastParsers/Hmmer/Table.pm
Criterion Covered Total %
statement 33 33 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 1 1 100.0
total 49 50 98.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Front-end class for tabular HMMER parser
2             # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com>
3             $Bio::FastParsers::Hmmer::Table::VERSION = '0.221230';
4             use Moose;
5 7     7   51 use namespace::autoclean;
  7         15  
  7         51  
6 7     7   43073  
  7         21  
  7         66  
7             use autodie;
8 7     7   647  
  7         16  
  7         67  
9             use List::AllUtils qw(mesh);
10 7     7   33714  
  7         15  
  7         595  
11             extends 'Bio::FastParsers::Base';
12              
13             use Bio::FastParsers::Constants qw(:files);
14 7     7   53 use aliased 'Bio::FastParsers::Hmmer::Table::Hit';
  7         20  
  7         927  
15 7     7   62  
  7         15  
  7         60  
16              
17             # public attributes (inherited)
18              
19              
20             # private attributes
21              
22             has '_line_iterator' => (
23             traits => ['Code'],
24             is => 'ro',
25             isa => 'CodeRef',
26             init_arg => undef,
27             lazy => 1,
28             builder => '_build_line_iterator',
29             handles => {
30             _next_line => 'execute',
31             },
32             );
33              
34             ## no critic (ProhibitUnusedPrivateSubroutines)
35              
36             my $self = shift;
37              
38 2     2   6 open my $fh, '<', $self->file; # autodie
39             return sub { <$fh> }; # return closure
40 2         63 }
41 2     66   2293  
  66         522  
42             ## use critic
43              
44             my @attrs = qw(
45             target_name target_accession
46             query_name query_accession
47             evalue score bias
48             best_dom_evalue best_dom_score best_dom_bias
49             exp reg clu ov env dom rep inc
50             target_description
51             ); # DID try to use MOP to get Hit attrs but order was not preserved
52              
53              
54             my $self = shift;
55              
56             LINE:
57 60     60 1 119 while (my $line = $self->_next_line) {
58              
59             # skip header/comments and empty lines
60 60         2082 chomp $line;
61             next LINE if $line =~ $COMMENT_LINE
62             || $line =~ $EMPTY_LINE;
63 64         158  
64 64 100 66     879 # process Hit line
65             my @fields = split(/\s+/xms, $line, 19);
66              
67             # Fields
68 58         670 # 0. target name
69             # 1. accession
70             # 2. query name
71             # 3. accession
72             # 4. E-value
73             # 5. score
74             # 6. bias
75             # 7. E-value
76             # 8. score
77             # 9. bias
78             # 10. exp
79             # 11. reg
80             # 12. clu
81             # 13. ov
82             # 14. env
83             # 15. dom
84             # 16. rep
85             # 17. inc
86             # 18. description of target
87              
88             # coerce numeric fields to numbers
89             @fields[4..17] = map { 0 + $_ } @fields[4..17];
90              
91             # set missing field values to undef
92 58         260 @fields[1,3,18] = map { $_ eq '-' ? undef : $_ } @fields[1,3,18];
  812         1454  
93              
94             # return Hit object
95 58 100       155 return Hit->new( { mesh @attrs, @fields } );
  174         392  
96             }
97              
98 58         3031 return; # no more line to read
99             }
100              
101 2         11 __PACKAGE__->meta->make_immutable;
102             1;
103              
104              
105             =pod
106              
107             =head1 NAME
108              
109             Bio::FastParsers::Hmmer::Table - Front-end class for tabular HMMER parser
110              
111             =head1 VERSION
112              
113             version 0.221230
114              
115             =head1 SYNOPSIS
116              
117             use aliased 'Bio::FastParsers::Hmmer::Table';
118              
119             # open and parse HMMER report in tabular format
120             my $infile = 'test/hmmer.tblout';
121             my $report = Table->new( file => $infile );
122              
123             # loop through hits
124             while (my $hit = $hit->next_hit) {
125             my ($target_name, $evalue) = ($hit->target_name, $hit->evalue);
126             # ...
127             }
128              
129             =head1 DESCRIPTION
130              
131             # TODO
132              
133             =head1 ATTRIBUTES
134              
135             =head2 file
136              
137             Path to HMMER report file in tabular format (--tblout) to be parsed
138              
139             =head1 METHODS
140              
141             =head2 next_hit
142              
143             Shifts the first Hit of the report off and returns it, shortening the report
144             by 1 and moving everything down. If there are no more Hits in the report,
145             returns C<undef>.
146              
147             # $report is a Bio::FastParsers::Hmmer::Table
148             while (my $hit = $report->next_hit) {
149             # process $hit
150             # ...
151             }
152              
153             This method does not accept any arguments.
154              
155             =head1 AUTHOR
156              
157             Denis BAURAIN <denis.baurain@uliege.be>
158              
159             =head1 CONTRIBUTOR
160              
161             =for stopwords Arnaud DI FRANCO
162              
163             Arnaud DI FRANCO <arnaud.difranco@gmail.com>
164              
165             =head1 COPYRIGHT AND LICENSE
166              
167             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
168              
169             This is free software; you can redistribute it and/or modify it under
170             the same terms as the Perl 5 programming language system itself.
171              
172             =cut