Class: Mspire::Mzml::Scan

Inherits:
Object
  • Object
show all
Includes:
Paramable
Defined in:
lib/mspire/mzml/scan.rb

Instance Attribute Summary collapse

Attributes included from Paramable

#cv_params, #ref_param_groups, #user_params

Class Method Summary collapse

Instance Method Summary collapse

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!

Constructor Details

#initialize {|_self| ... } ⇒ Scan

Returns a new instance of Scan.

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
# File 'lib/mspire/mzml/scan.rb', line 24

def initialize
  params_init
  yield(self) if block_given?
end

Instance Attribute Details

#from_external_source_fileObject

a boolean indicating the spectrum is from an external source file



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

def from_external_source_file
  @from_external_source_file
end

#instrument_configurationObject

an InstrumentConfiguration object (optional).



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

def instrument_configuration
  @instrument_configuration
end

#scan_windowsObject

ScanWindow objects



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

def scan_windows
  @scan_windows
end

#spectrumObject

(optional) the Mspire::Mzml::Spectrum object from which the precursor is derived. (the sourceFileRef is derived from this spectrum object if from_external_source_file == true)



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

def spectrum
  @spectrum
end

Class Method Details

.from_xml(xml, link) ⇒ Object

link should have:

:ref_hash
:default_instrument_configuration
:instrument_configuration_hash


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/mspire/mzml/scan.rb', line 49

def self.from_xml(xml, link)
  ref_hash = link[:ref_hash]
  obj = self.new
  obj.instrument_configuration =
    if icf = xml[:instrumentConfigurationRef]
      link[:instrument_configuration_hash][icf]
    else
      link[:default_instrument_configuration]
    end
  scan_window_list_n = obj.describe_from_xml!(xml, ref_hash)
  if scan_window_list_n
    obj.scan_windows = scan_window_list_n.children.map do |scan_window_n|
      Mspire::Mzml::ScanWindow.new.describe_self_from_xml!(scan_window_n, ref_hash)
    end
  end
  obj
end

Instance Method Details

#scan_windowObject

returns the first existing scan window, or nil if none



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

def scan_window
  return nil unless scan_windows
  scan_windows.first
end

#scan_window_limitsObject

returns a doublet: the upper and lower scan window limits as floats. Returns an array of two values, but may be nil if they don’t exist.



37
38
39
40
41
42
# File 'lib/mspire/mzml/scan.rb', line 37

def scan_window_limits
  %w(MS:1000501 MS:1000500).map do |acc|
    val = scan_window.fetch_by_acc(acc)
    val && val.to_f
  end
end

#to_xml(builder, default_ids) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mspire/mzml/scan.rb', line 67

def to_xml(builder, default_ids)
  atts = {}
  if @from_external_source_file
    atts[:sourceFileRef] = @spectrum.source_file.id
    atts[:externalSpectrumRef] = @spectrum.id
  else
    atts[:spectrumRef] = @spectrum.id if @spectrum
  end
  if @instrument_configuration
    unless @instrument_configuration.id == default_ids[:instrument_configuration]
      atts[:instrumentConfigurationRef] = @instrument_configuration.id 
    end
  end
  builder.scan(atts) do |prec_n|
    super(prec_n) # description
    ScanWindow.list_xml(@scan_windows, prec_n) if @scan_windows
  end
end