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_id = nil, spectrum_list = nil) ⇒ Precursor

provide the SpectrumList object for #spectrum access



33
34
35
# File 'lib/mspire/mzml/precursor.rb', line 33

def initialize(spectrum_id=nil, spectrum_list=nil)
  @spectrum_id, @spectrum_list = spectrum_id, spectrum_list
end

Instance Attribute Details

#activationObject

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



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

def activation
  @activation
end

#isolation_windowObject

(optional)



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

def isolation_window
  @isolation_window
end

#selected_ionsObject

(optional) An array of ions that were selected.



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

def selected_ions
  @selected_ions
end

#source_fileObject

This is an EXTERNAL source file ONLY. It should NOT be set if the spectrum is internal.



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

def source_file
  @source_file
end

#spectrum_idObject

(optional) the id of the Spectrum object, whether internal or externally derived.



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

def spectrum_id
  @spectrum_id
end

#spectrum_listObject

the spectrum list object which enables the spectrum to be accessed directly



30
31
32
# File 'lib/mspire/mzml/precursor.rb', line 30

def spectrum_list
  @spectrum_list
end

Class Method Details

.from_xml(xml, link) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mspire/mzml/precursor.rb', line 41

def self.from_xml(xml, link)
  ref_hash = link[:ref_hash]
  obj = self.new
  obj.spectrum_id = xml[:spectrumRef] || xml[:externalSpectrumID]
  if source_file_ref = xml[:sourceFileRef]
    obj.source_file = link[:source_file_hash][ source_file_ref ]
  end

  xml.children.each do |child_n|
    case child_n.name
    when 'activation' # the only one required
      obj.activation = Mspire::Mzml::Activation.new.describe_self_from_xml!(child_n, ref_hash)
    when 'isolationWindow'
      obj.isolation_window = Mspire::Mzml::IsolationWindow.new.describe_self_from_xml!(child_n, ref_hash)
    when 'selectedIonList'
      obj.selected_ions = child_n.children.map do |si_n|
        Mspire::Mzml::SelectedIon.new.describe_self_from_xml!(si_n, ref_hash)
      end
    end
  end
  
  obj
end

Instance Method Details

#spectrumObject



37
38
39
# File 'lib/mspire/mzml/precursor.rb', line 37

def spectrum
  @spectrum_list[@spectrum_id]
end

#to_xml(builder) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mspire/mzml/precursor.rb', line 65

def to_xml(builder)
  atts = {}
  if @source_file
    atts[:sourceFileRef] = @source_file.id
    atts[:externalSpectrumRef] = @spectrum_id
  elsif @spectrum_id
    atts[:spectrumRef] = @spectrum_id
  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