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 0.0% 0 / 3 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 79 CC 2 SCAR 9.6
CC
2
Cov
0%
next_seq
6.0
_build_line_iterator
2.0
BEGIN
2.0
CRAP 2.6
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.262780';
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__