lib/Bio/MUST/Apps/Debrief42/TaxReport.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 76 SCAR 17.9
CC
2
Cov
0%
next_seq
6.0
_build_line_iterator
2.0
BEGIN
2.0
CRAP 6.0
1 package Bio::MUST::Apps::Debrief42::TaxReport;
2 # ABSTRACT: Front-end class for tabular tax-report parser
3 # CONTRIBUTOR: Mick VAN VLIERBERGHE <mvanvlierberghe@doct.uliege.be>
4 $Bio::MUST::Apps::Debrief42::TaxReport::VERSION = '0.210570';
5 use Moose;
6 use namespace::autoclean;
7  
8 use autodie;
9 use feature qw(say);
10  
11 use List::AllUtils qw(mesh);
12  
13 extends 'Bio::FastParsers::Base';
14  
15 use Bio::MUST::Core;
16 use Bio::MUST::Core::Utils qw(change_suffix);
17 use Bio::FastParsers::Constants qw(:files);
18 use aliased 'Bio::MUST::Apps::Debrief42::TaxReport::NewSeq';
19  
20 use Smart::Comments;
21  
22 # public attributes (inherited)
23  
24  
25 # private attributes
26  
27 has '_line_iterator' => (
28 traits => ['Code'],
29 is => 'ro',
30 isa => 'CodeRef',
31 init_arg => undef,
32 lazy => 1,
33 builder => '_build_line_iterator',
34 handles => {
35 _next_line => 'execute',
36 },
37 );
38  
39  
40 ## no critic (ProhibitUnusedPrivateSubroutines)
41  
42 sub _build_line_iterator {
43 my $self = shift;
44  
45 open my $fh, '<', $self->file; # autodie
46 return sub { <$fh> }; # return closure
47 }
48  
49 ## use critic
50  
51  
52  
53 my @attrs = ( NewSeq->heads, 'outfile' );
54  
55 sub next_seq {
56 my $self = shift;
57  
58 LINE:
59 while (my $line = $self->_next_line) {
60  
61 # skip header/comments and empty lines
62 chomp $line;
63 next LINE if $line =~ $COMMENT_LINE
64 || $line =~ $EMPTY_LINE;
65  
66 # process TaxReport line
67 my $outfile = change_suffix( $self->filename, '.ali' );
68 my @fields = ( split(/\t/xms, $line), $outfile );
69  
70 # TODO: store top_ident? (Hervé)
71  
72 # Fields for tax-report file:
73 # 0. seq_id
74 # 1. contam_org
75 # 2. top_score
76 # 3. rel_n
77 # 4. mean_len
78 # 5. mean_ident
79 # 6. lca
80 # 7. lineage
81 # 8. acc
82 # 9. start
83 # 10. end
84 # 11. strand
85 # 12. seq
86 # 13. outfile
87  
88 # coerce numeric fields to numbers...
89 @fields[2..5,9..11] = map { 0 + ($_ || 0) } @fields[2..5,9..11];
90  
91 # build NewSeq object
92 my $new_seq = NewSeq->new( { mesh @attrs, @fields } );
93  
94 # return NewSeq object
95 return $new_seq;
96 }
97  
98 return; # no more line to read
99 }
100  
101  
102 __PACKAGE__->meta->make_immutable;
103 1;
104  
105 __END__
106  
107 =pod
108  
109 =head1 NAME
110  
111 Bio::MUST::Apps::Debrief42::TaxReport - Front-end class for tabular tax-report parser
112  
113 =head1 VERSION
114  
115 version 0.210570
116  
117 =head1 SYNOPSIS
118  
119 use aliased 'Bio::MUST::Apps::Debrief42::TaxReport';
120  
121 # open and parse FortyTwo tax-report in tabular format
122 my $infile = 'test/uL4.tax-report';
123 my $report = TaxReport->new( file => $infile );
124  
125 # loop through lines
126 while (my $new_seq = $report->next_line) {
127 my ($seq_id, $contam) = ($new_seq->hit_id, $new_seq->contam_org);
128 # ...
129 }
130  
131 =head1 DESCRIPTION
132  
133 # TODO
134  
135 =head1 ATTRIBUTES
136  
137 =head2 file
138  
139 Path to FortyTwo tax-report file in tabular format to be parsed
140  
141 =head1 METHODS
142  
143 =head2 next_seq
144  
145 Shifts the first line of the report off and returns it, shortening the report
146 by 1 and moving everything down. If there are no more lines in the report,
147 returns C<undef>.
148  
149 # $report is a Bio::MUST::Apps::Debrief42::TaxReport
150 while (my $new_seq = $report->next_seq) {
151 # process $new_seq
152 # ...
153 }
154  
155 This method does not accept any arguments.
156  
157 =head1 AUTHOR
158  
159 Denis BAURAIN <denis.baurain@uliege.be>
160  
161 =head1 CONTRIBUTOR
162  
163 =for stopwords Mick VAN VLIERBERGHE
164  
165 Mick VAN VLIERBERGHE <mvanvlierberghe@doct.uliege.be>
166  
167 =head1 COPYRIGHT AND LICENSE
168  
169 This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
170  
171 This is free software; you can redistribute it and/or modify it under
172 the same terms as the Perl 5 programming language system itself.
173  
174 =cut