mspire 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/mspire/isotope/distribution.rb +34 -24
- data/lib/mspire/version.rb +1 -1
- data/spec/mspire/isotope/distribution_spec.rb +28 -12
- metadata +35 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d16ef25df8a77a1eade1a626b95f7bf0f74e9c3
|
4
|
+
data.tar.gz: d0711a02fdf295ea0cd168a47ef256dafe3f6fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 500186266f05fb0fc4d151e005e5959631db99c3d9e08f0f1f4b752cca017238408798c8155150e4c6de4a23488ffc58c4c4a31482281a6363593b08d5b2de10
|
7
|
+
data.tar.gz: 5ca19c3e84c71cfe4b99d9f409f0d78a97eb6f7c61e3f20d51c57114c9403e37c1353be92843cc9ea6d802548f72c94d2559e6504fafdfe4fe1b9a008cb5ad76
|
data/.gitignore
CHANGED
@@ -17,11 +17,19 @@ end
|
|
17
17
|
module Mspire
|
18
18
|
class MolecularFormula < Hash
|
19
19
|
|
20
|
-
#
|
20
|
+
# Returns isotopic distribution beginning with the lightest possible peak.
|
21
|
+
# (for most molecules this will also be the monoisotopic peak)
|
21
22
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
23
|
+
# Two cutoff protocols may be specified, percent_cutoff or
|
24
|
+
# peak_cutoff. Normalization is performed *after* cutoff.
|
25
|
+
#
|
26
|
+
# percent_cutoff: cuts off when no more peaks contribute more than percent_cutoff
|
27
|
+
# to the total distribution.
|
28
|
+
# peak_cutoff: cuts off after that many peaks.
|
29
|
+
#
|
30
|
+
# prefer_lowest_index controls the behavior if both percent_cutoff and
|
31
|
+
# peak_cutoff are specified. If true, then the lowest index found between
|
32
|
+
# the two methods will be used, otherwise the highest index.
|
25
33
|
#
|
26
34
|
# all values will be fractional. normalize may be one of:
|
27
35
|
#
|
@@ -29,22 +37,24 @@ module Mspire
|
|
29
37
|
# :max normalize to the highest peak intensity
|
30
38
|
# :first normalize to the intensity of the first peak
|
31
39
|
# (this is typically the monoisotopic peak)
|
32
|
-
def isotope_distribution(normalize
|
33
|
-
mono_dist = raw_isotope_distribution(isotope_table)
|
40
|
+
def isotope_distribution(normalize: Mspire::Isotope::Distribution::NORMALIZE, peak_cutoff: nil, percent_cutoff: nil, prefer_lowest_index: true, isotope_table: Mspire::Isotope::BY_ELEMENT)
|
41
|
+
mono_dist = raw_isotope_distribution(isotope_table: isotope_table)
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
(mono_dist
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
cutoff_index = [
|
44
|
+
if percent_cutoff
|
45
|
+
total_signal = mono_dist.reduce(:+)
|
46
|
+
cutoff_index_less1 = (mono_dist.size-1).downto(0).find do |i|
|
47
|
+
# finds the index
|
48
|
+
(mono_dist[i] / total_signal) >= (percent_cutoff/100.0)
|
49
|
+
end
|
50
|
+
cutoff_index = cutoff_index_less1 ? (cutoff_index_less1 + 1) : 0
|
51
|
+
end,
|
52
|
+
peak_cutoff
|
53
|
+
].compact.send( prefer_lowest_index ? :min : :max ) || mono_dist.size
|
54
|
+
|
55
|
+
# mono_dist.size will result in nothing sliced off (i.e., for no cutoff)
|
56
|
+
|
57
|
+
mono_dist.slice!(cutoff_index..-1)
|
48
58
|
|
49
59
|
# normalization
|
50
60
|
norm_by =
|
@@ -83,7 +93,7 @@ module Mspire
|
|
83
93
|
|
84
94
|
# returns relative ratios from low nominal mass to high nominal mass.
|
85
95
|
# These are *not* normalized at all.
|
86
|
-
def raw_isotope_distribution(isotope_table
|
96
|
+
def raw_isotope_distribution(isotope_table: Mspire::Isotope::BY_ELEMENT)
|
87
97
|
low_nominal = 0
|
88
98
|
high_nominal = 0
|
89
99
|
self.each do |el,cnt|
|
@@ -112,14 +122,14 @@ module Mspire
|
|
112
122
|
obj.is_a?(Mspire::MolecularFormula) ? obj : Mspire::MolecularFormula.from_any(obj)
|
113
123
|
end
|
114
124
|
|
115
|
-
def calculate(molecular_formula_like,
|
125
|
+
def calculate(molecular_formula_like, *args)
|
116
126
|
mf = to_mf(molecular_formula_like)
|
117
|
-
mf.isotope_distribution(
|
127
|
+
mf.isotope_distribution(*args)
|
118
128
|
end
|
119
129
|
|
120
|
-
def spectrum(molecular_formula_like,
|
130
|
+
def spectrum(molecular_formula_like, *args)
|
121
131
|
mf = to_mf(molecular_formula_like)
|
122
|
-
mf.isotope_distribution_spectrum(
|
132
|
+
mf.isotope_distribution_spectrum(*args)
|
123
133
|
end
|
124
134
|
end
|
125
135
|
end
|
data/lib/mspire/version.rb
CHANGED
@@ -4,6 +4,12 @@ require 'mspire/isotope/distribution'
|
|
4
4
|
|
5
5
|
describe 'Mspire::Isotope::Distribution class methods' do
|
6
6
|
|
7
|
+
def similar_distributions(a_dist, b_dist)
|
8
|
+
b_dist.zip(a_dist) do |b,a|
|
9
|
+
expect(a).to be_within(1e-9).of b
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
before(:all) do
|
8
14
|
@nist = Mspire::Isotope::NIST::BY_ELEMENT
|
9
15
|
@norm = Mspire::Isotope::Distribution::NORMALIZE
|
@@ -19,47 +25,57 @@ describe 'Mspire::Isotope::Distribution class methods' do
|
|
19
25
|
|
20
26
|
describe 'normalizing isotope distributions' do
|
21
27
|
|
28
|
+
|
22
29
|
it 'defaults to normalizing by total signal with no cutoff' do
|
23
|
-
dist = Mspire::Isotope::Distribution.calculate( subject, @norm, @pcut, @nist )
|
24
|
-
dist.size.
|
25
|
-
dist[0,5]
|
30
|
+
dist = Mspire::Isotope::Distribution.calculate( subject, normalize: @norm, percent_cutoff: @pcut, isotope_table: @nist )
|
31
|
+
expect(dist.size).to eq(253)
|
32
|
+
similar_distributions dist[0,5], [0.31740518639058685, 0.35635707398291416, 0.20793431846543858, 0.08373257192958428, 0.026084566135229446]
|
26
33
|
end
|
27
34
|
|
28
35
|
it 'can normalize by first peak' do
|
29
|
-
dist = Mspire::Isotope::Distribution.calculate( subject, :first, @pcut, @nist )
|
36
|
+
dist = Mspire::Isotope::Distribution.calculate( subject, normalize: :first, percent_cutoff: @pcut, isotope_table: @nist )
|
30
37
|
dist.size.should == 253
|
31
38
|
dist[0].should == 1.0
|
32
39
|
dist[1].should_not == 1.0
|
33
40
|
end
|
34
41
|
|
35
42
|
it 'can normalize by the max peak' do
|
36
|
-
dist = Mspire::Isotope::Distribution.calculate( subject, :max, @pcut, @nist )
|
43
|
+
dist = Mspire::Isotope::Distribution.calculate( subject, normalize: :max, percent_cutoff: @pcut, isotope_table: @nist )
|
37
44
|
dist.size.should == 253
|
38
45
|
dist[0].should_not == 1.0
|
39
46
|
dist[1].should == 1.0
|
40
47
|
end
|
41
48
|
|
42
49
|
it 'can cutoff based on percent of total signal' do
|
43
|
-
Mspire::Isotope::Distribution.calculate(subject, :max, 100, @nist).should == []
|
44
|
-
Mspire::Isotope::Distribution.calculate(subject, :max, 20, @nist)
|
45
|
-
Mspire::Isotope::Distribution.calculate(subject, :max, 5, @nist)
|
46
|
-
Mspire::Isotope::Distribution.calculate(subject, :max, 0.0001, @nist).size.should == 11
|
50
|
+
Mspire::Isotope::Distribution.calculate(subject, normalize: :max, percent_cutoff: 100, isotope_table: @nist).should == []
|
51
|
+
similar_distributions Mspire::Isotope::Distribution.calculate(subject, normalize: :max, percent_cutoff: 20, isotope_table: @nist), [0.8906942209481861, 1.0, 0.5834999040187656]
|
52
|
+
similar_distributions Mspire::Isotope::Distribution.calculate(subject, normalize: :max, percent_cutoff: 5, isotope_table: @nist), [0.8906942209481861, 1.0, 0.5834999040187656, 0.23496817670469172]
|
53
|
+
Mspire::Isotope::Distribution.calculate(subject, normalize: :max, percent_cutoff: 0.0001, isotope_table: @nist).size.should == 11
|
47
54
|
end
|
55
|
+
|
56
|
+
it 'can cutoff based on a given number of peaks' do
|
57
|
+
Mspire::Isotope::Distribution.calculate(subject, normalize: :max, peak_cutoff: 0, isotope_table: @nist).should == []
|
58
|
+
similar_distributions Mspire::Isotope::Distribution.calculate(subject, normalize: :total, peak_cutoff: 4, isotope_table: @nist), [0.3287710818944283, 0.3691177894299527, 0.2153801947039964, 0.08673093397162249]
|
59
|
+
expect(Mspire::Isotope::Distribution.calculate(subject, normalize: :max, peak_cutoff: 1, isotope_table: @nist)).to eql([1.0])
|
60
|
+
end
|
61
|
+
|
62
|
+
xspecify 'prefers the lowest of cutoffs' ## need to test
|
63
|
+
|
48
64
|
end
|
49
65
|
|
50
66
|
describe 'calculating an isotope distribution spectrum' do
|
51
67
|
|
52
68
|
it 'gives neutral masses if no charge' do
|
53
|
-
spec = Mspire::Isotope::Distribution.spectrum( subject, @norm, @pcut, @nist )
|
69
|
+
spec = Mspire::Isotope::Distribution.spectrum( subject, normalize: @norm, percent_cutoff: @pcut, isotope_table: @nist )
|
54
70
|
[:mzs, :intensities].each {|att| spec.send(att).size.should == 253 }
|
55
71
|
spec.mzs[0,5].should == [1584.8627231418, 1585.8713880574, 1586.8800529730001, 1587.8887178886002, 1588.8973828042003]
|
56
|
-
spec.intensities[0,5]
|
72
|
+
similar_distributions spec.intensities[0,5], [0.31740518639058685, 0.35635707398291416, 0.20793431846543858, 0.08373257192958428, 0.026084566135229446]
|
57
73
|
end
|
58
74
|
|
59
75
|
it 'gives proper m/z values if the molecule is charged' do
|
60
76
|
charged_molecule = Mspire::MolecularFormula.from_any( subject )
|
61
77
|
charged_molecule.charge = -3
|
62
|
-
spec = Mspire::Isotope::Distribution.spectrum( charged_molecule, @norm, @pcut, @nist )
|
78
|
+
spec = Mspire::Isotope::Distribution.spectrum( charged_molecule, normalize: @norm, percent_cutoff: @pcut, isotope_table: @nist )
|
63
79
|
[:mzs, :intensities].each {|att| spec.send(att).size.should == 253 }
|
64
80
|
spec.mzs[0,5].should == [-528.2881229806, -528.6243446191334, -528.9605662576668, -529.2967878962, -529.6330095347334]
|
65
81
|
end
|
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.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John T. Prince
|
@@ -9,202 +9,202 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 1.5.9
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.5.9
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bsearch
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 1.5.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 1.5.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: andand
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: 1.3.3
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 1.3.3
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: obo
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 0.1.3
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 0.1.3
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: builder
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ~>
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 3.2.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - ~>
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 3.2.0
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: bio
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ~>
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 1.4.3
|
91
91
|
type: :runtime
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - ~>
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 1.4.3
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: trollop
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - ~>
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: 2.0.0
|
105
105
|
type: :runtime
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - ~>
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: 2.0.0
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: bundler
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - ~>
|
116
|
+
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '1.3'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - ~>
|
123
|
+
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '1.3'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: rake
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- -
|
130
|
+
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- -
|
137
|
+
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: rspec
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- - ~>
|
144
|
+
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: 2.13.0
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
|
-
- - ~>
|
151
|
+
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: 2.13.0
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
name: rdoc
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- - ~>
|
158
|
+
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '3.12'
|
161
161
|
type: :development
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
|
-
- - ~>
|
165
|
+
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '3.12'
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: simplecov
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - ">="
|
173
173
|
- !ruby/object:Gem::Version
|
174
174
|
version: '0'
|
175
175
|
type: :development
|
176
176
|
prerelease: false
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- -
|
179
|
+
- - ">="
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
183
|
name: coveralls
|
184
184
|
requirement: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
|
-
- -
|
186
|
+
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '0'
|
189
189
|
type: :development
|
190
190
|
prerelease: false
|
191
191
|
version_requirements: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
|
-
- -
|
193
|
+
- - ">="
|
194
194
|
- !ruby/object:Gem::Version
|
195
195
|
version: '0'
|
196
196
|
- !ruby/object:Gem::Dependency
|
197
197
|
name: fftw3
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
|
-
- - ~>
|
200
|
+
- - "~>"
|
201
201
|
- !ruby/object:Gem::Version
|
202
202
|
version: '0.3'
|
203
203
|
type: :development
|
204
204
|
prerelease: false
|
205
205
|
version_requirements: !ruby/object:Gem::Requirement
|
206
206
|
requirements:
|
207
|
-
- - ~>
|
207
|
+
- - "~>"
|
208
208
|
- !ruby/object:Gem::Version
|
209
209
|
version: '0.3'
|
210
210
|
description: mass spectrometry proteomics, lipidomics, and tools, a rewrite of mspire,
|
@@ -216,8 +216,8 @@ executables:
|
|
216
216
|
extensions: []
|
217
217
|
extra_rdoc_files: []
|
218
218
|
files:
|
219
|
-
- .gitignore
|
220
|
-
- .travis.yml
|
219
|
+
- ".gitignore"
|
220
|
+
- ".travis.yml"
|
221
221
|
- Gemfile
|
222
222
|
- LICENSE
|
223
223
|
- README.md
|
@@ -450,17 +450,17 @@ require_paths:
|
|
450
450
|
- lib
|
451
451
|
required_ruby_version: !ruby/object:Gem::Requirement
|
452
452
|
requirements:
|
453
|
-
- -
|
453
|
+
- - ">="
|
454
454
|
- !ruby/object:Gem::Version
|
455
455
|
version: '0'
|
456
456
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
457
457
|
requirements:
|
458
|
-
- -
|
458
|
+
- - ">="
|
459
459
|
- !ruby/object:Gem::Version
|
460
460
|
version: '0'
|
461
461
|
requirements: []
|
462
462
|
rubyforge_project:
|
463
|
-
rubygems_version: 2.0
|
463
|
+
rubygems_version: 2.2.0
|
464
464
|
signing_key:
|
465
465
|
specification_version: 4
|
466
466
|
summary: mass spectrometry proteomics, lipidomics, and tools
|