Finnigan/Scan.pm

filter: Statementstmt 51.1% 129 / 252 Branchbran 28.3% 17 / 60 Conditioncond 22.8% 8 / 35 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 72.4% 21 / 29 Podpod 100% 4 / 4 totaltotal 45.0% 181 / 402 CC 54 SCAR 41.7
CC
54
Cov
44%
find_chunk
182.0
bins
126.0
find_peak_intensity
56.0
CRAP 64.7
« Finnigan/Decoder.pm ↑ Summary Finnigan/GenericDataDescriptor.pm »
1 2 ▶use feature qw/state say/;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
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  
6 # ----------------------------------------------------------------------------------------
7 package Finnigan::Scan::Profile;
8 2 our $VERSION = 0.0206;
9  
10 2 my $MAX_DIST = 0.025; # kHz
11 2 my $MAX_DIST_MZ = 0.001; # M/z
12  
13 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
14 1 my ($class, $buf, $layout) = @_;
15 1 my $self = {};
16 1 @{$self}{'first value', 'step', 'peak count', 'nbins'} = unpack 'd<d<VV', $buf;
17 1 my $offset = 24; # ddVV
18  
19 1 my $chunk;
20 1 foreach my $i (0 .. $self->{'peak count'} - 1) {
21 580 $chunk = new Finnigan::Scan::ProfileChunk $buf, $offset, $layout;
22 580 $offset += $chunk->{size};
23 580 push @{$self->{chunks}}, $chunk;
24 }
25  
26 1 return bless $self, $class;
27 }
28  
29 1 ▶sub set_converter {
Subroutine set_converter: called CC=1 SCAR=0.0
30 1 $_[0]->{converter} = $_[1];
31 }
32  
33 0 ▶sub set_inverse_converter {
Subroutine set_inverse_converter: not called CC=1 SCAR=6.9
34 0 $_[0]->{"inverse converter"} = $_[1];
35 }
36  
37 0 ▶sub nchunks { # instead of the deprecated peak_count()
Subroutine nchunks: not called CC=1 SCAR=6.9
38 0 $_[0]->{"peak count"};
39 }
40  
41 0 ▶sub peak_count { # deprecated
Subroutine peak_count: not called CC=1 SCAR=6.9
42 0 $_[0]->{"peak count"};
43 }
44  
45 0 ▶sub print_bins {
Subroutine print_bins: not called CC=2 SCAR=17.9
46 0 my ($self, $bookends) = @_;
47  
48 0 foreach ( @{$self->bins($bookends)} ) {
49 0 say join "\t", @$_;
50 }
51 }
52  
53 1 ▶sub bins {
Subroutine bins: called CC=19 SCAR=48.4
54 1 my ($self, $bookends) = @_;
55 1 my @list;
56 1 my $start = $self->{"first value"};
57 1 my $step = $self->{step};
58  
59 # Write something at the start of the range
60 1 my $front_bookend_needed;
61 1 ▶ if ($bookends) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bookends) 0 1 1
62 0 ▶ my $fudge = $self->{chunks}->[0]->{'fudge'} || 0;
Condition0%0/2
$self->{'chunks'}[0]{'fudge'} || 0
l!l
00
MC/DC0%0/1
$self->{'chunks'}[0]{'fudge'} || 0
$self->{'chunks'}[0]{'fudge'}
Truth table0%0/2
A
A= $self->{'chunks'}[0]{'fudge'}
Aresult
11
00
63 0 my $startMz = &{$self->{converter}}( $start + $step ) + $fudge;
64 0 my $next_chunk_start = $self->{chunks}->[0]->{'first bin'};
65 0 my $gap_size = $next_chunk_start - 0; # will see if it's 0 or 1
66 0 my $fill_size;
67 0 ▶ if ( $gap_size < 2 * $bookends ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gap_size < 2 * $bookends) { } 0 0 0
68 0 $fill_size = $gap_size;
69 0 $front_bookend_needed = 0;
70 }
71 else {
72 0 $fill_size = $bookends;
73 0 $front_bookend_needed = 1;
74 }
75  
76 0 foreach my $j ( 1 .. $fill_size ) {
77 0 push @list, [&{$self->{converter}}( $start + $j * $step ) + $fudge, 0]
78 }
79 }
80  
81 1 my $fudge = 0; # this is declared outside the chunk loop to allow
82 # writing the empty bins at the end of the range with
83 # the same amount of fudge as in the last chunk
84  
85 1 foreach my $i ( 0 .. $self->{"peak count"} - 1 ) { # each chunk
86 580 my $chunk = $self->{chunks}->[$i];
87 580 my $first_bin = $chunk->{'first bin'};
88 580 ▶ $fudge = $chunk->{fudge} || 0;
Condition100%2/2
$chunk->{'fudge'} || 0
l!l
356224
MC/DC100%1/1
$chunk->{'fudge'} || 0
$chunk->{'fudge'}
Truth table100%2/2
A
A= $chunk->{'fudge'}
Aresult
11
00
89 580 my $x = $start + $first_bin * $step;
90  
91 # front bookend
92 580 ▶ if ( $bookends and $front_bookend_needed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bookends and $front_bookend_needed) 0 580 580
Condition33%1/3
$bookends and $front_bookend_needed
!ll&&!rl&&r
58000
MC/DC0%0/2
$bookends and $front_bookend_needed
$bookends $front_bookend_needed
Truth table33%1/3
A and B
A= $bookendsB= $front_bookend_needed
ABresult
0X0
100
111
93 # add empty bins ahead of the chunk
94 0 foreach my $j ( $first_bin - $bookends .. $first_bin - 1) {
95 0 push @list, [&{$self->{converter}}( $start + $j * $step ) + $fudge, 0];
96 }
97 }
98  
99 # chunk data
100 580 foreach my $j ( 0 .. $chunk->{nbins} - 1) {
101 3878 push @list, [&{$self->{converter}}( $start + ($first_bin + $j) * $step ) + $fudge, $chunk->{signal}->[$j]];
102 }
103  
104 # tail bookeend
105 580 ▶ if ( $bookends ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bookends) 0 580 580
106  
107 # determine the number of gap bins
108 0 my $next_chunk_start;
109 my $next_chunks_fudge;
110 0 ▶ if ($i == $self->{'peak count'} - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $self->{'peak count'} - 1) { } 0 0 0
111 0 $next_chunk_start = $self->{nbins};
112 0 $next_chunks_fudge = $fudge;
113 }
114 else {
115 0 $next_chunk_start = $self->{chunks}->[$i + 1]->{'first bin'};
116 0 ▶ $next_chunks_fudge = $self->{chunks}->[$i + 1]->{fudge} || 0; # not all profiles have the fudge value
Condition0%0/2
$self->{'chunks'}[$i + 1]{'fudge'} || 0
l!l
00
MC/DC0%0/1
$self->{'chunks'}[$i + 1]{'fudge'} || 0
$self->{'chunks'}[$i + 1]{'fudge'}
Truth table0%0/2
A
A= $self->{'chunks'}[$i + 1]{'fudge'}
Aresult
11
00
117 }
118 0 my $gap_size = $next_chunk_start - $first_bin - $chunk->{nbins}; # will see if it's 0 or 1
119 0 my $fill_size = $bookends;
120 0 ▶ if ( $gap_size < 2 * $bookends ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gap_size < 2 * $bookends) { } 0 0 0
121 0 $fill_size = $gap_size;
122 0 $front_bookend_needed = 0;
123 }
124 else {
125 0 $front_bookend_needed = 1;
126 }
127  
128 # write the tail bookend
129 0 foreach my $j ( $chunk->{nbins} .. $chunk->{nbins} + $fill_size - 1 ) {
130 # Using the next chunk's fudge to add zeroes to this chunk is unreasonable, but whatever they please...
131 0 push @list, [&{$self->{converter}}( $start + ($first_bin + $j) * $step ) + $next_chunks_fudge, 0]
132 }
133 }
134 }
135  
136 # filling the bookend at the end of the range
137 1 ▶ if ( $bookends and $front_bookend_needed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bookends and $front_bookend_needed) 0 1 1
Condition33%1/3
$bookends and $front_bookend_needed
!ll&&!rl&&r
100
MC/DC0%0/2
$bookends and $front_bookend_needed
$bookends $front_bookend_needed
Truth table33%1/3
A and B
A= $bookendsB= $front_bookend_needed
ABresult
0X0
100
111
138 0 my $last_bin = $self->{nbins};
139 0 foreach my $j ( $last_bin - $bookends + 1 .. $last_bin) {
140 0 push @list, [&{$self->{converter}}( $start + $j * $step ) + $fudge, 0];
141 }
142 }
143  
144 1 return \@list;
145 }
146  
147 0 ▶sub find_peak_intensity {
Subroutine find_peak_intensity: not called CC=7 SCAR=40.3
148 # Finds the nearest peak in the profile for a given query value.
149 # One possible use is to look up the precursor ion intensity, since
150 # it is not stored as a separate item anywhere in the data file.
151 # Return the intensity the peak matching the query M/z.
152 0 my ($self, $query) = @_;
153 0 my $raw_query = &{$self->{"inverse converter"}}($query);
154  
155 # find the closest chunk
156 0 my ($nearest_chunk, $dist) = $self->find_chunk($raw_query);
157 0 ▶ if (not defined $dist or $dist > $MAX_DIST) { # undefind $dist means we're outside the full range of peaks in the scan
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dist or $dist > $MAX_DIST) 0 0 0
Condition0%0/3
not defined $dist or $dist > $MAX_DIST
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $dist or $dist > $MAX_DIST
not defined $dist $dist > $MAX_DIST
Truth table0%0/3
not(A) or B
A= not defined $distB= $dist > $MAX_DIST
ABresult
1X1
011
000
158 0 say STDERR "$self->{'dependent scan number'}: could not find a profile peak in parent scan $self->{'scan number'} within ${MAX_DIST} M/z of the target frequency $raw_query (M/z $query)";
159 0 return 0;
160 }
161  
162 0 my @chunk_ix = ($nearest_chunk);
163 0 my $i = $nearest_chunk;
164 0 ▶ while ( $i < $self->{"peak count"} - 1 and $self->chunk_dist($i, $i++) <= $MAX_DIST ) { # kHz
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"peak count"} - 1 and $self->chunk_dist($i, $i++) <= $MAX_DIST) 0 0 0
Condition0%0/3
$i < $self->{"peak count"} - 1 and $self->chunk_dist($i, $i++) <= $MAX_DIST
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $self->{"peak count"} - 1 and $self->chunk_dist($i, $i++) <= $MAX_DIST
$i < $self->{"peak count"} - 1 $self->chunk_dist($i, $i++) <= $MAX_DIST
Truth table0%0/3
A and B
A= $i < $self->{"peak count"} - 1B= $self->chunk_dist($i, $i++) <= $MAX_DIST
ABresult
0X0
100
111
165 0 push @chunk_ix, $i;
166 }
167 0 $i = $nearest_chunk;
168 0 ▶ while ( $i > 0 and $self->chunk_dist($i, $i--) <= $MAX_DIST ) { # kHz
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $self->chunk_dist($i, $i--) <= $MAX_DIST) 0 0 0
Condition0%0/3
$i > 0 and $self->chunk_dist($i, $i--) <= $MAX_DIST
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $self->chunk_dist($i, $i--) <= $MAX_DIST
$i > 0 $self->chunk_dist($i, $i--) <= $MAX_DIST
Truth table0%0/3
A and B
A= $i > 0B= $self->chunk_dist($i, $i--) <= $MAX_DIST
ABresult
0X0
100
111
169 0 push @chunk_ix, $i;
170 }
171  
172 0 return (sort {$b <=> $a} map {$self->chunk_max($_)} @chunk_ix)[0]; # max. intensity
173 }
174  
175 0 ▶sub chunk_dist {
Subroutine chunk_dist: not called CC=1 SCAR=6.9
176 # find the gap distance between the chunks
177 0 my ($self, $i, $j) = @_;
178 0 my ($chunk_i, $chunk_j) = ($self->{chunks}->[$i], $self->{chunks}->[$j]);
179 0 my $start = $self->{"first value"};
180 0 my $step = $self->{step};
181 0 my $min_i = $start + ($chunk_i->{"first bin"} - 1) * $step;
182 0 my $max_i = $min_i + $chunk_i->{nbins} * $step;
183 0 my $min_j = $start + ($chunk_j->{"first bin"} - 1) * $step;
184 0 my $max_j = $min_j + $chunk_j->{nbins} * $step;
185 0 my $dist = (sort {$a <=> $b}
186 (
187 abs($min_i - $min_j),
188 abs($min_i - $max_j),
189 abs($max_i - $min_j),
190 abs($max_i - $max_j)
191 )
192 )[0];
193 0 return $dist;
194 }
195  
196 0 ▶sub chunk_max {
Subroutine chunk_max: not called CC=3 SCAR=24.8
197 0 my ($self, $num) = @_;
198 0 my $chunk = $self->{chunks}->[$num];
199 0 my $max = 0;
200 0 foreach my $i ( 0 .. $chunk->{nbins} - 1) {
201 0 my $intensity = $chunk->{signal}->[$i];
202 0 ▶ $max = $intensity if $intensity > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $intensity > $max 0 0 0
203 }
204 0 return $max;
205 }
206  
207 0 ▶sub find_chunk {
Subroutine find_chunk: not called CC=13 SCAR=52.0
208 # Use binary search to find a pair of profile chunks
209 # in the (sorted) chunk list surrounding the probe value
210  
211 0 my ( $self, $value) = @_;
212 0 my $chunks = $self->{chunks};
213 0 my $first_value = $self->{"first value"};
214 0 my $step = $self->{step};
215 0 my ( $lower, $upper, $low_ix, $high_ix, $cur );
216 0 my $safety_count = 15;
217 0 my $last_match = [undef, 100000];
218 0 my $dist;
219  
220 0 ( $upper, $lower ) = ( $first_value, $first_value + $step * $self->{nbins} ) ;
221 0 ▶ if ( $value < $lower - $MAX_DIST or $value > $upper + $MAX_DIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $lower - $MAX_DIST or $value > $upper + $MAX_DIST) { } 0 0 0
Condition0%0/3
$value < $lower - $MAX_DIST or $value > $upper + $MAX_DIST
l!l&&r!l&&!r
000
MC/DC0%0/2
$value < $lower - $MAX_DIST or $value > $upper + $MAX_DIST
$value < $lower - $MAX_DIST $value > $upper + $MAX_DIST
Truth table0%0/3
A or B
A= $value < $lower - $MAX_DISTB= $value > $upper + $MAX_DIST
ABresult
1X1
011
000
222 0 return (undef, undef);
223 }
224 else {
225 0 ( $low_ix, $high_ix ) = ( 0, $self->{"peak count"} - 1 );
226 0 ▶ while ( $low_ix < $high_ix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($low_ix < $high_ix) 0 0 0
227 0 ▶ die "broken find_chunk algorithm" unless $safety_count--;
Branch: 1 branch
BranchTrueFalseTotal
unless $safety_count-- 0 0 0
228 0 $cur = int ( ( $low_ix + $high_ix ) / 2 );
229 0 my $chunk = $chunks->[$cur];
230 0 $upper = $first_value + $chunk->{"first bin"} * $step;
231 0 $lower = $upper + $chunk->{nbins} * $step;
232 # say STDERR " testing: $cur [$lower .. $upper] against $value in [$low_ix .. $high_ix]";
233 0 ▶ if ( $value >= $lower and $value <= $upper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value >= $lower and $value <= $upper) 0 0 0
Condition0%0/3
$value >= $lower and $value <= $upper
!ll&&!rl&&r
000
MC/DC0%0/2
$value >= $lower and $value <= $upper
$value >= $lower $value <= $upper
Truth table0%0/3
A and B
A= $value >= $lowerB= $value <= $upper
ABresult
0X0
100
111
234 # say STDERR " direct hit";
235 0 return ($cur, 0);
236 }
237 0 ▶ if ( $value > $upper ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $upper) 0 0 0
238 0 $dist = (sort {$a <=> $b} (abs($value - $lower), abs($value - $upper)))[0];
239 0 ▶ $last_match = [$cur, $dist] if $dist < $last_match->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $dist < $last_match->[1] 0 0 0
240 # say STDERR " distance = $dist, shifting up";
241 0 $high_ix = $cur;
242 }
243 0 ▶ if ( $value < $lower ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $lower) 0 0 0
244 0 $dist = (sort {$a <=> $b} (abs($value - $lower), abs($value - $upper)))[0];
245 0 ▶ $last_match = [$cur, $dist] if $dist < $last_match->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $dist < $last_match->[1] 0 0 0
246 # say STDERR " distance = $dist; shifting down";
247 0 $low_ix = $cur + 1;
248 }
249 # say STDERR "The remainder: $low_ix, $high_ix";
250 }
251 # say STDERR "The final remainder: $low_ix, $high_ix";
252 }
253  
254 0 ▶ if ( $low_ix == $high_ix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($low_ix == $high_ix) 0 0 0
255 # this is one of possibly two closest chunks, with no direct hits found
256 0 my $chunk = $chunks->[$low_ix];
257 0 $upper = $first_value + $chunk->{"first bin"} * $step;
258 0 $lower = $upper + $chunk->{nbins} * $step;
259 0 my $dist = (sort {$a <=> $b} (abs($value - $lower), abs($value - $upper)))[0];
260  
261 0 my ($closest_chunk, $min_dist) = ($low_ix, $dist);
262 0 ▶ if ( $dist > $last_match->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist > $last_match->[1]) 0 0 0
263 0 ($closest_chunk, $min_dist) = @$last_match;
264 }
265 # say STDERR " no direct hit; closest chunk is $closest_chunk; distance between $value and [$lower, $upper] is $min_dist";
266 0 return ($closest_chunk, $min_dist);
267 }
268  
269 0 die "unexpected condition";
270 }
271  
272 #----------------------------------------------------------------------------------------
273 package Finnigan::Scan;
274 2 our $VERSION = 0.0206;
275  
276 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
277 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
278  
279 2 ▶use Finnigan;
Subroutine BEGIN: called CC=1 SCAR=0.0
280  
281 1 ▶sub decode {
Subroutine decode: called CC=3 SCAR=11.0
Pod documented
282 1 my ($class, $stream) = @_;
283  
284 1 my $self = {
285 addr => tell $stream
286 };
287 1 my $buf;
288 my $nbytes;
289 1 my $bytes_to_read;
290 1 my $current_addr;
291  
292 1 $self->{header} = Finnigan::PacketHeader->decode($stream);
293 1 $self->{size} = $self->{header}->{size};
294 1 my $header_data = $self->{header}->{data};
295  
296 1 $bytes_to_read = 4 * $header_data->{"profile size"}->{value};
297 1 $nbytes = CORE::read $stream, $self->{"raw profile"}, $bytes_to_read;
298 $nbytes == $bytes_to_read
299 1 ▶ or die "could not read all $bytes_to_read bytes of scan profile at " . ($self->{addr} + $self->{size});
Branch: 1 branch
BranchTrueFalseTotal
$nbytes == $bytes_to_read or die "could not read all $bytes_to_read bytes of scan profile at " . ($self->{"addr"} + $self->{"size"}) 1 0 1
300 1 $self->{size} += $nbytes;
301  
302 1 $bytes_to_read = 4 * $header_data->{"peak list size"}->{value};
303 1 $nbytes = CORE::read $stream, $self->{"raw centroids"}, $bytes_to_read;
304 $nbytes == $bytes_to_read
305 1 ▶ or die "could not read all $bytes_to_read bytes of scan profile at " . ($self->{addr} + $self->{size});
Branch: 1 branch
BranchTrueFalseTotal
$nbytes == $bytes_to_read or die "could not read all $bytes_to_read bytes of scan profile at " . ($self->{"addr"} + $self->{"size"}) 1 0 1
306 1 $self->{size} += $nbytes;
307  
308 # skip peak descriptors and the unknown streams
309 $self->{size} += 4 * (
310 $header_data->{"descriptor list size"}->{value} +
311 $header_data->{"size of unknown stream"}->{value} +
312 $header_data->{"size of triplet stream"}->{value}
313 1 );
314 1 seek $stream, $self->{addr} + $self->{size}, 0;
315  
316 1 return bless $self, $class;
317 }
318  
319 1 ▶sub header {
Subroutine header: called CC=1 SCAR=0.0
Pod documented
320 1 return shift->{header};
321 }
322  
323 1 ▶sub profile {
Subroutine profile: called CC=1 SCAR=0.0
Pod documented
324 1 new Finnigan::Scan::Profile $_[0]->{"raw profile"}, $_[0]->{header}->{data}->{layout}->{value};
325 }
326  
327 1 ▶sub centroids {
Subroutine centroids: called CC=1 SCAR=0.0
Pod documented
328 1 new Finnigan::Scan::CentroidList $_[0]->{"raw centroids"};
329 }
330  
331 # end Finnigan::Scan::Profile
332 # ----------------------------------------------------------------------------------------
333 package Finnigan::Scan::ProfileChunk;
334 2 our $VERSION = 0.0206;
335  
336 580 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
337 580 my ($class, $buf, $offset, $layout) = @_;
338 580 my $self = {};
339 580 ▶ if ( $layout > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout > 0) { } 580 0 580
340 580 @{$self}{'first bin', 'nbins', 'fudge'} = unpack "x${offset} VVf<", $buf;
341 580 $self->{size} = 12;
342 }
343 else {
344 0 @{$self}{'first bin', 'nbins'} = unpack "x${offset} VV", $buf;
345 0 $self->{size} = 8;
346 }
347 580 $offset += $self->{size};
348  
349 580 @{$self->{signal}} = unpack "x${offset} f<$self->{nbins}", $buf;
350 580 $self->{size} += 4 * $self->{nbins};
351  
352 580 return bless $self, $class;
353 }
354  
355 #----------------------------------------------------------------------------------------
356 package Finnigan::Scan::CentroidList;
357 2 our $VERSION = 0.0206;
358  
359 1 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
360 1 my ($class, $buf) = @_;
361 1 my $self = {count => unpack 'V', $buf};
362 1 my $offset = 4; # V
363  
364 1 my $chunk;
365 1 foreach my $i (0 .. $self->{count} - 1) {
366 580 push @{$self->{peaks}}, [unpack "x${offset} f<f<", $buf];
367 580 $offset += 8;
368 }
369  
370 1 return bless $self, $class;
371 }
372  
373 1 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
374 1 shift->{count};
375 }
376  
377 2 ▶sub list {
Subroutine list: called CC=1 SCAR=0.0
378 2 shift->{peaks};
379 }
380  
381 2 ▶sub find_peak_intensity {
Subroutine find_peak_intensity: called CC=3 SCAR=11.0
382 # Finds the nearest peak in the profile for a given query value.
383  
384 2 my ($self, $query) = @_;
385  
386 # find the closest peak
387 2 my ($nearest_peak, $dist) = $self->find_peak($query);
388 2 ▶ if (not defined $dist or $dist > $MAX_DIST_MZ) { # undefind $dist means we're outside the full range of peaks in the scan
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dist or $dist > $MAX_DIST_MZ) 1 1 2
Condition66%2/3
not defined $dist or $dist > $MAX_DIST_MZ
l!l&&r!l&&!r
011
MC/DC50%1/2
not defined $dist or $dist > $MAX_DIST_MZ
not defined $dist $dist > $MAX_DIST_MZ
Truth table66%2/3
not(A) or B
A= not defined $distB= $dist > $MAX_DIST_MZ
ABresult
1X1
011
000
389 1 say STDERR "$self->{'dependent scan number'}: could not find a profile peak in parent scan $self->{'scan number'} within ${MAX_DIST_MZ} M/z the target value $query";
390 1 return 0;
391 }
392  
393 1 return $self->{peaks}->[$nearest_peak]->[1];
394 }
395  
396 5 ▶sub find_peak {
Subroutine find_peak: called CC=7 SCAR=19.8
397 # Use binary search to find a pair of peaks
398 # surrounding the probe value
399  
400 # One possible use is to look up the precursor ion intensity, since
401 # it is not stored as a separate item anywhere in the data file.
402  
403 5 my ( $self, $value) = @_;
404 5 my ( $lower, $upper, $low_ix, $high_ix, $mid_ix );
405 5 my $safety_count = 15;
406 5 my $dist;
407  
408 39 ▶ sub num_equal {
Subroutine num_equal: called CC=2 SCAR=7.2
409 39 my( $float1, $float2, $diff ) = @_;
410 39 ▶ abs( $float1 - $float2 ) < ($diff or 0.00001);
Condition50%1/2
$diff || 1e-05
l!l
390
MC/DC0%0/1
$diff || 1e-05
$diff
Truth table50%1/2
A
A= $diff
Aresult
11
00
411 }
412  
413 5 ( $low_ix, $high_ix ) = ( 0, $self->{count} - 1 );
414 5 ( $lower, $upper ) = ($self->{peaks}->[$low_ix]->[0], $self->{peaks}->[$high_ix]->[0]);
415 5 ▶ if ( $value < $lower - $MAX_DIST_MZ or $value > $upper + $MAX_DIST_MZ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $lower - $MAX_DIST_MZ or $value > $upper + $MAX_DIST_MZ) { } 0 5 5
Condition33%1/3
$value < $lower - $MAX_DIST_MZ or $value > $upper + $MAX_DIST_MZ
l!l&&r!l&&!r
005
MC/DC0%0/2
$value < $lower - $MAX_DIST_MZ or $value > $upper + $MAX_DIST_MZ
$value < $lower - $MAX_DIST_MZ $value > $upper + $MAX_DIST_MZ
Truth table33%1/3
A or B
A= $value < $lower - $MAX_DIST_MZB= $value > $upper + $MAX_DIST_MZ
ABresult
1X1
011
000
416 0 return (undef, undef);
417 }
418 else {
419 5 my $dist;
420 5 ▶ while ( $low_ix <= $high_ix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($low_ix <= $high_ix) 39 2 41
421 39 ▶ die "broken find_peak algorithm" unless $safety_count--;
Branch: 1 branch
BranchTrueFalseTotal
unless $safety_count-- 0 39 39
422 39 $mid_ix = $low_ix + int ( ( $high_ix - $low_ix ) / 2 );
423 39 my $peak = $self->{peaks}->[$mid_ix];
424 39 $dist = abs($value - $peak->[0]);
425 # say STDERR " testing: $mid_ix [$peak->[0]] against $value";
426 39 ▶ if ( num_equal($peak->[0], $value, $MAX_DIST_MZ ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (num_equal($peak->[0], $value, $MAX_DIST_MZ)) { } 3 36 39
elsif ($peak->[0] < $value) { } 29 7 36
427 3 return ($mid_ix, $dist)
428 }
429 elsif ( $peak->[0] < $value) {
430 # say STDERR " distance = $dist, shifting up";
431 29 $low_ix = $mid_ix + 1;
432 }
433 else { # $peak->[0] > $value
434 # say STDERR " distance = $dist; shifting down";
435 7 $high_ix = $mid_ix - 1;
436 }
437 }
438 2 return (undef, $dist);
439 }
440 }
441  
442 2 1;
443  
444 __END__
« Finnigan/Decoder.pm ↑ Summary Finnigan/GenericDataDescriptor.pm »