mspire 0.8.7 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'mspire/mass/all'
3
+
4
+ describe Mspire::Mass::All do
5
+ it 'accesses elements by lower case and amino acids by upper case' do
6
+ {
7
+ 'c' => 12.0, # carbon
8
+ 'C' => 103.00918, # cysteine
9
+ 'br' => 78.9183361, # bromine
10
+ 'd' => 2.014101779, # deuterium
11
+ 'D' => 115.0269430, # aspartic acid
12
+ 'h+' => 1.00727646677, # proton
13
+ 'h' => 1.007825035, # hydrogen
14
+ 'h2o' => 18.0105647, # water
15
+ 'oh' => 17.002739665, # oh
16
+ 'e' => 0.0005486, # electron
17
+ }.each do |el, mass|
18
+ Mspire::Mass::All::MONO[el].should_not be_nil
19
+ Mspire::Mass::All::MONO[el].should == Mspire::Mass::All::MONO[el.to_sym]
20
+ Mspire::Mass::All::MONO[el].should be_within(0.00001).of(mass)
21
+ end
22
+
23
+ { h: 1.00794, he: 4.002602, ni: 58.6934, H: 137.13928 }.each do |el, mass|
24
+ Mspire::Mass::All::AVG[el].should_not be_nil
25
+ Mspire::Mass::All::AVG[el].should == Mspire::Mass::All::AVG[el.to_sym]
26
+ Mspire::Mass::All::AVG[el].should be_within(0.00001).of(mass)
27
+ end
28
+ end
29
+
30
+ it 'mono may be accessed directly' do
31
+ Mspire::Mass::All[:c].should == 12.0
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/mass/common'
4
+
5
+ describe Mspire::Mass::Common do
6
+ it 'provides string and symbol access to common mass spec masses' do
7
+ mono = Mspire::Mass::Common::MONO
8
+
9
+ mono['OH'].should be_within(0.0000001).of( 17.002739651629998 )
10
+ mono[:OH].should == mono['OH']
11
+ Mspire::Mass::Common[:OH].should == mono[:OH]
12
+
13
+ avg = Mspire::Mass::Common::AVG
14
+ avg['OH'].should == 17.00734
15
+ avg[:OH].should == avg['OH']
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/mass/element'
4
+
5
+ describe Mspire::Mass::Element do
6
+ it 'provides string and symbol access to element masses' do
7
+ mono = Mspire::Mass::Element::MONO
8
+
9
+ mono['Se'].should == 79.9165213
10
+ mono[:Se].should == mono['Se']
11
+ Mspire::Mass::Element[:Se].should == mono[:Se]
12
+
13
+ avg = Mspire::Mass::Element::AVG
14
+ avg['Se'].should == 78.96
15
+ avg[:Se].should == avg['Se']
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/mass/subatomic'
4
+
5
+ describe Mspire::Mass::Subatomic do
6
+ it 'provides string and symbol access to element masses' do
7
+ mono = Mspire::Mass::Subatomic::MONO
8
+
9
+ mono['neutron'].should == 1.0086649156
10
+ mono[:neutron].should == mono['neutron']
11
+ Mspire::Mass::Subatomic[:neutron].should == mono[:neutron]
12
+ end
13
+ end
@@ -2,41 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  require 'mspire/mass'
4
4
 
5
- describe 'Mspire::Mass' do
6
- it 'can access elemental masses by string or symbol' do
7
- {
8
- 'c' => 12.0, # +
9
- 'br' => 78.9183361, # +
10
- 'd' => 2.014101779, # +
11
- 'f' => 18.99840322, # +
12
- 'n' => 14.003074, # +
13
- 'o' => 15.99491463, # +
14
- 'na' => 22.9897677, # +
15
- 'p' => 30.973762, # +
16
- 's' => 31.9720707, # +
17
- 'li' => 7.016003, # +
18
- 'cl' => 34.96885272, # +
19
- 'k' => 38.9637074, # +
20
- 'si' => 27.9769265325,
21
- 'i' => 126.904473, # +
22
- 'h+' => 1.00727646677,
23
- 'h' => 1.007825035, # +
24
- 'h2o' => 18.0105647,
25
- 'oh' => 17.002739665,
26
- 'e' => 0.0005486,
27
- 'se' => 79.9165196
28
- }.each do |el, mass|
29
- Mspire::Mass::MONO[el].should_not be_nil
30
- Mspire::Mass::MONO[el].should == Mspire::Mass::MONO[el.to_sym]
31
- Mspire::Mass::MONO[el].should be_within(0.00001).of(mass)
32
- end
33
-
34
-
35
- { h: 1.00794, he: 4.002602, ni: 58.6934 }.each do |el, mass|
36
- Mspire::Mass::AVG[el].should_not be_nil
37
- Mspire::Mass::AVG[el].should == Mspire::Mass::AVG[el.to_sym]
38
- Mspire::Mass::AVG[el].should be_within(0.00001).of(mass)
39
- end
5
+ describe Mspire::Mass do
6
+ it 'calculates formula masses' do
7
+ Mspire::Mass.formula('CHCl3').should be_within(0.00001).of(117.91439)
8
+ end
40
9
 
10
+ it 'calculates peptide/protein (AA) masses' do
11
+ Mspire::Mass.aa('ADALL').should be_within(0.00001).of(501.27986)
41
12
  end
42
13
  end
@@ -8,34 +8,34 @@ describe Mspire::MolecularFormula do
8
8
  describe 'initialization' do
9
9
 
10
10
  it 'is initialized with Hash' do
11
- data = {h: 22, c: 12, n: 1, o: 3, s: 2}
11
+ data = {H: 22, C: 12, N: 1, O: 3, S: 2}
12
12
  mf = Mspire::MolecularFormula.new(data)
13
- mf.to_hash.should == {:h=>22, :c=>12, :n=>1, :o=>3, :s=>2}
13
+ mf.to_hash.should == {:H=>22, :C=>12, :N=>1, :O=>3, :S=>2}
14
14
  mf.to_hash.should == data
15
15
  end
16
16
 
17
17
  it 'can be initialized with charge, too' do
18
18
  mf = Mspire::MolecularFormula["H22BeC12N1O3S2Li2", 2]
19
- mf.to_hash.should == {:h=>22, :be=>1, :c=>12, :n=>1, :o=>3, :s=>2, :li=>2}
19
+ mf.to_hash.should == {:H=>22, :Be=>1, :C=>12, :N=>1, :O=>3, :S=>2, :Li=>2}
20
20
  mf.charge.should == 2
21
21
  end
22
22
 
23
23
  it 'from_string or ::[] to make from a capitalized string formula' do
24
- Mspire::MolecularFormula.from_string("H22BeC12N1O3S2Li2").to_hash.should == {:h=>22, :be=>1, :c=>12, :n=>1, :o=>3, :s=>2, :li=>2}
24
+ Mspire::MolecularFormula.from_string("H22BeC12N1O3S2Li2").to_hash.should == {:H=>22, :Be=>1, :C=>12, :N=>1, :O=>3, :S=>2, :Li=>2}
25
25
 
26
26
  mf = Mspire::MolecularFormula['Ni7Se3', 1]
27
27
  mf.charge.should == 1
28
- mf.to_hash.should == {:ni=>7, :se=>3}
28
+ mf.to_hash.should == {:Ni=>7, :Se=>3}
29
29
 
30
30
  # there is no such thing as the E element, so this is going to get the
31
31
  # user in trouble. However, this is the proper interpretation of the
32
32
  # formula.
33
- Mspire::MolecularFormula['Ni7SE3'].to_hash.should == {:ni=>7, :s=>1, :e=>3}
33
+ Mspire::MolecularFormula['Ni7SE3'].to_hash.should == {:Ni=>7, :S=>1, :E=>3}
34
34
  end
35
35
 
36
36
  describe 'correct to_s' do
37
37
  subject {
38
- Mspire::MolecularFormula.new({:c=>669, :h=>1129, :o=>185, :n=>215, :s=>4, :p=>0, :se=>0})
38
+ Mspire::MolecularFormula.new({:C=>669, :H=>1129, :O=>185, :N=>215, :S=>4, :P=>0, :Se=>0})
39
39
  }
40
40
  it 'to_s gives output' do
41
41
  subject.to_s.should == "C669H1129N215O185S4"
@@ -45,7 +45,7 @@ describe Mspire::MolecularFormula do
45
45
  describe 'conversion' do
46
46
 
47
47
  subject {
48
- data = {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
48
+ data = {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
49
49
  Mspire::MolecularFormula.new(data)
50
50
  }
51
51
 
@@ -54,13 +54,13 @@ describe Mspire::MolecularFormula do
54
54
  end
55
55
 
56
56
  it 'can be converted to a hash' do
57
- subject.to_hash.should == {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
57
+ subject.to_hash.should == {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
58
58
  end
59
59
  end
60
60
 
61
61
  describe 'equality' do
62
62
  subject {
63
- data = {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
63
+ data = {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
64
64
  Mspire::MolecularFormula.new(data)
65
65
  }
66
66
  it 'is only equal if the charge is equal' do
@@ -73,43 +73,43 @@ describe Mspire::MolecularFormula do
73
73
 
74
74
  describe 'arithmetic' do
75
75
  subject {
76
- data = {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
76
+ data = {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
77
77
  Mspire::MolecularFormula.new(data, 2)
78
78
  }
79
79
  it 'can do non-destructive arithmetic' do
80
80
  orig = subject.dup
81
81
  reply = subject + MF["H2C3P2", 2]
82
- reply.to_hash.should == {h: 24, c: 15, n: 1, o: 3, s: 2, be: 1, p: 2}
82
+ reply.to_hash.should == {H: 24, C: 15, N: 1, O: 3, S: 2, Be: 1, P: 2}
83
83
  reply.charge.should == 4
84
84
  subject.should == orig
85
85
 
86
86
  reply = subject - MF["H2C3P2", 2]
87
- reply.to_hash.should == {h: 20, c: 9, n: 1, o: 3, s: 2, be: 1, p: -2}
87
+ reply.to_hash.should == {H: 20, C: 9, N: 1, O: 3, S: 2, Be: 1, P: -2}
88
88
  reply.charge.should == 0
89
89
  subject.should == orig
90
90
 
91
91
  by2 = subject * 2
92
- by2.to_hash.should == {h: 44, c: 24, n: 2, o: 6, s: 4, be: 2}
92
+ by2.to_hash.should == {H: 44, C: 24, N: 2, O: 6, S: 4, Be: 2}
93
93
  by2.charge.should == 4
94
94
  subject.should == orig
95
95
 
96
96
  reply = by2 / 2
97
- reply.to_hash.should == {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
97
+ reply.to_hash.should == {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
98
98
  reply.charge.should == 2
99
99
  subject.should == orig
100
100
  end
101
101
 
102
102
  it 'can do destructive arithmetic' do
103
103
  orig = subject.dup
104
- subject.sub!(MF["H2C3"]).to_hash.should == {h: 20, c: 9, n: 1, o: 3, s: 2, be: 1}
104
+ subject.sub!(MF["H2C3"]).to_hash.should == {H: 20, C: 9, N: 1, O: 3, S: 2, Be: 1}
105
105
  subject.should_not == orig
106
- subject.add!(MF["H2C3"]).to_hash.should == {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
106
+ subject.add!(MF["H2C3"]).to_hash.should == {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
107
107
  subject.should == orig
108
108
 
109
109
  by2 = subject.mul!(2)
110
110
  subject.should_not == orig
111
- by2.to_hash.should == {h: 44, c: 24, n: 2, o: 6, s: 4, be: 2}
112
- by2.div!(2).to_hash.should == {h: 22, c: 12, n: 1, o: 3, s: 2, be: 1}
111
+ by2.to_hash.should == {H: 44, C: 24, N: 2, O: 6, S: 4, Be: 2}
112
+ by2.div!(2).to_hash.should == {H: 22, C: 12, N: 1, O: 3, S: 2, Be: 1}
113
113
  by2.to_hash.should == orig
114
114
  end
115
115
 
@@ -83,9 +83,8 @@ describe 'performing what is on the readme' do
83
83
  aa_to_mass = Mspire::Mass::AA::MONO # a hash with residue masses
84
84
  aa_to_mass['A'] # or access by symbol - Alanine
85
85
 
86
- # elements
87
- Mspire::Mass::MONO[:c] # carbon
88
- Mspire::Mass::MONO[:e] # electron (includes other useful symbols)
86
+ Mspire::Mass::Element::MONO[:C] # carbon
87
+ Mspire::Mass::Subatomic::MONO[:electron] # electron
89
88
  end
90
89
 
91
90
  specify 'isotopes and molecular formulas' do
@@ -95,7 +94,7 @@ describe 'performing what is on the readme' do
95
94
  isotopes = Mspire::Isotope::ISOTOPES # 288 isotopes
96
95
  hydrogen_isotopes = isotopes.select {|iso| iso.element == :h }
97
96
 
98
- c12 = Mspire::Isotope::BY_ELEMENT[:c].first
97
+ c12 = Mspire::Isotope::BY_ELEMENT[:C].first
99
98
  c12.atomic_number # also: mass_number atomic_mass relative_abundance average_mass
100
99
  c12.mono # => true (this is the monoisotopic isotope)
101
100
 
@@ -1,6 +1,3 @@
1
- #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- #$LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
1
  require 'simplecov'
5
2
  SimpleCov.start
6
3
 
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.8.7
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John T. Prince
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -272,6 +272,11 @@ files:
272
272
  - lib/mspire/mascot.rb
273
273
  - lib/mspire/mass.rb
274
274
  - lib/mspire/mass/aa.rb
275
+ - lib/mspire/mass/all.rb
276
+ - lib/mspire/mass/common.rb
277
+ - lib/mspire/mass/element.rb
278
+ - lib/mspire/mass/subatomic.rb
279
+ - lib/mspire/mass/util.rb
275
280
  - lib/mspire/molecular_formula.rb
276
281
  - lib/mspire/mzml.rb
277
282
  - lib/mspire/mzml/activation.rb
@@ -331,6 +336,7 @@ files:
331
336
  - lib/obo/unit.rb
332
337
  - lib/openany.rb
333
338
  - lib/write_file_or_string.rb
339
+ - mspire.gemspec
334
340
  - obo/ims.obo
335
341
  - obo/mod.obo
336
342
  - obo/ms.obo
@@ -365,6 +371,11 @@ files:
365
371
  - spec/mspire/isotope/aa_spec.rb
366
372
  - spec/mspire/isotope/distribution_spec.rb
367
373
  - spec/mspire/isotope_spec.rb
374
+ - spec/mspire/mass/aa_spec.rb
375
+ - spec/mspire/mass/all_spec.rb
376
+ - spec/mspire/mass/common_spec.rb
377
+ - spec/mspire/mass/element_spec.rb
378
+ - spec/mspire/mass/subatomic_spec.rb
368
379
  - spec/mspire/mass_spec.rb
369
380
  - spec/mspire/molecular_formula_spec.rb
370
381
  - spec/mspire/mzml/cv_spec.rb
@@ -466,6 +477,11 @@ test_files:
466
477
  - spec/mspire/isotope/aa_spec.rb
467
478
  - spec/mspire/isotope/distribution_spec.rb
468
479
  - spec/mspire/isotope_spec.rb
480
+ - spec/mspire/mass/aa_spec.rb
481
+ - spec/mspire/mass/all_spec.rb
482
+ - spec/mspire/mass/common_spec.rb
483
+ - spec/mspire/mass/element_spec.rb
484
+ - spec/mspire/mass/subatomic_spec.rb
469
485
  - spec/mspire/mass_spec.rb
470
486
  - spec/mspire/molecular_formula_spec.rb
471
487
  - spec/mspire/mzml/cv_spec.rb