mspire 0.7.12 → 0.7.13
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mspire.rb +1 -1
- data/lib/mspire/isotope/aa.rb +0 -5
- data/lib/mspire/molecular_formula.rb +2 -1
- data/lib/mspire/{peak_list.rb → peaklist.rb} +56 -21
- data/lib/mspire/spectrum_like.rb +22 -1
- data/lib/mspire/tagged_peak.rb +44 -0
- data/script/quant_compare_direct_injections.rb +14 -54
- data/spec/mspire/peak_list_spec.rb +42 -42
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.13
|
data/lib/mspire.rb
CHANGED
data/lib/mspire/isotope/aa.rb
CHANGED
@@ -2,9 +2,9 @@ require 'mspire/bin'
|
|
2
2
|
require 'mspire/peak'
|
3
3
|
|
4
4
|
module Mspire
|
5
|
-
# a collection of
|
5
|
+
# a collection of Peak objects. At a minimum, each peak should respond to
|
6
6
|
# :x and :y
|
7
|
-
class
|
7
|
+
class Peaklist < Array
|
8
8
|
|
9
9
|
def lo_x
|
10
10
|
self.first[0]
|
@@ -38,7 +38,7 @@ module Mspire
|
|
38
38
|
# class methods
|
39
39
|
class << self
|
40
40
|
|
41
|
-
# creates a new Mspire::
|
41
|
+
# creates a new Mspire::Peaklist and coerces each peak into an
|
42
42
|
# Mspire::Peak. If your peaks already behave like peaks you should use
|
43
43
|
# .new
|
44
44
|
def [](*peaks)
|
@@ -98,17 +98,17 @@ module Mspire
|
|
98
98
|
Mspire::Peak.new( [bin, bin.data.reduce(0.0) {|sum,peak| sum + peak.y }] )
|
99
99
|
end
|
100
100
|
|
101
|
-
pseudo_peaklist = Mspire::
|
101
|
+
pseudo_peaklist = Mspire::Peaklist.new(pseudo_peaks)
|
102
102
|
|
103
103
|
separate_peaklists = pseudo_peaklist.split(opts[:split])
|
104
104
|
|
105
105
|
normalize_factor = opts[:normalize] ? peaklists.size : 1
|
106
106
|
|
107
107
|
return_data = []
|
108
|
-
final_peaklist = Mspire::
|
108
|
+
final_peaklist = Mspire::Peaklist.new unless opts[:only_data]
|
109
109
|
|
110
110
|
separate_peaklists.each do |pseudo_peaklist|
|
111
|
-
data_peaklist = Mspire::
|
111
|
+
data_peaklist = Mspire::Peaklist.new
|
112
112
|
weight_x = 0.0
|
113
113
|
tot_intensity = pseudo_peaklist.inject(0.0) {|sum, bin_peak| sum + bin_peak.y }
|
114
114
|
#puts "TOT INTENSITY:"
|
@@ -144,7 +144,7 @@ module Mspire
|
|
144
144
|
[final_peaklist, return_data]
|
145
145
|
end
|
146
146
|
|
147
|
-
# returns a new
|
147
|
+
# returns a new peaklist which has been merged with the others.
|
148
148
|
# opts[:resolution]) and then segment according to monotonicity (sharing
|
149
149
|
# intensity between abutting points). The final m/z is the weighted
|
150
150
|
# averaged of all the m/z's in each peak. Valid opts (with default listed
|
@@ -157,6 +157,7 @@ module Mspire
|
|
157
157
|
# number of spectra
|
158
158
|
# :return_data => false returns a parallel array containing
|
159
159
|
# the peaks associated with each returned peak
|
160
|
+
# :only_data => false only returns the binned peaks
|
160
161
|
# :split => :zero|:greedy_y|:share see Mspire::Peak#split
|
161
162
|
# :centroided => true treat the data as centroided
|
162
163
|
#
|
@@ -186,8 +187,42 @@ module Mspire
|
|
186
187
|
peaklist
|
187
188
|
end
|
188
189
|
end
|
189
|
-
end # end class << self
|
190
190
|
|
191
|
+
# takes an array of peaklists, merges them together (like merge), then
|
192
|
+
# returns an array of doublets. Each doublet is an m/z and an array of
|
193
|
+
# values (parallel to input) of intensities]
|
194
|
+
#
|
195
|
+
# If you are already using tagged peak objects, then you should set
|
196
|
+
# have_tagged_peaks to false (default is true). The peaks will be
|
197
|
+
# deconvolved based on the sample_id in this case.
|
198
|
+
#
|
199
|
+
# :have_tagged_peaks => false|true
|
200
|
+
#
|
201
|
+
def merge_and_deconvolve(peaklists, opts={})
|
202
|
+
unless htp=opts.delete(:have_tagged_peaks)
|
203
|
+
peaklists.each_with_index do |peaklist,i|
|
204
|
+
peaklist.map! do |peak|
|
205
|
+
TaggedPeak.new(peak, i)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# make sure we get the data back out
|
211
|
+
opts[:return_data] = true
|
212
|
+
opts[:only_data] = false
|
213
|
+
|
214
|
+
sample_ids = peaklists.map {|pl| pl.first.sample_id }
|
215
|
+
peaks, data = merge(peaklists, opts)
|
216
|
+
data.zip(peaks).map do |bucket_of_peaks, meta_peak|
|
217
|
+
signal_by_sample_id = Hash.new {|h,k| h[k] = 0.0 }
|
218
|
+
bucket_of_peaks.each do |peak|
|
219
|
+
signal_by_sample_id[peak.sample_id] += peak.y
|
220
|
+
end
|
221
|
+
[meta_peak.x, sample_ids.map {|sample_id| signal_by_sample_id[sample_id] } ]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end # end class << self
|
191
226
|
|
192
227
|
# returns an array with the indices outlining each peak. The first index
|
193
228
|
# is the start of the peak, the last index is the last of the peak.
|
@@ -230,7 +265,7 @@ module Mspire
|
|
230
265
|
peak_inds
|
231
266
|
end
|
232
267
|
|
233
|
-
# returns an array of
|
268
|
+
# returns an array of Peaklist objects
|
234
269
|
def split_on_zeros(given_peak_boundaries=nil)
|
235
270
|
pk_bounds = given_peak_boundaries || peak_boundaries(0.0)
|
236
271
|
pk_bounds.map do |indices|
|
@@ -238,7 +273,7 @@ module Mspire
|
|
238
273
|
end
|
239
274
|
end
|
240
275
|
|
241
|
-
# returns an array of
|
276
|
+
# returns an array of Peaklist objects
|
242
277
|
# assumes that this is one connected list of peaks (i.e., no
|
243
278
|
# zeros/whitespace on the edges or internally)
|
244
279
|
#
|
@@ -255,31 +290,31 @@ module Mspire
|
|
255
290
|
else
|
256
291
|
peak_class = first.class
|
257
292
|
prev_lm_i = 0 # <- don't worry, will be set to bumped to zero
|
258
|
-
|
293
|
+
peaklists = [ self.class.new([self[0]]) ]
|
259
294
|
local_min_indices.each do |lm_i|
|
260
|
-
|
295
|
+
peaklists.last.push( *self[(prev_lm_i+1)..(lm_i-1)] )
|
261
296
|
case methd
|
262
297
|
when :greedy_y
|
263
298
|
if self[lm_i-1].y >= self[lm_i+1].y
|
264
|
-
|
265
|
-
|
299
|
+
peaklists.last << self[lm_i]
|
300
|
+
peaklists << self.class.new
|
266
301
|
else
|
267
|
-
|
302
|
+
peaklists << self.class.new( [self[lm_i]] )
|
268
303
|
end
|
269
304
|
when :share
|
270
305
|
# for each local min, two new peaks will be created, with
|
271
|
-
# intensity shared between adjacent
|
306
|
+
# intensity shared between adjacent peaklists
|
272
307
|
lm = self[lm_i]
|
273
308
|
sum = self[lm_i-1].y + self[lm_i+1].y
|
274
309
|
# push onto the last peaklist its portion of the local min
|
275
|
-
|
310
|
+
peaklists.last << peak_class.new( [lm.x, lm.y * (self[lm_i-1].y.to_f/sum)] )
|
276
311
|
# create a new peaklist that contains its portion of the local min
|
277
|
-
|
312
|
+
peaklists << self.class.new( [peak_class.new([lm.x, lm.y * (self[lm_i+1].y.to_f/sum)])] )
|
278
313
|
end
|
279
314
|
prev_lm_i = lm_i
|
280
315
|
end
|
281
|
-
|
282
|
-
|
316
|
+
peaklists.last.push(*self[(prev_lm_i+1)...(self.size)] )
|
317
|
+
peaklists
|
283
318
|
end
|
284
319
|
end
|
285
320
|
|
@@ -310,7 +345,7 @@ module Mspire
|
|
310
345
|
if indices.size == 2
|
311
346
|
no_lm_pklsts << peak
|
312
347
|
else # have local minima
|
313
|
-
multipeak =
|
348
|
+
multipeak = Peaklist.new(peak)
|
314
349
|
local_min_inds = indices[1..-2].map {|i| i-indices.first}
|
315
350
|
peaklists = multipeak.split_contiguous(split_multipeaks_mthd, local_min_inds)
|
316
351
|
no_lm_pklsts.push *peaklists
|
data/lib/mspire/spectrum_like.rb
CHANGED
@@ -64,7 +64,9 @@ module Mspire
|
|
64
64
|
[@data_arrays[0][array_index], @data_arrays[1][array_index]]
|
65
65
|
end
|
66
66
|
|
67
|
-
# yields(mz, inten) across the spectrum, or array of doublets if no block
|
67
|
+
# yields(mz, inten) across the spectrum, or array of doublets if no block.
|
68
|
+
# Note that each peak is merely an array of m/z and intensity. For a
|
69
|
+
# genuine
|
68
70
|
def peaks(&block)
|
69
71
|
@data_arrays[0].zip(@data_arrays[1], &block)
|
70
72
|
end
|
@@ -72,6 +74,25 @@ module Mspire
|
|
72
74
|
alias_method :each, :peaks
|
73
75
|
alias_method :each_peak, :peaks
|
74
76
|
|
77
|
+
# returns a bonafide Peaklist object (i.e., each peak is cast as a
|
78
|
+
# Mspire::Peak object). If peak_id is defined, each peak will be cast
|
79
|
+
# as a TaggedPeak object with the given peak_id
|
80
|
+
def to_peaklist(peak_id=nil)
|
81
|
+
# realize this isn't dry, but it is in such an inner loop it needs to be
|
82
|
+
# as fast as possible.
|
83
|
+
pl = Peaklist.new
|
84
|
+
if peak_id
|
85
|
+
peaks.each_with_index do |peak,i|
|
86
|
+
pl[i] = Mspire::Peak.new( peak )
|
87
|
+
end
|
88
|
+
else
|
89
|
+
peaks.each_with_index do |peak,i|
|
90
|
+
pl[i] = Mspire::TaggedPeak.new( peak, peak_id )
|
91
|
+
end
|
92
|
+
end
|
93
|
+
pl
|
94
|
+
end
|
95
|
+
|
75
96
|
# if the mzs and intensities are the same then the spectra are considered
|
76
97
|
# equal
|
77
98
|
def ==(other)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
module Mspire
|
3
|
+
# A TaggedPeak has a sample_id attribute. In the rest of its interface it
|
4
|
+
# behaves like a normal Mspire::Peak. There are no forward compatible
|
5
|
+
# guarantees if you use the array interface, but currently the TaggedPeak is
|
6
|
+
# arranged internally like this:
|
7
|
+
#
|
8
|
+
# [x, sample_id, y]
|
9
|
+
#
|
10
|
+
# Note that the object is instantiated like this:
|
11
|
+
#
|
12
|
+
# TaggedPeak.new( [x,y], sample_id )
|
13
|
+
#
|
14
|
+
# x and y value access are very fast because they are merely aliases against
|
15
|
+
# first and last.
|
16
|
+
class TaggedPeak < Array
|
17
|
+
# the m/z or x value
|
18
|
+
alias_method :x, :first
|
19
|
+
# the intensity or y value
|
20
|
+
alias_method :y, :last
|
21
|
+
|
22
|
+
def x=(val)
|
23
|
+
self[0] = val
|
24
|
+
end
|
25
|
+
|
26
|
+
def y=(val)
|
27
|
+
self[2] = val
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(data, sample_id)
|
31
|
+
self[0] = data.first
|
32
|
+
self[1] = sample_id
|
33
|
+
self[2] = data.last
|
34
|
+
end
|
35
|
+
|
36
|
+
def sample_id
|
37
|
+
self[1]
|
38
|
+
end
|
39
|
+
|
40
|
+
def sample_id=(val)
|
41
|
+
self[1] = val
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'trollop'
|
4
4
|
require 'mspire/mzml'
|
5
|
-
require 'mspire/
|
5
|
+
require 'mspire/peaklist'
|
6
|
+
require 'mspire/tagged_peak'
|
6
7
|
require 'mspire/peak'
|
7
8
|
|
8
9
|
def putsv(*args)
|
@@ -48,34 +49,6 @@ if ARGV.size == 0
|
|
48
49
|
exit
|
49
50
|
end
|
50
51
|
|
51
|
-
class TracedPeak < Array
|
52
|
-
# the m/z or x value
|
53
|
-
alias_method :x, :first
|
54
|
-
# the intensity or y value
|
55
|
-
alias_method :y, :last
|
56
|
-
|
57
|
-
def x=(val)
|
58
|
-
self[0] = val
|
59
|
-
end
|
60
|
-
|
61
|
-
def y=(val)
|
62
|
-
self[2] = val
|
63
|
-
end
|
64
|
-
|
65
|
-
def initialize(data, sample_id)
|
66
|
-
self[0] = data.first
|
67
|
-
self[1] = sample_id
|
68
|
-
self[2] = data.last
|
69
|
-
end
|
70
|
-
|
71
|
-
def sample_id
|
72
|
-
self[1]
|
73
|
-
end
|
74
|
-
|
75
|
-
def sample_id=(val)
|
76
|
-
self[1] = val
|
77
|
-
end
|
78
|
-
end
|
79
52
|
|
80
53
|
files = ARGV.dup
|
81
54
|
|
@@ -85,52 +58,39 @@ if opts[:sample_ids]
|
|
85
58
|
basename_to_sample_id = YAML.load_file(opts[:sample_ids])
|
86
59
|
end
|
87
60
|
|
88
|
-
|
89
|
-
sample_ids = files.each_with_index.map do |filename,index|
|
61
|
+
sample_ids = files.map do |filename|
|
90
62
|
basename = filename.chomp(File.extname(filename))
|
91
|
-
|
63
|
+
basename_to_sample_id ? basename_to_sample_id[basename] : basename
|
64
|
+
end
|
65
|
+
|
66
|
+
peaklists = files.map do |filename|
|
92
67
|
putsv "processing: #{filename}"
|
68
|
+
bunch_of_peaks = []
|
93
69
|
Mspire::Mzml.open(filename) do |mzml|
|
94
70
|
mzml.each_with_index do |spec,i|
|
95
71
|
if spec.ms_level == 1
|
96
|
-
|
97
|
-
#p peaks.size
|
98
|
-
peaks.each do |peak|
|
99
|
-
tp = TracedPeak.new(peak, index)
|
100
|
-
peaklist << tp
|
101
|
-
end
|
72
|
+
bunch_of_peaks.push(*spec.peaks)
|
102
73
|
end
|
103
74
|
end
|
104
75
|
end
|
105
|
-
|
106
|
-
|
76
|
+
peaklist.sort_by!(&:x)
|
77
|
+
peaklist
|
107
78
|
end
|
108
79
|
|
109
|
-
putsv "gathered #{peaklist.size} peaks!"
|
110
|
-
|
111
|
-
putsv "sorting all peaks"
|
112
|
-
peaklist.sort!
|
113
|
-
|
114
80
|
putsv "merging peaks"
|
115
81
|
share_method = :greedy_y
|
116
82
|
#share_method = :share
|
117
83
|
|
118
|
-
|
119
|
-
peaks, data = Mspire::PeakList.merge([peaklist], opts.merge( {:split => share_method, :return_data => true} ))
|
84
|
+
ar_of_doublets = Mspire::PeakList.merge_and_deconvolve(peaklists, opts.merge( {:split => share_method, :return_data => true} ))
|
120
85
|
|
121
86
|
File.open(opts[:outfile],'w') do |out|
|
122
87
|
|
123
88
|
header = ["mzs", *sample_ids]
|
124
89
|
out.puts header.join("\t")
|
125
90
|
|
126
|
-
|
127
|
-
|
128
|
-
signal_by_sample_index = Hash.new {|h,k| h[k] = 0.0 }
|
129
|
-
bucket_of_peaks.each do |peak|
|
130
|
-
signal_by_sample_index[peak.sample_id] += peak.y
|
131
|
-
end
|
91
|
+
ar_of_doublets.each do |mz, ar_of_signals|
|
132
92
|
|
133
|
-
row = [opts[:mz_prefix] + (
|
93
|
+
row = [opts[:mz_prefix] + (mz + opts[:simple_calibrate]).round(opts[:round_mz]).to_s, *ar_of_signals.map {|signal| signal.round(opts[:round_intensity]) }]
|
134
94
|
out.puts row.join("\t")
|
135
95
|
end
|
136
96
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'mspire/
|
3
|
+
require 'mspire/peaklist'
|
4
4
|
require 'mspire/peak'
|
5
5
|
|
6
|
-
describe Mspire::
|
6
|
+
describe Mspire::Peaklist do
|
7
7
|
|
8
8
|
describe '#split' do
|
9
9
|
|
@@ -30,28 +30,28 @@ describe Mspire::PeakList do
|
|
30
30
|
|
31
31
|
it 'outlines peak boundaries' do
|
32
32
|
|
33
|
-
peaklist = Mspire::
|
33
|
+
peaklist = Mspire::Peaklist[[5.08, 3]]
|
34
34
|
boundaries = peaklist.peak_boundaries
|
35
35
|
boundaries.should == [[0,0]]
|
36
36
|
|
37
|
-
peaklist = Mspire::
|
37
|
+
peaklist = Mspire::Peaklist[[5.08, 3], [5.09, 8]]
|
38
38
|
boundaries = peaklist.peak_boundaries
|
39
39
|
boundaries.should == [[0,1]]
|
40
40
|
|
41
|
-
peaklist = Mspire::
|
41
|
+
peaklist = Mspire::Peaklist[*@peaks]
|
42
42
|
boundaries = peaklist.peak_boundaries
|
43
43
|
# 5 8 10 13 14 17 19 22 23 26 27
|
44
44
|
#act = [0, 3, 8, 9, 7, 2, 0, 0, 3, 8, 2, 9, 7, 1, 3, 0, 0, 10, 8, 2, 9, 7, 1, 3, 0, 0, 10, 8, 0]
|
45
45
|
boundaries.should == [[1, 5], [8, 10, 13, 14], [17, 19, 22, 23], [26, 27]]
|
46
46
|
|
47
47
|
# another case that was failing early on:
|
48
|
-
peaklist = Mspire::
|
48
|
+
peaklist = Mspire::Peaklist[[5.08, 3], [5.09, 8], [5.1, 2], [5.11, 9], [5.12, 7], [5.13, 1], [5.14, 3]]
|
49
49
|
boundaries = peaklist.peak_boundaries
|
50
50
|
boundaries.should == [[0,2,5,6]]
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'splits on zeros by default' do
|
54
|
-
peaklist = Mspire::
|
54
|
+
peaklist = Mspire::Peaklist[*@peaks] # <- maybe more like a collection of peaks, but Peaklist is flexible
|
55
55
|
split_peaklist = peaklist.split
|
56
56
|
split_peaklist.size.should == 4
|
57
57
|
split_peaklist.should == [
|
@@ -64,36 +64,36 @@ describe Mspire::PeakList do
|
|
64
64
|
|
65
65
|
# which it should since zeros are the ultimate local min!
|
66
66
|
it 'always cleans up surrounding zeros and does not split non-multipeaks' do
|
67
|
-
peak = Mspire::
|
67
|
+
peak = Mspire::Peaklist[*@peaks[0,7]] # simple
|
68
68
|
[:share, :greedy_y].each do |multipeak_split_method|
|
69
69
|
peaks = peak.split(multipeak_split_method)
|
70
|
-
peaks.first.should be_an_instance_of(Mspire::
|
70
|
+
peaks.first.should be_an_instance_of(Mspire::Peaklist)
|
71
71
|
peaks.first.to_a.should == [[50.01, 3], [50.02, 8], [50.03, 9], [50.04, 7], [50.05, 2]]
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe 'splitting a
|
75
|
+
describe 'splitting a peaklist that is a multipeak' do
|
76
76
|
subject do
|
77
|
-
Mspire::
|
77
|
+
Mspire::Peaklist[[50.07, 0], [50.08, 3], [50.09, 8], [50.1, 2], [50.11, 9], [50.12, 7], [50.13, 1], [50.14, 3], [50.15, 0]]
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'can split a multipeak' do
|
81
|
-
multipeak = Mspire::
|
81
|
+
multipeak = Mspire::Peaklist[[5.08, 3], [5.09, 8]]
|
82
82
|
peaklists = multipeak.split_contiguous(:greedy_y)
|
83
83
|
peaklists.should == [[5.08, 3], [5.09, 8]]
|
84
84
|
|
85
|
-
multipeak = Mspire::
|
85
|
+
multipeak = Mspire::Peaklist[[5.08, 3]]
|
86
86
|
peaklists = multipeak.split_contiguous(:greedy_y)
|
87
87
|
peaklists.should == [[5.08, 3]]
|
88
88
|
|
89
|
-
multipeak = Mspire::
|
89
|
+
multipeak = Mspire::Peaklist[[5.08, 3], [5.09, 8], [5.1, 2], [5.11, 9], [5.12, 7], [5.13, 1], [5.14, 3]]
|
90
90
|
peaklists = multipeak.split_contiguous(:greedy_y)
|
91
|
-
peaklists.all? {|pl| pl.should be_a(Mspire::
|
91
|
+
peaklists.all? {|pl| pl.should be_a(Mspire::Peaklist) }
|
92
92
|
peaklists.should == [[[5.08, 3], [5.09, 8]], [[5.1, 2], [5.11, 9], [5.12, 7], [5.13, 1]], [[5.14, 3]]]
|
93
93
|
|
94
|
-
multipeak = Mspire::
|
94
|
+
multipeak = Mspire::Peaklist[[5.08, 3], [5.09, 8], [5.1, 2], [5.11, 9], [5.12, 7], [5.13, 1], [5.14, 3]]
|
95
95
|
peaklists = multipeak.split_contiguous(:share)
|
96
|
-
peaklists.all? {|pl| pl.should be_a(Mspire::
|
96
|
+
peaklists.all? {|pl| pl.should be_a(Mspire::Peaklist) }
|
97
97
|
peaklists.should == [[[5.08, 3], [5.09, 8], [5.1, 2*(8.0/17)]], [[5.1, 2*(9.0/17)], [5.11, 9], [5.12, 7], [5.13, 7.0/10]], [[5.13, 3.0/10], [5.14, 3]]]
|
98
98
|
|
99
99
|
end
|
@@ -133,7 +133,7 @@ describe Mspire::PeakList do
|
|
133
133
|
# test a tie -> goes left!
|
134
134
|
peaks = @peaks[7,9]
|
135
135
|
peaks[2] = Mspire::Peak.new([peaks[2][0], 9])
|
136
|
-
multipeak2 = Mspire::
|
136
|
+
multipeak2 = Mspire::Peaklist[ *peaks ]
|
137
137
|
multipeak2.split(:greedy_y).should == answer
|
138
138
|
end
|
139
139
|
|
@@ -154,34 +154,34 @@ describe Mspire::PeakList do
|
|
154
154
|
list2 = [[9.11, 6], [10.49, 5], [10.71, 7], [13.48, 8]].map {|pair| Mspire::Peak.new pair }
|
155
155
|
list3 = [[9.09, 11], [10.51, 9], [10.72, 10], [13.51, 12]].map {|pair| Mspire::Peak.new pair }
|
156
156
|
|
157
|
-
[list1, list2, list3].map {|peaks| Mspire::
|
157
|
+
[list1, list2, list3].map {|peaks| Mspire::Peaklist.new( peaks ) }
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'whether we ask for data back or not, the peaklist is equal' do
|
161
|
-
(peaklist1, data) = Mspire::
|
162
|
-
peaklist2 = Mspire::
|
161
|
+
(peaklist1, data) = Mspire::Peaklist.merge(subject, :bin_width => 0.08, :bin_unit => :amu, :return_data => true, :split => false)
|
162
|
+
peaklist2 = Mspire::Peaklist.merge(subject, :bin_width => 0.08, :bin_unit => :amu, :split => :zero)
|
163
163
|
peaklist1.should == peaklist2
|
164
164
|
|
165
165
|
peaks = [[10.097333333333331, 10.502222222222223, 10.713809523809525, 11.498333333333333], [5.0, 6.0, 7.0, 8.0]].transpose
|
166
|
-
#compare_peaklist_sets(peaklist1, Mspire::
|
166
|
+
#compare_peaklist_sets(peaklist1, Mspire::Peaklist.new(peaks))
|
167
167
|
#compare_peaklist_sets(data, [[[10.1, 1], [10.11, 5], [10.09, 9]], [[10.5, 2], [10.49, 6], [10.51, 10]], [[10.7, 3], [10.71, 7], [10.72, 11]], [[11.5, 4], [11.48, 8], [11.51, 12]]] )
|
168
168
|
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'gives one peak with large bin width' do
|
172
172
|
[true, false].zip([26.0, 78.0]) do |normalize, inten|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
173
|
+
peaklist = Mspire::Peaklist.merge(subject, :bin_width => 2.5, :bin_unit => :amu, :normalize => normalize, :split => :greedy_y)
|
174
|
+
peaklist.size.should == 1
|
175
|
+
peaklist.first.x.should be_within(0.00000000001).of(11.136153846153846)
|
176
|
+
peaklist.first.y.should == inten
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'regardless of split method, the total intensity remains the same' do
|
181
181
|
(0.1..2.3).step(0.1).to_a.each do |bw|
|
182
182
|
tot_ints = [:zero, :split, :greedy_y].map do |splt|
|
183
|
-
|
184
|
-
|
183
|
+
peaklist = Mspire::Peaklist.merge(subject, :bin_width => bw, :bin_unit => :amu, :split => :zero)
|
184
|
+
peaklist.map(&:y).reduce(:+)
|
185
185
|
end
|
186
186
|
tot_ints.all? {|v| tot_ints.first == v }.should be_true
|
187
187
|
end
|
@@ -191,7 +191,7 @@ describe Mspire::PeakList do
|
|
191
191
|
before = Marshal.load(Marshal.dump(subject))
|
192
192
|
subj = Marshal.load(Marshal.dump(subject))
|
193
193
|
[:zero, :greedy_y].each do |split_mthd|
|
194
|
-
Mspire::
|
194
|
+
Mspire::Peaklist.merge(subj, :bin_width => 2.2, :bin_unit => :amu, :split => split_mthd, :return_data => true)
|
195
195
|
subj.should == before
|
196
196
|
end
|
197
197
|
end
|
@@ -201,9 +201,9 @@ describe Mspire::PeakList do
|
|
201
201
|
it "gives reasonable m/z values with very small binwidths (#{methd})" do
|
202
202
|
expected = [[9.09, 3.6666666666666665], [9.1, 0.6666666666666666], [9.11, 2.0], [10.49, 1.6666666666666667], [10.5, 0.3333333333333333], [10.51, 3.0], [10.7, 1.0], [10.71, 2.3333333333333335], [10.72, 3.3333333333333335], [13.48, 2.6666666666666665], [13.5, 1.3333333333333333], [13.51, 4.0]]
|
203
203
|
bw = 0.001
|
204
|
-
|
205
|
-
|
206
|
-
expected.zip(
|
204
|
+
peaklist = Mspire::Peaklist.merge(subject, :bin_width => bw, :bin_unit => :amu, :split => methd)
|
205
|
+
peaklist.size.should == expected.size
|
206
|
+
expected.zip(peaklist) do |exp, act|
|
207
207
|
act.first.should == exp.first
|
208
208
|
act.last.should be_within(0.00000000001).of(exp.last)
|
209
209
|
end
|
@@ -211,24 +211,24 @@ describe Mspire::PeakList do
|
|
211
211
|
|
212
212
|
it 'gives reasonable m/z values for large binwidths' do
|
213
213
|
bw = 2.2
|
214
|
-
|
215
|
-
(
|
216
|
-
(
|
214
|
+
peaklist = Mspire::Peaklist.merge(subject, :bin_width => bw, :bin_unit => :amu, :split => methd)
|
215
|
+
(peaklist.last.x > 13.51).should_not be_true
|
216
|
+
(peaklist.size > 2).should_not be_true
|
217
217
|
end
|
218
218
|
|
219
219
|
it 'gives same total intensity' do
|
220
220
|
bw = 0.8
|
221
221
|
total_intensity = subject.inject(0.0) {|sum,peaklist| sum + peaklist.map(&:y).reduce(:+) }
|
222
|
-
|
223
|
-
after =
|
222
|
+
peaklist, data = Mspire::Peaklist.merge(subject, :bin_width => bw, :bin_unit => :amu, :split => methd, :normalize => false, :return_data => true)
|
223
|
+
after = peaklist.inject(0.0) {|sum,peak| sum + peak.y }
|
224
224
|
after.should be_within(0.00000001).of(total_intensity)
|
225
225
|
end
|
226
226
|
|
227
227
|
it 'gives reasonable m/z values for medium-large binwidths' do
|
228
228
|
expected = [[10.086296296296297, 18.0], [13.498333333333333, 8.0]]
|
229
229
|
bw = 1.3
|
230
|
-
|
231
|
-
expected.zip(
|
230
|
+
peaklist = Mspire::Peaklist.merge(subject, :bin_width => bw, :bin_unit => :amu, :split => methd)
|
231
|
+
expected.zip(peaklist) do |exp, act|
|
232
232
|
|
233
233
|
act.first.should == exp.first
|
234
234
|
act.last.should be_within(0.00000000001).of(exp.last)
|
@@ -239,14 +239,14 @@ describe Mspire::PeakList do
|
|
239
239
|
|
240
240
|
|
241
241
|
=begin
|
242
|
-
data = Mspire::
|
242
|
+
data = Mspire::Peaklist.merge(subject, :bin_width => 1000, :bin_unit => :ppm, :only_data => true)
|
243
243
|
# just frozen, and checking for sanity, not checked for perfect, accuracy at this level:
|
244
244
|
data.should == [[[10.09, 9]], [[10.1, 1]], [[10.11, 5]], [[10.49, 6]], [[10.5, 2]], [[10.51, 10]], [[10.7, 3]], [[10.71, 7]], [[10.72, 11]], [[11.48, 8]], [[11.5, 4]], [[11.51, 12]]]
|
245
245
|
|
246
246
|
[[[10.1, 1], [10.09, 9], [10.11, 5]], [[10.49, 6], [10.5, 2]], [[10.5, 2], [10.51, 10]], [[10.7, 3], [10.71, 7], [10.72, 11]], [[11.48, 8], [11.5, 4]], [[11.5, 4], [11.51, 12]]]
|
247
|
-
#peaklist3 = Mspire::
|
247
|
+
#peaklist3 = Mspire::Peaklist.merge(subject, :bin_width => 100, :bin_unit => :ppm)
|
248
248
|
#p peaklist3
|
249
|
-
peaklist4 = Mspire::
|
249
|
+
peaklist4 = Mspire::Peaklist.merge(subject, :bin_width => 1000, :bin_unit => :ppm, :normalize => false)
|
250
250
|
peaklist4.should == [[10.097333333333331, 15.0], [10.49111111111111, 6.75], [10.508888888888887, 11.25], [10.713809523809525, 21.0], [11.483333333333334, 9.6], [11.508333333333331, 14.4]]
|
251
251
|
=end
|
252
252
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -282,13 +282,14 @@ files:
|
|
282
282
|
- lib/mspire/mzml/spectrum_list.rb
|
283
283
|
- lib/mspire/obo.rb
|
284
284
|
- lib/mspire/peak.rb
|
285
|
-
- lib/mspire/
|
285
|
+
- lib/mspire/peaklist.rb
|
286
286
|
- lib/mspire/plms1.rb
|
287
287
|
- lib/mspire/quant/qspec.rb
|
288
288
|
- lib/mspire/quant/qspec/protein_group_comparison.rb
|
289
289
|
- lib/mspire/spectrum.rb
|
290
290
|
- lib/mspire/spectrum/centroid.rb
|
291
291
|
- lib/mspire/spectrum_like.rb
|
292
|
+
- lib/mspire/tagged_peak.rb
|
292
293
|
- lib/mspire/user_param.rb
|
293
294
|
- lib/obo/ims.rb
|
294
295
|
- lib/obo/ms.rb
|