| 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 | 1 | ▶ | sub _load_new { | ||||||||||||||||||||||||||
|
Subroutine
_load_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | $self->_parse; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | $self->{pos} = 0; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | return; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub _post_load { | ||||||||||||||||||||||||||
|
Subroutine
_post_load: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 32 | 1 | $self->{pos} = 0; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=13 SCAR=26.4
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 11768 | ▶ | next if ($line =~ /^#/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 11768 | ▶ | next if ($line !~ /\S/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 11768 | chomp $line; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 11768 | ▶ | if ($line eq 'BEGIN IONS') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | 32 | ▶ | die "No spectrum TITLE found\n" if (! defined $title); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$in_spectrum and defined $title
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
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 32 | ▶ | if ($line =~ /^(\w+)\=(.+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 32 | my ($key, $val) = ($1, $2); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # uncoverable branch false | ||||||||||||||||||||||||||||
| 77 | 32 | ▶ | if ($in_spectrum) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 32 | ▶ | $title = $val if ($key eq 'TITLE'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||
| 81 | croak "$key already defined\n" | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if (exists $self->{params}->{$key}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 22 | ▶ | sub fetch_spectrum { | ||||||||||||||||||||||||||
|
Subroutine
fetch_spectrum: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 22 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 22 | my $offset = $self->{offsets}->[$idx]; | |||||||||||||||||||||||||||
| 102 | 22 | ▶ | croak "Record not found for $idx" if (! defined $offset); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 23 | ▶ | sub next_spectrum { | ||||||||||||||||||||||||||
|
Subroutine
next_spectrum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 23 | ▶ | return if ($self->{pos} == $self->{count}); #EOF | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 22 | return $self->fetch_spectrum($self->{pos}++); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub goto_spectrum { | ||||||||||||||||||||||||||
|
Subroutine
goto_spectrum: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 123 | die "Index out of bounds in goto()\n" | ||||||||||||||||||||||||||||
| 124 | 1 | ▶ | if ($idx < 0 || $idx >= $self->{count}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 0 or $idx >= $self->{"count"}
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"}
| |||||||||||||||||||||||||||||
| 125 | 1 | $self->{pos} = $idx; | |||||||||||||||||||||||||||
| 126 | 1 | return; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | sub get_index_by_id { | ||||||||||||||||||||||||||
|
Subroutine
get_index_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||
| 133 | 1 | return $self->{index}->{$id}; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | sub curr_index { | ||||||||||||||||||||||||||
|
Subroutine
curr_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 140 | 2 | return $self->{pos}; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | ▶ | sub n_spectra { | ||||||||||||||||||||||||||
|
Subroutine
n_spectra: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 147 | 1 | return $self->{count}; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 2 | 1; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||