bahuvrihi-molecules 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,4 @@
1
1
  Copyright (c) 2006-2008, Regents of the University of Colorado.
2
- Developer:: Simon Chiang, Biomolecular Structure Program
3
- Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
4
  software and associated documentation files (the "Software"), to deal in the Software
data/README CHANGED
@@ -47,8 +47,8 @@ Molecules provides a mass calculator tap task. Tap[http://tap.rubyforge.org]
47
47
  is not required by molecules in general, but you get this bonus if you have tap
48
48
  installed:
49
49
 
50
- % tap -- molecules/calc ":RPPGFSPFR + H2O"
51
- I[15:34:30] 1077.57 Da :RPPGFSPFR + H2O
50
+ % tap run -- molecules/calc H2O
51
+ I[17:08:00] 18.0105646863 Da H2O
52
52
 
53
53
  == Known Issues
54
54
 
@@ -1,4 +1,5 @@
1
- require 'molecules/empirical_formula'
1
+ require 'tap/task'
2
+ require 'molecules/empirical_formula'
2
3
  require 'molecules/libraries/polypeptide'
3
4
 
4
5
  # patch for ruby units
@@ -7,29 +8,37 @@ class Unit < Numeric # :nodoc:
7
8
  UNIT_DEFINITIONS['<dalton>'] = [%w{Da Dalton Daltons dalton daltons}, 1/6.0221415e26, :mass, %w{<kilogram>}]
8
9
  end
9
10
  Unit.setup
10
-
11
- module Molecules
12
-
13
- # :startdoc::manifest a mass calculator
14
- #
15
- # Calculates the mass of a molecule. Compound formulae are allowed and you may
16
- # specify a list of formulae. The options can be used to alter the output (precision,
17
- # mass calculation method etc.)
18
- #
19
- # % tap run -- molecules/calc H2O
20
- # I[17:08:00] 18.0105646863 Da H2O
11
+
12
+ module Molecules
13
+
14
+ # :startdoc::task a mass calculator
15
+ #
16
+ # Calculates the mass of a molecule or formula. The options can be used to
17
+ # alter the output (precision, mass calculation method etc.)
18
+ #
19
+ # % tap run -- molecules/calc H2O --: dump
20
+ # 18.0106 Da
21
+ #
22
+ # % tap run -- molecules/calc "NH3 + H2O" --precision 2 --: dump
23
+ # 35.04 Da
24
+ #
25
+ # Units can carry prefixes (ex 'mm', 'kg'). See {Ruby Units}[http://ruby-units.rubyforge.org/ruby-units/]
26
+ # for more information.
27
+ #
28
+ # % tap run -- molecules/calc H2O --units yg --precision 2 --: dump
29
+ # 29.91 yg
21
30
  #
22
- # % tap run -- molecules/calc H2O --units yg --precision 6
23
- # I[17:08:21] 29.907243 yg H2O
24
- #
25
- # % tap run -- molecules/calc 'C3H5NO + H2O' C50H73N15O11 -p 2
26
- # I[17:08:53] 89.05 Da C3H5NO + H2O
27
- # I[17:08:53] 1059.56 Da C50H73N15O11
28
- #
29
- class Calc < Tap::Task
30
-
31
- config :type, :monoisotopic # the mass type calculated
32
- config :precision, nil, :short => 'p' # the precision of the mass
31
+ # Note that Calc returns instances of Unit, which by default prints itself
32
+ # with a precison of 4. To view the full-precision value, inspect the scalar
33
+ # value of the result.
34
+ #
35
+ # % tap run -- molecules/calc H2O --: inspect -m scalar
36
+ # 18.0105646863
37
+ #
38
+ class Calc < Tap::Task
39
+
40
+ config :type, :monoisotopic # the mass type calculated
41
+ config :precision, nil, :short => 'p' # the precision of the mass
33
42
  config :units, "Da", :short => 'u', &c.string # the mass unit reported
34
43
  config :composition, false, :short => 'c', &c.flag # reports the composition, not the formula
35
44
 
@@ -40,27 +49,23 @@ module Molecules
40
49
  EmpiricalFormula.parse(formula)
41
50
  end
42
51
 
43
- # Returns an array of the calculated masses, in the correct unit.
44
- def process(*formulae)
45
- formulae.collect do |formula_str|
46
- mass = parse(formula_str).mass do |element|
47
- case type
48
- when :monoisotopic then element.mass
49
- when :average then element.std_atomic_weight.value
50
- else raise "unknown mass type: #{type}"
51
- end
52
+ # Returns an array of the calculated masses, in the correct unit.
53
+ def process(formula)
54
+ mass = parse(formula).mass do |element|
55
+ case type
56
+ when :monoisotopic then element.mass
57
+ when :average then element.std_atomic_weight.value
58
+ else raise "unknown mass type: #{type}"
52
59
  end
60
+ end
53
61
 
54
- mass = Unit.new(mass, "Da").convert_to(units)
55
- unless precision == nil
56
- mass = Unit.new( Utils.round(mass.scalar, precision), units)
57
- end
58
-
59
- log "#{mass.scalar} #{mass.units}", composition ? formula : formula_str
60
-
61
- mass
62
- end
62
+ mass = Unit.new(mass, "Da").convert_to(units)
63
+ unless precision == nil
64
+ mass = Unit.new( Utils.round(mass.scalar, precision), units)
65
+ end
66
+
67
+ mass
63
68
  end
64
-
65
- end
69
+
70
+ end
66
71
  end
@@ -299,7 +299,7 @@ module Molecules
299
299
  # - Masses are calculated such that mathematical operations
300
300
  # are performed on the return of the block.
301
301
  #
302
- def mass(&block)
302
+ def mass(&block) # :yields: element
303
303
  if block_given?
304
304
  mass = 0
305
305
  each {|e, n| mass = (yield(e) * n) + mass }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bahuvrihi-molecules
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2009-04-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: constants
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -21,6 +22,16 @@ dependencies:
21
22
  - !ruby/object:Gem::Version
22
23
  version: 0.1.0
23
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: tap
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.0
34
+ version:
24
35
  description:
25
36
  email: simon.a.chiang@gmail.com
26
37
  executables: []
@@ -31,9 +42,6 @@ extra_rdoc_files:
31
42
  - README
32
43
  - MIT-LICENSE
33
44
  files:
34
- - MIT-LICENSE
35
- - Rakefile
36
- - README
37
45
  - lib/molecules.rb
38
46
  - lib/molecules/calc.rb
39
47
  - lib/molecules/empirical_formula.rb
@@ -41,16 +49,8 @@ files:
41
49
  - lib/molecules/libraries/residue.rb
42
50
  - lib/molecules/utils.rb
43
51
  - tap.yml
44
- - test/molecules/calc_test.rb
45
- - test/molecules/empirical_formula_class_test.rb
46
- - test/molecules/empirical_formula_test.rb
47
- - test/molecules/libraries/polypeptide_test.rb
48
- - test/molecules/libraries/residue_test.rb
49
- - test/molecules/utils_test.rb
50
- - test/molecules_test.rb
51
- - test/molecules_test_helper.rb
52
- - test/molecules_test_suite.rb
53
- - test/tap_test_helper.rb
52
+ - README
53
+ - MIT-LICENSE
54
54
  has_rdoc: true
55
55
  homepage: http://bioactive.rubyforge.org/molecules/
56
56
  post_install_message:
@@ -77,5 +77,5 @@ rubygems_version: 1.2.0
77
77
  signing_key:
78
78
  specification_version: 2
79
79
  summary: A library of molecules for scientific calculations in Ruby.
80
- test_files:
81
- - test/molecules_test_suite.rb
80
+ test_files: []
81
+
data/Rakefile DELETED
@@ -1,79 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
- require 'yaml'
6
-
7
- # tasks
8
- desc 'Default: Run tests.'
9
- task :default => :test
10
-
11
- desc 'Run tests.'
12
- Rake::TestTask.new(:test) do |t|
13
- t.libs << 'lib'
14
- t.pattern = File.join('test', ENV['subset'] || '', ENV['pattern'] || '**/*_test.rb')
15
- t.verbose = true
16
- t.warning = true
17
- end
18
-
19
- #
20
- # admin tasks
21
- #
22
-
23
- def gemspec
24
- data = File.read("molecules.gemspec")
25
- spec = nil
26
- Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
27
- spec
28
- end
29
-
30
- Rake::GemPackageTask.new(gemspec) do |pkg|
31
- pkg.need_tar = true
32
- end
33
-
34
- task :print_manifest do
35
- # collect files from the gemspec, labeling
36
- # with true or false corresponding to the
37
- # file existing or not
38
- files = gemspec.files.inject({}) do |files, file|
39
- files[File.expand_path(file)] = [File.exists?(file), file]
40
- files
41
- end
42
-
43
- # gather non-rdoc/pkg files for the project
44
- # and add to the files list if they are not
45
- # included already (marking by the absence
46
- # of a label)
47
- Dir.glob("**/*").each do |file|
48
- next if file =~ /^(rdoc|pkg)/ || File.directory?(file)
49
-
50
- path = File.expand_path(file)
51
- files[path] = ["", file] unless files.has_key?(path)
52
- end
53
-
54
- # sort and output the results
55
- files.values.sort_by {|exists, file| file }.each do |entry|
56
- puts "%-5s : %s" % entry
57
- end
58
- end
59
-
60
- desc 'Generate documentation.'
61
- Rake::RDocTask.new(:rdoc) do |rdoc|
62
- rdoc.rdoc_dir = 'rdoc'
63
- rdoc.title = "molecules"
64
- rdoc.options << '--line-numbers' << '--inline-source'
65
- rdoc.rdoc_files.include(["README", 'MIT-LICENSE'])
66
- rdoc.rdoc_files.include(gemspec.files.select {|file| file =~ /^lib/})
67
- end
68
-
69
- desc "Publish RDoc to RubyForge"
70
- task :publish_rdoc => [:rdoc] do
71
- config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
72
- host = "#{config["username"]}@rubyforge.org"
73
-
74
- rsync_args = "-v -c -r"
75
- remote_dir = "/var/www/gforge-projects/bioactive/molecules"
76
- local_dir = "rdoc"
77
-
78
- sh %{rsync #{rsync_args} #{local_dir}/ #{host}:#{remote_dir}}
79
- end
@@ -1,37 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../tap_test_helper.rb')
2
- require 'molecules/calc'
3
-
4
- class Molecules::CalcTest < Test::Unit::TestCase
5
- acts_as_tap_test
6
-
7
- attr_reader :t
8
-
9
- def setup
10
- super
11
- @t = Molecules::Calc.new
12
- end
13
-
14
- def test_mass_calculation
15
- t.enq("H2O")
16
- app.run
17
-
18
- assert_equal [[Unit.new(18.0105646863, "Da")]], app.results(t)
19
- end
20
-
21
- def test_mass_calculation_with_precision
22
- t.precision = 2
23
- t.enq("H2O", "NH3 + H2O")
24
- app.run
25
-
26
- assert_equal [[Unit.new(18.01, "Da"), Unit.new(35.04, "Da")]], app.results(t)
27
- end
28
-
29
- def test_mass_calculation_with_precision_and_unit_conversion
30
- t.units = "yg"
31
- t.precision = 3
32
- t.enq("H2O")
33
- app.run
34
-
35
- assert_equal [[Unit.new(29.907, "yg")]], app.results(t)
36
- end
37
- end
@@ -1,196 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../molecules_test_helper.rb'))
2
- require 'molecules/empirical_formula'
3
-
4
- class EmpiricalFormulaClassTest < Test::Unit::TestCase
5
- include Molecules
6
-
7
- #
8
- # parse_simple test
9
- #
10
-
11
- def test_parse_simple_documentation
12
- assert_equal "H(2)O", EmpiricalFormula.parse_simple("H(2)O").to_s
13
- assert_equal "H(2)O", EmpiricalFormula.parse_simple("H (2) O").to_s
14
- assert_equal "H(2)O", EmpiricalFormula.parse_simple("HO(-1)O(2)H").to_s
15
- end
16
-
17
- def test_parse_simple
18
- assert_equal([2,1], EmpiricalFormula.parse_simple("HO(-1)O(2)H").formula)
19
- assert_equal([2,1], EmpiricalFormula.parse_simple("H O (-1 )O( 2) H ").formula)
20
- end
21
-
22
- def test_parse_simple_fails_for_malformed_formulae
23
- [
24
- # numbers outside parenthesis
25
- "H2",
26
- # empty parenthesis
27
- "H()",
28
- # mismatched parenthesis
29
- "H(",
30
- ")H",
31
- # anything complex
32
- "H + O"
33
- ].each do |formula|
34
- assert_raise(EmpiricalFormula::ParseError) { EmpiricalFormula.parse_simple(formula) }
35
- end
36
- end
37
-
38
- #
39
- # test class parse
40
- #
41
-
42
- def test_parse_documentation
43
- assert_equal "H(2)O", EmpiricalFormula.parse("H2O").to_s
44
- assert_equal "C(52)H(106)", EmpiricalFormula.parse("CH3(CH2)50CH3").to_s
45
- assert_equal "C(2)H(4)N(2)", EmpiricalFormula.parse("C2H3NO - H2O + NH3").to_s
46
-
47
- block = lambda do |formula|
48
- case formula
49
- when /\[(.*)\]/
50
- factors = $1.split(/,/).collect {|i| i.strip.to_i }
51
- EmpiricalFormula.new(factors)
52
- else nil
53
- end
54
- end
55
-
56
- assert_equal "H(4)O(2)", EmpiricalFormula.parse("H2O + [2, 1]", &block).to_s
57
- assert_raise(EmpiricalFormula::ParseError) { EmpiricalFormula.parse("H2O + :not_expected", &block) }
58
- end
59
-
60
- def test_parse
61
- {
62
- nil => "",
63
- "" => "",
64
- "H" => "H",
65
- "HO" => "HO",
66
- "HFe" => "FeH",
67
- "FeH" => "FeH",
68
- "OH2" => "H(2)O",
69
- "H2O" => "H(2)O",
70
- "C6H12O4" => "C(6)H(12)O(4)",
71
- "Fe2OMg3" => "Fe(2)Mg(3)O",
72
- "(H)2" => "H(2)",
73
- "(OH)2" => "H(2)O(2)",
74
- "(HFe)" => "FeH",
75
- "(FeH)" => "FeH",
76
- "(OH2)2" => "H(4)O(2)",
77
- "(H2O)2" => "H(4)O(2)",
78
- "(C6H12O4)2" => "C(12)H(24)O(8)",
79
- "(Fe2OMg3)2" => "Fe(4)Mg(6)O(2)",
80
- "C6H12O4(C6H12O4)2C6H12O4" => "C(24)H(48)O(16)",
81
- "Fe2OMg3(Fe2OMg3(Fe2OMg3))Fe2OMg3" => "Fe(8)Mg(12)O(4)",
82
- "Fe2OMg3(Fe2OMg3)(Fe2OMg3)Fe2OMg3" => "Fe(8)Mg(12)O(4)",
83
- "Fe2OMg3(Fe2OMg3(Fe2OMg3)3((C)6H12O4)2)2C" => "C(25)Fe(18)H(48)Mg(27)O(25)",
84
- " (H2O) 10 0 " => "H(200)O(100)",
85
- "CH3(CH2)7CH" => "C(9)H(18)",
86
- "H3NCHCO2" => "C(2)H(4)NO(2)",
87
- "(CH3)2CuLi" => "C(2)CuH(6)Li",
88
-
89
- # multipart
90
- "-H" => "H(-1)",
91
- "H2O-H" => "HO",
92
- "H2O - (OH)2+ H2O2-H2O" => ""
93
- }.each_pair do |formula, composition_str|
94
- m = EmpiricalFormula.parse(formula)
95
- assert_equal composition_str, m.to_s, formula
96
- end
97
- end
98
-
99
- def test_parse_fails_for_malformed_formulae
100
- [
101
- # mismatched parenthesis
102
- "H)2",
103
- "(H2",
104
- "(O2(H2)",
105
- "(O)2H2)",
106
- # hanging factors
107
- "2C",
108
- #"(2)",
109
- "(2)2",
110
- "(2C)",
111
- "(2C)2",
112
- "C(2C)",
113
- # empty parenthesis
114
- "()",
115
- "()2"
116
- ].each do |formula|
117
- assert_raise(EmpiricalFormula::ParseError) { EmpiricalFormula.parse(formula) }
118
- end
119
- end
120
-
121
- #
122
- # class mass test
123
- #
124
-
125
- def break_test_class_mass_method
126
- water_mass = EmpiricalFormula::Element::H.mass * 2 + EmpiricalFormula::Element::O.mass
127
- assert_equal 18.010565, water_mass
128
-
129
- assert_equal 18.010565, EmpiricalFormula.mass("H2O")
130
- assert_equal 18.010565, EmpiricalFormula.mass("H + OH")
131
- assert_equal 18, EmpiricalFormula.mass("H2O", 0)
132
- end
133
-
134
- #
135
- # library molecules
136
- #
137
-
138
- def break_test_access_library_molecules
139
- water = EmpiricalFormula::H2O
140
-
141
- assert_equal water, EmpiricalFormula.lookup('h2o')
142
- assert_equal water, EmpiricalFormula.h2o
143
- assert_equal 18.010565, EmpiricalFormula.h2o.mass
144
- end
145
-
146
- # vs the VG Analytical Organic Mass Spectrometry reference, reference date unknown (prior to 2005)
147
- # the data from the data sheet was copied manually to doc/VG Analytical DataSheet.txt
148
- def test_molecule_mass_values_vs_vg_analytical
149
- str = %Q{
150
- NH2 16.01872 16.0226
151
- OH 17.00274 17.0073
152
- OCH3 31.01839 31.0342
153
- CH3CO 43.01839 43.0452}
154
-
155
- molecules = str.split(/\n/)
156
- molecules.each do |mol_str|
157
- next if mol_str.empty?
158
-
159
- name, monoisotopic, average = mol_str.split(/\s/)
160
- monoisotopic = monoisotopic.to_f
161
- average = average.to_f
162
-
163
- molecule = EmpiricalFormula.parse(name)
164
- assert_in_delta monoisotopic, molecule.mass, delta_mass, mol_str
165
- # TODO -- check average mass
166
- end
167
- end
168
-
169
- #
170
- # benchmark
171
- #
172
-
173
- def test_parse_speed
174
- benchmark_test(20) do |x|
175
- n = 10
176
-
177
- ["H20","H2(H2(H2))H2"].each do |formula|
178
- x.report("#{n}k #{formula}") do
179
- (n*1000).times { EmpiricalFormula.parse(formula) }
180
- end
181
- end
182
- end
183
- end
184
-
185
- def test_parse_simple_speed
186
- benchmark_test(20) do |x|
187
- n = 10
188
-
189
- ["H(20)","H(2)H(2)H(2)H(2)"].each do |formula|
190
- x.report("#{n}k #{formula}") do
191
- (n*1000).times { EmpiricalFormula.parse_simple(formula) }
192
- end
193
- end
194
- end
195
- end
196
- end
@@ -1,204 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../molecules_test_helper.rb'))
2
- require 'molecules/empirical_formula'
3
-
4
- class EmpiricalFormulaTest < Test::Unit::TestCase
5
- include Molecules
6
-
7
- #
8
- # documentation test
9
- #
10
-
11
- def test_documentation
12
- assert_equal "Hydrogen", EmpiricalFormula::ELEMENT_INDEX[0].name
13
- assert_equal "Oxygen", EmpiricalFormula::ELEMENT_INDEX[1].name
14
-
15
- water = EmpiricalFormula.new [2,1]
16
- assert_equal 'H(2)O', water.to_s
17
- assert_equal 18.0105646863, water.mass
18
-
19
- alanine = EmpiricalFormula.new [5,1,3,1]
20
- assert_equal [3,0,3,1], (alanine - water).formula
21
- end
22
-
23
- #
24
- # initialize test
25
- #
26
-
27
- def test_initialize
28
- e = EmpiricalFormula.new([])
29
- assert_equal([], e.formula)
30
-
31
- e = EmpiricalFormula.new([2,1])
32
- assert_equal([2,1], e.formula)
33
-
34
- e = EmpiricalFormula.new([2,-1])
35
- assert_equal([2,-1], e.formula)
36
- end
37
-
38
- def test_intialize_normalizes_formula_by_removing_trailing_zeros
39
- zero = EmpiricalFormula.new([0,1,0])
40
- assert_equal([0,1], zero.formula)
41
- end
42
-
43
- def test_intialize_normalizes_formula_by_converting_nils_to_zero
44
- zero = EmpiricalFormula.new([nil,1,nil,0])
45
- assert_equal([0,1], zero.formula)
46
- end
47
-
48
- def test_intialize_freezes_formula
49
- formula = [1,2,3]
50
- e = EmpiricalFormula.new(formula)
51
-
52
- assert e.formula.frozen?
53
- assert_equal formula.object_id, e.formula.object_id
54
- end
55
-
56
- #
57
- # + test
58
- #
59
-
60
- def test_PLUS
61
- c1 = EmpiricalFormula.new([1, 0, -1])
62
- c2 = EmpiricalFormula.new([1, 1, 1])
63
-
64
- c3 = c1 + c2
65
- assert_equal([2,1], c3.formula)
66
- end
67
-
68
- #
69
- # - test
70
- #
71
-
72
- def test_MINUS
73
- c1 = EmpiricalFormula.new([1, 0, -1])
74
- c2 = EmpiricalFormula.new([1, 1, 1])
75
-
76
- c3 = c1 - c2
77
- assert_equal([0, -1, -2], c3.formula)
78
- end
79
-
80
- #
81
- # * test
82
- #
83
-
84
- def test_MULTIPLY
85
- c1 = EmpiricalFormula.new([1, 0, -1])
86
-
87
- c3 = c1 * 2 * 3
88
- assert_equal([6, 0, -6], c3.formula)
89
- end
90
-
91
- #
92
- # == test
93
- #
94
-
95
- def test_EQUAL
96
- assert EmpiricalFormula.new([1]) == EmpiricalFormula.new([1])
97
- assert EmpiricalFormula.new([1]) == EmpiricalFormula.new([1, 0])
98
- end
99
-
100
- #
101
- # each test
102
- #
103
-
104
- def test_each_returns_elements_and_formula_for_non_zero_formula
105
- formula = EmpiricalFormula.new([2,0,1])
106
- composition = {}
107
- formula.each {|element, factor| composition[element] = factor }
108
-
109
- assert_equal({EmpiricalFormula::ELEMENT_INDEX[0] => 2, EmpiricalFormula::ELEMENT_INDEX[2] => 1}, composition)
110
- end
111
-
112
- #
113
- # to_s test
114
- #
115
-
116
- def test_to_s
117
- c1 = EmpiricalFormula.new([2,1])
118
- assert_equal "H(2)O", c1.to_s
119
-
120
- c1 = EmpiricalFormula.new([-2,-1])
121
- assert_equal "H(-2)O(-1)", c1.to_s
122
- end
123
-
124
- def test_to_s_symbols_are_sorted_alphabetically
125
- c = EmpiricalFormula.new([1, 1, 1])
126
- assert_equal "CHO", c.to_s
127
- end
128
-
129
- #
130
- # mass test
131
- #
132
-
133
- def test_mass_documentation
134
- water = EmpiricalFormula.new [2,1]
135
-
136
- assert_equal 18.0105646863, water.mass
137
- assert_equal 18.0105646863, water.mass {|e| e.mass }
138
-
139
- assert_equal 18.01528, water.mass {|e| e.std_atomic_weight.value }
140
- end
141
-
142
- def test_mass_returns_monoisotopic_mass_if_no_block_is_given
143
- water = EmpiricalFormula.new [2,1]
144
- assert_equal 18.0105646863, water.mass
145
- end
146
-
147
- def test_mass_calculates_mass_using_block_result
148
- water = EmpiricalFormula.new [2,1]
149
- assert_equal 18.01528, water.mass {|e| e.std_atomic_weight.value }
150
- end
151
-
152
- class AltMass
153
- attr_reader :value
154
-
155
- def initialize(value)
156
- @value = value
157
- end
158
-
159
- def +(another)
160
- another = another.value if another.kind_of?(AltMass)
161
- AltMass.new @value + another
162
- end
163
-
164
- def *(another)
165
- another = another.value if another.kind_of?(AltMass)
166
- AltMass.new @value * another
167
- end
168
- end
169
-
170
- def test_mass_calculation_operates_on_block_result
171
- water = EmpiricalFormula.new [2,1]
172
- result = water.mass {|e| AltMass.new e.mass }
173
-
174
- assert result.kind_of?(AltMass)
175
- assert_equal 18.0105646863, result.value
176
- end
177
-
178
- #
179
- # benchmark
180
- #
181
-
182
- def test_operation_speed
183
- benchmark_test(20) do |x|
184
- n = 10
185
- a = EmpiricalFormula.new [1,2,3,4]
186
- b = EmpiricalFormula.new [0,-1]
187
-
188
- x.report("#{n}k +") { (n*1000).times { a + b } }
189
- x.report("#{n}k -") { (n*1000).times { a - b } }
190
- x.report("#{n}k *") { (n*1000).times { a * 3} }
191
- end
192
- end
193
-
194
- def test_mass_speed
195
- benchmark_test(20) do |x|
196
- n = 10
197
- a = EmpiricalFormula.new [1,2,3,4]
198
- b = EmpiricalFormula.new [0,-1]
199
-
200
- x.report("#{n}k [1,2,3,4] mass") { (n*1000).times { a.mass {|e| e.mass } } }
201
- x.report("#{n}k [0,-1] mass") { (n*1000).times { b.mass {|e| e.mass } } }
202
- end
203
- end
204
- end
@@ -1,128 +0,0 @@
1
- require File.expand_path( File.join(File.dirname(__FILE__), '../../molecules_test_helper.rb') )
2
- require 'molecules/libraries/polypeptide'
3
-
4
- class PolypeptideTest < Test::Unit::TestCase
5
- include Molecules::Libraries
6
-
7
- #
8
- # normalize test
9
- #
10
-
11
- def test_normalize_removes_whitespace_and_upcases_sequence
12
- assert_equal "ABC", Polypeptide.normalize("Ab\n\rC\t\s")
13
- end
14
-
15
- #
16
- # initialize test
17
- #
18
-
19
- def test_initialize
20
- p = Polypeptide.new("")
21
- assert_equal "", p.sequence
22
- assert_equal([],p.formula)
23
- assert_equal({},p.residue_composition)
24
-
25
- bradykinin = Polypeptide.new("RPPGFSPFR")
26
- assert_equal "RPPGFSPFR", bradykinin.sequence
27
- assert_equal [71, 10, 50, 15], bradykinin.formula
28
- assert_equal({
29
- Residue::R => 2,
30
- Residue::P => 3,
31
- Residue::G => 1,
32
- Residue::F => 2,
33
- Residue::S => 1},
34
- bradykinin.residue_composition)
35
- end
36
-
37
- def test_spaces_are_allowed_in_initialize
38
- p = Polypeptide.new("\s\t\r\n")
39
- assert_equal "\s\t\r\n", p.sequence
40
- assert_equal([],p.formula)
41
- assert_equal({},p.residue_composition)
42
-
43
- bradykinin = Polypeptide.new(" R PP\t\nGFSP\s FR\r")
44
- assert_equal " R PP\t\nGFSP\s FR\r", bradykinin.sequence
45
- assert_equal [71, 10, 50, 15], bradykinin.formula
46
- assert_equal({
47
- Residue::R => 2,
48
- Residue::P => 3,
49
- Residue::G => 1,
50
- Residue::F => 2,
51
- Residue::S => 1},
52
- bradykinin.residue_composition)
53
- end
54
-
55
- def test_initialize_raises_error_for_unknown_residues
56
- assert_nil Residue['Z']
57
- assert_raise(Polypeptide::UnknownResidueError) { Polypeptide.new("Z") }
58
- end
59
-
60
- def test_initialize_is_case_sensitive_for_residues
61
- assert_not_nil Residue['A']
62
- assert_raise(Polypeptide::UnknownResidueError) { Polypeptide.new("a") }
63
- end
64
-
65
- #
66
- # each_residue test
67
- #
68
-
69
- def test_each_residue_returns_each_residue_sequentially
70
- residues = []
71
- p = Polypeptide.new("\sRP PG\t F")
72
- p.each_residue {|r| residues << r}
73
-
74
- assert_equal [Residue::R, Residue::P, Residue::P, Residue::G, Residue::F], residues
75
- end
76
-
77
- #
78
- # benchmark
79
- #
80
-
81
- def test_initialize_speed
82
- benchmark_test(20) do |x|
83
- n = 10
84
-
85
- x.report("#{n}k RPPGFSPFR") do
86
- (n*1000).times { Polypeptide.new("RPPGFSPFR") }
87
- end
88
- x.report("#{n}k RPPGFSPFR * 10") do
89
- (n*1000).times { Polypeptide.new("RPPGFSPFR" * 10) }
90
- end
91
- x.report("#{n*10} RPPGFSPFR * 1000") do
92
- (n*10).times { Polypeptide.new("RPPGFSPFR" * 1000) }
93
- end
94
- end
95
- end
96
-
97
- def test_each_residue_speed
98
- benchmark_test(20) do |x|
99
- p = Polypeptide.new("RPPGFSPFR" * 10)
100
-
101
- x.report("1k RPPGFSPFR * 10") do
102
- 1000.times { p.each_residue {|r| r} }
103
- end
104
- x.report("1k each_byte:") do
105
- 1000.times { p.sequence.each_byte {|b| b} }
106
- end
107
- end
108
- end
109
-
110
- #def test_counting_vs_each_byte
111
- # benchmark_test(20) do |x|
112
- # sequence = "RPPGFSPFR" * 1000
113
- #
114
- # x.report("1k count") do
115
- # 1000.times do
116
- # Utils.count(sequence, Polypeptide::SEQUENCE_TOKENS)
117
- # end
118
- # end
119
- #
120
- # x.report("1k each_byte") do
121
- # 1000.times do
122
- # array = Array.new(100, 0)
123
- # sequence.each_byte {|b| array[b] += 1}
124
- # end
125
- # end
126
- # end
127
- #end
128
- end
@@ -1,289 +0,0 @@
1
- require File.expand_path( File.join(File.dirname(__FILE__), '../../molecules_test_helper.rb'))
2
- require 'molecules/libraries/residue'
3
-
4
- class ResidueTest < Test::Unit::TestCase
5
- include Molecules::Libraries
6
-
7
- #
8
- # documentation test
9
- #
10
-
11
- def test_documentation
12
- r = Residue::A
13
- assert_equal "Alanine", r.name
14
- assert_equal "Ala", r.abbr
15
- assert_equal "A", r.letter
16
- assert_equal "CH(3)", r.side_chain.to_s
17
- end
18
-
19
- def test_common_returns_array_of_common_residues
20
- assert_equal 20, Residue.common.length
21
- assert_equal ['A', 'R', 'N', 'D', 'C', 'E', 'Q', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V'].sort, Residue.common.collect {|e| e.letter}.sort
22
- end
23
-
24
- def test_class_lookup
25
- a = Residue::A
26
-
27
- assert_equal a, Residue['A']
28
- assert_equal a, Residue['Ala']
29
- assert_equal a, Residue['Alanine']
30
-
31
- assert_nil Residue['X']
32
- assert_nil Residue['BACKBONE']
33
- assert_raise(NoMethodError) { Residue.backbone }
34
- end
35
-
36
- def test_residue_mass_equals_mass_with_parameters
37
- ala = Residue::A
38
- assert_equal ala.mass, ala.residue_mass
39
- end
40
-
41
- def test_mass_values
42
- {
43
- 'A' => 71.03711,
44
- 'R' => 156.10111,
45
- 'N' => 114.04293,
46
- 'D' => 115.02694,
47
- 'C' => 103.00919,
48
- 'E' => 129.04259,
49
- 'Q' => 128.05858,
50
- 'G' => 57.02146,
51
- 'H' => 137.05891,
52
- 'I' => 113.08406,
53
- 'L' => 113.08406,
54
- 'K' => 128.09496,
55
- 'M' => 131.04049,
56
- 'O' => 211.14465,
57
- 'F' => 147.06841,
58
- 'P' => 97.05276,
59
- 'S' => 87.03203,
60
- 'T' => 101.04768,
61
- 'U' => 150.95363,
62
- 'W' => 186.07931,
63
- 'Y' => 163.06333,
64
- 'V' => 99.06841
65
- }.each_pair do |residue, expected|
66
- assert_in_delta expected, Residue[residue].mass, delta_mass
67
- end
68
- end
69
-
70
- def test_immonium_ion_mass
71
- {
72
- 'A' => 44.05002,
73
- 'R' => 129.11402,
74
- 'N' => 87.05584,
75
- 'D' => 88.03985,
76
- 'C' => 76.02210,
77
- 'E' => 102.05550,
78
- 'Q' => 101.07149,
79
- 'G' => 30.03437,
80
- 'H' => 110.07182,
81
- 'I' => 86.09697,
82
- 'L' => 86.09697,
83
- 'K' => 101.10787,
84
- 'M' => 104.05340,
85
- 'O' => 184.15756,
86
- 'F' => 120.08132,
87
- 'P' => 70.06567,
88
- 'S' => 60.04494,
89
- 'T' => 74.06059,
90
- 'U' => 123.96654,
91
- 'W' => 159.09222,
92
- 'Y' => 136.07624,
93
- 'V' => 72.08132
94
- }.each_pair do |residue, expected|
95
- assert_in_delta expected, Residue[residue].immonium_ion_mass, delta_mass
96
- end
97
- end
98
-
99
- # vs the Proteome Commons Residue Reference, 2008-01-11
100
- # http://www.proteomecommons.org/archive/1129086318745/docs/residue-reference.html
101
- def test_mass_values_vs_proteome_commons
102
- str = %Q{
103
- Alanine A 71.0371137878
104
- Arginine R 156.1011110281
105
- Asparagine N 114.0429274472
106
- Aspartic Acid D 115.02694303199999
107
- Cysteine C 103.00918447779999
108
- Glutamic Acid E 129.0425930962
109
- Glutamine Q 128.05857751140002
110
- Glycine G 57.0214637236
111
- Histidine H 137.0589118624
112
- Isoleucine I 113.0840639804
113
- Leucine L 113.0840639804
114
- Lysine K 128.0949630177
115
- Methionine M 131.0404846062
116
- Phenylalanine F 147.0684139162
117
- Proline P 97.052763852
118
- Serine S 87.0320284099
119
- Threonine T 101.0476784741
120
- Tryptophan W 186.0793129535
121
- Tyrosine Y 163.0633285383
122
- Valine V 99.0684139162}
123
-
124
- residues = str.split(/\n/)
125
- residues.each do |residue_str|
126
- next if residue_str.empty?
127
-
128
- residue_str =~ /(.*)\s(\w)\s(\d+\.\d+)/
129
- name = $1.strip
130
- letter = $2
131
- mass = $3.to_f
132
-
133
- residue = Residue[letter]
134
- assert_not_nil residue, residue_str
135
- assert_equal name, residue.name
136
- assert_in_delta mass, residue.mass, delta_mass, residue_str
137
- end
138
- end
139
-
140
- # vs the Mascot Amino Acid Reference Data, 2008-01-11
141
- # http://hsc-mascot.uchsc.edu/mascot/help/aa_help.html
142
- #
143
- # minor formatting was done on this table to make it nice for the test;
144
- # the formatting consisted of condensing residue names and formula
145
- # to the same line and moving composites to a separate string. ex:
146
- # Alanine
147
- # C3H5NO Ala A 71.03712 71.08 Ala
148
- # became
149
- # Alanine C3H5NO Ala A 71.03712 71.08 Ala
150
- #
151
- # Note there are minor capitalization differences in the names and
152
- # abbreviations relative to those in Residue
153
- def test_mass_values_vs_mascot
154
- str = %Q{
155
- Alanine C3H5NO Ala A 71.03712 71.08 Ala
156
- Arginine C6H12N4O Arg R 156.10112 156.19 Arg
157
- Asparagine C4H6N2O2 Asn N 114.04293 114.10 Asn
158
- Aspartic acid C4H5NO3 Asp D 115.02695 115.09 Asp
159
- Cysteine C3H5NOS Cys C 103.00919 103.14 Cys
160
- Glutamic acid C5H7NO3 Glu E 129.04260 129.12 Glu
161
- Glutamine C5H8N2O2 Gln Q 128.05858 128.13 Gln
162
- Glycine C2H3NO Gly G 57.02147 57.05 Gly
163
- Histidine C6H7N3O His H 137.05891 137.14 His
164
- Isoleucine C6H11NO Ile I 113.08407 113.16 Ile
165
- Leucine C6H11NO Leu L 113.08407 113.16 Leu
166
- Lysine C6H12N2O Lys K 128.09497 128.17 Lys
167
- Methionine C5H9NOS Met M 131.04049 131.19 Met
168
- Phenylalanine C9H9NO Phe F 147.06842 147.18 Phe
169
- Proline C5H7NO Pro P 97.05277 97.12 Pro
170
- Serine C3H5NO2 Ser S 87.03203 87.08 Ser
171
- Threonine C4H7NO2 Thr T 101.04768 101.10 Thr
172
- Selenocysteine C3H5NOSe SeC U 150.95364 150.03 SeC
173
- Tryptophan C11H10N2O Trp W 186.07932 186.21 Trp
174
- Tyrosine C9H9NO2 Tyr Y 163.06333 163.18 Tyr
175
- Valine C5H9NO Val V 99.06842 99.13 Val}
176
-
177
- composites = %Q{
178
- Asn or Asp Asx B
179
- Glu or Gln Glx Z
180
- Unknown Xaa X}
181
-
182
- residues = str.split(/\n/)
183
- residues.each do |residue_str|
184
- next if residue_str.empty?
185
-
186
- residue_str =~ /(.*)\s+([\w\d]+)\s+(\w\w\w)\s+(\w)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\w\w\w/
187
- name = $1
188
- formula = $2
189
- abbr = $3
190
- letter = $4
191
- monoisotopic = $5.to_f
192
- average = $6.to_f
193
-
194
- residue = Residue[letter]
195
- assert_not_nil residue, residue_str
196
- assert_equal name.upcase, residue.name.upcase, residue_str
197
- assert_equal abbr.upcase, residue.abbr.upcase, residue_str
198
- assert_equal formula, residue.to_s.gsub(/\(|\)/, ""), residue_str
199
-
200
- assert_in_delta monoisotopic, residue.mass, delta_mass, residue_str
201
- # TODO -- check average mass
202
- end
203
- end
204
-
205
- # vs the VG Analytical Organic Mass Spectrometry reference, reference date unknown (prior to 2005)
206
- # the data from the data sheet was copied manually to doc/VG Analytical DataSheet.txt
207
- def test_mass_values_vs_vg_analytical
208
- common = %Q{
209
- Ala A Alanine C3H5NO 71.03711 71.0788
210
- Arg R Arginine C6H12N4O 156.10111 156.1875
211
- Asn N Asparagine C4H6N2O2 114.04293 114.1038
212
- Asp D Aspartic Acid C4H5NO3 115.02694 115.0886
213
- Cys C Cysteine C3H5NOS 103.00919 103.1388
214
- Glu E Glutamic Acid C5H7NO3 129.04259 129.115
215
- Gln Q Glutamine C5H8N2O2 128.05858 128.1307
216
- Gly G Glycine C2H3NO 57.02146 57.0519
217
- His H Histidine C6H7N3O 137.05891 137.1411
218
- Ile I Isoleucine C6H11NO 113.08406 113.1594
219
- Leu L Leucine C6H11NO 113.08406 113.1594
220
- Lys K Lysine C6H12N2O 128.09496 128.1741
221
- Met M Methionine C5H9NOS 131.04049 131.1926
222
- Phe F Phenylalanine C9H9NO 147.06841 147.1766
223
- Pro P Proline C5H7NO 97.05276 97.1167
224
- Ser S Serine C3H5NO2 87.03203 87.0782
225
- Thr T Threonine C4H7NO2 101.04768 101.1051
226
- Trp W Tryptophan C11H10N2O 186.07931 186.2132
227
- Tyr Y Tyrosine C9H9NO2 163.06333 163.1760
228
- Val V Valine C5H9NO 99.06841 99.1326}
229
-
230
- residues = common.split(/\n/)
231
- residues.each do |residue_str|
232
- next if residue_str.empty?
233
-
234
- residue_str =~ /(\w\w\w) (\w) (\w+( Acid)?) ([\w\d]+) (\d+\.\d+) (\d+\.\d+)/
235
- abbr = $1
236
- letter = $2
237
- name = $3
238
- formula = $5
239
- monoisotopic = $6.to_f
240
- average = $7.to_f
241
-
242
- residue = Residue[letter]
243
- assert_not_nil residue, residue_str
244
- assert_equal name, residue.name, residue_str
245
- assert_equal abbr, residue.abbr, residue_str
246
- assert_equal formula, residue.to_s.gsub(/\(|\)/, ""), residue_str
247
-
248
- assert_in_delta monoisotopic, residue.mass, delta_mass, residue_str
249
- # TODO -- check average mass
250
- end
251
-
252
- uncommon = %Q{
253
- Orn Ornithine C5H10N2O 114.07931 114.1472
254
- Aba Aminobutyric Acid C4H7NO 85.05276 85.1057
255
- AECys Aminoethylcysteine C5H10N2OS 146.05138 146.2072
256
- Aib alpha-Aminoisobutyric Acid C4H7NO 85.05276 85.1057
257
- CMCys Carboxymethylcysteine C5H7NO3S 161.01466 161.1755
258
- Dha Dehydroalanine C3H3NO 69.02146 69.0629
259
- Dhb Dehydroamino-alpha-butyric Acid C4H5NO 83.03711 83.0898
260
- Hyl Hydroxylysine C6H12N2O2 144.08988 144.1735
261
- Hyp Hydroxyproline C5H7NO2 113.04768 113.1161
262
- Iva Isovaline C5H9NO 99.06841 99.1326
263
- nLeu Norleucine C6H11NO 113.08406 113.1594
264
- Pip 2-Piperidinecarboxylic Acid C6H9NO 111.06841 111.1436
265
- pGlu Pyroglutamic Acid C5H5NO2 111.03203 111.1002
266
- Sar Sarcosine C3H5NO 71.03711 71.0788}
267
-
268
- residues = uncommon.split(/\n/)
269
- residues.each do |residue_str|
270
- next if residue_str.empty?
271
-
272
- residue_str =~ /(\w+) ([\w-]+( Acid)?) ([\w\d]+) (\d+\.\d+) (\d+\.\d+)/
273
- abbr = $1
274
- name = $2
275
- formula = $4
276
- monoisotopic = $5.to_f
277
- average = $6.to_f
278
-
279
- residue = Residue[abbr]
280
- assert_not_nil residue, residue_str
281
- assert_equal name, residue.name, residue_str
282
- assert_equal formula, residue.to_s.gsub(/\(|\)/, ""), residue_str
283
-
284
- assert_in_delta monoisotopic, residue.mass, delta_mass, residue_str
285
- # TODO -- check average mass
286
- end
287
- end
288
-
289
- end
@@ -1,147 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../molecules_test_helper.rb'))
2
- require 'molecules/utils'
3
-
4
- class UtilsTest < Test::Unit::TestCase
5
- include Molecules::Utils
6
-
7
- #
8
- # round test
9
- #
10
-
11
- def test_round
12
- assert_equal 0, round(0.20, 0)
13
- assert_equal 0.2, round(0.20, 1)
14
- assert_equal 0.2, round(0.20, 2)
15
- assert_equal 0.2, round(0.20, 3)
16
-
17
- assert_equal 0.2, round(0.18, 1)
18
- assert_equal 0.2, round(0.15, 1)
19
- assert_equal 0.1, round(0.13, 1)
20
- assert_equal 0.13, round(0.13, 3)
21
-
22
- assert_equal 10, round(13, -1)
23
- assert_equal 0, round(13, -2)
24
- end
25
-
26
- #
27
- # add
28
- #
29
-
30
- def test_add_adds_the_elements_of_b_to_a_at_corresponding_indicies
31
- assert_equal [2,3,4], add([1,3,-1], [1,0,5])
32
- end
33
-
34
- def test_add_multiplies_the_elements_of_b_by_factor
35
- assert_equal [3,3,9], add([1,3,-1], [1,0,5], 2)
36
- assert_equal [1,3,-1], add([1,3,-1], [1,0,5], 0)
37
- end
38
-
39
- def test_add_removes_trailing_zeros_from_a
40
- assert_equal [], add([1,1,1], [-1,-1,-1])
41
- end
42
-
43
- def test_add_returns_a
44
- a = [1,2,4]
45
- assert_equal a.object_id, add(a, [1,0,4]).object_id
46
- end
47
-
48
- def test_add_does_not_require_a_and_b_to_be_the_same_length
49
- a = [1,2]
50
- b = [1]
51
-
52
- assert_equal [2,2], add(a, b)
53
-
54
- a = [1,2]
55
- b = [1]
56
-
57
- assert_equal [2,2], add(b, a)
58
- end
59
-
60
- #
61
- # multiply test
62
- #
63
-
64
- def test_multiply_multiplies_elements_of_a_by_factor
65
- assert_equal [2,4,-6], multiply([1,2,-3], 2)
66
- assert_equal [-2,-4,6], multiply([1,2,-3], -2)
67
- end
68
-
69
- def test_multiply_clears_a_for_zero_factor
70
- assert_equal [], multiply([1,2,-3], 0)
71
- end
72
-
73
- def test_mulitply_returns_a
74
- a = [1,2,4]
75
- assert_equal a.object_id, multiply(a, 2).object_id
76
- assert_equal a.object_id, multiply(a, 0).object_id
77
- end
78
-
79
- #
80
- # count test
81
- #
82
-
83
- def test_count_documenation
84
- assert_equal [3, 2, 2] , count("abcabca", ["a", "b", "c"])
85
- assert_equal [3, 4], count("abcabca", ["a", "bc"])
86
- end
87
-
88
- #
89
- # benchmark tests
90
- #
91
-
92
- def test_round_speed
93
- benchmark_test(24) do |x|
94
- n = 100
95
- x.report("#{n}k 1234.5678.round") do
96
- (n*10**3).times { 1234.5678.round }
97
- end
98
-
99
- x.report("#{n}k 1234.5678 (2)") do
100
- (n*10**3).times { round(1234.5678, 2) }
101
- end
102
-
103
- x.report("#{n}k 1234.5678 (5)") do
104
- (n*10**3).times { round(1234.5678, 5) }
105
- end
106
- end
107
- end
108
-
109
- def test_add_speed
110
- benchmark_test(30) do |x|
111
- n = 100
112
- x.report("#{n}k add([1,3,-1], [1,0,5])") do
113
- (n*10**3).times { add([1,3,-1], [1,0,5]) }
114
- end
115
-
116
- x.report("#{n}k add([1,3,-1], [1])") do
117
- (n*10**3).times { add([1,3,-1], [1]) }
118
- end
119
-
120
- x.report("#{n}k add([1], [1,3,-1])") do
121
- (n*10**3).times { add([1], [1,3,-1]) }
122
- end
123
-
124
- x.report("#{n}k add([1,1,1], [-1,-1,-1])") do
125
- (n*10**3).times { add([1,1,1], [-1,-1,-1]) }
126
- end
127
-
128
- x.report("#{n}k add([1,3,-1], [1,0,5], 2)") do
129
- (n*10**3).times { add([1,3,-1], [1,0,5], 2) }
130
- end
131
- end
132
- end
133
-
134
- def test_multiply_speed
135
- benchmark_test(30) do |x|
136
- n = 100
137
- x.report("#{n}k multiply([1,3,-1], 2)") do
138
- (n*10**3).times { multiply([1,3,-1], 2) }
139
- end
140
-
141
- x.report("#{n}k multiply([1,3,-1], 0)") do
142
- (n*10**3).times { multiply([1,3,-1], 0) }
143
- end
144
- end
145
- end
146
-
147
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path( File.join(File.dirname(__FILE__), 'molecules_test_helper.rb') )
2
- require 'molecules'
3
-
4
- class MoleculesTest < Test::Unit::TestCase
5
-
6
- include Molecules::Libraries
7
-
8
- def test_readme_documentation
9
- r = Residue::A
10
- assert_equal "Alanine", r.name
11
- assert_equal "Ala", r.abbr
12
- assert_equal "A", r.letter
13
- assert_equal "CH(3)", r.side_chain.to_s
14
- assert_in_delta 71.03711, r.mass, 0.00001
15
- assert_in_delta 44.05002, r.immonium_ion_mass, 0.00001
16
-
17
- p = Polypeptide.new("RPPGFSPFR")
18
- assert_equal "C(50)H(71)N(15)O(10)", p.to_s
19
- assert_in_delta 1041.5508, p.mass , 0.0001
20
-
21
- caffeine = Molecules::EmpiricalFormula.parse("C8H10N4O2")
22
- coffee = Molecules::EmpiricalFormula.parse("C8H10N4O2 + H2O")
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'benchmark'
4
- require 'pp'
5
-
6
- class Test::Unit::TestCase
7
- include Benchmark
8
-
9
- #
10
- # mass tests
11
- #
12
-
13
- def delta_mass
14
- 10**-5
15
- end
16
-
17
- def delta_abundance
18
- 10**-1
19
- end
20
-
21
- def benchmark_test(length=10, &block)
22
- if ENV["benchmark"] =~ /true/i
23
- puts
24
- puts method_name
25
- bm(length, &block)
26
- else
27
- print 'b'
28
- end
29
- end
30
-
31
- end
@@ -1,3 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
-
3
- Dir.glob("./**/*_test.rb").each {|test| require test}
@@ -1,3 +0,0 @@
1
- require 'rubygems'
2
- require 'tap'
3
- require 'tap/test'