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
#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*!.
-
#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 CV::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, #size, #sort!, #tic, #to_peaklist
Methods included from Enumerable
Constructor Details
#initialize(id) {|_self| ... } ⇒ Spectrum
167 168 169 170 171 |
# File 'lib/mspire/mzml/spectrum.rb', line 167 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.
176 177 178 179 180 181 182 |
# File 'lib/mspire/mzml/spectrum.rb', line 176 def self.from_arrays(id, arrays) spec = self.new(id) arrays.zip(['MS:1000514','MS:1000515']).each do |ar, acc| dar = 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
124 125 126 127 128 129 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 |
# File 'lib/mspire/mzml/spectrum.rb', line 124 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
95 96 97 |
# File 'lib/mspire/mzml/spectrum.rb', line 95 def centroided? fetch_by_acc('MS:1000127') end |
#ms_level ⇒ Object
returns the ms_level as an Integer
91 92 93 |
# File 'lib/mspire/mzml/spectrum.rb', line 91 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
104 105 106 |
# File 'lib/mspire/mzml/spectrum.rb', line 104 def precursor_charge precursors.andand.first.andand.selected_ions.andand.first.andand.fetch_by_acc('MS:1000041') end |
#precursor_mz ⇒ Object
108 109 110 |
# File 'lib/mspire/mzml/spectrum.rb', line 108 def precursor_mz precursors.andand.first.andand.selected_ions.andand.first.andand.fetch_by_acc('MS:1000744') end |
#profile? ⇒ Boolean
99 100 101 |
# File 'lib/mspire/mzml/spectrum.rb', line 99 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 |
#to_xml(builder, default_ids) ⇒ Object
see SpectrumList for generating the entire list
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/mspire/mzml/spectrum.rb', line 185 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 |