mspire 0.7.18 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- 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.rb
CHANGED
@@ -1,25 +1,12 @@
|
|
1
|
+
|
2
|
+
# TODO: trim down these require statements to only include upper level
|
1
3
|
require 'mspire'
|
2
4
|
require 'builder'
|
3
|
-
require '
|
4
|
-
|
5
|
-
require '
|
6
|
-
|
7
|
-
require 'mspire/mzml/spectrum'
|
8
|
-
require 'mspire/mzml/file_description'
|
9
|
-
require 'mspire/mzml/software'
|
10
|
-
require 'mspire/mzml/scan_list'
|
11
|
-
require 'mspire/mzml/selected_ion'
|
12
|
-
require 'mspire/mzml/scan'
|
5
|
+
require 'core_ext/enumerable'
|
6
|
+
|
7
|
+
require 'mspire/mzml/reader'
|
8
|
+
|
13
9
|
require 'mspire/mzml/scan_settings'
|
14
|
-
require 'mspire/mzml/processing_method'
|
15
|
-
require 'mspire/mzml/run'
|
16
|
-
require 'mspire/mzml/spectrum_list'
|
17
|
-
require 'mspire/mzml/chromatogram_list'
|
18
|
-
require 'mspire/mzml/instrument_configuration'
|
19
|
-
require 'mspire/mzml/data_processing'
|
20
|
-
require 'mspire/mzml/referenceable_param_group'
|
21
|
-
require 'mspire/mzml/cv'
|
22
|
-
require 'mspire/mzml/sample'
|
23
10
|
|
24
11
|
module Mspire
|
25
12
|
# Reading an mzml file:
|
@@ -42,7 +29,8 @@ module Mspire
|
|
42
29
|
#
|
43
30
|
# Writing an mzml file from scratch:
|
44
31
|
#
|
45
|
-
# spec1 = Mspire::Mzml::Spectrum.new('scan=1'
|
32
|
+
# spec1 = Mspire::Mzml::Spectrum.new('scan=1') do |spec|
|
33
|
+
# spec.describe_many! ['MS:1000127', ['MS:1000511', 1]]
|
46
34
|
# spec.data_arrays = [[1,2,3], [4,5,6]]
|
47
35
|
# spec.scan_list = Mspire::Mzml::ScanList.new do |sl|
|
48
36
|
# scan = Mspire::Mzml::Scan.new do |scan|
|
@@ -60,7 +48,8 @@ module Mspire
|
|
60
48
|
# fd.file_content = Mspire::Mzml::FileContent.new
|
61
49
|
# fd.source_files << Mspire::Mzml::SourceFile.new
|
62
50
|
# end
|
63
|
-
# default_instrument_config = Mspire::Mzml::InstrumentConfiguration.new("IC",[]
|
51
|
+
# default_instrument_config = Mspire::Mzml::InstrumentConfiguration.new("IC",[])
|
52
|
+
# default_instrument_config.describe! 'MS:1000031'
|
64
53
|
# mzml.instrument_configurations << default_instrument_config
|
65
54
|
# software = Mspire::Mzml::Software.new
|
66
55
|
# mzml.software_list << software
|
@@ -73,6 +62,23 @@ module Mspire
|
|
73
62
|
# end
|
74
63
|
# end
|
75
64
|
class Mzml
|
65
|
+
include Enumerable # each_spectrum
|
66
|
+
|
67
|
+
class << self
|
68
|
+
# read-only right now
|
69
|
+
def open(filename, &block)
|
70
|
+
File.open(filename) do |io|
|
71
|
+
block.call(self.new(io))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def foreach(filename, &block)
|
76
|
+
block or return enum_for(__method__, filename)
|
77
|
+
open(filename) do |mzml|
|
78
|
+
mzml.each(&block)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
76
82
|
|
77
83
|
module Default
|
78
84
|
NAMESPACE = {
|
@@ -128,15 +134,17 @@ module Mspire
|
|
128
134
|
# (required) an Mspire::Mzml::Run object
|
129
135
|
attr_accessor :run
|
130
136
|
|
131
|
-
|
132
|
-
NOBLANKS = ::Nokogiri::XML::ParseOptions::DEFAULT_XML | ::Nokogiri::XML::ParseOptions::NOBLANKS
|
133
|
-
end
|
134
|
-
include Enumerable
|
135
|
-
|
137
|
+
# the io object of the mzml file
|
136
138
|
attr_accessor :io
|
139
|
+
|
140
|
+
# Mspire::Mzml::IndexList object associated with the file (only expected when reading
|
141
|
+
# mzml files at the moment)
|
137
142
|
attr_accessor :index_list
|
143
|
+
|
144
|
+
# xml file encoding
|
138
145
|
attr_accessor :encoding
|
139
146
|
|
147
|
+
|
140
148
|
# arg must be an IO object for automatic index and header parsing to
|
141
149
|
# occur. If arg is a hash, then attributes are set. In addition (or
|
142
150
|
# alternatively) a block called that yields self to setup the object.
|
@@ -145,211 +153,65 @@ module Mspire
|
|
145
153
|
# which allows seeking. get_index_list is called to get or create the
|
146
154
|
# index list.
|
147
155
|
def initialize(arg=nil, &block)
|
148
|
-
%w(cvs software_list instrument_configurations data_processing_list).each {|guy| self.send( guy + '=', [] ) }
|
156
|
+
%w(cvs software_list instrument_configurations samples data_processing_list).each {|guy| self.send( guy + '=', [] ) }
|
149
157
|
|
150
158
|
case arg
|
151
159
|
when IO
|
152
|
-
|
153
|
-
begin
|
154
|
-
@encoding = @io.bookmark(true) {|io| io.readline.match(/encoding=["'](.*?)["']/)[1] }
|
155
|
-
rescue EOFError
|
156
|
-
raise RuntimeError, "no encoding present in XML! (Is this even an xml file?)"
|
157
|
-
end
|
158
|
-
@index_list = get_index_list
|
159
|
-
read_header!
|
160
|
+
set_from_xml_io!(arg)
|
160
161
|
when Hash
|
161
162
|
arg.each {|k,v| self.send("#{k}=", v) }
|
162
163
|
end
|
163
|
-
if block
|
164
|
-
block.call(self)
|
165
|
-
end
|
164
|
+
block.call(self) if block
|
166
165
|
end
|
167
166
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
loc = 0
|
172
|
-
string = ''
|
173
|
-
while chunk = @io.read(chunk_size)
|
174
|
-
string << chunk
|
175
|
-
start_looking = ((loc-20) < 0) ? 0 : (loc-20)
|
176
|
-
break if string[start_looking..-1] =~ /<(spectrum|chromatogram)/
|
177
|
-
loc += chunk_size
|
167
|
+
module Convenience
|
168
|
+
def each_chromatogram(&block)
|
169
|
+
@run.chromatogram_list.each(&block)
|
178
170
|
end
|
179
|
-
doc = Nokogiri::XML.parse(string, nil, @encoding, Parser::NOBLANKS)
|
180
|
-
mzml_n = doc.root
|
181
|
-
if mzml_n.name == 'indexedmzML'
|
182
|
-
mzml_n = mzml_n.child
|
183
|
-
end
|
184
|
-
cv_list_n = mzml_n.child
|
185
|
-
file_description_n = cv_list_n.next
|
186
|
-
self.cvs = cv_list_n.children.map do |cv_n|
|
187
|
-
Mspire::Mzml::CV.from_xml(cv_n)
|
188
|
-
end
|
189
|
-
self.file_description = Mspire::Mzml::FileDescription.from_xml(file_description_n)
|
190
|
-
next_n = file_description_n.next
|
191
|
-
loop do
|
192
|
-
case next_n.name
|
193
|
-
when 'referenceableParamGroupList'
|
194
|
-
# get a hash ready
|
195
|
-
when 'sampleList'
|
196
|
-
# set objects
|
197
|
-
when 'softwareList' # required
|
198
|
-
# set objects
|
199
|
-
when 'instrumentConfigurationList'
|
200
|
-
# set objects
|
201
|
-
when 'dataProcessingList'
|
202
|
-
# set objects
|
203
|
-
when 'run'
|
204
|
-
# get defaults ready
|
205
|
-
break
|
206
|
-
end
|
207
|
-
next_n = next_n.next
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
class << self
|
212
171
|
|
213
|
-
|
214
|
-
|
215
|
-
File.open(filename) do |io|
|
216
|
-
block.call(self.new(io))
|
217
|
-
end
|
172
|
+
def each_spectrum(&block)
|
173
|
+
@run.spectrum_list.each(&block)
|
218
174
|
end
|
219
175
|
|
220
|
-
|
221
|
-
block or return enum_for(__method__, filename)
|
222
|
-
open(filename) do |mzml|
|
223
|
-
mzml.each(&block)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
176
|
+
alias_method :each, :each_spectrum
|
227
177
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
regexp = %r{</#{name}>}
|
233
|
-
io.each_line do |line|
|
234
|
-
data << line
|
235
|
-
#unless (line.index('<binary') && line[-12..-1].include?('</binary>'))
|
236
|
-
break if regexp.match(line)
|
237
|
-
#end
|
178
|
+
# @param [Object] arg an index number (Integer) or id string (String)
|
179
|
+
# @return [Mspire::Mzml::Spectrum] a spectrum object
|
180
|
+
def spectrum(arg)
|
181
|
+
run.spectrum_list[arg]
|
238
182
|
end
|
239
|
-
|
240
|
-
end
|
183
|
+
alias_method :'[]', :spectrum
|
241
184
|
|
242
|
-
|
243
|
-
|
244
|
-
(
|
245
|
-
|
185
|
+
# @param [Object] arg an index number (Integer) or id string (String)
|
186
|
+
# @return [Mspire::Mzml::Chromatogram] a spectrum object
|
187
|
+
def chromatogram(arg)
|
188
|
+
run.chromatogram_list[arg]
|
246
189
|
end
|
247
|
-
#block_given? or return enum_for(__method__)
|
248
|
-
#(0...@index_list[:spectrum].size).each do |int|
|
249
|
-
# yield spectrum(int)
|
250
|
-
#end
|
251
|
-
end
|
252
190
|
|
253
|
-
|
254
|
-
|
255
|
-
@index_list[:spectrum].each do |start_byte|
|
256
|
-
block.call spectrum_node_from_start_byte(start_byte)
|
191
|
+
def num_chromatograms
|
192
|
+
run.chromatogram_list.size
|
257
193
|
end
|
258
|
-
end
|
259
|
-
|
260
|
-
alias_method :each, :each_spectrum
|
261
|
-
|
262
|
-
# returns the nokogiri xml node for the spectrum at that index
|
263
|
-
def spectrum_node(index)
|
264
|
-
spectrum_node_from_start_byte(@index_list[:spectrum][index])
|
265
|
-
end
|
266
194
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
doc.root
|
271
|
-
end
|
272
|
-
|
273
|
-
# @param [Object] arg an index number (Integer) or id string (String)
|
274
|
-
# @return [Mspire::Spectrum] a spectrum object
|
275
|
-
def spectrum(arg)
|
276
|
-
start_byte = index_list[0].start_byte(arg)
|
277
|
-
spec_n = spectrum_node_from_start_byte(start_byte)
|
278
|
-
Mspire::Mzml::Spectrum.from_xml(spec_n)
|
279
|
-
end
|
280
|
-
|
281
|
-
# returns the number of spectra
|
282
|
-
def size
|
283
|
-
@index_list[:spectrum].size
|
284
|
-
end
|
285
|
-
|
286
|
-
alias_method :'[]', :spectrum
|
287
|
-
|
288
|
-
# @param [Integer] scan_num the scan number
|
289
|
-
# @return [Mspire::Spectrum] a spectrum object, or nil if not found
|
290
|
-
# @raise [ScanNumbersNotUnique] if scan numbers are not unique
|
291
|
-
# @raise [ScanNumbersNotFound] if spectra exist but scan numbers were not
|
292
|
-
# found
|
293
|
-
def spectrum_from_scan_num(scan_num)
|
294
|
-
@scan_to_index ||= @index_list[0].create_scan_index
|
295
|
-
raise ScanNumbersNotUnique if @scan_to_index == false
|
296
|
-
raise ScanNumbersNotFound if @scan_to_index == nil
|
297
|
-
spectrum(@scan_to_index[scan_num])
|
298
|
-
end
|
299
|
-
|
300
|
-
# @return [Mspire::Mzml::IndexList] or nil if there is no indexList in the
|
301
|
-
# mzML
|
302
|
-
def read_index_list
|
303
|
-
if offset=Mspire::Mzml::Index.index_offset(@io)
|
304
|
-
@io.seek(offset)
|
305
|
-
xml = Nokogiri::XML.parse(@io.read, nil, @encoding, Parser::NOBLANKS)
|
306
|
-
index_list = xml.root
|
307
|
-
num_indices = index_list['count'].to_i
|
308
|
-
array = index_list.children.map do |index_n|
|
309
|
-
#index = Index.new(index_n['name'])
|
310
|
-
index = Index.new
|
311
|
-
index.name = index_n['name'].to_sym
|
312
|
-
ids = []
|
313
|
-
index_n.children.map do |offset_n|
|
314
|
-
index << offset_n.text.to_i
|
315
|
-
ids << offset_n['idRef']
|
316
|
-
end
|
317
|
-
index.ids = ids
|
318
|
-
index
|
319
|
-
end
|
320
|
-
IndexList.new(array)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
# Reads through and captures start bytes
|
324
|
-
# @return [Mspire::Mzml::IndexList]
|
325
|
-
def create_index_list
|
326
|
-
indices_hash = @io.bookmark(true) do |inner_io| # sets to beginning of file
|
327
|
-
indices = {:spectrum => {}, :chromatogram => {}}
|
328
|
-
byte_total = 0
|
329
|
-
@io.each do |line|
|
330
|
-
if md=%r{<(spectrum|chromatogram).*?id=['"](.*?)['"][ >]}.match(line)
|
331
|
-
indices[md[1].to_sym][md[2]] = byte_total + md.pre_match.bytesize
|
332
|
-
end
|
333
|
-
byte_total += line.bytesize
|
334
|
-
end
|
335
|
-
indices
|
195
|
+
# returns the number of spectra
|
196
|
+
def length
|
197
|
+
run.spectrum_list.size
|
336
198
|
end
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
199
|
+
alias_method :size, :length
|
200
|
+
|
201
|
+
# @param [Integer] scan_num the scan number
|
202
|
+
# @return [Mspire::Spectrum] a spectrum object, or nil if not found
|
203
|
+
# @raise [ScanNumbersNotUnique] if scan numbers are not unique
|
204
|
+
# @raise [ScanNumbersNotFound] if spectra exist but scan numbers were not
|
205
|
+
# found
|
206
|
+
def spectrum_from_scan_num(scan_num)
|
207
|
+
@scan_to_index ||= @index_list[0].create_scan_index
|
208
|
+
raise ScanNumbersNotUnique if @scan_to_index == false
|
209
|
+
raise ScanNumbersNotFound if @scan_to_index == nil
|
210
|
+
spectrum(@scan_to_index[scan_num])
|
343
211
|
end
|
344
|
-
IndexList.new(indices)
|
345
|
-
end
|
346
|
-
|
347
|
-
# reads or creates an index list
|
348
|
-
# @return [Array] an array of indices
|
349
|
-
def get_index_list
|
350
|
-
read_index_list || create_index_list
|
351
212
|
end
|
352
|
-
|
213
|
+
include Convenience
|
214
|
+
|
353
215
|
# Because mzml files are often very large, we try to avoid storing the
|
354
216
|
# entire object tree in memory before writing.
|
355
217
|
#
|
@@ -374,7 +236,7 @@ module Mspire
|
|
374
236
|
if @referenceable_param_groups
|
375
237
|
Mspire::Mzml::ReferenceableParamGroup.list_xml(@referenceable_param_groups, mzml_n)
|
376
238
|
end
|
377
|
-
if @samples
|
239
|
+
if @samples && @samples.size > 0
|
378
240
|
Mspire::Mzml::Sample.list_xml(@samples, mzml_n)
|
379
241
|
end
|
380
242
|
Mspire::Mzml::Software.list_xml(@software_list, mzml_n)
|
data/lib/mspire/plms1.rb
CHANGED
@@ -118,6 +118,9 @@ module Mspire
|
|
118
118
|
out.puts scan_numbers.join(' ')
|
119
119
|
out.puts times.join(' ')
|
120
120
|
spectra.each do |spectrum|
|
121
|
+
puts "HIAYDSFA DSF"
|
122
|
+
puts spectrum.class
|
123
|
+
p spectrum
|
121
124
|
out.puts spectrum.size
|
122
125
|
if spectrum.size > 0
|
123
126
|
out.puts spectrum.mzs.size
|
@@ -5,16 +5,16 @@ require 'mspire/cv/param'
|
|
5
5
|
require 'mspire/user_param'
|
6
6
|
require 'mspire/mzml/referenceable_param_group'
|
7
7
|
|
8
|
-
class
|
8
|
+
class ParamableObject
|
9
9
|
include Mspire::CV::Paramable
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'Mspire::CV::Paramable' do
|
13
13
|
|
14
14
|
subject do
|
15
|
-
paramable =
|
15
|
+
paramable = ParamableObject.new.describe_many!(['MS:1000007', ['MS:1000511', 2]])
|
16
16
|
paramable.user_params << Mspire::UserParam.new('hello', 477)
|
17
|
-
paramable.ref_param_groups << Mspire::Mzml::ReferenceableParamGroup.new('id1'
|
17
|
+
paramable.ref_param_groups << Mspire::Mzml::ReferenceableParamGroup.new('id1').describe!('MS:1000512', 'filter string')
|
18
18
|
paramable
|
19
19
|
end
|
20
20
|
|
@@ -1,16 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'mspire/mzml/parser'
|
5
|
+
|
3
6
|
require 'mspire/mzml/data_array'
|
4
7
|
|
5
8
|
describe Mspire::Mzml::DataArray do
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
let(:xml_node) do
|
11
|
+
string = %Q{<binaryDataArray encodedLength="1588">
|
12
|
+
<cvParam cvRef="MS" accession="MS:1000523" name="64-bit float" value=""/>
|
13
|
+
<cvParam cvRef="MS" accession="MS:1000574" name="zlib compression" value=""/>
|
14
|
+
<cvParam cvRef="MS" accession="MS:1000514" name="m/z array" value="" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
|
15
|
+
<binary>eJwt0X1MVXUcBvADykoZOi8wFYf9BBFypKi3WWByEi+VMgsFVhhyQtTkomTImyicuLfEq2WG4FvSaQoS2lYCMd7sUIGKtiZXfEnDg8jVFjnjxWkpaz6Pf332PN/v+Z6zeyVJEh0jKbIkSXK+vhpmO1Jh1Iw1TzQeVkO11QWl7si1cHsfNHIC1z1RtERDKX4tdVRD/d3I95EDkqEadhfqpsD1eD54XRq0VVLf01CyuZjHvWHF/r00KCruQG2kOh19XcIG3L2mQ/nBuo3ojWKoplcxL79Ne5Mz0P/QRiNGf4D3hcyB8r1lUNnqtgnvme8Npa12qLtKoNHZDkWzi33IMPfKPD7E3Xu+UIpJgKKjiDqO0IzRmXif1RsqicHQqJpLwy1QDc+GelAN952X2d8f5t4Vt82415AK9aZMqOzuokV/QmPhQyi1z8uCVfFZ/H4FapPyoZpUwZzYBfWp7tn8nXygUhgF5cjlzCPJUIrNhPr+Ss4P1ELNo43z25ehcLvJPPSA+5dMOdgfmA6ltMVQeK6C+p4szhfbOZ/dzv6kExov9nK/6DHnw/656P8wQ/W9OOYhO9SKK6DU3QrlOz305wdQnDfl4f6UWCjXpkDDkQ2VwJ30Qmkef8cjUPOr5/6FVs71PihKH/Hetpgt2Nv4DpR61kNxMwuq+xzQyKuC+ux67rd0Qrm3m/nXQT6/Y0w+bPCGan0wlKeZoXjlNc6fi2e2WqHinkMTHewt+6G28ig0QurYR7bx7oxuqP/9mHt7p27ld4ZRPQqKxhV0osLeP4f5JQdN2QflpEqoJTRD5e5vnBtXoX7jFt0+wHnJqG3YnxYBxeDrzLvSoD6cxTy+CMo5B6Cx6hh11bMfex8qBeMKcGdBBjQ8vqLuDVBp8ymEodOhPstCi9dAzWWjllIotxx9qhOKw8Pcf95bRX9wMjROT6VnotkrsVAvX80+0cpcl898yE6PHoSK+WtmUyWU5BNQ2/wX5wGDzBbvj/C/LfKDxpshUNTMpZ0LOZ+zBMpVb0N9cjLn31vZX93E57/Mg4qws6/4jHlPJffTjz/ta6m1kaY5oXTuCu84bvO5Fr8iPNf+ApQCFkFtYAnt2gCNgM2ciwqoVp7g/HAN+29+4Z3oDqg/ckLF6zr3dvfzzndjbfgeX18b/xd/KHlOt/F3ioBavIW++hZUYnNpYyH7VQ7moDK6oJx9TQPvhHTwPZ5OKBL6+Z7qIe6fGIGG6Vk7vmOMD1TGT4PymdlQk+ez94/jXslK9iYrVL3y2ScXQSPoCPOMRii2nKNev9PcPvr5AH151Me4U+wFjVA/qJUr1NMORdkxzsMaodRzFioFnZyvuMX+5DDUs82fYH7JAo24pVDrWkH/TYJir417X/xE559n730RykHX+Xx5L/PMfqhO8NuO9yWEQuOGGcqzopgvLoeaM5E5ycr5pONQUZvoqTbueXRC0X+Nd38cgvqpgGLk1FA60QyVwHDmJBvU/imGormX8zFTdkBTDJXioLY0EYr/UqHxjIseug/VuTEO7B22QmHOpk12eraJzmzfyXweShPm7UIeWQY1n2+hkhL3qfw/0zSmlA==</binary>
|
16
|
+
</binaryDataArray>}
|
17
|
+
Nokogiri::XML.parse(string, nil, 'utf-8', Mspire::Mzml::Parser::NOBLANKS).root
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can be created from base64 binary xml' do
|
21
|
+
d_ar = Mspire::Mzml::DataArray.from_xml(xml_node, {})
|
12
22
|
d_ar.is_a?(Array)
|
13
|
-
|
23
|
+
# these are just frozen
|
24
|
+
d_ar.size.should == 315
|
25
|
+
d_ar.first.round(3).should == 151.962
|
26
|
+
d_ar.last.round(3).should == 938.548
|
14
27
|
end
|
15
28
|
|
16
29
|
it "can be initialized like any ol' array" do
|
@@ -6,7 +6,7 @@ require 'mspire/mzml/file_content'
|
|
6
6
|
describe Mspire::Mzml::FileContent do
|
7
7
|
|
8
8
|
it 'can be initialized with params' do
|
9
|
-
filecontent = Mspire::Mzml::FileContent.new(
|
9
|
+
filecontent = Mspire::Mzml::FileContent.new.describe_many!(['MS:1000579', ['IMS:1000080', "{9D501BDC-5344-4916-B7E9-7E795B02C856}"]])
|
10
10
|
|
11
11
|
desc = filecontent.params
|
12
12
|
desc.size.should == 2
|
@@ -18,9 +18,6 @@ describe Mspire::Mzml::FileContent do
|
|
18
18
|
xml.should match(regexp)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
it 'can be created from xml'
|
23
|
-
|
24
21
|
end
|
25
22
|
|
26
23
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'mspire/mzml'
|
4
|
-
require 'mspire/mzml/index_list'
|
3
|
+
require 'mspire/mzml' # require index and index_list
|
5
4
|
|
6
5
|
describe 'non-indexed uncompressed peaks, mzML file' do
|
7
6
|
subject { TESTFILES + "/mspire/mzml/openms.noidx_nocomp.12.mzML" }
|
@@ -26,12 +25,7 @@ describe 'non-indexed uncompressed peaks, mzML file' do
|
|
26
25
|
"scan=10935", "scan=10936", "scan=10937",
|
27
26
|
"scan=10938", "scan=10939", "scan=10940"
|
28
27
|
]
|
29
|
-
|
30
|
-
# there are no chromatograms... is that the right behavior???
|
31
|
-
chromatogram_idx = index_list[:chromatogram]
|
32
|
-
chromatogram_idx.name.should == :chromatogram
|
33
|
-
chromatogram_idx.should == []
|
34
|
-
chromatogram_idx.ids.should == []
|
28
|
+
index_list[:chromatogram].should == nil
|
35
29
|
end
|
36
30
|
end
|
37
31
|
end
|
@@ -52,7 +46,7 @@ describe 'indexed, compressed peaks, mzML file' do
|
|
52
46
|
correct_index_list = lambda do |index_list|
|
53
47
|
spectrum_idx = index_list[:spectrum]
|
54
48
|
spectrum_idx.name.should == :spectrum
|
55
|
-
spectrum_idx.should == [
|
49
|
+
spectrum_idx.should == [4397, 219666, 227894]
|
56
50
|
spectrum_idx.ids.should == [
|
57
51
|
"controllerType=0 controllerNumber=1 scan=1",
|
58
52
|
"controllerType=0 controllerNumber=1 scan=2",
|
@@ -60,7 +54,7 @@ describe 'indexed, compressed peaks, mzML file' do
|
|
60
54
|
]
|
61
55
|
chromatogram_idx = index_list[:chromatogram]
|
62
56
|
chromatogram_idx.name.should == :chromatogram
|
63
|
-
chromatogram_idx.should == [
|
57
|
+
chromatogram_idx.should == [239183]
|
64
58
|
chromatogram_idx.ids.should == ["TIC"]
|
65
59
|
end
|
66
60
|
|
@@ -71,8 +65,7 @@ describe 'indexed, compressed peaks, mzML file' do
|
|
71
65
|
end
|
72
66
|
|
73
67
|
it 'can create the index manually, if requested' do
|
74
|
-
|
75
|
-
index_list = mzml.create_index_list
|
68
|
+
index_list = Mspire::Mzml::IndexList.create_index_list(@io)
|
76
69
|
correct_index_list.call(index_list)
|
77
70
|
end
|
78
71
|
|
@@ -15,14 +15,13 @@ describe 'converting mzml to plms1' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can be converted into a plms1 object' do
|
18
|
-
scan_nums =
|
19
|
-
times =[6604.58, 6605.
|
18
|
+
scan_nums = [10929, 10931, 10933, 10935, 10937, 10939, 10940]
|
19
|
+
times =[ 6604.58, 6605.91, 6606.98, 6607.93, 6608.92, 6609.94, 6610.53]
|
20
20
|
plms1 = @mzml.to_plms1
|
21
21
|
plms1.spectra.respond_to?(:each).should be_true
|
22
22
|
plms1.times.should == times
|
23
23
|
plms1.scan_numbers.should == scan_nums
|
24
24
|
plms1.spectra.each do |spec|
|
25
|
-
spec.size.should == 2
|
26
25
|
spec.should be_a_kind_of(Mspire::SpectrumLike)
|
27
26
|
spec.mzs.should == []
|
28
27
|
spec.intensities.should == []
|
@@ -43,20 +42,17 @@ describe 'converting mzml to plms1' do
|
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'can be converted into a plms1 object' do
|
46
|
-
#scan_nums = ###
|
47
|
-
#times =[6604.58, 6605.5, 6605.91, 6606.48, 6606.98, 6607.53, 6607.93, 6608.49, 6608.92, 6609.49, 6609.94, 6610.53]
|
48
45
|
plms1 = @mzml.to_plms1
|
49
46
|
plms1.spectra.respond_to?(:each).should be_true
|
50
|
-
plms1.times.should == [1981.5726
|
51
|
-
plms1.scan_numbers.should == [1
|
52
|
-
sizes = [20168
|
47
|
+
plms1.times.should == [1981.5726]
|
48
|
+
plms1.scan_numbers.should == [1]
|
49
|
+
sizes = [20168]
|
53
50
|
plms1.spectra.zip(sizes).each do |spec,exp_size|
|
54
51
|
spec.should be_a_kind_of(Mspire::SpectrumLike)
|
55
52
|
spec.size.should == 2
|
56
53
|
spec.mzs.size.should == exp_size
|
57
54
|
spec.intensities.size.should == exp_size
|
58
55
|
end
|
59
|
-
#plms1.write("tmp.tmp.bin")
|
60
56
|
end
|
61
57
|
|
62
58
|
end
|
@@ -8,8 +8,8 @@ describe Mspire::Mzml::ReferenceableParamGroup do
|
|
8
8
|
it 'is created with an id and params' do
|
9
9
|
# the id is required for these objects
|
10
10
|
# no compression
|
11
|
-
rfgroup1 = Mspire::Mzml::ReferenceableParamGroup.new("mzArray"
|
12
|
-
rfgroup2 = Mspire::Mzml::ReferenceableParamGroup.new("intensityArray"
|
11
|
+
rfgroup1 = Mspire::Mzml::ReferenceableParamGroup.new("mzArray").describe_many!(['MS:1000576', 'MS:1000514'])
|
12
|
+
rfgroup2 = Mspire::Mzml::ReferenceableParamGroup.new("intensityArray").describe_many!(['MS:1000576', 'MS:1000515'])
|
13
13
|
|
14
14
|
b = Builder::XmlMarkup.new(:indent => 2)
|
15
15
|
z = Mspire::Mzml::ReferenceableParamGroup.list_xml([rfgroup1, rfgroup2], b)
|
@@ -20,7 +20,7 @@ describe Mspire::Mzml::ReferenceableParamGroup do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it '#to_xml gives a ReferenceableParamGroupRef' do
|
23
|
-
rfgroup1 = Mspire::Mzml::ReferenceableParamGroup.new("mzArray"
|
23
|
+
rfgroup1 = Mspire::Mzml::ReferenceableParamGroup.new("mzArray").describe_many!(['MS:1000576', 'MS:1000514'])
|
24
24
|
builder = Builder::XmlMarkup.new(:indent => 2)
|
25
25
|
rfgroup1.to_xml(builder)
|
26
26
|
xml = builder.to_xml
|
@@ -5,7 +5,7 @@ require 'builder'
|
|
5
5
|
|
6
6
|
describe 'making a SourceFile' do
|
7
7
|
it 'can be generated with params and a block' do
|
8
|
-
source_file = Mspire::Mzml::SourceFile.new("someFileID", "filename.mzML", "/home/jtprince/tmp"
|
8
|
+
source_file = Mspire::Mzml::SourceFile.new("someFileID", "filename.mzML", "/home/jtprince/tmp").describe!('MS:1000584')
|
9
9
|
|
10
10
|
params = source_file.params
|
11
11
|
params.size.should == 1
|
@@ -18,7 +18,6 @@ describe 'making a SourceFile' do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'can be created from xml'
|
22
21
|
end
|
23
22
|
|
24
23
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mspire/mzml/spectrum_list'
|
4
|
+
require 'builder'
|
5
|
+
|
6
|
+
class MockSpectrum
|
7
|
+
attr_accessor :index
|
8
|
+
attr_accessor :id
|
9
|
+
attr_accessor :source_file
|
10
|
+
attr_accessor :data_processing
|
11
|
+
def initialize(id)
|
12
|
+
@id = id
|
13
|
+
end
|
14
|
+
def to_xml(builder, default_ids)
|
15
|
+
builder.mockSpectrum {}
|
16
|
+
builder
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
MockObject = Struct.new(:id)
|
21
|
+
|
22
|
+
describe Mspire::Mzml::SpectrumList do
|
23
|
+
|
24
|
+
let :speclist do
|
25
|
+
Mspire::Mzml::SpectrumList.new(MockObject.new(:default_data_processing), [MockSpectrum.new('spec1')], { 'spec1' => 0 })
|
26
|
+
end
|
27
|
+
|
28
|
+
specify '#[Integer]' do
|
29
|
+
speclist[0].id.should == 'spec1'
|
30
|
+
end
|
31
|
+
|
32
|
+
specify '#[id]' do
|
33
|
+
speclist['spec1'].id.should == 'spec1'
|
34
|
+
end
|
35
|
+
|
36
|
+
specify '#create_id_to_index!' do
|
37
|
+
orig_index = speclist.id_to_index
|
38
|
+
speclist.create_id_to_index!
|
39
|
+
new_index = speclist.id_to_index
|
40
|
+
new_index.should == orig_index
|
41
|
+
new_index.equal?(orig_index).should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
specify '#to_xml' do
|
45
|
+
require 'stringio'
|
46
|
+
st = StringIO.new
|
47
|
+
builder = Builder::XmlMarkup.new(:target => st)
|
48
|
+
speclist.to_xml(builder, {})
|
49
|
+
st.string.should == "<spectrumList count=\"1\" defaultDataProcessingRef=\"default_data_processing\"><mockSpectrum></mockSpectrum></spectrumList>"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
@@ -16,8 +16,7 @@ describe Mspire::Mzml::Spectrum do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'gathers key data for ms1 spectrum' do
|
19
|
-
|
20
|
-
spec = Mspire::Mzml::Spectrum.from_xml(xml_node)
|
19
|
+
spec = @mzml.run.spectrum_list[0]
|
21
20
|
|
22
21
|
# convenient access to common attributes
|
23
22
|
spec.retention_time.should == 1981.5726
|
@@ -36,8 +35,7 @@ describe Mspire::Mzml::Spectrum do
|
|
36
35
|
end
|
37
36
|
|
38
37
|
it 'gathers key data for ms2 spectrum' do
|
39
|
-
|
40
|
-
spec = Mspire::Mzml::Spectrum.from_xml(xml_node)
|
38
|
+
spec = @mzml.run.spectrum_list[1]
|
41
39
|
|
42
40
|
# convenient access to common attributes
|
43
41
|
spec.retention_time.should == 1982.1077
|