Class: Mspire::Mzml::Run

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

Instance Attribute Summary collapse

Attributes included from CV::Paramable

#cv_params, #ref_param_groups, #user_params

Class Method Summary collapse

Instance Method Summary collapse

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!

Constructor Details

#initialize(id, default_instrument_configuration) ⇒ Run

yields self if given a block



33
34
35
36
37
38
39
40
# File 'lib/mspire/mzml/run.rb', line 33

def initialize(id, default_instrument_configuration)
  @id = id
  @default_instrument_configuration = default_instrument_configuration
  params_init
  if block_given?
    yield self
  end
end

Instance Attribute Details

#chromatogram_listObject

takes a ChromatogramList object (a special array of chromatograms)



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

def chromatogram_list
  @chromatogram_list
end

#default_instrument_configurationObject

required



12
13
14
# File 'lib/mspire/mzml/run.rb', line 12

def default_instrument_configuration
  @default_instrument_configuration
end

#default_source_fileObject

optional



15
16
17
# File 'lib/mspire/mzml/run.rb', line 15

def default_source_file
  @default_source_file
end

#idObject

required



18
19
20
# File 'lib/mspire/mzml/run.rb', line 18

def id
  @id
end

#sampleObject

optional



21
22
23
# File 'lib/mspire/mzml/run.rb', line 21

def sample
  @sample
end

#spectrum_listObject

a SpectrumList object (a special array of spectra)



27
28
29
# File 'lib/mspire/mzml/run.rb', line 27

def spectrum_list
  @spectrum_list
end

#start_time_stampObject

optional



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

def start_time_stamp
  @start_time_stamp
end

Class Method Details

.from_xml(io, xml, link) ⇒ Object

expects link to have the following keys:

:ref_hash
:instrument_config_hash
:source_file_hash
:sample_hash
:data_processing_hash
:spectrum_default_data_processing
:chromatogram_default_data_processing
:index_list


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mspire/mzml/run.rb', line 70

def self.from_xml(io, xml, link)

  # expects that the DataProcessing objects to link to have *already* been
  # parsed (parse the defaultDataProcessingRef's after grabbing the
  # index, then grab the DataProcessing object associated with that id).
  
  obj = self.new(xml[:id], 
    link[:instrument_configuration_hash][xml[:defaultInstrumentConfigurationRef]]
  )
  obj.start_time_stamp = xml[:startTimeStamp]

  link[:default_instrument_configuration] = obj.default_instrument_configuration

  # two optional object refs
  if def_source_ref=xml[:defaultSourceFileRef]
    obj.default_source_file = link[:source_file_hash][def_source_ref]
  end
  if sample_ref=xml[:sampleRef]
    obj.sample = link[:sample_hash][sample_ref]
  end

  obj.describe_from_xml!(xml, link[:ref_hash])

  index_list = link[:index_list]
  [:spectrum, :chromatogram].each do |list_type|
    next unless (byte_index = index_list[list_type])

    io_index = IOIndex.new(io, byte_index, link)

    list_obj = Mspire::Mzml.const_get(list_type.to_s.capitalize + "List")
      .new(link["#{list_type}_default_data_processing".to_sym], 
           io_index, 
           Hash[byte_index.ids.each_with_index.map.to_a]
          )

    obj.send(list_type.to_s + "_list=", list_obj)
  end
  obj
end

Instance Method Details

#to_xml(builder) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mspire/mzml/run.rb', line 42

def to_xml(builder)
  atts = { id: @id,
    defaultInstrumentConfigurationRef: @default_instrument_configuration.id
  }
  atts[:defaultSourceFileRef] = @default_source_file.id if @default_source_file
  atts[:sampleRef] = @sample.id if @sample
  atts[:startTimeStamp] = @start_time_stamp if @start_time_stamp

  default_ids = { instrument_configuration: @default_instrument_configuration.id }
  
  builder.run(atts) do |run_n|
    super(run_n)
    spectrum_list.to_xml(run_n, default_ids) if spectrum_list
    chromatogram_list.to_xml(run_n, default_ids) if chromatogram_list
  end
  builder
end