| 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 | sub _load_new { | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_load_new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | $self->_parse; | |||||||||||||||||||||||||||
| 21 | 2 | $self->{pos} = 0; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | return; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub _post_load { | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_post_load: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | $self->{pos} = 0; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _parse { | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 40502 | chomp $line; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 40502 | my ($f1, $f2) = split ' ', $line; | |||||||||||||||||||||||||||
| 50 | 40502 | ▶ | next LINE if (! defined $f1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 40502 | ▶ | if ($f1 eq 'H') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 8 | my ($str) = ($line =~ /^H\s+$f2\s+(.+)$/); | |||||||||||||||||||||||||||
| 53 | 8 | ▶ | die "Error parsing header line: $line\n" if (! defined $str); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 69 | 2 | push @{ $self->{lengths} }, $last_offset - $self->{offsets}->[-1]; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | $self->{count} = scalar @{ $self->{offsets} }; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub fetch_spectrum { | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 27 | ▶ | my ($self, $idx) = @_; | ||||||||||||||||||||||||||
|
Subroutine
fetch_spectrum: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 27 | my $offset = $self->{offsets}->[$idx]; | |||||||||||||||||||||||||||
| 81 | 27 | ▶ | croak "Record not found for $idx" if (! defined $offset); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | sub next_spectrum { | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 29 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
next_spectrum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 29 | ▶ | return undef if ($self->{pos} == $self->{count}); #EOF | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 27 | return $self->fetch_spectrum($self->{pos}++); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub goto_spectrum { | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my ($self, $idx) = @_; | ||||||||||||||||||||||||||
|
Subroutine
goto_spectrum: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | die "Index out of bounds in goto()\n" | ||||||||||||||||||||||||||||
| 103 | 2 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 104 | 2 | $self->{pos} = $idx; | |||||||||||||||||||||||||||
| 105 | 2 | return; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub get_index_by_id { | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_index_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 2 | return $self->{index}->{$id}; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub curr_index { | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
curr_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 4 | return $self->{pos}; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | sub n_spectra { | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
n_spectra: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 2 | return $self->{count}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 3 | 1; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||