mspire 0.8.1 → 0.8.2
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/lib/mspire/cv/paramable.rb +25 -4
- data/lib/mspire/digester.rb +0 -16
- data/lib/mspire/imzml/writer.rb +1 -1
- data/lib/mspire/mzml/activation.rb +4 -0
- data/lib/mspire/mzml/chromatogram.rb +7 -3
- data/lib/mspire/mzml/component.rb +3 -1
- data/lib/mspire/mzml/data_array.rb +77 -87
- data/lib/mspire/mzml/data_array_container_like.rb +3 -8
- data/lib/mspire/mzml/isolation_window.rb +4 -0
- data/lib/mspire/mzml/precursor.rb +1 -1
- data/lib/mspire/mzml/reader.rb +3 -0
- data/lib/mspire/mzml/scan_window.rb +7 -0
- data/lib/mspire/mzml/selected_ion.rb +4 -0
- data/lib/mspire/mzml/spectrum.rb +18 -3
- data/lib/mspire/mzml.rb +2 -0
- data/lib/mspire/user_param.rb +13 -0
- data/spec/mspire/imzml/writer_spec.rb +17 -21
- data/spec/mspire/mzml/data_array_spec.rb +0 -5
- data/spec/mspire/mzml_spec.rb +56 -13
- data/spec/spec_helper.rb +22 -0
- data/spec/testfiles/mspire/{mzml → imzml}/1_BB7_SIM_478.5.CHECK.ibd +0 -0
- data/spec/testfiles/mspire/{mzml → imzml}/1_BB7_SIM_478.5.CHECK.imzML +144 -432
- data/spec/testfiles/mspire/imzml/{continuous_binary_check.ibd → continuous_binary.CHECK.ibd} +0 -0
- data/spec/testfiles/mspire/imzml/{processed_binary_check.ibd → processed_binary.CHECK.ibd} +0 -0
- data/spec/testfiles/mspire/mzml/j24z.idx_comp.3.NORMALIZED.CHECK.mzML +257 -0
- data/spec/testfiles/mspire/mzml/j24z.idx_comp.3.ROUNDTRIP.CHECK.mzML +257 -0
- data/spec/testfiles/mspire/mzml/{mspire_simulated.MSn.check.mzML → mspire_simulated.MSn.CHECK.mzML} +8 -6
- metadata +10 -8
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.8. | 
| 1 | 
            +
            0.8.2
         | 
    
        data/lib/mspire/cv/paramable.rb
    CHANGED
    
    | @@ -25,10 +25,9 @@ module Mspire | |
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| 27 27 | 
             
                  def params?
         | 
| 28 | 
            -
                     | 
| 29 | 
            -
                      ref_param_groups. | 
| 30 | 
            -
             | 
| 31 | 
            -
                    total_num_params > 0
         | 
| 28 | 
            +
                    cv_params.size > 0 || 
         | 
| 29 | 
            +
                      ref_param_groups.any? {|group| group.params.size > 0 } || 
         | 
| 30 | 
            +
                      user_params.size > 0
         | 
| 32 31 | 
             
                  end
         | 
| 33 32 |  | 
| 34 33 | 
             
                  def each_accessionable_param(&block)
         | 
| @@ -42,6 +41,25 @@ module Mspire | |
| 42 41 | 
             
                    cv_params + ref_param_groups.flat_map(&:params)
         | 
| 43 42 | 
             
                  end
         | 
| 44 43 |  | 
| 44 | 
            +
                  # yields each current param.  If the return value is not false or nil,
         | 
| 45 | 
            +
                  # it is deleted (i.e., any true value and it is deleted).  Then adds the
         | 
| 46 | 
            +
                  # given parameter or makes a new one by accession number.
         | 
| 47 | 
            +
                  def replace!(*describe_args, &block)
         | 
| 48 | 
            +
                    reject!(&block).describe!(*describe_args)
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  # returns self
         | 
| 52 | 
            +
                  def reject!(&block)
         | 
| 53 | 
            +
                    cv_params.reject!(&block)
         | 
| 54 | 
            +
                    ref_param_groups.each {|group| group.reject!(&block) }
         | 
| 55 | 
            +
                    user_params.reject!(&block)
         | 
| 56 | 
            +
                    self
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  def replace_many!(describe_many_arg, &block)
         | 
| 60 | 
            +
                    reject!(&block).describe_many!(describe_many_arg)
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
             | 
| 45 63 | 
             
                  #def params_by_name
         | 
| 46 64 | 
             
                  #  params.index_by &:name
         | 
| 47 65 | 
             
                  #end
         | 
| @@ -61,6 +79,9 @@ module Mspire | |
| 61 79 | 
             
                    end
         | 
| 62 80 | 
             
                  end
         | 
| 63 81 |  | 
| 82 | 
            +
                  # returns the value if the param exists with that accession.  Returns
         | 
| 83 | 
            +
                  # true if the param exists but has no value. returns false if no param
         | 
| 84 | 
            +
                  # with that accession.
         | 
| 64 85 | 
             
                  def fetch_by_accession(acc)
         | 
| 65 86 | 
             
                    param = accessionable_params.find {|v| v.accession == acc }
         | 
| 66 87 | 
             
                    if param
         | 
    
        data/lib/mspire/digester.rb
    CHANGED
    
    | @@ -219,22 +219,6 @@ module Mspire | |
| 219 219 | 
             
                  :trypsin => 'Trypsin 	C-Term	KR 	P 	no 	no',
         | 
| 220 220 | 
             
                  :v8_e_trypsin => 'V8-E+Trypsin 	C-Term 	EKRZ 	P 	no 	no',
         | 
| 221 221 | 
             
                  :v8_de_trypsin => 'V8-DE+Trypsin 	C-Term 	BDEKRZ 	P 	no 	no',
         | 
| 222 | 
            -
                  :arg_c => 'Arg-C 	C-Term 	R 	P 	 no 	 no',
         | 
| 223 | 
            -
                  :asp_n => 'Asp-N 	N-Term 	BD 	  	no 	no',
         | 
| 224 | 
            -
                  :asp_n_ambic => 'Asp-N_ambic 	N-Term 	DE 	  	no 	no',
         | 
| 225 | 
            -
                  :chymotrypsin => 'Chymotrypsin 	C-Term 	FLWY 	P 	no 	no',
         | 
| 226 | 
            -
                  :cnbr => 'CNBr 	C-Term 	M 	  	no 	no',
         | 
| 227 | 
            -
                  :lys_c => 'Lys-C 	C-Term 	K 	P 	no 	no',
         | 
| 228 | 
            -
                  :lys_c_p => 'Lys-C/P 	C-Term 	K 	  	no 	no',
         | 
| 229 | 
            -
                  :pepsin_a => 'PepsinA 	C-Term 	FL 	  	no 	no',
         | 
| 230 | 
            -
                  :tryp_cnbr => 'Tryp-CNBr 	C-Term 	KMR 	P 	no 	no',
         | 
| 231 | 
            -
                  :tryp_chymo => 'TrypChymo 	C-Term 	FKLRWY 	P 	no 	no',
         | 
| 232 | 
            -
                  :trypsin_p => 'Trypsin/P 	C-Term 	KR 	  	no 	no',
         | 
| 233 | 
            -
                  :v8_de => 'V8-DE 	C-Term 	BDEZ 	P 	no 	no',
         | 
| 234 | 
            -
                  :v8_e => 'V8-E 	C-Term 	EZ 	P 	no 	no',
         | 
| 235 | 
            -
                  :trypsin => 'Trypsin 	C-Term	KR 	P 	no 	no',
         | 
| 236 | 
            -
                  :v8_e_trypsin => 'V8-E+Trypsin 	C-Term 	EKRZ 	P 	no 	no',
         | 
| 237 | 
            -
                  :v8_de_trypsin => 'V8-DE+Trypsin 	C-Term 	BDEKRZ 	P 	no 	no',
         | 
| 238 222 | 
             
                }
         | 
| 239 223 |  | 
| 240 224 | 
             
                ENZYMES = MASCOT_ENZYME_CONFIG_STRINGS.inject(Hash.new) do |hash,(k,v)| 
         | 
    
        data/lib/mspire/imzml/writer.rb
    CHANGED
    
    | @@ -422,8 +422,8 @@ module Mspire::Imzml | |
| 422 422 |  | 
| 423 423 | 
             
                        data_arrays = %w(mz intensity).zip(pair).map do |type, data_array_info|
         | 
| 424 424 | 
             
                          rparmgroup = rparms_by_id[(type + "_array").to_sym]
         | 
| 425 | 
            +
                          # the type is defined in the refparams
         | 
| 425 426 | 
             
                          data_array = Mspire::Mzml::DataArray.new
         | 
| 426 | 
            -
                          data_array.type = type
         | 
| 427 427 | 
             
                          data_array.external = true
         | 
| 428 428 | 
             
                          data_array.describe_many! [rparmgroup, *%w(IMS:1000103 IMS:1000102 IMS:1000104).zip(data_array_info).map.to_a]
         | 
| 429 429 | 
             
                          data_array
         | 
| @@ -49,9 +49,13 @@ module Mspire | |
| 49 49 | 
             
                    data_arrays[1]
         | 
| 50 50 | 
             
                  end
         | 
| 51 51 |  | 
| 52 | 
            -
                  # see  | 
| 53 | 
            -
                  def to_xml(builder,  | 
| 54 | 
            -
                    atts = data_array_xml_atts | 
| 52 | 
            +
                  # see ChromatogramList for generating the entire list
         | 
| 53 | 
            +
                  def to_xml(builder, default_ids)
         | 
| 54 | 
            +
                    atts = data_array_xml_atts
         | 
| 55 | 
            +
                    if @data_processing && default_ids[:chromatogram_data_processing] != @data_processing.id 
         | 
| 56 | 
            +
                      atts[:dataProcessingRef] = @data_processing.id 
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
             | 
| 55 59 | 
             
                    builder.chromatogram(atts) do |chrom_n|
         | 
| 56 60 | 
             
                      super(chrom_n)
         | 
| 57 61 | 
             
                      @precursor.to_xml(chrom_n) if @precursor
         | 
| @@ -8,56 +8,43 @@ module Mspire | |
| 8 8 | 
             
            end
         | 
| 9 9 |  | 
| 10 10 |  | 
| 11 | 
            -
             | 
| 11 | 
            +
            # Mspire::Mzml::DataArray's are currently implemented as a standard Ruby
         | 
| 12 | 
            +
            # array.  Data may be input or output with less precision, but a standard data
         | 
| 13 | 
            +
            # array will be accessible from ruby as Float (float64).  Thus, the params
         | 
| 14 | 
            +
            # merely alter what will be output to xml, so, to alter what is written with
         | 
| 15 | 
            +
            # to_xml, change the params.  If no params are changed in the data array it
         | 
| 16 | 
            +
            # will be written with the same precision as it was read in with.
         | 
| 17 | 
            +
            class Mspire::Mzml::DataArray < Array 
         | 
| 12 18 | 
             
              alias_method :array_init, :initialize
         | 
| 13 19 | 
             
              include Mspire::CV::Paramable
         | 
| 14 20 |  | 
| 15 | 
            -
               | 
| 16 | 
            -
               | 
| 17 | 
            -
               | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                 | 
| 21 | 
            -
                 | 
| 22 | 
            -
                 | 
| 21 | 
            +
              DEFAULT_DTYPE_ACC = 'MS:1000523' # float64
         | 
| 22 | 
            +
              DEFAULT_COMPRESSION_ACC = 'MS:1000574'
         | 
| 23 | 
            +
              COMPRESSION_ACC = 'MS:1000574'
         | 
| 24 | 
            +
              NO_COMPRESSION_ACC = 'MS:1000576'
         | 
| 25 | 
            +
              ACC_TO_DTYPE = {
         | 
| 26 | 
            +
                'MS:1000523' => :float64,
         | 
| 27 | 
            +
                'MS:1000521' => :float32,
         | 
| 28 | 
            +
                #'MS:1000520' => :float16,  # <- not supported w/o other gems
         | 
| 29 | 
            +
                'MS:1000522' => :int64, # signed
         | 
| 30 | 
            +
                'MS:1000519' => :int32, # signed
         | 
| 23 31 | 
             
              }
         | 
| 24 | 
            -
               | 
| 25 | 
            -
                 | 
| 26 | 
            -
                 | 
| 32 | 
            +
              ACC_TO_UNPACK_CODE = {
         | 
| 33 | 
            +
                'MS:1000523' => 'E*',
         | 
| 34 | 
            +
                'MS:1000521' => 'e*',
         | 
| 35 | 
            +
                #'MS:1000520' => :float16,  # <- not supported w/o other gems
         | 
| 36 | 
            +
                'MS:1000522' => 'q<*',
         | 
| 37 | 
            +
                'MS:1000519' => 'l<*',
         | 
| 27 38 | 
             
              }
         | 
| 28 39 |  | 
| 40 | 
            +
              DTYPE_ACCS = ACC_TO_DTYPE.keys
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              # unless data type (see DTYPE_TO_ACC) or TYPE
         | 
| 29 43 | 
             
              def initialize(*args)
         | 
| 30 44 | 
             
                params_init # paramable
         | 
| 31 45 | 
             
                array_init(*args)
         | 
| 32 46 | 
             
              end
         | 
| 33 47 |  | 
| 34 | 
            -
              # takes :mz or :intensity and sets the proper param among cvParams.  Does not do
         | 
| 35 | 
            -
              # referenceableParamGroup resolution.
         | 
| 36 | 
            -
              def type=(symbol)
         | 
| 37 | 
            -
                new_cv_params = []
         | 
| 38 | 
            -
                already_present = false
         | 
| 39 | 
            -
                cvs = ['MS:1000514', 'MS:1000515']
         | 
| 40 | 
            -
                cvs.reverse! if symbol == :intensity
         | 
| 41 | 
            -
                (keep, remove) = cvs
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                @cv_params.each do |param|
         | 
| 44 | 
            -
                  new_cv_params << param unless param.accession == remove
         | 
| 45 | 
            -
                  (already_present = true) if (param.accession == keep)
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
                new_cv_params.push(Mspire::CV::Param[keep]) unless already_present
         | 
| 48 | 
            -
                @cv_params = new_cv_params
         | 
| 49 | 
            -
                symbol
         | 
| 50 | 
            -
              end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
              # :mz or :intensity (or nil if none found)
         | 
| 53 | 
            -
              def type
         | 
| 54 | 
            -
                each_accessionable_param do |param|
         | 
| 55 | 
            -
                  return :mz if (param.accession == 'MS:1000514')
         | 
| 56 | 
            -
                  return :intensity if (param.accession == 'MS:1000515')
         | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
                nil
         | 
| 59 | 
            -
              end
         | 
| 60 | 
            -
             | 
| 61 48 | 
             
              # (optional) the DataProcessing object associated with this DataArray
         | 
| 62 49 | 
             
              attr_accessor :data_processing
         | 
| 63 50 |  | 
| @@ -65,8 +52,19 @@ class Mspire::Mzml::DataArray < Array | |
| 65 52 | 
             
              # file for imzML files)
         | 
| 66 53 | 
             
              attr_accessor :external
         | 
| 67 54 |  | 
| 68 | 
            -
               | 
| 69 | 
            -
             | 
| 55 | 
            +
              # returns a DataArray object. Analogous to [] for creating an array.
         | 
| 56 | 
            +
              def self.[](*data)
         | 
| 57 | 
            +
                self.new(data)
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              # returns an array of DataArray objects based on the given arrays
         | 
| 61 | 
            +
              def self.from_arrays(arrays)
         | 
| 62 | 
            +
                arrays.map {|ar| self.new(ar) }
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                # returns an array of DataArray objects (2)
         | 
| 66 | 
            +
              def self.empty_data_arrays(num=2)
         | 
| 67 | 
            +
                Array.new(num) { self.new }
         | 
| 70 68 | 
             
              end
         | 
| 71 69 |  | 
| 72 70 | 
             
              def self.data_arrays_from_xml(xml, link)
         | 
| @@ -115,74 +113,66 @@ class Mspire::Mzml::DataArray < Array | |
| 115 113 | 
             
                da
         | 
| 116 114 | 
             
              end
         | 
| 117 115 |  | 
| 118 | 
            -
              #  | 
| 119 | 
            -
              #  | 
| 120 | 
            -
              #
         | 
| 121 | 
            -
               | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
                 | 
| 126 | 
            -
                   | 
| 127 | 
            -
                   | 
| 128 | 
            -
                     | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 116 | 
            +
              # creates a base64 binary string based on the objects params.  If no dtype
         | 
| 117 | 
            +
              # or compression are specified, then it will be set (i.e., params added to
         | 
| 118 | 
            +
              # the object).
         | 
| 119 | 
            +
              def to_binary
         | 
| 120 | 
            +
                # single pass over params for speed
         | 
| 121 | 
            +
                pack_code = nil
         | 
| 122 | 
            +
                compression = nil
         | 
| 123 | 
            +
                each_accessionable_param do |param|
         | 
| 124 | 
            +
                  acc = param.accession
         | 
| 125 | 
            +
                  if !pack_code && (code=ACC_TO_UNPACK_CODE[acc])
         | 
| 126 | 
            +
                    pack_code = code
         | 
| 127 | 
            +
                  end
         | 
| 128 | 
            +
                  if compression.nil?
         | 
| 129 | 
            +
                    compression = 
         | 
| 130 | 
            +
                      case acc
         | 
| 131 | 
            +
                      when COMPRESSION_ACC then true
         | 
| 132 | 
            +
                      when NO_COMPRESSION_ACC then false
         | 
| 133 | 
            +
                      end
         | 
| 134 | 
            +
                  end
         | 
| 135 | 
            +
                end
         | 
| 136 | 
            +
                # can speed these up:
         | 
| 137 | 
            +
                unless pack_code
         | 
| 138 | 
            +
                  describe! DEFAULT_DTYPE_ACC
         | 
| 139 | 
            +
                  pack_code = ACC_TO_UNPACK_CODE[DEFAULT_DTYPE_ACC]
         | 
| 140 | 
            +
                end
         | 
| 141 | 
            +
                if compression.nil?
         | 
| 142 | 
            +
                  describe! DEFAULT_COMPRESSION_ACC
         | 
| 143 | 
            +
                  compression = 
         | 
| 144 | 
            +
                    case DEFAULT_COMPRESSION_ACC
         | 
| 145 | 
            +
                    when COMPRESSION_ACC then true
         | 
| 146 | 
            +
                    when NO_COMPRESSION_ACC then false
         | 
| 132 147 | 
             
                    end
         | 
| 133 | 
            -
                  compression = accessions.include?('MS:1000576') ? false : true 
         | 
| 134 | 
            -
                else
         | 
| 135 | 
            -
                  dtype = args[0] || DEFAULT_DTYPE
         | 
| 136 | 
            -
                  compression = args[1] || DEFAULT_COMPRESSION
         | 
| 137 148 | 
             
                end
         | 
| 138 149 |  | 
| 139 | 
            -
                 | 
| 140 | 
            -
             | 
| 141 | 
            -
                  when :float64 ; 'E*'
         | 
| 142 | 
            -
                  when :float32 ; 'e*'
         | 
| 143 | 
            -
                  when :int64   ; 'q<*'
         | 
| 144 | 
            -
                  when :int32   ; 'l<*'
         | 
| 145 | 
            -
                  else ; raise "unsupported dtype: #{dtype}"
         | 
| 146 | 
            -
                  end
         | 
| 147 | 
            -
                # TODO: support faster pack method for NArray's in future
         | 
| 148 | 
            -
                string = array_ish.to_a.pack(pack_code) 
         | 
| 150 | 
            +
                # TODO: support faster pack method with nmatrix or narray
         | 
| 151 | 
            +
                string = self.pack(pack_code) 
         | 
| 149 152 | 
             
                string = Zlib::Deflate.deflate(string) if compression
         | 
| 150 153 | 
             
                Base64.strict_encode64(string)
         | 
| 151 154 | 
             
              end
         | 
| 152 155 |  | 
| 153 | 
            -
              #  | 
| 154 | 
            -
              def  | 
| 155 | 
            -
                self.class.to_binary(self, *args)
         | 
| 156 | 
            -
              end
         | 
| 157 | 
            -
             | 
| 158 | 
            -
              def to_xml(builder, dtype=DEFAULT_DTYPE, compression=DEFAULT_COMPRESSION)
         | 
| 156 | 
            +
              # will set the data type to DEFAULT_DTYPE and compression if n
         | 
| 157 | 
            +
              def to_xml(builder)
         | 
| 159 158 | 
             
                encoded_length = 
         | 
| 160 159 | 
             
                  if @external
         | 
| 161 160 | 
             
                    0
         | 
| 162 161 | 
             
                  else
         | 
| 163 | 
            -
                    base64 =  | 
| 162 | 
            +
                    base64 = to_binary
         | 
| 164 163 | 
             
                    base64.bytesize
         | 
| 165 164 | 
             
                  end
         | 
| 166 165 |  | 
| 167 166 | 
             
                builder.binaryDataArray(encodedLength: encoded_length) do |bda_n|
         | 
| 168 167 | 
             
                  super(bda_n)
         | 
| 169 | 
            -
                  unless self.external
         | 
| 170 | 
            -
                    # can significantly speed up the below 2 lines:
         | 
| 171 | 
            -
                    Mspire::CV::Param[ DTYPE_TO_ACC[dtype] ].to_xml(bda_n)
         | 
| 172 | 
            -
                    Mspire::CV::Param[ compression ? 'MS:1000574' : 'MS:1000576' ].to_xml(bda_n)
         | 
| 173 | 
            -
                    bda_n.binary(base64)
         | 
| 174 | 
            -
                  end
         | 
| 168 | 
            +
                  bda_n.binary(base64) unless self.external
         | 
| 175 169 | 
             
                end
         | 
| 176 170 | 
             
              end
         | 
| 177 171 |  | 
| 178 172 | 
             
              # takes an array of DataArray objects or other kinds of objects
         | 
| 179 173 | 
             
              def self.list_xml(arrays, builder)
         | 
| 180 174 | 
             
                builder.binaryDataArrayList(count: arrays.size) do |bdal_n|
         | 
| 181 | 
            -
                  arrays. | 
| 182 | 
            -
                    ar = 
         | 
| 183 | 
            -
                      if data_ar.is_a?(Mspire::Mzml::DataArray) then data_ar
         | 
| 184 | 
            -
                      else Mspire::Mzml::DataArray.new(data_ar) end
         | 
| 185 | 
            -
                    ar.type = typ unless ar.type
         | 
| 175 | 
            +
                  arrays.each do |ar|
         | 
| 186 176 | 
             
                    ar.to_xml(bdal_n)
         | 
| 187 177 | 
             
                  end
         | 
| 188 178 | 
             
                end
         | 
| @@ -38,14 +38,9 @@ module Mspire | |
| 38 38 | 
             
                    end
         | 
| 39 39 | 
             
                  end
         | 
| 40 40 |  | 
| 41 | 
            -
                  # returns a hash with id, index, defaultArrayLength | 
| 42 | 
            -
                   | 
| 43 | 
            -
             | 
| 44 | 
            -
                    atts = {id: @id, index: @index, defaultArrayLength: default_array_length}
         | 
| 45 | 
            -
                    if @data_processing && default_ids[:data_processing] != @data_processing.id 
         | 
| 46 | 
            -
                      atts[:dataProcessingRef] = @data_processing.id 
         | 
| 47 | 
            -
                    end
         | 
| 48 | 
            -
                    atts
         | 
| 41 | 
            +
                  # returns a hash with id, index, defaultArrayLength
         | 
| 42 | 
            +
                  def data_array_xml_atts
         | 
| 43 | 
            +
                    {index: @index, id: @id, defaultArrayLength: default_array_length}
         | 
| 49 44 | 
             
                  end
         | 
| 50 45 |  | 
| 51 46 | 
             
                end
         | 
| @@ -7,6 +7,7 @@ module Mspire | |
| 7 7 | 
             
              class Mzml
         | 
| 8 8 | 
             
                # The method of precursor ion selection and activation
         | 
| 9 9 | 
             
                class Precursor
         | 
| 10 | 
            +
                  extend Mspire::Mzml::List
         | 
| 10 11 |  | 
| 11 12 | 
             
                  # (optional) the id of the Spectrum object, whether internal or
         | 
| 12 13 | 
             
                  # externally derived.
         | 
| @@ -77,7 +78,6 @@ module Mspire | |
| 77 78 | 
             
                    end
         | 
| 78 79 | 
             
                  end
         | 
| 79 80 |  | 
| 80 | 
            -
                  extend(Mspire::Mzml::List)
         | 
| 81 81 |  | 
| 82 82 | 
             
                end
         | 
| 83 83 | 
             
              end
         | 
    
        data/lib/mspire/mzml/reader.rb
    CHANGED
    
    
| @@ -8,6 +8,13 @@ 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 | 
            +
                  extend Mspire::Mzml::List
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def to_xml(builder)
         | 
| 14 | 
            +
                    builder.scanWindow do |xml|
         | 
| 15 | 
            +
                      super(xml)
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 11 18 | 
             
                end
         | 
| 12 19 | 
             
              end
         | 
| 13 20 | 
             
            end
         | 
    
        data/lib/mspire/mzml/spectrum.rb
    CHANGED
    
    | @@ -155,8 +155,6 @@ module Mspire | |
| 155 155 | 
             
                      obj.data_arrays = Mspire::Mzml::DataArray.empty_data_arrays
         | 
| 156 156 | 
             
                    end
         | 
| 157 157 |  | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 158 | 
             
                    obj
         | 
| 161 159 | 
             
                  end
         | 
| 162 160 |  | 
| @@ -172,9 +170,25 @@ module Mspire | |
| 172 170 | 
             
                    yield(self) if block_given?
         | 
| 173 171 | 
             
                  end
         | 
| 174 172 |  | 
| 173 | 
            +
                  # sets the data_arrays from the given array objects.  Sets the type of
         | 
| 174 | 
            +
                  # the first array to be an m/z array, and the second to be an intensity
         | 
| 175 | 
            +
                  # array.
         | 
| 176 | 
            +
                  def self.from_arrays(id, arrays)
         | 
| 177 | 
            +
                    spec = self.new(id)
         | 
| 178 | 
            +
                    arrays.zip(['MS:1000514','MS:1000515']).each do |ar, acc|
         | 
| 179 | 
            +
                      dar = DataArray.new(ar).describe!(acc)
         | 
| 180 | 
            +
                    end
         | 
| 181 | 
            +
                    spec
         | 
| 182 | 
            +
                  end
         | 
| 183 | 
            +
             | 
| 175 184 | 
             
                  # see SpectrumList for generating the entire list
         | 
| 176 185 | 
             
                  def to_xml(builder, default_ids)
         | 
| 177 | 
            -
                     | 
| 186 | 
            +
                    io = builder.target!
         | 
| 187 | 
            +
             | 
| 188 | 
            +
                    atts = data_array_xml_atts
         | 
| 189 | 
            +
                    if @data_processing && default_ids[:spectrum_data_processing] != @data_processing.id 
         | 
| 190 | 
            +
                      atts[:dataProcessingRef] = @data_processing.id 
         | 
| 191 | 
            +
                    end
         | 
| 178 192 | 
             
                    atts[:sourceFileRef] = @source_file.id if @source_file
         | 
| 179 193 | 
             
                    atts[:spotID] = @spot_id if @spot_id
         | 
| 180 194 |  | 
| @@ -185,6 +199,7 @@ module Mspire | |
| 185 199 | 
             
                      Mspire::Mzml::Product.list_xml(@products, sp_n) if @products
         | 
| 186 200 | 
             
                      Mspire::Mzml::DataArray.list_xml(@data_arrays, sp_n) if @data_arrays
         | 
| 187 201 | 
             
                    end
         | 
| 202 | 
            +
                    builder
         | 
| 188 203 | 
             
                  end
         | 
| 189 204 |  | 
| 190 205 | 
             
                end
         | 
    
        data/lib/mspire/mzml.rb
    CHANGED
    
    | @@ -85,6 +85,7 @@ module Mspire | |
| 85 85 | 
             
                    :xmlns => "http://psi.hupo.org/ms/mzml",
         | 
| 86 86 | 
             
                    "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", 
         | 
| 87 87 | 
             
                    "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", 
         | 
| 88 | 
            +
                    "xsi:schemaLocation" => "http://psi.hupo.org/ms/mzml http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd"
         | 
| 88 89 | 
             
                  }
         | 
| 89 90 |  | 
| 90 91 | 
             
                  VERSION = '1.1.0'
         | 
| @@ -255,6 +256,7 @@ module Mspire | |
| 255 256 | 
             
                    io.string
         | 
| 256 257 | 
             
                  end
         | 
| 257 258 | 
             
                end
         | 
| 259 | 
            +
                alias_method :write, :to_xml
         | 
| 258 260 |  | 
| 259 261 | 
             
                class ScanNumbersNotUnique < Exception
         | 
| 260 262 | 
             
                end
         | 
    
        data/lib/mspire/user_param.rb
    CHANGED
    
    | @@ -25,5 +25,18 @@ module Mspire | |
| 25 25 | 
             
                  self.name, self.value, self.type = args
         | 
| 26 26 | 
             
                end
         | 
| 27 27 |  | 
| 28 | 
            +
                def to_xml(xml)
         | 
| 29 | 
            +
                  atts = { name: name, value: value, type: type }
         | 
| 30 | 
            +
                  if unit
         | 
| 31 | 
            +
                    atts.merge!( 
         | 
| 32 | 
            +
                                { :unitCvRef => unit.cv_ref, 
         | 
| 33 | 
            +
                                  :unitAccession => unit.accession,
         | 
| 34 | 
            +
                                  :unitName => unit.name } 
         | 
| 35 | 
            +
                               )
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                  xml.userParam(atts)
         | 
| 38 | 
            +
                  xml
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 28 41 | 
             
              end
         | 
| 29 42 | 
             
            end
         | 
| @@ -54,10 +54,10 @@ describe Mspire::Imzml::Writer do | |
| 54 54 | 
             
              end
         | 
| 55 55 |  | 
| 56 56 | 
             
              it 'writes :processed binary file with spectra and returns DataArrayInfo objects' do
         | 
| 57 | 
            -
                 | 
| 58 | 
            -
                write_to = TESTFILES + "/mspire/imzml/processed_binary.tmp.ibd"
         | 
| 57 | 
            +
                write_to = TESTFILES + "/mspire/imzml/processed_binary.ibd"
         | 
| 59 58 | 
             
                array = subject.write_binary(write_to, @spectra.each, @config.merge( {:data_structure => :processed} ))
         | 
| 60 | 
            -
                 | 
| 59 | 
            +
                file_check(write_to)
         | 
| 60 | 
            +
             | 
| 61 61 | 
             
                array.should be_an(Array)
         | 
| 62 62 | 
             
                length = 3
         | 
| 63 63 | 
             
                offsets = (16..76).step(12)
         | 
| @@ -71,14 +71,12 @@ describe Mspire::Imzml::Writer do | |
| 71 71 | 
             
                    obj.offset.should == offsets.next
         | 
| 72 72 | 
             
                  end
         | 
| 73 73 | 
             
                end
         | 
| 74 | 
            -
                File.unlink(write_to) if File.exist?(write_to)
         | 
| 75 74 | 
             
              end
         | 
| 76 75 |  | 
| 77 76 | 
             
              it 'writes :continuous binary file with spectra and returns DataArrayInfo objects' do
         | 
| 78 | 
            -
                 | 
| 79 | 
            -
                write_to = TESTFILES + "/mspire/imzml/continuous_binary.tmp.ibd"
         | 
| 77 | 
            +
                write_to = TESTFILES + "/mspire/imzml/continuous_binary.ibd"
         | 
| 80 78 | 
             
                array = subject.write_binary(write_to, @spectra.each, @config.merge( {:data_structure => :continuous} ))
         | 
| 81 | 
            -
                 | 
| 79 | 
            +
                file_check(write_to)
         | 
| 82 80 | 
             
                array.should be_an(Array)
         | 
| 83 81 |  | 
| 84 82 | 
             
                length = 3
         | 
| @@ -95,7 +93,6 @@ describe Mspire::Imzml::Writer do | |
| 95 93 | 
             
                  info_pair.first.offset.should == first_offset
         | 
| 96 94 | 
             
                  info_pair.last.offset.should == offsets.next
         | 
| 97 95 | 
             
                end
         | 
| 98 | 
            -
                File.unlink(write_to) if File.exist?(write_to)
         | 
| 99 96 | 
             
              end
         | 
| 100 97 |  | 
| 101 98 | 
             
              describe 'full conversion of a file' do
         | 
| @@ -105,25 +102,24 @@ describe Mspire::Imzml::Writer do | |
| 105 102 | 
             
                end
         | 
| 106 103 |  | 
| 107 104 | 
             
                # reads file and removes parts that change run to run
         | 
| 108 | 
            -
                def sanitize( | 
| 105 | 
            +
                def sanitize(string)
         | 
| 106 | 
            +
                  string = sanitize_mspire_version_xml(string)
         | 
| 109 107 | 
             
                  reject = ['xmlns="http://psi.hupo.org/ms/mzml', 'universally unique identifier', 'ibd SHA-1']
         | 
| 110 | 
            -
                   | 
| 108 | 
            +
                  string.split(/\r?\n/).reject do |line| 
         | 
| 111 109 | 
             
                    reject.any? {|fragment| line.include?(fragment) }
         | 
| 112 | 
            -
                  end.join
         | 
| 110 | 
            +
                  end.join("\n")
         | 
| 113 111 | 
             
                end
         | 
| 114 112 |  | 
| 115 113 | 
             
                it 'converts sim files' do
         | 
| 116 | 
            -
                   | 
| 117 | 
            -
                   | 
| 118 | 
            -
                  imzml_check = TESTFILES + "/mspire/mzml/1_BB7_SIM_478.5.CHECK.imzML"
         | 
| 119 | 
            -
                  ibd_check = TESTFILES + "/mspire/mzml/1_BB7_SIM_478.5.CHECK.ibd"
         | 
| 114 | 
            +
                  outbase = TESTFILES + "/mspire/imzml/1_BB7_SIM_478.5"
         | 
| 115 | 
            +
                  Mspire::Imzml::Writer::Commandline.run([@file, @file, "--max-dimensions-microns", "72x2", "--max-dimensions-pixels", "72x2", "--outfile", outbase])
         | 
| 120 116 | 
             
                  # really just frozen for now until I inspect it more critically
         | 
| 121 | 
            -
                   | 
| 122 | 
            -
             | 
| 123 | 
            -
                   | 
| 124 | 
            -
                   | 
| 125 | 
            -
             | 
| 126 | 
            -
                   | 
| 117 | 
            +
                  file_check( TESTFILES + "/mspire/imzml/1_BB7_SIM_478.5.imzML" ) do |st|
         | 
| 118 | 
            +
                    sanitize(st)
         | 
| 119 | 
            +
                  end
         | 
| 120 | 
            +
                  file_check( TESTFILES + "/mspire/imzml/1_BB7_SIM_478.5.ibd" ) do |st|
         | 
| 121 | 
            +
                    st.each_byte.map.to_a[20..-1]
         | 
| 122 | 
            +
                  end
         | 
| 127 123 | 
             
                end
         | 
| 128 124 | 
             
              end
         | 
| 129 125 |  | 
| @@ -35,11 +35,6 @@ describe Mspire::Mzml::DataArray do | |
| 35 35 | 
             
              describe 'an instantiated Mspire::Mzml::DataArray' do
         | 
| 36 36 | 
             
                subject { Mspire::Mzml::DataArray.new [1,2,3] }
         | 
| 37 37 |  | 
| 38 | 
            -
                it "can have a 'type'" do
         | 
| 39 | 
            -
                  subject.type = :mz
         | 
| 40 | 
            -
                  subject.type.should == :mz
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
             | 
| 43 38 | 
             
                it 'can be converted to a binary string' do
         | 
| 44 39 | 
             
                  string = subject.to_binary
         | 
| 45 40 | 
             
                  # frozen
         |