blib/lib/MS/Reader/MGF.pm

filter: Statementstmt 96.3% 80 / 82 Branchbran 67.8% 18 / 28 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 16 / 16 Podpod 100% 6 / 6 totaltotal 87.3% 124 / 142 CC 17 SCAR 18.9
CC
17
Cov
87%
_parse
14.0
goto_spectrum
3.3
fetch_spectrum
2.0
CRAP 6.6
« blib/lib/MS/Protein.pm ↑ Summary Build »
1 package MS::Reader::MGF;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use parent qw/MS::Reader/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Data::Lock;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use MS::Reader::MGF::Spectrum;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Perform parsing of the MGF (this is called by the parent class - do not
15 # change the method name )
16  
17 sub _load_new {
18  
19 1 ▶ my ($self) = @_;
Subroutine _load_new: called CC=1 SCAR=0.0
20  
21 1 $self->_parse;
22
23 1 $self->{pos} = 0;
24
25 1 return;
26  
27 }
28  
29 sub _post_load {
30  
31 1 ▶ my ($self) = @_;
Subroutine _post_load: called CC=1 SCAR=0.0
32 1 $self->{pos} = 0;
33  
34 }
35  
36 sub _parse {
37  
38 1 ▶ my ($self) = @_;
Subroutine _parse: called CC=13 SCAR=26.4
39  
40 1 my $fh = $self->{__fh};
41 1 my $last_offset = tell $fh;
42 1 my $offset;
43 my $title;
44 1 my $in_spectrum;
45  
46 LINE:
47 1 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 11768 1 11769
48
49 11768 ▶ next if ($line =~ /^#/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 0 11768 11768
50 11768 ▶ next if ($line !~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 11768 11768
51 11768 chomp $line;
52  
53 11768 ▶ if ($line eq 'BEGIN IONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "BEGIN IONS") 32 11736 11768
54 32 $offset = tell $fh;
55 32 $in_spectrum = 1;
56 32 next LINE;
57 }
58  
59 11736 ▶ if ($line eq 'END IONS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "END IONS") 32 11704 11736
60 32 ▶ die "No spectrum TITLE found\n" if (! defined $title);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 0 32 32
61 32 push @{ $self->{offsets} }, $offset;
62 32 push @{ $self->{lengths} }, $last_offset - $offset;
63 32 $self->{index}->{$title} = $#{ $self->{offsets} };
64 32 $in_spectrum = 0;
65 32 $title = undef;
66 32 next LINE;
67 }
68  
69 11704 $last_offset = tell $fh;
70  
71 11704 ▶ next LINE if ($in_spectrum && defined $title);
Branch: 1 branch
BranchTrueFalseTotal
if $in_spectrum and defined $title 11672 32 11704
Condition66%2/3
$in_spectrum and defined $title
!ll&&!rl&&r
03211672
MC/DC50%1/2
$in_spectrum and defined $title
$in_spectrum defined $title
Truth table66%2/3
A and B
A= $in_spectrumB= defined $title
ABresult
0X0
100
111
72  
73 32 ▶ if ($line =~ /^(\w+)\=(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\w+)\=(.+)$/) 32 0 32
74 32 my ($key, $val) = ($1, $2);
75  
76 # uncoverable branch false
77 32 ▶ if ($in_spectrum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_spectrum) { } 32 0 32
78 32 ▶ $title = $val if ($key eq 'TITLE');
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "TITLE" 32 0 32
79 }
80 else {
81 croak "$key already defined\n"
82 0 ▶ if (exists $self->{params}->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"params"}{$key} 0 0 0
83 0 $self->{params}->{$key} = $val;
84 }
85  
86 # should really never get here
87 # uncoverable statement
88 32 next LINE;
89 }
90  
91 }
92  
93 1 $self->{count} = scalar @{ $self->{offsets} };
94  
95 }
96  
97 sub fetch_spectrum {
98  
99 22 ▶ my ($self, $idx) = @_;
Subroutine fetch_spectrum: called CC=2 SCAR=7.0
Pod documented
100
101 22 my $offset = $self->{offsets}->[$idx];
102 22 ▶ croak "Record not found for $idx" if (! defined $offset);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 22 22
103
104 22 my $to_read = $self->{lengths}->[ $idx ];
105 22 my $el = $self->_read_element($offset,$to_read);
106  
107 22 return MS::Reader::MGF::Spectrum->new($el);
108  
109 }
110  
111 sub next_spectrum {
112  
113 23 ▶ my ($self) = @_;
Subroutine next_spectrum: called CC=2 SCAR=6.9
Pod documented
114  
115 23 ▶ return undef if ($self->{pos} == $self->{count}); #EOF
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} == $self->{"count"} 1 22 23
116 22 return $self->fetch_spectrum($self->{pos}++);
117  
118 }
119  
120 sub goto_spectrum {
121  
122 1 ▶ my ($self, $idx) = @_;
Subroutine goto_spectrum: called CC=3 SCAR=12.0
Pod documented
123 die "Index out of bounds in goto()\n"
124 1 ▶ if ($idx < 0 || $idx >= $self->{count});
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 or $idx >= $self->{"count"} 0 1 1
Condition33%1/3
$idx < 0 or $idx >= $self->{"count"}
l!l&&r!l&&!r
001
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
125 1 $self->{pos} = $idx;
126 1 return;
127  
128 }
129  
130 sub get_index_by_id {
131  
132 1 ▶ my ($self, $id) = @_;
Subroutine get_index_by_id: called CC=1 SCAR=0.0
Pod documented
133 1 return $self->{index}->{$id};
134  
135 }
136  
137 sub curr_index {
138  
139 2 ▶ my ($self) = @_;
Subroutine curr_index: called CC=1 SCAR=0.0
Pod documented
140 2 return $self->{pos};
141  
142 }
143  
144 sub n_spectra {
145  
146 1 ▶ my ($self) = @_;
Subroutine n_spectra: called CC=1 SCAR=0.0
Pod documented
147 1 return $self->{count};
148  
149 }
150 2 1;
151  
152  
153 __END__
« blib/lib/MS/Protein.pm ↑ Summary Build »