blib/lib/MS/Reader/MzML/Spectrum.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/MS/Reader/MzML/Record.pm ↑ Summary blib/lib/MS/Reader/MzQuantML.pm »
1 package MS::Reader::MzML::Spectrum;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent qw/MS::Spectrum MS::Reader::MzML::Record/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use Carp;
9 use MS::CV qw/:MS :UO/;
10  
11 sub _pre_load {
12  
13 my ($self) = @_;
14 $self->{_toplevel} = 'spectrum';
15 $self->SUPER::_pre_load();
16  
17 }
18  
19 sub id { return $_[0]->{id} };
20  
21 sub ms_level {
22  
23 my ($self) = @_;
24 my $given = $self->param(MS_MS_LEVEL);
25 return defined $self->param(MS_MS1_SPECTRUM) ? 1
26 : defined $given ? $given
27 : croak "Undefined MS level";
28  
29 }
30  
31 sub mz {
32  
33 my ($self) = @_;
34 return $self->get_array(MS_M_Z_ARRAY);
35  
36 }
37  
38 sub int {
39  
40 my ($self) = @_;
41 return $self->get_array(MS_INTENSITY_ARRAY);
42  
43 }
44  
45 sub rt {
46  
47 # get retention time in seconds
48 #
49 my ($self) = @_;
50  
51 croak "rt() only valid for single scan spectra, use direct access.\n"
52 if ($self->{scanList}->{count} != 1);
53 my $scan = $self->{scanList}->{scan}->[0];
54 my ($rt, $units) = $self->param(MS_SCAN_START_TIME, ref => $scan);
55 croak "missing RT value" if (! defined $rt);
56 $rt *= 60 if ($units eq UO_MINUTE);
57
58 return $rt;
59
60 }
61  
62 sub precursor {
63  
64 my ($self) = @_;
65 croak "precursor() only valid for MSn spectra"
66 if ($self->param(MS_MS_LEVEL) < 2);
67 croak "precursor() only valid for single precursor spectra, use direct access.\n"
68 if ($self->{precursorList}->{count} != 1);
69 my $pre = $self->{precursorList}->{precursor}->[0];
70 my $id = $pre->{spectrumRef};
71 my $win = $pre->{isolationWindow};
72 my $iso_mz = $self->param(MS_ISOLATION_WINDOW_TARGET_M_Z, ref => $win);
73 my $iso_l = $self->param(MS_ISOLATION_WINDOW_LOWER_OFFSET, ref => $win);
74 my $iso_u = $self->param(MS_ISOLATION_WINDOW_UPPER_OFFSET, ref => $win);
75 croak "missing precursor id" if (! defined $id);
76 croak "missing precursor m/z" if (! defined $iso_mz);
77 croak "missing precursor lower" if (! defined $iso_l);
78 croak "missing precursor upper" if (! defined $iso_u);
79  
80 croak "precursor() only valid for single precursor spectra, use direct access.\n"
81 if ($pre->{selectedIonList}->{count} != 1);
82 my $ion = $pre->{selectedIonList}->{selectedIon}->[0];
83 my $charge = $self->param(MS_CHARGE_STATE, ref => $ion);
84 my $mono_mz = $self->param(MS_SELECTED_ION_M_Z, ref => $ion);
85 my $int = $self->param(MS_PEAK_INTENSITY, ref => $ion);
86 croak "missing monoisotopic m/z" if (! defined $mono_mz);
87 return {
88 scan_id => $id,
89 iso_mz => $iso_mz,
90 iso_lower => $iso_mz - $iso_l,
91 iso_upper => $iso_mz + $iso_u,
92 mono_mz => $mono_mz,
93 charge => $charge,
94 intensity => $int,
95 };
96  
97 }
98  
99 sub scan_window {
100  
101 my ($self, $i) = @_;
102 $i //= 0;
103
104 my $win =
105 $self->{scanList}->{scan}->[$i]->{scanWindowList}->{scanWindow}->[0];
106 my $l = $self->param(MS_SCAN_WINDOW_LOWER_LIMIT, ref => $win);
107 my $r = $self->param(MS_SCAN_WINDOW_UPPER_LIMIT, ref => $win);
108  
109 return undef if (! defined $l || ! defined $r);
110 return [$l, $r];
111  
112 }
113  
114 sub scan_number {
115  
116 my ($self) = @_;
117 if ($self->{id} =~ /\bscan=(\d+)/) {
118 return $1;
119 }
120 return undef;
121  
122 }
123  
124 1;
125  
126 __END__
« blib/lib/MS/Reader/MzML/Record.pm ↑ Summary blib/lib/MS/Reader/MzQuantML.pm »