Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/spectral_summing.rb
Instance Attribute Summary collapse
-
#spectra ⇒ Object
Returns the value of attribute spectra.
Instance Method Summary collapse
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
- #parse(file = nil) ⇒ Object
- #parse_by_scan_num(scan_nums, file = nil) ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
5 6 7 |
# File 'lib/spectral_summing.rb', line 5 def initialize(file) @file = file end |
Instance Attribute Details
#spectra ⇒ Object
Returns the value of attribute spectra.
4 5 6 |
# File 'lib/spectral_summing.rb', line 4 def spectra @spectra end |
Instance Method Details
#parse(file = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/spectral_summing.rb', line 8 def parse(file = nil) file ||= @file require 'ms/msrun' @spectra = [] Ms::Msrun.open(file) do |ms| ms.each(:ms_level => 2) do |scan| @spectra << Spectrum.new(scan, scan.num, scan.time, (scan.start_mz..scan.end_mz), scan.precursor.mz, scan.precursor.charge_states, scan.spectrum.intensities, scan.spectrum.mzs) end end end |
#parse_by_scan_num(scan_nums, file = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/spectral_summing.rb', line 18 def parse_by_scan_num(scan_nums, file = nil) file ||= @file require 'ms/msrun' @spectra = [] Ms::Msrun.open(file) do |ms| ms.each(:ms_level => 2) do |scan| if scan_nums.include?(scan.num) @spectra << Spectrum.new(scan, scan.num, scan.time, (scan.start_mz..scan.end_mz), scan.precursor.mz, scan.precursor.charge_states, scan.spectrum.intensities, scan.spectrum.mzs) end end end end |