File Coverage

lib/MS2/Parser.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package MS2::Parser;
2              
3 1     1   16189 use v5.12;
  1         3  
  1         33  
4 1     1   4 use strict;
  1         1  
  1         26  
5 1     1   4 use warnings;
  1         5  
  1         22  
6 1     1   169 use Moose;
  0            
  0            
7             use namespace::autoclean;
8             use MS2::Header;
9             use MS2::Scan;
10              
11             =head1 NAME
12              
13             MS2::Parser - A parser for MS2 files, commonly used in mass spectrometry based proteomics projects.
14              
15             =head1 VERSION
16              
17             Version 0.061'
18              
19             =cut
20              
21             our $VERSION = '0.061';
22              
23             =head1 SYNOPSIS
24              
25             Quick summary of what the module does.
26              
27             use MS2::Parser;
28              
29             my $ms = MS2::Parser->new();
30              
31             $ms->parse("file.ms2");
32              
33             # accessing header information
34             print $ms->header->ScanType;
35              
36              
37             =cut
38              
39             =head1 DESCRIPTION
40              
41             This is a Moose based parser for the MS2 file format. The MS2 file format is used to
42             record MS/MS spectra. A full description of the MS2 file format may be found in:
43             McDonald,W.H. et al. MS1, MS2, and SQT-three unified, compact, and easily parsed
44             file formats for the storage of shotgun proteomic spectra and identifications.
45             Rapid Commun. Mass Spectrom. 18, 2162-2168 (2004).
46              
47             =cut
48              
49             =head2 Methods
50              
51             =head3 parse
52              
53             This is the main function to call. The parse method recieves a path to the ms2 file
54             and returns a Moose object containing two attributes; A MS2::Header (header info)
55             and a list of MS2::Scan (scan info).
56              
57             $ms->parse("file.ms2");
58              
59             =head2 Attributes
60              
61             =head2 header
62              
63             # accessing header information
64             print $ms->header->ScanType;
65              
66              
67             This is a representation of how MS2 data is organized inside the object. The MS2 object
68             has a MS2::Header object with the following structure:
69              
70             internals: {
71             AcquisitionMethod "Data-Dependent",
72             Comments "RawXtract modified by Tao Xu, 2007",
73             CreationDate "4/13/2009 6:45:15 PM",
74             DataType "Centroid",
75             Extractor "RAWXtract",
76             ExtractorOptions "MS2",
77             ExtractorVersion "1.9.9.2",
78             FirstScan 1,
79             InstrumentType "ITMS",
80             IsolationWindow undef,
81             LastScan 33000,
82             ScanType "MS2"
83             }
84              
85              
86             =head2 scan
87              
88             # accessing header information
89             print $ms->scan->[0]->Mass;
90              
91             # copiyng the arraylist reference to an array.
92             my @array = $ms->scanlist;
93              
94              
95             The MS2 object has a MS2::Scan object list with the following structure:
96              
97             internals: {
98             ActivationType "CID",
99             Charge 7,
100             DataIntensity [
101             [0] 15.6,
102             [1] 27.8,
103             [2] 12.6,
104             [3] 16.2,
105             [4] 28.7,
106             [5] 15.6
107             ],
108             DataMZ [
109             [0] 308.8282,
110             [1] 362.2597,
111             [2] 390.5037,
112             [3] 547.0424,
113             [4] 563.5495,
114             [5] 661.8907
115             ],
116             FirstScan 000006,
117             InstrumentType "ITMS",
118             IonInjectionTime 25.000,
119             Mass 2833.0688,
120             PrecursorFile "Pfu_Orbit_041209_05.ms1",
121             PrecursorInt 214647.2,
122             PrecursorMZ 405.58749,
123             PrecursorScan 1,
124             RetTime 0.03,
125             SecondScan 000006
126             }
127              
128             The Data attribute is represented by two distinct array references; DataMZ and DataIntensity.
129             Both arrays are used to maintain the data order.
130              
131              
132             =cut
133              
134             has 'header' => (
135             is => 'rw',
136             isa => 'MS2::Header',
137             );
138              
139             has 'scanlist' => (
140             is => 'rw',
141             isa => 'ArrayRef',
142             );
143              
144              
145             sub parse {
146             my $self = shift;
147             my $path = shift;
148              
149             open (my $file, '<', $path) or die "[Error]: Could not opne file!\n";
150              
151             my $header = MS2::Header->new();
152             my $scan;
153             my @scanlist;
154              
155             my $flag = 0;
156              
157             while ( my $line = <$file> ) {
158             chomp $line;
159              
160             if ( $line =~ m/^H/ ) {
161              
162             $flag = 1;
163              
164             } elsif ( $line =~ m/^S/ ) {
165              
166             if ($scan) {
167             push(@scanlist, $scan);
168             }
169              
170             $flag = 2;
171             $scan = MS2::Scan->new();
172              
173             } elsif ( $line =~ m/^[IZ]/ ) {
174              
175             $flag = 2;
176              
177             } elsif ( $line =~ m/^\d/ ) {
178              
179             $flag = 3;
180              
181             }
182            
183             if ( eof ) {
184              
185             push(@scanlist, $scan);
186             }
187              
188             if ( $flag == 1 ) {
189            
190             $header->parse($line);
191              
192             } elsif ( $flag == 2 ) {
193              
194             $scan->parse($line);
195              
196             } elsif ( $flag == 3 ) {
197              
198             $scan->parse($line);
199             }
200             }
201              
202             $self->header($header);
203             $self->scanlist(\@scanlist);
204             }
205              
206             =head1 AUTHOR
207              
208             Felipe da Veiga Leprevost, C<< <leprevost at cpan.org> >>
209              
210             =head1 BUGS
211              
212             Please report any bugs or feature requests to C<bug-ms2-parser at rt.cpan.org>, or through
213             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MS2-Parser>. I will be notified, and then you'll
214             automatically be notified of progress on your bug as I make changes.
215              
216              
217             =head1 SUPPORT
218              
219             You can find documentation for this module with the perldoc command.
220              
221             perldoc MS2::Parser
222              
223              
224             You can also look for information at:
225              
226             =over 4
227              
228             =item * RT: CPAN's request tracker (report bugs here)
229              
230             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MS2-Parser>
231              
232             =item * AnnoCPAN: Annotated CPAN documentation
233              
234             L<http://annocpan.org/dist/MS2-Parser>
235              
236             =item * CPAN Ratings
237              
238             L<http://cpanratings.perl.org/d/MS2-Parser>
239              
240             =item * Search CPAN
241              
242             L<http://search.cpan.org/dist/MS2-Parser/>
243              
244             =back
245              
246              
247             =head1 ACKNOWLEDGEMENTS
248              
249              
250             =head1 LICENSE AND COPYRIGHT
251              
252             Copyright 2014 Felipe da Veiga Leprevost.
253              
254             This program is free software; you can redistribute it and/or modify it
255             under the terms of the the Artistic License (2.0). You may obtain a
256             copy of the full license at:
257              
258             L<http://www.perlfoundation.org/artistic_license_2_0>
259              
260             Any use, modification, and distribution of the Standard or Modified
261             Versions is governed by this Artistic License. By using, modifying or
262             distributing the Package, you accept this license. Do not use, modify,
263             or distribute the Package, if you do not accept this license.
264              
265             If your Modified Version has been derived from a Modified Version made
266             by someone other than you, you are nevertheless required to ensure that
267             your Modified Version complies with the requirements of this license.
268              
269             This license does not grant you the right to use any trademark, service
270             mark, tradename, or logo of the Copyright Holder.
271              
272             This license includes the non-exclusive, worldwide, free-of-charge
273             patent license to make, have made, use, offer to sell, sell, import and
274             otherwise transfer the Package with respect to any patent claims
275             licensable by the Copyright Holder that are necessarily infringed by the
276             Package. If you institute patent litigation (including a cross-claim or
277             counterclaim) against any party alleging that the Package constitutes
278             direct or contributory patent infringement, then this Artistic License
279             to you shall terminate on the date that such litigation is filed.
280              
281             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
282             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
283             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
284             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
285             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
286             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
287             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
288             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289              
290              
291             =cut
292              
293             1; # End of MS2::Parser