Class: Mspire::Mzml::SpectrumList

Inherits:
Array
  • Object
show all
Defined in:
lib/mspire/mzml/spectrum_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#in_groups

Constructor Details

#initialize(default_data_processing, spectra = []) ⇒ SpectrumList

Returns a new instance of SpectrumList.



10
11
12
13
# File 'lib/mspire/mzml/spectrum_list.rb', line 10

def initialize(default_data_processing, spectra=[])
  @default_data_processing = default_data_processing
  super(spectra)
end

Instance Attribute Details

#default_data_processingObject (readonly)

a DataProcessing object



8
9
10
# File 'lib/mspire/mzml/spectrum_list.rb', line 8

def default_data_processing
  @default_data_processing
end

Instance Method Details

#add_ms_spectra!(spectra, ids = []) ⇒ Object

takes an array of spectra and performs add_spectrum on each returns self



26
27
28
29
# File 'lib/mspire/mzml/spectrum_list.rb', line 26

def add_ms_spectra!(spectra, ids=[])
  spectra.zip(ids).each_with_index {|(spec,id),i| add_spectrum(spec, "spectrum=#{i+1}") }
  self
end

#add_ms_spectrum!(spectrum, id) ⇒ Object

This method takes an object responding to :data, creates a new Mspire::Mzml::Spectrum object with that data and puts it in the internal list



18
19
20
21
22
# File 'lib/mspire/mzml/spectrum_list.rb', line 18

def add_ms_spectrum!(spectrum, id)
  mzml_spec = Mspire::Mzml::Spectrum.new(id)
  mzml_spec.data = spectrum.data
  self << mzml_spec
end

#to_xml(builder) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/mspire/mzml/spectrum_list.rb', line 31

def to_xml(builder)
  builder.spectrumList(count: self.size, defaultDataProcessingRef: @default_data_processing.id) do |spl_n|
    self.each_with_index do |spectrum,i|
      spectrum.index = i unless spectrum.index
      spectrum.to_xml(spl_n)
    end
  end
  builder
end