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



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

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.



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

def activation
  @activation
end

#isolation_windowObject

(optional)



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

def isolation_window
  @isolation_window
end

#selected_ionsObject

(optional) An array of ions that were selected.



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

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.



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

def source_file
  @source_file
end

#spectrum_idObject

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



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

def spectrum_id
  @spectrum_id
end

#spectrum_listObject

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



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

def spectrum_list
  @spectrum_list
end

Class Method Details

.from_xml(xml, link) ⇒ Object



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

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



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

def spectrum
  @spectrum_list[@spectrum_id]
end

#to_xml(builder) ⇒ Object



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

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