FastParsers/Hmmer/Standard/Iteration.pm

filter: Statementstmt 92.8% 52 / 56 Branchbran 100% 10 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 4 totaltotal 85.8% 73 / 85 CC 8 SCAR 14.3
CC
8
Cov
94%
__ANON__
8.0
next_hit
2.0
get_hit
2.0
CRAP 4.2
« FastParsers/CdHit.pm ↑ Summary FastParsers/Hmmer/DomTable.pm »
1 package Bio::FastParsers::Hmmer::Standard::Iteration;
2 # ABSTRACT: Front-end class for standard HMMER parser
3 # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com>
4 7 $Bio::FastParsers::Hmmer::Standard::Iteration::VERSION = '0.221230';
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 autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use List::AllUtils qw(indexes firstidx mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use Bio::FastParsers::Constants qw(:files);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use aliased 'Bio::FastParsers::Hmmer::Standard::Target';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # public attributes
17  
18 7 has 'query' => (
19 is => 'ro',
20 isa => 'Str',
21 required => 1,
22 );
23  
24 7 has 'query_length' => (
25 is => 'ro',
26 isa => 'Int',
27 required => 1,
28 );
29  
30 7 has 'targets' => (
31 traits => ['Array'],
32 is => 'ro',
33 isa => 'ArrayRef[Bio::FastParsers::Hmmer::Standard::Target]',
34 required => 1,
35 handles => {
36 next_target => 'shift',
37 get_target => 'get',
38 all_targets => 'elements',
39 count_targets => 'count',
40 },
41 );
42  
43 ## no critic (ProhibitUnusedPrivateSubroutines)
44  
45 10 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
46 10 my ($orig, $class, $iter_block) = @_;
47  
48 10 my %outargs;
49 my @hits;
50  
51 # Parse Iteration to separate header information (q, qlen), header hit
52 # table (Hit) and main output information per target (Target).
53 # Hit and Target are the same entity but Hit is close to what is retrieved
54 # from a Hmmer::Table output. For now, we chose to conserve Target as
55 # primary name since it is how it is called in the file.
56  
57 10 my @lines = split /\n/xms, $iter_block;
58  
59 LINE:
60 10 for my $line (@lines) {
61  
62 # parse header
63 110 ▶ if ($line =~ m/Query:/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Query:/msx) 10 100 110
64 10 my @fields = split /\s+/xms, $line;
65 10 $outargs{'query'} = $fields[1];
66 10 ( $outargs{'query_length'} = $fields[2] ) =~ s/\D//xmsg;
67 }
68  
69 # parse Hit
70 110 my @attrs = qw(
71 evalue score bias
72 best_dom_evalue best_dom_score best_dom_bias
73 exp dom query_name target_description
74 );
75  
76 110 ▶ if ($line =~ m/^\s+ (\d .*)/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s+ (\d .*)/msx) 20 90 110
77 20 my @fields = split /\s+/xms, $1;
78  
79 # Fields
80 # 0. full seq - evalue
81 # 1. full seq - score
82 # 2. full seq - bias
83 # 3. best domain - evalue
84 # 4. best domain - score
85 # 5. best domain - bias
86 # 6. #domain - exp
87 # 7. #domain - N
88 # 8. sequence
89 # 9. description
90  
91 # coerce numeric fields to numbers
92 20 @fields[0..7] = map { 0 + $_ } @fields[0..7];
93  
94 # fixing description
95 20 $fields[9] = join q{ }, @fields[9..$#fields];
96 # set missing/empty field values to undef
97 20 ▶ @fields[8..9] = map { $_ || undef } @fields[8..9];
Condition100%2/2
$_ || undef
l!l
2119
MC/DC100%1/1
$_ || undef
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
98  
99 20 my @wanted = @fields[0..9];
100 20 push @hits, { mesh @attrs, @wanted };
101 }
102  
103 # process only header
104 110 ▶ last LINE if $line =~ m/^\>\>/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\>\>/msx 10 100 110
105 }
106  
107 # split Targets (Hits)
108 10 ▶ my @target_indexes = indexes { m/^\>\>/xms } @lines;
Subroutine __ANON__: called CC=1 SCAR=0.0
109 10 my @targets;
110 10 ▶ for (my $i = 0; $i < @target_indexes; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @target_indexes) 20 10 30
111 20 ▶ my @block = defined $target_indexes[$i+1]
Branch: 1 branch
BranchTrueFalseTotal
defined $target_indexes[$i + 1] ? : 10 10 20
112 ? @lines[ $target_indexes[$i] .. $target_indexes[$i+1] ]
113 : splice @lines, $target_indexes[$i]
114 ;
115 20 push @targets, Target->new( { raw => \@block, hit => $hits[$i] } );
116 }
117 10 $outargs{targets} = \@targets;
118  
119 # return expected constructor hash
120 10 return $class->$orig(%outargs);
121 7 };
122  
123  
124 # aliases for Target/Hit
125  
126 0 ▶sub next_hit {
Subroutine next_hit: not called CC=1 SCAR=6.9
Pod undocumented
127 0 return shift->next_target;
128 }
129  
130 0 ▶sub get_hit { ## no critic (RequireArgUnpacking)
Subroutine get_hit: not called CC=1 SCAR=6.9
Pod undocumented
131 0 return shift->get_target(@_);
132 }
133  
134 0 ▶sub all_hits {
Subroutine all_hits: not called CC=1 SCAR=6.9
Pod undocumented
135 0 return shift->all_targets;
136 }
137  
138 0 ▶sub count_hits {
Subroutine count_hits: not called CC=1 SCAR=6.9
Pod undocumented
139 0 return shift->count_targets;
140 }
141  
142 7 __PACKAGE__->meta->make_immutable;
143 7 1;
144  
145 __END__
« FastParsers/CdHit.pm ↑ Summary FastParsers/Hmmer/DomTable.pm »