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 Paramable
#cv_params, #ref_param_groups, #user_params
Attributes included from SpectrumLike
#centroided, #data_arrays, #scans
Class Method Summary collapse
-
.from_arrays(id, arrays) ⇒ Object
sets the data_arrays from the given array objects.
-
.from_xml(xml, link) ⇒ Object
takes a Nokogiri node and sets relevant properties.
Instance Method Summary collapse
- #centroided? ⇒ Boolean
-
#initialize(id) {|_self| ... } ⇒ 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.
- #params_initialize ⇒ Object
-
#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*!.
-
#scan ⇒ Object
returns the first scan from the scan_list, or nil if none are found.
-
#to_xml(builder, default_ids) ⇒ Object
see SpectrumList for generating the entire list.
Methods included from DataArrayContainerLike
#data_array_xml_atts, #default_array_length
Methods included from Paramable
#accessionable_params, #describe!, #describe_from_xml!, #describe_many!, #describe_self_from_xml!, #each_accessionable_param, #each_param, #fetch, #fetch_by_accession, #param?, #param_by_accession, #params, #params?, #reject!, #replace!, #replace_many!
Methods included from SpectrumLike
#==, #[], #find_all_nearest, #find_all_nearest_index, #find_nearest, #find_nearest_index, #intensities, #intensities=, #mzs, #mzs=, #mzs_and_intensities, #normalize, #peaks, #select_indices, #size, #sort!, #tic, #to_peaklist
Methods included from Enumerable
Constructor Details
#initialize(id) {|_self| ... } ⇒ Spectrum
173 174 175 176 177 |
# File 'lib/mspire/mzml/spectrum.rb', line 173 def initialize(id) @id = id params_initialize yield(self) if block_given? end |
Instance Attribute Details
#precursors ⇒ Object
(optional) List and descriptions of precursor isolations to the spectrum currently being described, ordered.
67 68 69 |
# File 'lib/mspire/mzml/spectrum.rb', line 67 def precursors @precursors end |
#products ⇒ Object
(optional) List and descriptions of product isolations to the spectrum currently being described, ordered.
71 72 73 |
# File 'lib/mspire/mzml/spectrum.rb', line 71 def products @products end |
#scan_list ⇒ Object
(optional) a ScanList object
63 64 65 |
# File 'lib/mspire/mzml/spectrum.rb', line 63 def scan_list @scan_list end |
#source_file ⇒ Object
(optional) an Mspire::Mzml::SourceFile object
50 51 52 |
# File 'lib/mspire/mzml/spectrum.rb', line 50 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.
56 57 58 |
# File 'lib/mspire/mzml/spectrum.rb', line 56 def spot_id @spot_id end |
Class Method Details
.from_arrays(id, arrays) ⇒ Object
sets the data_arrays from the given array objects. Sets the type of the first array to be an m/z array, and the second to be an intensity array.
182 183 184 185 186 187 188 |
# File 'lib/mspire/mzml/spectrum.rb', line 182 def self.from_arrays(id, arrays) spec = self.new(id) spec.data_arrays = arrays.zip(['MS:1000514','MS:1000515']).map do |ar, acc| DataArray.new(ar).describe!(acc) end spec end |
.from_xml(xml, link) ⇒ Object
takes a Nokogiri node and sets relevant properties
link is a hash that should contain the following keys and associated objects (some are required by downstream objects, like Scan):
:ref_hash id -> ReferenceableParamGroup
:spectrum_list SpectrumList object
:data_processing_hash id -> DataProcessing object
:default_data_processing DataProcessing object
:instrument_configuration_hash id -> InstrumentConfiguration object
:default_instrument_configuration InstrumentConfiguration object
:source_file_hash id -> SourceFile object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/mspire/mzml/spectrum.rb', line 130 def self.from_xml(xml, link) obj = self.new(xml[:id]) obj.spot_id = xml[:spotID] obj.data_processing = link[:data_processing_hash][xml[:dataProcessingRef]] || link[:spectrum_default_data_processing] if source_file_ref=xml[:sourceFileRef] obj.source_file = link[:source_file_hash][source_file_ref] end xml_n = obj.describe_from_xml!(xml, link[:ref_hash]) return obj unless xml_n loop do case xml_n.name when 'scanList' obj.scan_list = Mspire::Mzml::ScanList.from_xml(xml_n, link) when 'precursorList' obj.precursors = xml_n.children.map do |prec_n| Mspire::Mzml::Precursor.from_xml(prec_n, link) end when 'productList' obj.products = xml_n.children.map do |product_n| Mspire::Mzml::Product.from_xml(product_n, link) end when 'binaryDataArrayList' obj.data_arrays = Mspire::Mzml::DataArray.data_arrays_from_xml(xml_n, link) end break unless xml_n = xml_n.next end unless obj.data_arrays obj.data_arrays = Mspire::Mzml::DataArray.empty_data_arrays end obj end |
Instance Method Details
#centroided? ⇒ Boolean
101 102 103 |
# File 'lib/mspire/mzml/spectrum.rb', line 101 def centroided? fetch_by_acc('MS:1000127') end |
#ms_level ⇒ Object
returns the ms_level as an Integer
97 98 99 |
# File 'lib/mspire/mzml/spectrum.rb', line 97 def ms_level fetch_by_acc('MS:1000511') end |
#params_initialize ⇒ Object
47 |
# File 'lib/mspire/mzml/spectrum.rb', line 47 alias_method :params_initialize, :initialize |
#precursor_charge ⇒ Object
returns the charge state of the first precursor as an integer
110 111 112 |
# File 'lib/mspire/mzml/spectrum.rb', line 110 def precursor_charge precursors.andand.first.andand.selected_ions.andand.first.andand.fetch_by_acc('MS:1000041') end |
#precursor_mz ⇒ Object
114 115 116 |
# File 'lib/mspire/mzml/spectrum.rb', line 114 def precursor_mz precursors.andand.first.andand.selected_ions.andand.first.andand.fetch_by_acc('MS:1000744') end |
#profile? ⇒ Boolean
105 106 107 |
# File 'lib/mspire/mzml/spectrum.rb', line 105 def profile? fetch_by_acc('MS:1000128') end |
#retention_time ⇒ Object
returns the retention time of the first scan object in the scan list *in seconds*!
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mspire/mzml/spectrum.rb', line 75 def retention_time rt_param = scan_list.first.param_by_acc('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 |
#scan ⇒ Object
returns the first scan from the scan_list, or nil if none are found
91 92 93 94 |
# File 'lib/mspire/mzml/spectrum.rb', line 91 def scan return nil unless scan_list scan_list.first end |
#to_xml(builder, default_ids) ⇒ Object
see SpectrumList for generating the entire list
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/mspire/mzml/spectrum.rb', line 191 def to_xml(builder, default_ids) io = builder.target! atts = data_array_xml_atts if @data_processing && default_ids[:spectrum_data_processing] != @data_processing.id atts[:dataProcessingRef] = @data_processing.id end atts[:sourceFileRef] = @source_file.id if @source_file atts[:spotID] = @spot_id if @spot_id builder.spectrum(atts) do |sp_n| super(sp_n) @scan_list.list_xml( sp_n, default_ids ) if @scan_list Mspire::Mzml::Precursor.list_xml(@precursors, sp_n) if @precursors Mspire::Mzml::Product.list_xml(@products, sp_n) if @products Mspire::Mzml::DataArray.list_xml(@data_arrays, sp_n) if @data_arrays end builder end |