Class: Mspire::Mzml::Spectrum
- Inherits:
-
Object
- Object
- Mspire::Mzml::Spectrum
- Includes:
- DataArrayContainerLike, SpectrumLike
- Defined in:
- lib/mspire/mzml/spectrum.rb
Overview
MAY supply a child term of MS:1000465 (scan polarity) only once
e.g.: MS:1000129 (negative scan)
e.g.: MS:1000130 (positive scan)
MUST supply a *child* term of MS:1000559 (spectrum type) only once
e.g.: MS:1000322 (charge inversion mass spectrum)
e.g.: MS:1000325 (constant neutral gain spectrum)
e.g.: MS:1000326 (constant neutral loss spectrum)
e.g.: MS:1000328 (e/2 mass spectrum)
e.g.: MS:1000341 (precursor ion spectrum)
e.g.: MS:1000581 (CRM spectrum)
e.g.: MS:1000582 (SIM spectrum)
e.g.: MS:1000583 (SRM spectrum)
e.g.: MS:1000789 (enhanced multiply charged spectrum)
e.g.: MS:1000790 (time-delayed fragmentation spectrum)
et al.
MUST supply term MS:1000525 (spectrum representation) or any of its children only once
e.g.: MS:1000127 (centroid spectrum)
e.g.: MS:1000128 (profile spectrum)
MAY supply a *child* term of MS:1000499 (spectrum attribute) one or more times
e.g.: MS:1000285 (total ion current)
e.g.: MS:1000497 (zoom scan)
e.g.: MS:1000504 (base peak m/z)
e.g.: MS:1000505 (base peak intensity)
e.g.: MS:1000511 (ms level)
e.g.: MS:1000527 (highest observed m/z)
e.g.: MS:1000528 (lowest observed m/z)
e.g.: MS:1000618 (highest observed wavelength)
e.g.: MS:1000619 (lowest observed wavelength)
e.g.: MS:1000796 (spectrum title)
et al.
Instance Attribute Summary collapse
-
#precursors ⇒ Object
(optional) List and descriptions of precursor isolations to the spectrum currently being described, ordered.
-
#products ⇒ Object
(optional) List and descriptions of product isolations to the spectrum currently being described, ordered.
-
#scan_list ⇒ Object
(optional) a ScanList object.
-
#source_file ⇒ Object
(optional) an Mspire::Mzml::SourceFile object.
-
#spot_id ⇒ Object
(optional) The identifier for the spot from which this spectrum was derived, if a MALDI or similar run.
Attributes included from DataArrayContainerLike
#data_arrays, #data_processing, #id, #index
Attributes included from CV::Paramable
Attributes included from SpectrumLike
#centroided, #data_arrays, #scans
Class Method Summary collapse
-
.from_xml(xml) ⇒ Object
takes a Nokogiri node and sets relevant properties.
Instance Method Summary collapse
- #centroided? ⇒ Boolean
-
#initialize(id, opts = {params: []}, &block) ⇒ Spectrum
constructor
the most common param to pass in would be ms level: ‘MS:1000511’.
-
#ms_level ⇒ Object
returns the ms_level as an Integer.
-
#precursor_charge ⇒ Object
returns the charge state of the first precursor as an integer.
- #precursor_mz ⇒ Object
- #profile? ⇒ Boolean
-
#retention_time ⇒ Object
returns the retention time of the first scan object in the scan list *in seconds*!.
-
#to_xml(builder) ⇒ Object
see SpectrumList for generating the entire list.
Methods included from DataArrayContainerLike
Methods included from CV::Paramable
#describe!, #describe_many!, #find_param_by_accession, #find_param_value_by_accession, #param_exists_by_accession?
Methods included from SpectrumLike
#==, #[], #find_all_nearest, #find_all_nearest_index, #find_nearest, #find_nearest_index, #intensities, #intensities=, #merge, #mzs, #mzs=, #mzs_and_intensities, #normalize, #points, #size, #sort!, #tic
Constructor Details
#initialize(id, opts = {params: []}, &block) ⇒ Spectrum
145 146 147 148 149 |
# File 'lib/mspire/mzml/spectrum.rb', line 145 def initialize(id, opts={params: []}, &block) @id = id describe_many! opts[:params] block.call(self) if block end |
Instance Attribute Details
#precursors ⇒ Object
(optional) List and descriptions of precursor isolations to the spectrum currently being described, ordered.
63 64 65 |
# File 'lib/mspire/mzml/spectrum.rb', line 63 def precursors @precursors end |
#products ⇒ Object
(optional) List and descriptions of product isolations to the spectrum currently being described, ordered.
67 68 69 |
# File 'lib/mspire/mzml/spectrum.rb', line 67 def products @products end |
#scan_list ⇒ Object
(optional) a ScanList object
59 60 61 |
# File 'lib/mspire/mzml/spectrum.rb', line 59 def scan_list @scan_list end |
#source_file ⇒ Object
(optional) an Mspire::Mzml::SourceFile object
48 49 50 |
# File 'lib/mspire/mzml/spectrum.rb', line 48 def source_file @source_file end |
#spot_id ⇒ Object
(optional) The identifier for the spot from which this spectrum was derived, if a MALDI or similar run.
52 53 54 |
# File 'lib/mspire/mzml/spectrum.rb', line 52 def spot_id @spot_id end |
Class Method Details
.from_xml(xml) ⇒ Object
takes a Nokogiri node and sets relevant properties
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/mspire/mzml/spectrum.rb', line 109 def self.from_xml(xml) spec = Mspire::Mzml::Spectrum.new(xml[:id]) spec.spot_id = xml[:spotID] [:cvParam, :userParam].each {|v| spec.describe! xml.xpath("./#{v}") } scan_list = Mspire::Mzml::ScanList.new xml.xpath('./scanList/scan').each do |scan_n| scan_list << Mspire::Mzml::Scan.from_xml(scan_n) end spec.scan_list = scan_list spec.precursors = xml.xpath('./precursorList/precursor').map do |prec_n| Mspire::Mzml::Precursor.from_xml(prec_n) end data_arrays = xml.xpath('./binaryDataArrayList/binaryDataArray').map do |binary_data_array_n| accessions = binary_data_array_n.xpath('./cvParam').map {|node| node['accession'] } base64 = binary_data_array_n.xpath('./binary').text Mspire::Mzml::DataArray.from_binary(base64, accessions) end # if there is no spectrum, we will still return a spectrum object, it # just has no mzs or intensities data_arrays = [Mspire::Mzml::DataArray.new, Mspire::Mzml::DataArray.new] if data_arrays.size == 0 spec.data_arrays = data_arrays spec end |
Instance Method Details
#centroided? ⇒ Boolean
91 92 93 |
# File 'lib/mspire/mzml/spectrum.rb', line 91 def centroided? param_exists_by_accession?('MS:1000127') end |
#ms_level ⇒ Object
returns the ms_level as an Integer
87 88 89 |
# File 'lib/mspire/mzml/spectrum.rb', line 87 def ms_level find_param_value_by_accession('MS:1000511', :to_i) end |
#precursor_charge ⇒ Object
returns the charge state of the first precursor as an integer
100 101 102 |
# File 'lib/mspire/mzml/spectrum.rb', line 100 def precursor_charge precursors.andand.first.andand.selected_ions.andand.first.andand.find_param_value_by_accession('MS:1000041', :to_i) end |
#precursor_mz ⇒ Object
104 105 106 |
# File 'lib/mspire/mzml/spectrum.rb', line 104 def precursor_mz precursors.andand.first.andand.selected_ions.andand.first.andand.find_param_value_by_accession('MS:1000744', :to_f) end |
#profile? ⇒ Boolean
95 96 97 |
# File 'lib/mspire/mzml/spectrum.rb', line 95 def profile? param_exists_by_accession?('MS:1000128') end |
#retention_time ⇒ Object
returns the retention time of the first scan object in the scan list *in seconds*!
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mspire/mzml/spectrum.rb', line 71 def retention_time rt_param = scan_list.first.find_param_by_accession('MS:1000016') if rt_param multiplier = case rt_param.unit.accession when 'UO:0000010' ; 1 # second when 'UO:0000031' ; 60 # minute when 'UO:0000032' ; 3600 # hour when 'UO:0000028' ; 0.001 # millisecond else raise 'unsupported units' end rt_param.value.to_f * multiplier end end |
#to_xml(builder) ⇒ Object
see SpectrumList for generating the entire list
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/mspire/mzml/spectrum.rb', line 153 def to_xml(builder) atts = {} atts[:sourceFileRef] = @source_file.id if @source_file atts[:spotID] = @spot_id if @spot_id super(builder, atts) do |node| @scan_list.list_xml( node ) if @scan_list Mspire::Mzml::Precursor.list_xml(@precursors, node) if @precursors Mspire::Mzml::Product.list_xml(@products, node) if @products end end |