Class: Mspire::Mzml::Precursor

Inherits:
Object
  • Object
show all
Extended by:
List
Defined in:
lib/mspire/mzml/precursor.rb

Overview

The method of precursor ion selection and activation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from List

list_xml, list_xml_element

Constructor Details

#initialize(spectrum_derived_from = nil) ⇒ Precursor

Returns a new instance of Precursor.



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

def initialize(spectrum_derived_from=nil)
  @spectrum=spectrum_derived_from
end

Instance Attribute Details

#activationObject

(required) The type and energy level used for activation.



21
22
23
# File 'lib/mspire/mzml/precursor.rb', line 21

def activation
  @activation
end

#from_external_source_fileObject

a boolean indicating the spectrum is from an external source file



24
25
26
# File 'lib/mspire/mzml/precursor.rb', line 24

def from_external_source_file
  @from_external_source_file
end

#isolation_windowObject

(optional)



15
16
17
# File 'lib/mspire/mzml/precursor.rb', line 15

def isolation_window
  @isolation_window
end

#selected_ionsObject

(optional) An array of ions that were selected.



18
19
20
# File 'lib/mspire/mzml/precursor.rb', line 18

def selected_ions
  @selected_ions
end

#spectrumObject

(optional) the Mspire::Mzml::Spectrum object from which the precursor is derived



12
13
14
# File 'lib/mspire/mzml/precursor.rb', line 12

def spectrum
  @spectrum
end

Class Method Details

.from_xml(xml) ⇒ Object



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

def self.from_xml(xml)
  obj = self.new
  %w(isolationWindow activation).each do |el|
    sub_node = xml.xpath("./#{el}").first
    el[0] = el[0].capitalize
    Mspire::Mzml.const_get(el).from_xml(sub_node) if sub_node
  end
  obj.selected_ions = xml.xpath('./selectedIonList/selectedIon').map do |si_n|
    Mspire::Mzml::SelectedIon.from_xml(si_n)
  end
  obj
end

Instance Method Details

#to_xml(builder) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mspire/mzml/precursor.rb', line 43

def to_xml(builder)
  atts = {}
  if @from_external_source_file
    atts[:sourceFileRef] = @spectrum.source_file.id
    atts[:externalSpectrumRef] = @spectrum.id
  else
    atts[:spectrumRef] = @spectrum.id if @spectrum
  end
  builder.precursor(atts) do |prec_n|
    @isolation_window.to_xml(prec_n) if @isolation_window
    Mspire::Mzml::SelectedIon.list_xml(@selected_ions, prec_n) if @selected_ions
    @activation.to_xml(prec_n) if @activation
  end
end