class Ms::Spectrum

Attributes

data[R]

The underlying data store.

Public Class Methods

from_peaks(ar_of_doublets) click to toggle source
# 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
new(data) click to toggle source

data takes an array: [mzs, intensities] @return [Ms::Spectrum] @param [Array] data two element array of mzs and intensities

# File lib/ms/spectrum.rb, line 11
def initialize(data)
  @data = data
end

Public Instance Methods

==(other) click to toggle source

if the mzs and intensities are the same then the spectra are considered equal

# File lib/ms/spectrum.rb, line 55
def ==(other)
  mzs == other.mzs && intensities == other.intensities
end
[](array_index) click to toggle source

retrieve an m/z and intensity doublet at that index

# File lib/ms/spectrum.rb, line 40
def [](array_index)
  [mzs[array_index], intensities[array_index]]
end
each(&block)
Alias for: peaks
each_peak(&block)
Alias for: peaks
intensities() click to toggle source

An array of the intensities data, corresponding to mzs.

# File lib/ms/spectrum.rb, line 31
def intensities
  @data[1]
end
mzs() click to toggle source

An array of the mz data.

# File lib/ms/spectrum.rb, line 26
def mzs
  @data[0]
end
mzs_and_intensities() click to toggle source
# File lib/ms/spectrum.rb, line 35
def mzs_and_intensities
  [@data[0], @data[1]]
end
normalize() click to toggle source

returns a new spectrum whose intensities have been normalized by the tic

# 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) click to toggle source

yields(mz, inten) across the spectrum, or array of doublets if no block

# File lib/ms/spectrum.rb, line 45
def peaks(&block)
  (m, i) = mzs_and_intensities
  m.zip(i, &block)
end
Also aliased as: each, each_peak