mspire 0.7.18 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
 - data/bin/mspire +5 -0
 - data/lib/core_ext/enumerable.rb +8 -0
 - data/lib/mspire/commandline.rb +39 -0
 - data/lib/mspire/cv/paramable.rb +72 -35
 - data/lib/mspire/imzml/writer/commandline.rb +16 -7
 - data/lib/mspire/imzml/writer.rb +22 -14
 - data/lib/mspire/mzml/activation.rb +0 -5
 - data/lib/mspire/mzml/chromatogram.rb +41 -6
 - data/lib/mspire/mzml/chromatogram_list.rb +2 -19
 - data/lib/mspire/mzml/component.rb +28 -4
 - data/lib/mspire/mzml/cv.rb +1 -0
 - data/lib/mspire/mzml/data_array.rb +164 -154
 - data/lib/mspire/mzml/data_array_container_like.rb +6 -13
 - data/lib/mspire/mzml/data_processing.rb +19 -5
 - data/lib/mspire/mzml/file_description.rb +22 -4
 - data/lib/mspire/mzml/index.rb +53 -0
 - data/lib/mspire/mzml/index_list.rb +64 -55
 - data/lib/mspire/mzml/instrument_configuration.rb +22 -7
 - data/lib/mspire/mzml/io_index.rb +79 -0
 - data/lib/mspire/mzml/io_indexable_list.rb +71 -0
 - data/lib/mspire/mzml/isolation_window.rb +0 -5
 - data/lib/mspire/mzml/parser.rb +10 -0
 - data/lib/mspire/mzml/plms1.rb +14 -24
 - data/lib/mspire/mzml/precursor.rb +41 -19
 - data/lib/mspire/mzml/processing_method.rb +34 -7
 - data/lib/mspire/mzml/product.rb +14 -1
 - data/lib/mspire/mzml/reader.rb +154 -0
 - data/lib/mspire/mzml/referenceable_param_group.rb +9 -2
 - data/lib/mspire/mzml/run.rb +62 -5
 - data/lib/mspire/mzml/sample.rb +16 -6
 - data/lib/mspire/mzml/scan.rb +31 -16
 - data/lib/mspire/mzml/scan_list.rb +18 -5
 - data/lib/mspire/mzml/scan_settings.rb +4 -5
 - data/lib/mspire/mzml/scan_window.rb +0 -6
 - data/lib/mspire/mzml/selected_ion.rb +1 -8
 - data/lib/mspire/mzml/software.rb +9 -4
 - data/lib/mspire/mzml/source_file.rb +8 -4
 - data/lib/mspire/mzml/spectrum.rb +60 -35
 - data/lib/mspire/mzml/spectrum_list.rb +5 -34
 - data/lib/mspire/mzml.rb +72 -210
 - data/lib/mspire/plms1.rb +3 -0
 - data/spec/mspire/cv/paramable_spec.rb +3 -3
 - data/spec/mspire/mzml/data_array_spec.rb +19 -6
 - data/spec/mspire/mzml/file_content_spec.rb +1 -4
 - data/spec/mspire/mzml/index_list_spec.rb +5 -12
 - data/spec/mspire/mzml/plms1_spec.rb +5 -9
 - data/spec/mspire/mzml/referenceable_param_group_spec.rb +3 -3
 - data/spec/mspire/mzml/source_file_spec.rb +1 -2
 - data/spec/mspire/mzml/spectrum_list_spec.rb +54 -0
 - data/spec/mspire/mzml/spectrum_spec.rb +2 -4
 - data/spec/mspire/mzml_spec.rb +241 -21
 - data/spec/spec_helper.rb +1 -0
 - data/spec/testfiles/mspire/mzml/1_BB7_SIM_478.5.mzML +103 -0
 - data/spec/testfiles/mspire/mzml/j24z.idx_comp.3.mzML +6 -6
 - metadata +14 -6
 - data/bin/mzml_to_imzml +0 -9
 - data/spec/mspire/mzml/file_description_spec.rb +0 -12
 
    
        data/lib/mspire/mzml/run.rb
    CHANGED
    
    | 
         @@ -1,4 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mspire/cv/paramable'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'mspire/mzml/io_index'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'mspire/mzml/spectrum_list'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'mspire/mzml/chromatogram_list'
         
     | 
| 
       2 
5 
     | 
    
         | 
| 
       3 
6 
     | 
    
         
             
            module Mspire
         
     | 
| 
       4 
7 
     | 
    
         
             
              class Mzml
         
     | 
| 
         @@ -27,11 +30,13 @@ module Mspire 
     | 
|
| 
       27 
30 
     | 
    
         
             
                  attr_accessor :chromatogram_list
         
     | 
| 
       28 
31 
     | 
    
         | 
| 
       29 
32 
     | 
    
         
             
                  # yields self if given a block
         
     | 
| 
       30 
     | 
    
         
            -
                  def initialize(id, default_instrument_configuration 
     | 
| 
      
 33 
     | 
    
         
            +
                  def initialize(id, default_instrument_configuration)
         
     | 
| 
       31 
34 
     | 
    
         
             
                    @id = id
         
     | 
| 
       32 
35 
     | 
    
         
             
                    @default_instrument_configuration = default_instrument_configuration
         
     | 
| 
       33 
     | 
    
         
            -
                     
     | 
| 
       34 
     | 
    
         
            -
                     
     | 
| 
      
 36 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 37 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 38 
     | 
    
         
            +
                      yield self
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
       35 
40 
     | 
    
         
             
                  end
         
     | 
| 
       36 
41 
     | 
    
         | 
| 
       37 
42 
     | 
    
         
             
                  def to_xml(builder)
         
     | 
| 
         @@ -41,14 +46,66 @@ module Mspire 
     | 
|
| 
       41 
46 
     | 
    
         
             
                    atts[:defaultSourceFileRef] = @default_source_file.id if @default_source_file
         
     | 
| 
       42 
47 
     | 
    
         
             
                    atts[:sampleRef] = @sample.id if @sample
         
     | 
| 
       43 
48 
     | 
    
         
             
                    atts[:startTimeStamp] = @start_time_stamp if @start_time_stamp
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    default_ids = { instrument_configuration: @default_instrument_configuration.id }
         
     | 
| 
       44 
51 
     | 
    
         | 
| 
       45 
52 
     | 
    
         
             
                    builder.run(atts) do |run_n|
         
     | 
| 
       46 
53 
     | 
    
         
             
                      super(run_n)
         
     | 
| 
       47 
     | 
    
         
            -
                      spectrum_list.to_xml(run_n) if spectrum_list
         
     | 
| 
       48 
     | 
    
         
            -
                      chromatogram_list.to_xml(run_n) if chromatogram_list
         
     | 
| 
      
 54 
     | 
    
         
            +
                      spectrum_list.to_xml(run_n, default_ids) if spectrum_list
         
     | 
| 
      
 55 
     | 
    
         
            +
                      chromatogram_list.to_xml(run_n, default_ids) if chromatogram_list
         
     | 
| 
       49 
56 
     | 
    
         
             
                    end
         
     | 
| 
       50 
57 
     | 
    
         
             
                    builder
         
     | 
| 
       51 
58 
     | 
    
         
             
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  # expects link to have the following keys:
         
     | 
| 
      
 61 
     | 
    
         
            +
                  #
         
     | 
| 
      
 62 
     | 
    
         
            +
                  #     :ref_hash
         
     | 
| 
      
 63 
     | 
    
         
            +
                  #     :instrument_config_hash
         
     | 
| 
      
 64 
     | 
    
         
            +
                  #     :source_file_hash
         
     | 
| 
      
 65 
     | 
    
         
            +
                  #     :sample_hash
         
     | 
| 
      
 66 
     | 
    
         
            +
                  #     :data_processing_hash
         
     | 
| 
      
 67 
     | 
    
         
            +
                  #     :spectrum_default_data_processing
         
     | 
| 
      
 68 
     | 
    
         
            +
                  #     :chromatogram_default_data_processing
         
     | 
| 
      
 69 
     | 
    
         
            +
                  #     :index_list
         
     | 
| 
      
 70 
     | 
    
         
            +
                  def self.from_xml(io, xml, link)
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    # expects that the DataProcessing objects to link to have *already* been
         
     | 
| 
      
 73 
     | 
    
         
            +
                    # parsed (parse the defaultDataProcessingRef's after grabbing the
         
     | 
| 
      
 74 
     | 
    
         
            +
                    # index, then grab the DataProcessing object associated with that id).
         
     | 
| 
      
 75 
     | 
    
         
            +
                    
         
     | 
| 
      
 76 
     | 
    
         
            +
                    obj = self.new(xml[:id], 
         
     | 
| 
      
 77 
     | 
    
         
            +
                      link[:instrument_configuration_hash][xml[:defaultInstrumentConfigurationRef]]
         
     | 
| 
      
 78 
     | 
    
         
            +
                    )
         
     | 
| 
      
 79 
     | 
    
         
            +
                    obj.start_time_stamp = xml[:startTimeStamp]
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                    link[:default_instrument_configuration] = obj.default_instrument_configuration
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                    # two optional object refs
         
     | 
| 
      
 84 
     | 
    
         
            +
                    if def_source_ref=xml[:defaultSourceFileRef]
         
     | 
| 
      
 85 
     | 
    
         
            +
                      obj.default_source_file = link[:source_file_hash][def_source_ref]
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
                    if sample_ref=xml[:sampleRef]
         
     | 
| 
      
 88 
     | 
    
         
            +
                      obj.sample = link[:sample_hash][sample_ref]
         
     | 
| 
      
 89 
     | 
    
         
            +
                    end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                    obj.describe_from_xml!(xml, link[:ref_hash])
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                    index_list = link[:index_list]
         
     | 
| 
      
 94 
     | 
    
         
            +
                    [:spectrum, :chromatogram].each do |list_type|
         
     | 
| 
      
 95 
     | 
    
         
            +
                      next unless (byte_index = index_list[list_type])
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                      io_index = IOIndex.new(io, byte_index, link)
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                      list_obj = Mspire::Mzml.const_get(list_type.to_s.capitalize + "List")
         
     | 
| 
      
 100 
     | 
    
         
            +
                        .new(link["#{list_type}_default_data_processing".to_sym], 
         
     | 
| 
      
 101 
     | 
    
         
            +
                             io_index, 
         
     | 
| 
      
 102 
     | 
    
         
            +
                             Hash[byte_index.ids.each_with_index.map.to_a]
         
     | 
| 
      
 103 
     | 
    
         
            +
                            )
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                      obj.send(list_type.to_s + "_list=", list_obj)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    end
         
     | 
| 
      
 107 
     | 
    
         
            +
                    obj
         
     | 
| 
      
 108 
     | 
    
         
            +
                  end
         
     | 
| 
       52 
109 
     | 
    
         
             
                end
         
     | 
| 
       53 
110 
     | 
    
         
             
              end
         
     | 
| 
       54 
111 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mspire/mzml/sample.rb
    CHANGED
    
    | 
         @@ -5,13 +5,18 @@ module Mspire 
     | 
|
| 
       5 
5 
     | 
    
         
             
              class Mzml
         
     | 
| 
       6 
6 
     | 
    
         
             
                class Sample
         
     | 
| 
       7 
7 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
      
 8 
     | 
    
         
            +
                  extend Mspire::Mzml::List
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
      
 10 
     | 
    
         
            +
                  # A unique identifier across the samples with which to reference this sample description.
         
     | 
| 
      
 11 
     | 
    
         
            +
                  attr_accessor :id
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                  # An optional name for the sample description, mostly intended as a quick mnemonic.
         
     | 
| 
      
 14 
     | 
    
         
            +
                  attr_accessor :name
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def initialize(id)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @id = id
         
     | 
| 
      
 18 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 19 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       15 
20 
     | 
    
         
             
                  end
         
     | 
| 
       16 
21 
     | 
    
         | 
| 
       17 
22 
     | 
    
         
             
                  def to_xml(builder)
         
     | 
| 
         @@ -21,7 +26,12 @@ module Mspire 
     | 
|
| 
       21 
26 
     | 
    
         
             
                    builder
         
     | 
| 
       22 
27 
     | 
    
         
             
                  end
         
     | 
| 
       23 
28 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                   
     | 
| 
      
 29 
     | 
    
         
            +
                  def self.from_xml(xml, link)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    obj = self.new(xml[:id])
         
     | 
| 
      
 31 
     | 
    
         
            +
                    obj.name = xml[:name]
         
     | 
| 
      
 32 
     | 
    
         
            +
                    obj.describe_self_from_xml!(xml, link[:ref_hash])
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       25 
35 
     | 
    
         
             
                end
         
     | 
| 
       26 
36 
     | 
    
         
             
              end
         
     | 
| 
       27 
37 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mspire/mzml/scan.rb
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mspire/cv/paramable'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'mspire/cv/paramable'
         
     | 
| 
       2 
3 
     | 
    
         
             
            require 'mspire/mzml/scan_window'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            module Mspire
         
     | 
| 
         @@ -14,31 +15,41 @@ module Mspire 
     | 
|
| 
       14 
15 
     | 
    
         
             
                  # a boolean indicating the spectrum is from an external source file
         
     | 
| 
       15 
16 
     | 
    
         
             
                  attr_accessor :from_external_source_file
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                  # an InstrumentConfiguration object
         
     | 
| 
      
 18 
     | 
    
         
            +
                  # an InstrumentConfiguration object (optional).
         
     | 
| 
       18 
19 
     | 
    
         
             
                  attr_accessor :instrument_configuration
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
                  # ScanWindow objects
         
     | 
| 
       21 
22 
     | 
    
         
             
                  attr_accessor :scan_windows
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  def initialize 
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
       25 
     | 
    
         
            -
                     
     | 
| 
      
 24 
     | 
    
         
            +
                  def initialize
         
     | 
| 
      
 25 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 26 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       26 
27 
     | 
    
         
             
                  end
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                  #  
     | 
| 
       29 
     | 
    
         
            -
                  # 
     | 
| 
       30 
     | 
    
         
            -
                  # 
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                   
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                    [: 
     | 
| 
       35 
     | 
    
         
            -
                     
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
                  # link should have:
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #     :ref_hash
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #     :default_instrument_configuration
         
     | 
| 
      
 33 
     | 
    
         
            +
                  #     :instrument_configuration_hash
         
     | 
| 
      
 34 
     | 
    
         
            +
                  def self.from_xml(xml, link)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    ref_hash = link[:ref_hash]
         
     | 
| 
      
 36 
     | 
    
         
            +
                    obj = self.new
         
     | 
| 
      
 37 
     | 
    
         
            +
                    obj.instrument_configuration =
         
     | 
| 
      
 38 
     | 
    
         
            +
                      if icf = xml[:instrumentConfigurationRef]
         
     | 
| 
      
 39 
     | 
    
         
            +
                        link[:instrument_configuration_hash][icf]
         
     | 
| 
      
 40 
     | 
    
         
            +
                      else
         
     | 
| 
      
 41 
     | 
    
         
            +
                        link[:default_instrument_configuration]
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    scan_window_list_n = obj.describe_from_xml!(xml, ref_hash)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    if scan_window_list_n
         
     | 
| 
      
 45 
     | 
    
         
            +
                      obj.scan_windows = scan_window_list_n.children.map do |scan_window_n|
         
     | 
| 
      
 46 
     | 
    
         
            +
                        Mspire::Mzml::ScanWindow.new.describe_self_from_xml!(scan_window_n, ref_hash)
         
     | 
| 
      
 47 
     | 
    
         
            +
                      end
         
     | 
| 
       37 
48 
     | 
    
         
             
                    end
         
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
      
 49 
     | 
    
         
            +
                    obj
         
     | 
| 
       39 
50 
     | 
    
         
             
                  end
         
     | 
| 
       40 
51 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                  def to_xml(builder)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  def to_xml(builder, default_ids)
         
     | 
| 
       42 
53 
     | 
    
         
             
                    atts = {}
         
     | 
| 
       43 
54 
     | 
    
         
             
                    if @from_external_source_file
         
     | 
| 
       44 
55 
     | 
    
         
             
                      atts[:sourceFileRef] = @spectrum.source_file.id
         
     | 
| 
         @@ -46,7 +57,11 @@ module Mspire 
     | 
|
| 
       46 
57 
     | 
    
         
             
                    else
         
     | 
| 
       47 
58 
     | 
    
         
             
                      atts[:spectrumRef] = @spectrum.id if @spectrum
         
     | 
| 
       48 
59 
     | 
    
         
             
                    end
         
     | 
| 
       49 
     | 
    
         
            -
                     
     | 
| 
      
 60 
     | 
    
         
            +
                    if @instrument_configuration
         
     | 
| 
      
 61 
     | 
    
         
            +
                      unless @instrument_configuration.id == default_ids[:instrument_configuration]
         
     | 
| 
      
 62 
     | 
    
         
            +
                        atts[:instrumentConfigurationRef] = @instrument_configuration.id 
         
     | 
| 
      
 63 
     | 
    
         
            +
                      end
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
       50 
65 
     | 
    
         
             
                    builder.scan(atts) do |prec_n|
         
     | 
| 
       51 
66 
     | 
    
         
             
                      super(prec_n) # description
         
     | 
| 
       52 
67 
     | 
    
         
             
                      ScanWindow.list_xml(@scan_windows, prec_n) if @scan_windows
         
     | 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mspire/cv/paramable'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'mspire/mzml/scan'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            module Mspire
         
     | 
| 
       4 
5 
     | 
    
         
             
              class Mzml
         
     | 
| 
         @@ -12,21 +13,33 @@ module Mspire 
     | 
|
| 
       12 
13 
     | 
    
         
             
                class ScanList < Array
         
     | 
| 
       13 
14 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                  def initialize 
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                  def initialize
         
     | 
| 
      
 17 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 18 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       18 
19 
     | 
    
         
             
                  end
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                  def to_xml(builder)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  def to_xml(builder, default_ids)
         
     | 
| 
       21 
22 
     | 
    
         
             
                    builder.scanList(count: self.size) do |sl_n|
         
     | 
| 
       22 
23 
     | 
    
         
             
                      super(sl_n)
         
     | 
| 
       23 
24 
     | 
    
         
             
                      self.each do |scan|
         
     | 
| 
       24 
     | 
    
         
            -
                        scan.to_xml(sl_n)
         
     | 
| 
      
 25 
     | 
    
         
            +
                        scan.to_xml(sl_n, default_ids)
         
     | 
| 
       25 
26 
     | 
    
         
             
                      end
         
     | 
| 
       26 
27 
     | 
    
         
             
                    end
         
     | 
| 
       27 
28 
     | 
    
         
             
                    builder
         
     | 
| 
       28 
29 
     | 
    
         
             
                  end
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
      
 31 
     | 
    
         
            +
                  def self.from_xml(xml, link)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    scan_list = self.new
         
     | 
| 
      
 33 
     | 
    
         
            +
                    scan_n = scan_list.describe_from_xml!(xml, link[:ref_hash])
         
     | 
| 
      
 34 
     | 
    
         
            +
                    if scan_n
         
     | 
| 
      
 35 
     | 
    
         
            +
                      loop do
         
     | 
| 
      
 36 
     | 
    
         
            +
                        scan_list << Mspire::Mzml::Scan.from_xml(scan_n, link)
         
     | 
| 
      
 37 
     | 
    
         
            +
                        break unless scan_n = scan_n.next
         
     | 
| 
      
 38 
     | 
    
         
            +
                      end
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    scan_list
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       30 
43 
     | 
    
         
             
                  alias_method :list_xml, :to_xml
         
     | 
| 
       31 
44 
     | 
    
         
             
                end
         
     | 
| 
       32 
45 
     | 
    
         
             
              end
         
     | 
| 
         @@ -5,13 +5,14 @@ module Mspire 
     | 
|
| 
       5 
5 
     | 
    
         
             
              class Mzml
         
     | 
| 
       6 
6 
     | 
    
         
             
                class ScanSettings
         
     | 
| 
       7 
7 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
      
 8 
     | 
    
         
            +
                  extend Mspire::Mzml::List
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                  attr_accessor :id
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                  def initialize(id 
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize(id)
         
     | 
| 
       12 
13 
     | 
    
         
             
                    @id = id
         
     | 
| 
       13 
     | 
    
         
            -
                     
     | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
      
 14 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 15 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       15 
16 
     | 
    
         
             
                  end
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
                  def to_xml(builder)
         
     | 
| 
         @@ -21,8 +22,6 @@ module Mspire 
     | 
|
| 
       21 
22 
     | 
    
         
             
                    builder
         
     | 
| 
       22 
23 
     | 
    
         
             
                  end
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                  extend(Mspire::Mzml::List)
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
25 
     | 
    
         
             
                end
         
     | 
| 
       27 
26 
     | 
    
         
             
              end
         
     | 
| 
       28 
27 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,12 +8,6 @@ module Mspire 
     | 
|
| 
       8 
8 
     | 
    
         
             
                #     accession="MS:1000500" name="scan window upper limit" value="1800"
         
     | 
| 
       9 
9 
     | 
    
         
             
                class ScanWindow
         
     | 
| 
       10 
10 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  def self.from_xml(xml)
         
     | 
| 
       13 
     | 
    
         
            -
                    obj = self.new
         
     | 
| 
       14 
     | 
    
         
            -
                    [:cvParam, :userParam].each {|v| obj.describe! xml.xpath("./#{v}") }
         
     | 
| 
       15 
     | 
    
         
            -
                    obj
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
       17 
11 
     | 
    
         
             
                end
         
     | 
| 
       18 
12 
     | 
    
         
             
              end
         
     | 
| 
       19 
13 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,7 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mspire/mzml/list'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'mspire/cv/paramable'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
4 
     | 
    
         
             
            module Mspire
         
     | 
| 
       6 
5 
     | 
    
         
             
              class Mzml
         
     | 
| 
       7 
6 
     | 
    
         
             
                # MUST supply a *child* term of MS:1000455 (ion selection attribute) one or more times
         
     | 
| 
         @@ -12,13 +11,7 @@ module Mspire 
     | 
|
| 
       12 
11 
     | 
    
         
             
                #     e.g.: MS:1000744 (selected ion m/z)
         
     | 
| 
       13 
12 
     | 
    
         
             
                class SelectedIon
         
     | 
| 
       14 
13 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
       15 
     | 
    
         
            -
                  extend 
     | 
| 
       16 
     | 
    
         
            -
                  
         
     | 
| 
       17 
     | 
    
         
            -
                  def self.from_xml(xml)
         
     | 
| 
       18 
     | 
    
         
            -
                    obj = self.new
         
     | 
| 
       19 
     | 
    
         
            -
                    [:cvParam, :userParam].each {|v| obj.describe! xml.xpath("./#{v}") }
         
     | 
| 
       20 
     | 
    
         
            -
                    obj
         
     | 
| 
       21 
     | 
    
         
            -
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  extend Mspire::Mzml::List
         
     | 
| 
       22 
15 
     | 
    
         
             
                end
         
     | 
| 
       23 
16 
     | 
    
         
             
              end
         
     | 
| 
       24 
17 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mspire/mzml/software.rb
    CHANGED
    
    | 
         @@ -6,13 +6,14 @@ module Mspire 
     | 
|
| 
       6 
6 
     | 
    
         
             
              class Mzml
         
     | 
| 
       7 
7 
     | 
    
         
             
                class Software
         
     | 
| 
       8 
8 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
      
 9 
     | 
    
         
            +
                  extend Mspire::Mzml::List
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                  attr_accessor :id, :version
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                  def initialize(id='mspire', version=Mspire::VERSION 
     | 
| 
      
 13 
     | 
    
         
            +
                  def initialize(id='mspire', version=Mspire::VERSION)
         
     | 
| 
       13 
14 
     | 
    
         
             
                    @id, @version = id, version
         
     | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
      
 15 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 16 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       16 
17 
     | 
    
         
             
                  end
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                  def to_xml(builder)
         
     | 
| 
         @@ -22,7 +23,11 @@ module Mspire 
     | 
|
| 
       22 
23 
     | 
    
         
             
                    builder
         
     | 
| 
       23 
24 
     | 
    
         
             
                  end
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
      
 26 
     | 
    
         
            +
                  def self.from_xml(xml, link)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    obj = self.new(xml[:id], xml[:version])
         
     | 
| 
      
 28 
     | 
    
         
            +
                    obj.describe_self_from_xml!(xml, link[:ref_hash])
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       26 
31 
     | 
    
         
             
                end
         
     | 
| 
       27 
32 
     | 
    
         
             
              end
         
     | 
| 
       28 
33 
     | 
    
         
             
            end
         
     | 
| 
         @@ -6,6 +6,7 @@ module Mspire 
     | 
|
| 
       6 
6 
     | 
    
         
             
              class Mzml
         
     | 
| 
       7 
7 
     | 
    
         
             
                class SourceFile
         
     | 
| 
       8 
8 
     | 
    
         
             
                  include Mspire::CV::Paramable
         
     | 
| 
      
 9 
     | 
    
         
            +
                  extend Mspire::Mzml::List
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                  DEFAULT_SOURCEFILE_ID = 'sourcefile1'
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
         @@ -31,10 +32,10 @@ module Mspire 
     | 
|
| 
       31 
32 
     | 
    
         
             
                    [pathname.basename, 'file://'+ dir]
         
     | 
| 
       32 
33 
     | 
    
         
             
                  end
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                  def initialize(id="sourcefile1", name="mspire-simulated", location='file://' 
     | 
| 
      
 35 
     | 
    
         
            +
                  def initialize(id="sourcefile1", name="mspire-simulated", location='file://')
         
     | 
| 
       35 
36 
     | 
    
         
             
                    @id, @name, @location = id, name, location
         
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
       37 
     | 
    
         
            -
                     
     | 
| 
      
 37 
     | 
    
         
            +
                    params_init
         
     | 
| 
      
 38 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       38 
39 
     | 
    
         
             
                  end
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
       40 
41 
     | 
    
         
             
                  def to_xml(builder)
         
     | 
| 
         @@ -44,7 +45,10 @@ module Mspire 
     | 
|
| 
       44 
45 
     | 
    
         
             
                    builder
         
     | 
| 
       45 
46 
     | 
    
         
             
                  end
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
      
 48 
     | 
    
         
            +
                  def self.from_xml(xml, ref_hash)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    self.new(xml[:id], xml[:name], xml[:location]).describe_self_from_xml!(xml, ref_hash)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       48 
52 
     | 
    
         
             
                end
         
     | 
| 
       49 
53 
     | 
    
         
             
              end
         
     | 
| 
       50 
54 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mspire/mzml/spectrum.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
       2 
2 
     | 
    
         
             
            require 'mspire/spectrum_like'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'mspire/mzml/data_array'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'mspire/mzml/data_array_container_like'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require 'mspire/mzml/scan_list'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'mspire/mzml/precursor'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'mspire/mzml/product'
         
     | 
| 
         @@ -48,6 +49,8 @@ module Mspire 
     | 
|
| 
       48 
49 
     | 
    
         
             
                  # (optional) an Mspire::Mzml::SourceFile object
         
     | 
| 
       49 
50 
     | 
    
         
             
                  attr_accessor :source_file
         
     | 
| 
       50 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                  # data_processing is included with DataArrayContainerLike
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       51 
54 
     | 
    
         
             
                  # (optional) The identifier for the spot from which this spectrum was derived, if a
         
     | 
| 
       52 
55 
     | 
    
         
             
                  # MALDI or similar run.
         
     | 
| 
       53 
56 
     | 
    
         
             
                  attr_accessor :spot_id
         
     | 
| 
         @@ -107,58 +110,80 @@ module Mspire 
     | 
|
| 
       107 
110 
     | 
    
         
             
                  end
         
     | 
| 
       108 
111 
     | 
    
         | 
| 
       109 
112 
     | 
    
         
             
                  # takes a Nokogiri node and sets relevant properties
         
     | 
| 
       110 
     | 
    
         
            -
                   
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
                  # 
         
     | 
| 
      
 114 
     | 
    
         
            +
                  # link is a hash that should contain the following keys and associated
         
     | 
| 
      
 115 
     | 
    
         
            +
                  # objects (some are required by downstream objects, like Scan):
         
     | 
| 
      
 116 
     | 
    
         
            +
                  #
         
     | 
| 
      
 117 
     | 
    
         
            +
                  #     :ref_hash                         id -> ReferenceableParamGroup
         
     | 
| 
      
 118 
     | 
    
         
            +
                  #     :spectrum_list                    SpectrumList object
         
     | 
| 
      
 119 
     | 
    
         
            +
                  #     :data_processing_hash             id -> DataProcessing object
         
     | 
| 
      
 120 
     | 
    
         
            +
                  #     :default_data_processing          DataProcessing object
         
     | 
| 
      
 121 
     | 
    
         
            +
                  #     :instrument_configuration_hash    id -> InstrumentConfiguration object
         
     | 
| 
      
 122 
     | 
    
         
            +
                  #     :default_instrument_configuration InstrumentConfiguration object
         
     | 
| 
      
 123 
     | 
    
         
            +
                  #     :source_file_hash                 id -> SourceFile object
         
     | 
| 
      
 124 
     | 
    
         
            +
                  def self.from_xml(xml, link)
         
     | 
| 
      
 125 
     | 
    
         
            +
                    obj = self.new(xml[:id])
         
     | 
| 
      
 126 
     | 
    
         
            +
                    obj.spot_id = xml[:spotID]
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                    obj.data_processing = link[:data_processing_hash][xml[:dataProcessingRef]] || link[:spectrum_default_data_processing]
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                    if source_file_ref=xml[:sourceFileRef]
         
     | 
| 
      
 131 
     | 
    
         
            +
                      obj.source_file = link[:source_file_hash][source_file_ref]
         
     | 
| 
      
 132 
     | 
    
         
            +
                    end
         
     | 
| 
       114 
133 
     | 
    
         | 
| 
       115 
     | 
    
         
            -
                     
     | 
| 
      
 134 
     | 
    
         
            +
                    xml_n = obj.describe_from_xml!(xml, link[:ref_hash])
         
     | 
| 
      
 135 
     | 
    
         
            +
                    return obj unless xml_n
         
     | 
| 
       116 
136 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
                     
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                       
     | 
| 
      
 137 
     | 
    
         
            +
                    loop do
         
     | 
| 
      
 138 
     | 
    
         
            +
                      case xml_n.name
         
     | 
| 
      
 139 
     | 
    
         
            +
                      when 'scanList'
         
     | 
| 
      
 140 
     | 
    
         
            +
                        obj.scan_list = Mspire::Mzml::ScanList.from_xml(xml_n, link)
         
     | 
| 
      
 141 
     | 
    
         
            +
                      when 'precursorList'
         
     | 
| 
      
 142 
     | 
    
         
            +
                        obj.precursors = xml_n.children.map do |prec_n|
         
     | 
| 
      
 143 
     | 
    
         
            +
                          Mspire::Mzml::Precursor.from_xml(prec_n, link)
         
     | 
| 
      
 144 
     | 
    
         
            +
                        end
         
     | 
| 
      
 145 
     | 
    
         
            +
                      when 'productList'
         
     | 
| 
      
 146 
     | 
    
         
            +
                        obj.products = xml_n.children.map do |product_n|
         
     | 
| 
      
 147 
     | 
    
         
            +
                          Mspire::Mzml::Product.from_xml(product_n, link)
         
     | 
| 
      
 148 
     | 
    
         
            +
                        end
         
     | 
| 
      
 149 
     | 
    
         
            +
                      when 'binaryDataArrayList'
         
     | 
| 
      
 150 
     | 
    
         
            +
                        obj.data_arrays = Mspire::Mzml::DataArray.data_arrays_from_xml(xml_n, link)
         
     | 
| 
      
 151 
     | 
    
         
            +
                      end
         
     | 
| 
      
 152 
     | 
    
         
            +
                      break unless xml_n = xml_n.next
         
     | 
| 
       120 
153 
     | 
    
         
             
                    end
         
     | 
| 
       121 
     | 
    
         
            -
                     
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                    spec.precursors = xml.xpath('./precursorList/precursor').map do |prec_n|
         
     | 
| 
       124 
     | 
    
         
            -
                      Mspire::Mzml::Precursor.from_xml(prec_n)
         
     | 
| 
      
 154 
     | 
    
         
            +
                    unless obj.data_arrays
         
     | 
| 
      
 155 
     | 
    
         
            +
                      obj.data_arrays = Mspire::Mzml::DataArray.empty_data_arrays
         
     | 
| 
       125 
156 
     | 
    
         
             
                    end
         
     | 
| 
       126 
157 
     | 
    
         | 
| 
       127 
     | 
    
         
            -
                    data_arrays = xml.xpath('./binaryDataArrayList/binaryDataArray').map do |binary_data_array_n|
         
     | 
| 
       128 
     | 
    
         
            -
                      accessions = binary_data_array_n.xpath('./cvParam').map {|node| node['accession'] }
         
     | 
| 
       129 
     | 
    
         
            -
                      base64 = binary_data_array_n.xpath('./binary').text
         
     | 
| 
       130 
     | 
    
         
            -
                      Mspire::Mzml::DataArray.from_binary(base64, accessions)
         
     | 
| 
       131 
     | 
    
         
            -
                    end
         
     | 
| 
       132 
158 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                     
     | 
| 
       135 
     | 
    
         
            -
                    data_arrays = [Mspire::Mzml::DataArray.new, Mspire::Mzml::DataArray.new] if data_arrays.size == 0
         
     | 
| 
       136 
     | 
    
         
            -
                    spec.data_arrays = data_arrays
         
     | 
| 
       137 
     | 
    
         
            -
                    spec
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                    obj
         
     | 
| 
       138 
161 
     | 
    
         
             
                  end
         
     | 
| 
       139 
162 
     | 
    
         | 
| 
       140 
163 
     | 
    
         
             
                  # the most common param to pass in would be ms level: 'MS:1000511'
         
     | 
| 
       141 
164 
     | 
    
         
             
                  #
         
     | 
| 
       142 
     | 
    
         
            -
                  # This would generate a spectrum of ms_level 
     | 
| 
      
 165 
     | 
    
         
            +
                  # This would generate a spectrum of ms_level 2 :
         
     | 
| 
       143 
166 
     | 
    
         
             
                  #
         
     | 
| 
       144 
     | 
    
         
            -
                  #     Mspire::Mzml::Spectrum.new( 
     | 
| 
      
 167 
     | 
    
         
            +
                  #     spec = Mspire::Mzml::Spectrum.new("scan=1").describe!('MS:1000511')
         
     | 
| 
       145 
168 
     | 
    
         
             
                  #
         
     | 
| 
       146 
     | 
    
         
            -
                  def initialize(id 
     | 
| 
      
 169 
     | 
    
         
            +
                  def initialize(id)
         
     | 
| 
       147 
170 
     | 
    
         
             
                    @id = id
         
     | 
| 
       148 
     | 
    
         
            -
                    params_initialize 
     | 
| 
       149 
     | 
    
         
            -
                     
     | 
| 
      
 171 
     | 
    
         
            +
                    params_initialize
         
     | 
| 
      
 172 
     | 
    
         
            +
                    yield(self) if block_given?
         
     | 
| 
       150 
173 
     | 
    
         
             
                  end
         
     | 
| 
       151 
174 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
175 
     | 
    
         
             
                  # see SpectrumList for generating the entire list
         
     | 
| 
       154 
     | 
    
         
            -
                  def to_xml(builder)
         
     | 
| 
       155 
     | 
    
         
            -
                    atts =  
     | 
| 
      
 176 
     | 
    
         
            +
                  def to_xml(builder, default_ids)
         
     | 
| 
      
 177 
     | 
    
         
            +
                    atts = data_array_xml_atts(default_ids)
         
     | 
| 
       156 
178 
     | 
    
         
             
                    atts[:sourceFileRef] = @source_file.id if @source_file
         
     | 
| 
       157 
179 
     | 
    
         
             
                    atts[:spotID] = @spot_id if @spot_id
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                       
     | 
| 
       161 
     | 
    
         
            -
                       
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
      
 181 
     | 
    
         
            +
                    builder.spectrum(atts) do |sp_n|
         
     | 
| 
      
 182 
     | 
    
         
            +
                      super(sp_n)
         
     | 
| 
      
 183 
     | 
    
         
            +
                      @scan_list.list_xml( sp_n, default_ids ) if @scan_list
         
     | 
| 
      
 184 
     | 
    
         
            +
                      Mspire::Mzml::Precursor.list_xml(@precursors, sp_n) if @precursors
         
     | 
| 
      
 185 
     | 
    
         
            +
                      Mspire::Mzml::Product.list_xml(@products, sp_n) if @products
         
     | 
| 
      
 186 
     | 
    
         
            +
                      Mspire::Mzml::DataArray.list_xml(@data_arrays, sp_n) if @data_arrays
         
     | 
| 
       162 
187 
     | 
    
         
             
                    end
         
     | 
| 
       163 
188 
     | 
    
         
             
                  end
         
     | 
| 
       164 
189 
     | 
    
         | 
| 
         @@ -1,43 +1,14 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'mspire/mzml/ 
     | 
| 
      
 1 
     | 
    
         
            +
            require 'mspire/mzml/io_indexable_list'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Mspire
         
     | 
| 
       4 
4 
     | 
    
         
             
              class Mzml
         
     | 
| 
       5 
     | 
    
         
            -
                class SpectrumList <  
     | 
| 
      
 5 
     | 
    
         
            +
                class SpectrumList < IOIndexableList
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                   
     | 
| 
       8 
     | 
    
         
            -
                  attr_reader :default_data_processing
         
     | 
| 
      
 7 
     | 
    
         
            +
                  attr_accessor :scan_to_index
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  def  
     | 
| 
       11 
     | 
    
         
            -
                    @ 
     | 
| 
       12 
     | 
    
         
            -
                    super(spectra)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  def fetch_by_scan_num(scan_num)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    __getobj__[@scan_to_index[scan_num]]
         
     | 
| 
       13 
11 
     | 
    
         
             
                  end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  # This method takes an object responding to :data, creates a new
         
     | 
| 
       16 
     | 
    
         
            -
                  # Mspire::Mzml::Spectrum object with that data and puts it in the internal
         
     | 
| 
       17 
     | 
    
         
            -
                  # list
         
     | 
| 
       18 
     | 
    
         
            -
                  def add_ms_spectrum!(spectrum, id)
         
     | 
| 
       19 
     | 
    
         
            -
                    mzml_spec = Mspire::Mzml::Spectrum.new(id)
         
     | 
| 
       20 
     | 
    
         
            -
                    mzml_spec.data = spectrum.data
         
     | 
| 
       21 
     | 
    
         
            -
                    self << mzml_spec
         
     | 
| 
       22 
     | 
    
         
            -
                  end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                  # takes an array of spectra and performs add_spectrum on each
         
     | 
| 
       25 
     | 
    
         
            -
                  # returns self
         
     | 
| 
       26 
     | 
    
         
            -
                  def add_ms_spectra!(spectra, ids=[])
         
     | 
| 
       27 
     | 
    
         
            -
                    spectra.zip(ids).each_with_index {|(spec,id),i| add_spectrum(spec, "spectrum=#{i+1}") }
         
     | 
| 
       28 
     | 
    
         
            -
                    self
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  def to_xml(builder)
         
     | 
| 
       32 
     | 
    
         
            -
                    builder.spectrumList(count: self.size, defaultDataProcessingRef: @default_data_processing.id) do |spl_n|
         
     | 
| 
       33 
     | 
    
         
            -
                      self.each_with_index do |spectrum,i|
         
     | 
| 
       34 
     | 
    
         
            -
                        spectrum.index = i unless spectrum.index
         
     | 
| 
       35 
     | 
    
         
            -
                        spectrum.to_xml(spl_n)
         
     | 
| 
       36 
     | 
    
         
            -
                      end
         
     | 
| 
       37 
     | 
    
         
            -
                    end
         
     | 
| 
       38 
     | 
    
         
            -
                    builder
         
     | 
| 
       39 
     | 
    
         
            -
                  end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
12 
     | 
    
         
             
                end
         
     | 
| 
       42 
13 
     | 
    
         
             
              end
         
     | 
| 
       43 
14 
     | 
    
         
             
            end
         
     |