Finnigan/Profile.pm

filter: Statementstmt 41.5% 54 / 130 Branchbran 12.2% 10 / 82 Conditioncond 10.2% 4 / 39 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 76.4% 13 / 17 Podpod 100% 12 / 12 totaltotal 30.4% 93 / 305 CC 61 SCAR 65.1
CC
61
Cov
27%
print_bins
1332.0
bins
150.2
step
2.0
CRAP 671.8
↑ Summary Finnigan/Decoder.pm »
1 package Finnigan::Profile;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings FATAL => qw( all );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = 0.0206;
6  
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Finnigan;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use base 'Finnigan::Decoder';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 my $preamble = [
12 "first value" => ['d<', 'Float64'],
13 "step" => ['d<', 'Float64'],
14 "peak count" => ['V', 'UInt32'],
15 "nbins" => ['V', 'UInt32'],
16 ];
17  
18  
19 1 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
20 1 my $self = bless Finnigan::Decoder->read($_[1], $preamble), $_[0];
21 1 return $self->iterate_object($_[1], $self->{data}->{"peak count"}->{value}, chunks => 'Finnigan::ProfileChunk', $_[2]); # the last arg is layout
22 }
23  
24 1 ▶sub nchunks { # in place of the erroneous "peak_count"
Subroutine nchunks: called CC=1 SCAR=0.0
Pod documented
25 1 shift->{data}->{"peak count"}->{value};
26 }
27  
28 0 ▶sub peak_count { # deprecated
Subroutine peak_count: not called CC=1 SCAR=6.9
Pod documented
29 0 shift->{data}->{"peak count"}->{value};
30 }
31  
32 1 ▶sub nbins {
Subroutine nbins: called CC=1 SCAR=0.0
Pod documented
33 1 shift->{data}->{"nbins"}->{value};
34 }
35  
36 1 ▶sub first_value {
Subroutine first_value: called CC=1 SCAR=0.0
Pod documented
37 1 shift->{data}->{"first value"}->{value};
38 }
39  
40 1 ▶sub step {
Subroutine step: called CC=2 SCAR=7.1
Pod documented
41 1 my $self = shift;
42 1 ▶ confess "undefined" unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 1 1
43 1 $self->{data}->{"step"}->{value};
44 }
45  
46 0 ▶sub chunks {
Subroutine chunks: not called CC=1 SCAR=6.9
Pod documented
47 0 shift->{data}->{"chunks"}->{value};
48 }
49  
50 5 ▶sub chunk { # a syntactic eye-sore remover
Subroutine chunk: called CC=1 SCAR=0.0
Pod documented
51 5 shift->{data}->{"chunks"}->{value};
52 }
53  
54 1 ▶sub set_converter {
Subroutine set_converter: called CC=1 SCAR=0.0
Pod documented
55 1 $_[0]->{converter} = $_[1];
56 }
57  
58 0 ▶sub set_inverse_converter {
Subroutine set_inverse_converter: not called CC=1 SCAR=6.9
Pod documented
59 0 $_[0]->{"inverse converter"} = $_[1];
60 }
61  
62 1 ▶sub bins {
Subroutine bins: called CC=25 SCAR=50.1
Pod documented
63 1 my ($self, $range, $add_zeroes) = @_;
64 1 my @list;
65 1 my $start = $self->{data}->{"first value"}->{value};
66 1 my $step = $self->{data}->{step}->{value};
67 1 ▶ unless ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($range) 1 0 1
68 1 ▶ unless ( exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"converter"}) 0 1 1
69 0 $range = [$start, $start + $self->{data}->{nbins}->{value} * $step];
70 }
71 }
72  
73 1 ▶ push @list, [$range->[0], 0] if $add_zeroes;
Branch: 1 branch
BranchTrueFalseTotal
if $add_zeroes 0 1 1
74 1 my $last_bin_written = 0;
75  
76 1 my $shift = 0; # this is declared outside the chunk loop to allow
77 # writing the empty bin following the last chunk with
78 # the same amount of shift as in the last chunk
79  
80 1 foreach my $i ( 0 .. $self->{data}->{"peak count"}->{value} - 1 ) { # each chunk
81 580 my $chunk = $self->{data}->{chunks}->{value}->[$i];
82 580 my $first_bin = $chunk->{data}->{"first bin"}->{value};
83 580 ▶ $shift = $chunk->{data}->{fudge} ? $chunk->{data}->{fudge}->{value} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$chunk->{'data'}{'fudge'} ? : 580 0 580
84 580 my $x = $start + $first_bin * $step;
85  
86 580 ▶ if ( $add_zeroes and $last_bin_written < $first_bin - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_zeroes and $last_bin_written < $first_bin - 1) 0 580 580
Condition33%1/3
$add_zeroes and $last_bin_written < $first_bin - 1
!ll&&!rl&&r
58000
MC/DC0%0/2
$add_zeroes and $last_bin_written < $first_bin - 1
$add_zeroes $last_bin_written < $first_bin - 1
Truth table33%1/3
A and B
A= $add_zeroesB= $last_bin_written < $first_bin - 1
ABresult
0X0
100
111
87 # add an empty bin ahead of the chunk, unless there is no gap
88 # between this and the previous chunk
89 0 my $x0 = $x - $step;
90 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x0) + $shift : $x0;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
91 0 push @list, [$x_conv, 0];
92 }
93  
94 580 foreach my $j ( 0 .. $chunk->{data}->{nbins}->{value} - 1) {
95 3878 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift : $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 3878 0 3878
96 3878 $x += $step;
97 3878 ▶ if ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range) 0 3878 3878
98 0 ▶ if ( exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'converter'}) { } 0 0 0
99 0 ▶ next unless $x_conv >= $range->[0] and $x_conv <= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv >= $range->[0] and $x_conv <= $range->[1] 0 0 0
Condition0%0/3
$x_conv >= $range->[0] and $x_conv <= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv >= $range->[0] and $x_conv <= $range->[1]
$x_conv >= $range->[0] $x_conv <= $range->[1]
Truth table0%0/3
A and B
A= $x_conv >= $range->[0]B= $x_conv <= $range->[1]
ABresult
0X0
100
111
100 }
101 else {
102 # frequencies have the reverse order
103 0 ▶ next unless $x_conv <= $range->[0] and $x_conv >= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv <= $range->[0] and $x_conv >= $range->[1] 0 0 0
Condition0%0/3
$x_conv <= $range->[0] and $x_conv >= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv <= $range->[0] and $x_conv >= $range->[1]
$x_conv <= $range->[0] $x_conv >= $range->[1]
Truth table0%0/3
A and B
A= $x_conv <= $range->[0]B= $x_conv >= $range->[1]
ABresult
0X0
100
111
104 }
105 }
106 3878 my $bin = $first_bin + $j;
107 3878 push @list, [$x_conv, $chunk->{data}->{signal}->{value}->[$j]];
108 3878 $last_bin_written = $first_bin + $j;
109 }
110  
111 580 ▶ if ( $add_zeroes
Branch: 1 branch
BranchTrueFalseTotal
if ($add_zeroes and $i < $self->{"data"}{"peak count"}{"value"} - 1 and $last_bin_written < $self->{"data"}{"chunks"}{"value"}[$i + 1]{"data"}{"first bin"}{"value"} - 1) 0 580 580
Condition33%2/6
$add_zeroes and $i < $self->{"data"}{"peak count"}{"value"} - 1 and $last_bin_written < $self->{"data"}{"chunks"}{"value"}[$i + 1]{"data"}{"first bin"}{"value"} - 1
!ll&&!rl&&r
58000
$add_zeroes and $i < $self->{"data"}{"peak count"}{"value"} - 1
!ll&&!rl&&r
58000
MC/DC0%0/3
$add_zeroes and $i < $self->{"data"}{"peak count"}{"value"} - 1 and $last_bin_written < $self->{"data"}{"chunks"}{"value"}[$i + 1]{"data"}{"first bin"}{"value"} - 1
$add_zeroes $i < $self->{"data"}{"peak count"}{"value"} - 1 $last_bin_written < $self->{"data"}{"chunks"}{"value"}[$i + 1]{"data"}{"first bin"}{"value"} - 1
Truth table25%1/4
A and B and C
A= $add_zeroesB= $i < $self->{"data"}{"peak count"}{"value"} - 1C= $last_bin_written < $self->{"data"}{"chunks"}{"value"}[$i + 1]{"data"}{"first bin"}{"value"} - 1
ABCresult
0XX0
10X0
1100
1111
112 and
113 $i < $self->{data}->{"peak count"}->{value} - 1
114 and
115 $last_bin_written < $self->{data}->{chunks}->{value}->[$i+1]->{data}->{"first bin"}->{value} - 1
116 ) {
117 # add an empty bin following the chunk, unless there is no gap
118 # between this and the next chunk
119 0 my $bin = $last_bin_written + 1;
120 # $x has been incremented inside the chunk loop
121 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift: $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
122 0 push @list, [$x_conv, 0];
123 0 $last_bin_written++;
124 }
125 }
126  
127 1 ▶ if ( $add_zeroes and $last_bin_written < $self->{data}->{nbins}->{value} - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_zeroes and $last_bin_written < $self->{"data"}{"nbins"}{"value"} - 1) 0 1 1
Condition33%1/3
$add_zeroes and $last_bin_written < $self->{"data"}{"nbins"}{"value"} - 1
!ll&&!rl&&r
100
MC/DC0%0/2
$add_zeroes and $last_bin_written < $self->{"data"}{"nbins"}{"value"} - 1
$add_zeroes $last_bin_written < $self->{"data"}{"nbins"}{"value"} - 1
Truth table33%1/3
A and B
A= $add_zeroesB= $last_bin_written < $self->{"data"}{"nbins"}{"value"} - 1
ABresult
0X0
100
111
128 # add an empty bin following the last chunk, unless there is no gap
129 # left between it and the end of the range ($self->nbins - 1)
130 0 my $x = $start + ($last_bin_written + 1) * $step;
131 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift: $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
132 0 push @list, [$x_conv, 0];
133 0 ▶ push @list, [$range->[1], 0] if $add_zeroes;
Branch: 1 branch
BranchTrueFalseTotal
if $add_zeroes 0 0 0
134 }
135 1 return \@list;
136 }
137  
138 0 ▶sub print_bins {
Subroutine print_bins: not called CC=36 SCAR=71.9
Pod documented
139 0 my ($self, $range, $add_zeroes) = @_;
140 0 my @list;
141 0 my $data = $self->{data};
142 0 my $start = $data->{"first value"}->{value};
143 0 my $step = $data->{step}->{value};
144 0 my $chunks = $data->{chunks}->{value};
145  
146 0 ▶ unless ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($range) 0 0 0
147 0 ▶ unless (exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"converter"}) 0 0 0
148 0 $range = [$start, $start + $data->{nbins}->{value} * $step];
149 }
150 }
151  
152 0 ▶ print "$range->[0]\t0\n" if $add_zeroes;
Branch: 1 branch
BranchTrueFalseTotal
if $add_zeroes 0 0 0
153  
154 0 my $shift = 0; # this is declared outside the chunk loop to allow
155 # writing the empty bin following the last chunk with
156 # the same amount of shift as in the last chunk
157  
158 0 foreach my $i ( 0 .. $data->{"peak count"}->{value} - 1 ) { # each chunk
159 0 my $chunk = $chunks->[$i]->{data};
160 0 my $first_bin = $chunk->{"first bin"}->{value};
161 0 ▶ $shift = $chunk->{fudge} ? $chunk->{fudge}->{value} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$chunk->{'fudge'} ? : 0 0 0
162 0 my $x = $start + $first_bin * $step;
163 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift : $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
164  
165 # print all points in the chunk that fall within the specified range
166 0 foreach my $j ( 0 .. $chunk->{nbins}->{value} - 1) {
167 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift : $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
168 0 $x += $step;
169 0 ▶ if ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range) 0 0 0
170 0 ▶ if ( exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'converter'}) { } 0 0 0
171 0 ▶ next unless $x_conv >= $range->[0] and $x_conv <= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv >= $range->[0] and $x_conv <= $range->[1] 0 0 0
Condition0%0/3
$x_conv >= $range->[0] and $x_conv <= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv >= $range->[0] and $x_conv <= $range->[1]
$x_conv >= $range->[0] $x_conv <= $range->[1]
Truth table0%0/3
A and B
A= $x_conv >= $range->[0]B= $x_conv <= $range->[1]
ABresult
0X0
100
111
172 }
173 else {
174 # frequencies have the reverse order
175 0 ▶ next unless $x_conv <= $range->[0] and $x_conv >= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv <= $range->[0] and $x_conv >= $range->[1] 0 0 0
Condition0%0/3
$x_conv <= $range->[0] and $x_conv >= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv <= $range->[0] and $x_conv >= $range->[1]
$x_conv <= $range->[0] $x_conv >= $range->[1]
Truth table0%0/3
A and B
A= $x_conv <= $range->[0]B= $x_conv >= $range->[1]
ABresult
0X0
100
111
176 }
177 }
178 0 my $bin = $first_bin + $j;
179 0 print "$x_conv\t" . $chunk->{signal}->{value}->[$j] . "\n";
180 }
181  
182 0 ▶ if ( $add_zeroes and $i < $data->{"peak count"}->{value} - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_zeroes and $i < $data->{"peak count"}{"value"} - 1) 0 0 0
Condition0%0/3
$add_zeroes and $i < $data->{"peak count"}{"value"} - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$add_zeroes and $i < $data->{"peak count"}{"value"} - 1
$add_zeroes $i < $data->{"peak count"}{"value"} - 1
Truth table0%0/3
A and B
A= $add_zeroesB= $i < $data->{"peak count"}{"value"} - 1
ABresult
0X0
100
111
183 0 my $from = $chunks->[$i]->first_bin + $chunks->[$i]->{data}->{nbins}->{value};
184 0 my $to = $chunks->[$i+1]->first_bin - 1;
185 0 ▶ if ($to >= $from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to >= $from) 0 0 0
186 0 foreach my $bin ( $from .. $to ) {
187 0 my $x = $start + $bin * $step;
188 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift: $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
189 0 ▶ if ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range) 0 0 0
190 0 ▶ if ( exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'converter'}) { } 0 0 0
191 0 ▶ next unless $x_conv >= $range->[0] and $x_conv <= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv >= $range->[0] and $x_conv <= $range->[1] 0 0 0
Condition0%0/3
$x_conv >= $range->[0] and $x_conv <= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv >= $range->[0] and $x_conv <= $range->[1]
$x_conv >= $range->[0] $x_conv <= $range->[1]
Truth table0%0/3
A and B
A= $x_conv >= $range->[0]B= $x_conv <= $range->[1]
ABresult
0X0
100
111
192 }
193 else {
194 # frequencies have the reverse order
195 0 ▶ next unless $x_conv <= $range->[0] and $x_conv >= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv <= $range->[0] and $x_conv >= $range->[1] 0 0 0
Condition0%0/3
$x_conv <= $range->[0] and $x_conv >= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv <= $range->[0] and $x_conv >= $range->[1]
$x_conv <= $range->[0] $x_conv >= $range->[1]
Truth table0%0/3
A and B
A= $x_conv <= $range->[0]B= $x_conv >= $range->[1]
ABresult
0X0
100
111
196 }
197 }
198 0 print "$x_conv\t0\n";
199 }
200 }
201 }
202 }
203  
204 # get the last bin number in the last chunk
205 0 ▶ if ( $add_zeroes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add_zeroes) 0 0 0
206 0 my $last_chunk = $chunks->[$data->{"peak count"}->{value} - 1];
207 0 my $first_trailer_bin = $last_chunk->{data}->{"first bin"}->{value} + $last_chunk->{data}->{nbins}->{value};
208 0 ▶ if ( $first_trailer_bin < $data->{nbins}->{value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_trailer_bin < $data->{"nbins"}{"value"}) 0 0 0
209 0 foreach my $bin ( $first_trailer_bin .. $self->{data}->{nbins}->{value} - 1 ) {
210 0 my $x = $start + $bin * $step;
211 0 ▶ my $x_conv = exists $self->{converter} ? &{$self->{converter}}($x) + $shift : $x;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'converter'} ? : 0 0 0
212 0 ▶ if ( $range ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range) 0 0 0
213 0 ▶ if ( exists $self->{converter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'converter'}) { } 0 0 0
214 0 ▶ next unless $x_conv >= $range->[0] and $x_conv <= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv >= $range->[0] and $x_conv <= $range->[1] 0 0 0
Condition0%0/3
$x_conv >= $range->[0] and $x_conv <= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv >= $range->[0] and $x_conv <= $range->[1]
$x_conv >= $range->[0] $x_conv <= $range->[1]
Truth table0%0/3
A and B
A= $x_conv >= $range->[0]B= $x_conv <= $range->[1]
ABresult
0X0
100
111
215 }
216 else {
217 # frequencies have the reverse order
218 0 ▶ next unless $x_conv <= $range->[0] and $x_conv >= $range->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $x_conv <= $range->[0] and $x_conv >= $range->[1] 0 0 0
Condition0%0/3
$x_conv <= $range->[0] and $x_conv >= $range->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$x_conv <= $range->[0] and $x_conv >= $range->[1]
$x_conv <= $range->[0] $x_conv >= $range->[1]
Truth table0%0/3
A and B
A= $x_conv <= $range->[0]B= $x_conv >= $range->[1]
ABresult
0X0
100
111
219 }
220 }
221 0 print "$x_conv\t0\n";
222 }
223 }
224 0 print "$range->[1]\t0\n";
225 }
226 }
227  
228 2 1;
229 __END__
↑ Summary Finnigan/Decoder.pm »