lib/MS/Reader/MSn.pm

filter: Statementstmt 100% 71 / 71 Branchbran 75.0% 15 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 6 / 6 totaltotal 92.3% 108 / 117 CC 12 SCAR 12.8
CC
12
Cov
93%
_parse
8.0
goto_spectrum
3.3
fetch_spectrum
2.0
CRAP 3.6
« lib/MS/Reader/MSn/Spectrum.pm ↑ Summary lib/MS/Mass.pm »
1 package MS::Reader::MSn;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw/MS::Reader/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use MS::Reader::MSn::Spectrum;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Perform parsing of the MS1/MS2 (this is called by the parent class - do not
14 # change the method name )
15  
16 2 ▶sub _load_new {
Subroutine _load_new: called CC=1 SCAR=0.0
17  
18 2 my ($self) = @_;
19  
20 2 $self->_parse;
21 2 $self->{pos} = 0;
22
23 2 return;
24  
25 }
26  
27 2 ▶sub _post_load {
Subroutine _post_load: called CC=1 SCAR=0.0
28  
29 2 my ($self) = @_;
30 2 $self->{pos} = 0;
31  
32 }
33  
34 2 ▶sub _parse {
Subroutine _parse: called CC=8 SCAR=20.8
35  
36 2 my ($self) = @_;
37  
38 2 my $fh = $self->{__fh};
39 2 my $last_offset = tell $fh;
40 2 my $offset;
41 my $title;
42 2 my $seen_spectra = 0;
43  
44 LINE:
45 2 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 40502 2 40504
46
47 40502 chomp $line;
48  
49 40502 my ($f1, $f2) = split ' ', $line;
50 40502 ▶ next LINE if (! defined $f1);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f1 0 40502 40502
51 40502 ▶ if ($f1 eq 'H') {
Branch: 2 branches
BranchTrueFalseTotal
if ($f1 eq 'H') { } 8 40494 40502
elsif ($f1 eq 'S') { } 35 40459 40494
52 8 my ($str) = ($line =~ /^H\s+$f2\s+(.+)$/);
53 8 ▶ die "Error parsing header line: $line\n" if (! defined $str);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 8 8
54 8 $self->{headers}->{$f2} = $str;
55 }
56  
57 elsif ($f1 eq 'S') {
58 35 push @{ $self->{offsets} }, $last_offset;
59 35 $self->{index}->{$f2} = $#{ $self->{offsets} };
60 35 ▶ if ($seen_spectra) { # if not at first record
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_spectra) 33 2 35
61 33 push @{ $self->{lengths} }, $last_offset - $self->{offsets}->[-2];
62 }
63 35 $seen_spectra = 1;
64 }
65 40502 $last_offset = tell $fh;
66  
67 }
68 2 ▶ if ($seen_spectra) { # if not at first record
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_spectra) 2 0 2
69 2 push @{ $self->{lengths} }, $last_offset - $self->{offsets}->[-1];
70 }
71  
72 2 $self->{count} = scalar @{ $self->{offsets} };
73  
74 }
75  
76 27 ▶sub fetch_spectrum {
Subroutine fetch_spectrum: called CC=2 SCAR=7.0
Pod documented
77  
78 27 my ($self, $idx) = @_;
79
80 27 my $offset = $self->{offsets}->[$idx];
81 27 ▶ croak "Record not found for $idx" if (! defined $offset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 27 27
82
83 27 my $to_read = $self->{lengths}->[ $idx ];
84 27 my $el = $self->_read_element($offset,$to_read);
85  
86 27 return MS::Reader::MSn::Spectrum->new($el);
87  
88 }
89  
90 29 ▶sub next_spectrum {
Subroutine next_spectrum: called CC=2 SCAR=6.9
Pod documented
91  
92 29 my ($self) = @_;
93  
94 29 ▶ return if ($self->{pos} == $self->{count}); #EOF
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} == $self->{"count"} 2 27 29
95 27 return $self->fetch_spectrum($self->{pos}++);
96  
97 }
98  
99 2 ▶sub goto_spectrum {
Subroutine goto_spectrum: called CC=3 SCAR=12.0
Pod documented
100  
101 2 my ($self, $idx) = @_;
102 die "Index out of bounds in goto()\n"
103 2 ▶ if ($idx < 0 || $idx >= $self->{count});
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 or $idx >= $self->{"count"} 0 2 2
Condition33%1/3
$idx < 0 or $idx >= $self->{"count"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$idx < 0 or $idx >= $self->{"count"}
$idx < 0 $idx >= $self->{"count"}
Truth table33%1/3
A or B
A= $idx < 0B= $idx >= $self->{"count"}
ABresult
1X1
011
000
104 2 $self->{pos} = $idx;
105 2 return;
106  
107 }
108  
109 2 ▶sub get_index_by_id {
Subroutine get_index_by_id: called CC=1 SCAR=0.0
Pod documented
110  
111 2 my ($self, $id) = @_;
112 2 return $self->{index}->{$id};
113  
114 }
115  
116 4 ▶sub curr_index {
Subroutine curr_index: called CC=1 SCAR=0.0
Pod documented
117  
118 4 my ($self) = @_;
119 4 return $self->{pos};
120  
121 }
122  
123 2 ▶sub n_spectra {
Subroutine n_spectra: called CC=1 SCAR=0.0
Pod documented
124  
125 2 my ($self) = @_;
126 2 return $self->{count};
127  
128 }
129  
130 3 1;
131  
132  
133 __END__
« lib/MS/Reader/MSn/Spectrum.pm ↑ Summary lib/MS/Mass.pm »