Class: Ms::Spectrum
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The underlying data store.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
if the mzs and intensities are the same then the spectra are considered equal.
-
#[](array_index) ⇒ Object
retrieve an m/z and intensity doublet at that index.
-
#initialize(data) ⇒ Ms::Spectrum
constructor
data takes an array: [mzs, intensities].
-
#intensities ⇒ Object
An array of the intensities data, corresponding to mzs.
-
#mzs ⇒ Object
An array of the mz data.
- #mzs_and_intensities ⇒ Object
-
#normalize ⇒ Object
returns a new spectrum whose intensities have been normalized by the tic.
-
#peaks(&block) ⇒ Object
(also: #each, #each_peak)
yields(mz, inten) across the spectrum, or array of doublets if no block.
Constructor Details
#initialize(data) ⇒ Ms::Spectrum
data takes an array: [mzs, intensities]
11 12 13 |
# File 'lib/ms/spectrum.rb', line 11 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
The underlying data store.
6 7 8 |
# File 'lib/ms/spectrum.rb', line 6 def data @data end |
Class Method Details
.from_peaks(ar_of_doublets) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ms/spectrum.rb', line 15 def self.from_peaks(ar_of_doublets) _mzs = [] _ints = [] ar_of_doublets.each do |mz, int| _mzs << mz _ints << int end self.new([_mzs, _ints]) end |
Instance Method Details
#==(other) ⇒ Object
if the mzs and intensities are the same then the spectra are considered equal
55 56 57 |
# File 'lib/ms/spectrum.rb', line 55 def ==(other) mzs == other.mzs && intensities == other.intensities end |
#[](array_index) ⇒ Object
retrieve an m/z and intensity doublet at that index
40 41 42 |
# File 'lib/ms/spectrum.rb', line 40 def [](array_index) [mzs[array_index], intensities[array_index]] end |
#intensities ⇒ Object
An array of the intensities data, corresponding to mzs.
31 32 33 |
# File 'lib/ms/spectrum.rb', line 31 def intensities @data[1] end |
#mzs ⇒ Object
An array of the mz data.
26 27 28 |
# File 'lib/ms/spectrum.rb', line 26 def mzs @data[0] end |
#mzs_and_intensities ⇒ Object
35 36 37 |
# File 'lib/ms/spectrum.rb', line 35 def mzs_and_intensities [@data[0], @data[1]] end |
#normalize ⇒ Object
returns a new spectrum whose intensities have been normalized by the tic
60 61 62 63 |
# File 'lib/ms/spectrum.rb', line 60 def normalize tic = self.intensities.inject(0.0) {|sum,int| sum += int } Ms::Spectrum.new([self.mzs, self.intensities.map {|v| v / tic }]) end |
#peaks(&block) ⇒ Object Also known as: each, each_peak
yields(mz, inten) across the spectrum, or array of doublets if no block
45 46 47 48 |
# File 'lib/ms/spectrum.rb', line 45 def peaks(&block) (m, i) = mzs_and_intensities m.zip(i, &block) end |