ms-msrun 0.1.0 → 0.2.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.
Files changed (42) hide show
  1. data/.gitignore +3 -0
  2. data/.gitmodules +3 -0
  3. data/History +18 -0
  4. data/{README → README.rdoc} +0 -0
  5. data/Rakefile +93 -107
  6. data/VERSION +1 -0
  7. data/lib/lmat.rb +141 -39
  8. data/lib/ms/msrun/nokogiri.rb +1 -0
  9. data/lib/ms/msrun/search_dev_notes.txt +47 -0
  10. data/spec/lmat_spec.rb +87 -11
  11. data/spec/metadata/opd1/000.v1.mzXML.yml +3 -0
  12. data/spec/metadata/opd1/000.v2.1.mzXML.yml +3 -0
  13. data/spec/metadata/opd1/020.mzData.xml.yml +3 -0
  14. data/spec/metadata/opd1/020.v2.0.readw.mzXML.yml +3 -0
  15. data/spec/ms/msrun/hpricot.rb +38 -0
  16. data/spec/ms/msrun/index_spec.rb +12 -13
  17. data/spec/ms/msrun/search_spec.rb +5 -4
  18. data/spec/ms/msrun/sha1_spec.rb +3 -6
  19. data/spec/ms/msrun/test_parsing_xml_frags/parse_test.rb +25 -0
  20. data/spec/ms/msrun/test_parsing_xml_frags/test1.xml +5 -0
  21. data/spec/ms/msrun/test_parsing_xml_frags/test2.xml +6 -0
  22. data/spec/ms/msrun/test_parsing_xml_frags/test3.xml +4 -0
  23. data/spec/ms/msrun/test_parsing_xml_frags/test4.xml +11 -0
  24. data/spec/ms/msrun/test_parsing_xml_frags/test_failures.rb +47 -0
  25. data/spec/ms/msrun_bm.rb +22 -0
  26. data/spec/ms/msrun_spec.rb +90 -109
  27. data/spec/ms/scan_spec.rb +5 -6
  28. data/spec/ms/spectrum/compare_spec.rb +31 -28
  29. data/spec/ms/spectrum/filter_spec.rb +15 -13
  30. data/spec/spec_helper.rb +21 -0
  31. data/spec/testfiles/lmat/tmp1.lmat +0 -0
  32. data/spec/testfiles/lmat/tmp1.lmata +44 -0
  33. data/spec/testfiles/lmat/tmp2.lmata +11 -0
  34. data/spec/testfiles/opd1/000.v1.mzXML +418 -0
  35. data/spec/testfiles/opd1/000.v1.mzXML.key.yml +51 -0
  36. data/spec/testfiles/opd1/000.v2.1.mzXML +382 -0
  37. data/spec/testfiles/opd1/000.v2.1.mzXML.key.yml +51 -0
  38. data/spec/testfiles/opd1/020.mzData.xml +683 -0
  39. data/spec/testfiles/opd1/020.mzData.xml.key.yml +43 -0
  40. data/spec/testfiles/opd1/020.v2.0.readw.mzXML +382 -0
  41. data/spec/testfiles/opd1/020.v2.0.readw.mzXML.key.yml +46 -0
  42. metadata +85 -34
@@ -0,0 +1,22 @@
1
+ require "ms/msrun"
2
+
3
+ #Ms::Msrun.open("LPT_GFP_NUCLf.mzXML") do |ms|
4
+ Ms::Msrun.open("000.mzXML") do |ms|
5
+ #indices = (1..1000).to_a
6
+ #start = Time.now
7
+ #indices.each do |n|
8
+ # ms.scan(n).spectrum[0]
9
+ #end
10
+
11
+ start = Time.now
12
+ cnt = 0
13
+ ms.each do |scan|
14
+ scan.spectrum
15
+ cnt += 1
16
+ end
17
+
18
+ #puts "#{(Time.now - start) / indices.size} / scan"
19
+ #puts "#{Time.now - start} total secs for #{indices.size} scans"
20
+ puts "#{(Time.now - start) / cnt} / scan"
21
+ puts "#{Time.now - start} total secs for #{cnt} scans"
22
+ end
@@ -3,156 +3,137 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
3
3
  require 'ms/msrun'
4
4
 
5
5
  module MsrunSpec
6
- extend Shareable
7
6
 
8
- before do
9
- @file = nil # you need to define this!
10
- @key = nil # <- do nothing with this.
11
- @nums = (1..20).to_a # define scan numbers
7
+ before_all = lambda do |file|
8
+ nums = (1..20).to_a # define scan numbers
9
+ key = YAML.load_file(file + '.key.yml')
10
+ [key, nums]
12
11
  end
13
12
 
14
- def key
15
- @key || @key = YAML.load_file(@file + '.key.yml')
16
- end
13
+ shared 'an msrun object' do
17
14
 
18
- def hash_match(hash, obj)
19
- #$DEBUG = 1
20
- puts "SCAN: #{obj.num}" if $DEBUG && obj.respond_to?(:num)
21
- hash.each do |k,v|
22
- if v.is_a?(Hash)
23
- hash_match(v, obj.send(k.to_sym))
24
- else
25
- puts "#{k}: #{v} but was #{obj.send(k.to_sym)}" if obj.send(k.to_sym) != v
26
- obj.send(k.to_sym).must_equal v
15
+ it 'reads header information' do
16
+ Ms::Msrun.open(@file) do |ms|
17
+ @key['header'].each do |k,v|
18
+ #puts "K: #{k} Vexp: #{v} Vact: #{ms.send(k.to_sym)}"
19
+ ms.send(k.to_sym).is v
20
+ end
27
21
  end
28
22
  end
29
- end
30
23
 
31
- it 'reads header information' do
32
- Ms::Msrun.open(@file) do |ms|
33
- key['header'].each do |k,v|
34
- #puts "K: #{k} Vexp: #{v} Vact: #{ms.send(k.to_sym)}"
35
- ms.send(k.to_sym).must_equal v
24
+ it 'can access random scans' do
25
+ Ms::Msrun.open(@file) do |ms|
26
+ scan = ms.scan(20)
27
+ hash_match(@key['scans'][20], scan)
36
28
  end
37
29
  end
38
- end
39
30
 
40
- it 'can access random scans' do
41
- Ms::Msrun.open(@file) do |ms|
42
- scan = ms.scan(20)
43
- hash_match(key['scans'][20], scan)
44
- end
45
- end
46
-
47
- it 'can read all scans' do
48
- num_required_scans = key['scans'].size
49
- Ms::Msrun.open(@file) do |ms|
50
- ms.each do |scan|
51
- if hash = key['scans'][scan.num]
52
- hash_match(hash, scan)
53
- num_required_scans -= 1
31
+ it 'can read all scans' do
32
+ num_required_scans = @key['scans'].size
33
+ Ms::Msrun.open(@file) do |ms|
34
+ ms.each do |scan|
35
+ if hash = @key['scans'][scan.num]
36
+ hash_match(hash, scan)
37
+ num_required_scans -= 1
38
+ end
54
39
  end
55
40
  end
41
+ num_required_scans.is 0
56
42
  end
57
- num_required_scans.must_equal 0
58
- end
59
43
 
60
- it 'can read scans of a certain ms_level' do
61
- nums = [1,5,9,13,17]
62
- Ms::Msrun.open(@file) do |ms|
63
- ms.each(:ms_level => 1) do |scan|
64
- scan.num.must_equal nums.shift
44
+ it 'can read scans of a certain ms_level' do
45
+ nums = [1,5,9,13,17]
46
+ Ms::Msrun.open(@file) do |ms|
47
+ ms.each(:ms_level => 1) do |scan|
48
+ scan.num.is nums.shift
49
+ end
50
+ end
51
+ nums = [2,3,4,6,7,8,10,11,12,14,15,16,18,19,20]
52
+ Ms::Msrun.foreach(@file, :ms_level => 2) do |scan|
53
+ scan.num.is nums.shift
65
54
  end
66
55
  end
67
- nums = [2,3,4,6,7,8,10,11,12,14,15,16,18,19,20]
68
- Ms::Msrun.foreach(@file, :ms_level => 2) do |scan|
69
- scan.num.must_equal nums.shift
70
- end
71
- end
72
56
 
73
- it 'can avoid reading spectra' do
74
- nums = @nums.map
75
- Ms::Msrun.foreach(@file, :spectrum => false) do |scan|
76
- assert scan.spectrum.nil?
77
- scan.num.must_equal nums.shift
57
+ it 'can avoid reading spectra' do
58
+ nums = @nums.map
59
+ Ms::Msrun.foreach(@file, :spectrum => false) do |scan|
60
+ scan.spectrum.nil?.ok
61
+ scan.num.is nums.shift
62
+ end
78
63
  end
79
- end
80
64
 
81
- it 'can avoid reading precursor information' do
82
- Ms::Msrun.foreach(@file, :precursor => false) do |scan|
83
- assert scan.precursor.nil?
65
+ it 'can avoid reading precursor information' do
66
+ Ms::Msrun.foreach(@file, :precursor => false) do |scan|
67
+ scan.precursor.nil?.ok
68
+ end
84
69
  end
85
- end
86
70
 
87
- it 'gives scan counts for different ms levels' do
88
- Ms::Msrun.open(@file) do |ms|
89
- key['scan_count'].each do |index, count|
90
- ms.scan_count(index).must_equal count
71
+ it 'gives scan counts for different ms levels' do
72
+ Ms::Msrun.open(@file) do |ms|
73
+ @key['scan_count'].each do |index, count|
74
+ ms.scan_count(index).is count
75
+ end
91
76
  end
92
77
  end
93
- end
94
78
 
95
- it 'gives start and end mz even if the information is not given' do
96
- Ms::Msrun.open(@file) do |ms|
97
- ms.start_and_end_mz_brute_force.must_equal(key['start_and_end_mz'][1])
79
+ it 'gives start and end mz even if the information is not given' do
80
+ Ms::Msrun.open(@file) do |ms|
81
+ ms.start_and_end_mz_brute_force.is(@key['start_and_end_mz'][1])
82
+ end
98
83
  end
99
84
  end
100
85
 
101
- end
102
-
103
- class Mzxml_v1 < MiniTest::Spec
104
- include MsrunSpec
105
- before do
106
- super
86
+ describe 'reading an mzXML v1 file' do
107
87
  @file = TESTFILES + '/opd1/000.v1.mzXML'
108
- end
88
+
89
+ (@key, @nums) = before_all.call(@file)
90
+
109
91
 
110
- it 'can give start and end mz' do
111
- # scan has attributes startMz endMz
112
- Ms::Msrun.open(@file) do |ms|
113
- #ms.start_and_end_mz.must_equal([300.0, 1500.0])
114
- ms.start_and_end_mz.must_equal(key['start_and_end_mz'][1])
92
+ it 'can give start and end mz' do
93
+ # scan has attributes startMz endMz
94
+ Ms::Msrun.open(@file) do |ms|
95
+ #ms.start_and_end_mz.is([300.0, 1500.0])
96
+ ms.start_and_end_mz.is @key['start_and_end_mz'][1]
97
+ end
115
98
  end
99
+
100
+ behaves_like 'an msrun object'
101
+
116
102
  end
117
- end
118
103
 
119
- class Mzxml_v2_0 < MiniTest::Spec
120
- include MsrunSpec
121
- before do
122
- super
104
+ describe 'reading an mzXML v2.0 file' do
123
105
  @file = TESTFILES + '/opd1/020.v2.0.readw.mzXML'
106
+ (@key, @nums) = before_all.call(@file)
107
+ behaves_like 'an msrun object'
124
108
  end
125
- end
126
109
 
127
- class Mzxml_v2_1 < MiniTest::Spec
128
- include MsrunSpec
129
- before do
130
- super
110
+ describe 'reading an mzXML v2.1 file' do
131
111
  @file = TESTFILES + '/opd1/000.v2.1.mzXML'
132
- end
112
+ (@key, @nums) = before_all.call(@file)
113
+ behaves_like 'an msrun object'
133
114
 
134
- it 'gives nil if scans do not have start and end mz info' do
135
- # scans do not have startMz endMz or filterLine
136
- Ms::Msrun.open(@file) do |ms|
137
- ms.start_and_end_mz.must_equal([nil, nil])
115
+ it 'gives nil if scans do not have start and end mz info' do
116
+ # scans do not have startMz endMz or filterLine
117
+ Ms::Msrun.open(@file) do |ms|
118
+ ms.start_and_end_mz.is([nil, nil])
119
+ end
138
120
  end
139
- end
140
121
 
141
- it 'gives start and end mz if filterLine present' do
142
- newname = @file + ".TMP.mzXML"
143
- File.open(newname, 'w') do |out|
144
- IO.foreach(@file) do |line|
145
- if line =~ /msLevel="1"/
146
- out.puts %Q{ filterLine="FTMS + p NSI Full ms [300.00-1500.00]"}
122
+ it 'gives start and end mz if filterLine present' do
123
+ newname = @file + ".TMP.mzXML"
124
+ File.open(newname, 'w') do |out|
125
+ IO.foreach(@file) do |line|
126
+ if line =~ /msLevel="1"/
127
+ out.puts %Q{ filterLine="FTMS + p NSI Full ms [300.00-1500.00]"}
128
+ end
129
+ out.print line
147
130
  end
148
- out.print line
149
131
  end
132
+ Ms::Msrun.open(newname) do |ms|
133
+ ms.start_and_end_mz.is([300.0, 1500.0])
134
+ end
135
+ File.unlink(newname) if File.exist?(newname)
150
136
  end
151
- Ms::Msrun.open(newname) do |ms|
152
- ms.start_and_end_mz.must_equal([300.0, 1500.0])
153
- end
154
- File.unlink(newname) if File.exist?(newname)
155
- end
156
137
 
138
+ end
157
139
  end
158
-
data/spec/ms/scan_spec.rb CHANGED
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  require 'ms/msrun'
4
4
 
5
- class ScanUnitSpec < MiniTest::Spec
5
+ describe 'a scan' do
6
6
 
7
7
  before do
8
8
  @scan = Ms::Scan.new
@@ -10,25 +10,24 @@ class ScanUnitSpec < MiniTest::Spec
10
10
  @scan.spectrum = Ms::Spectrum.new([[1,2,3,4], [2,4,4,2]])
11
11
  end
12
12
 
13
-
14
- it 'determines if its +1 or not' do
13
+ it 'can determine if its +1 or not' do
15
14
  # these have not been checked for accuracy, just sanity
16
15
  reply = [0.1,2.5, 3.5, 5].map do |prec_mz|
17
16
  @scan.precursor.mz = prec_mz
18
17
  @scan.plus1?(-0.1)
19
18
  end
20
- reply.all? {|v| v == true }.must_equal true
19
+ reply.all? {|v| v == true }.ok
21
20
 
22
21
  reply = [0.1,2.5, 3.5, 5].map do |prec_mz|
23
22
  @scan.precursor.mz = prec_mz
24
23
  @scan.plus1?(1.0)
25
24
  end
26
- reply.all? {|v| v == false }.must_equal true
25
+ reply.all? {|v| v == false }.ok
27
26
 
28
27
  reply = [0.1,2.5, 3.5, 5].map do |prec_mz|
29
28
  @scan.precursor.mz = prec_mz
30
29
  @scan.plus1?(0.5)
31
30
  end
32
- reply.must_equal [false, false, true, true]
31
+ reply.enums [false, false, true, true]
33
32
  end
34
33
  end
@@ -9,42 +9,45 @@ class Array
9
9
  end
10
10
  end
11
11
 
12
- class CompareSpec < MiniTest::Spec
12
+ module CompareSpec
13
13
  include Ms
14
14
 
15
- before do
16
- @a = Spectrum.new([[0,2,3,4], [5,6,7,8]])
17
- @b = Spectrum.new([[0, 1.5, 3.5, 5.5], [9,10,11,12]])
15
+ describe 'comparison of spectra' do
18
16
 
19
- @c = Spectrum.new([[0, 1], [8,9]])
20
- @d = Spectrum.new([[0.6, 0.75], [10,11]])
21
- end
17
+ before do
18
+ @a = Spectrum.new([[0,2,3,4], [5,6,7,8]])
19
+ @b = Spectrum.new([[0, 1.5, 3.5, 5.5], [9,10,11,12]])
22
20
 
23
- it 'compares spectra' do
24
- # array form:
25
- @c.compare(@d).rev_ab.must_equal( @d.compare(@c) )
26
- @c.compare(@d).must_equal [[8, 10, 0.6]]
21
+ @c = Spectrum.new([[0, 1], [8,9]])
22
+ @d = Spectrum.new([[0.6, 0.75], [10,11]])
23
+ end
27
24
 
28
- # block form
29
- exp = [[5,9], [6,10], [7,11]]
30
- # default radius 1.0
31
- @a.compare(@b) do |int_a, int_b|
32
- exp.delete([int_a, int_b])
25
+ it 'compares spectra' do
26
+ # array form:
27
+ @c.compare(@d).rev_ab.is( @d.compare(@c) )
28
+ @c.compare(@d).is [[8, 10, 0.6]]
29
+
30
+ # block form
31
+ exp = [[5,9], [6,10], [7,11]]
32
+ # default radius 1.0
33
+ @a.compare(@b) do |int_a, int_b|
34
+ exp.delete([int_a, int_b])
35
+ end
36
+ exp.size.is 0
33
37
  end
34
- exp.size.must_equal 0
35
- end
36
38
 
37
- it 'computes similarity score' do
38
- @a.sim_score(@a, :radius => 0.1).must_equal 1.0
39
- # this is just frozen, not verified:
40
- @a.sim_score(@b).must_be_close_to 0.702945603476432, 0.000001
41
- end
39
+ it 'computes similarity score' do
40
+ @a.sim_score(@a, :radius => 0.1).is 1.0
41
+ # this is just frozen, not verified:
42
+ @a.sim_score(@b).should.be.close 0.702945603476432, 0.000001
43
+ end
42
44
 
43
- it 'computes a pic score' do
44
- @a.pic_score(@a, :radius => 0.01).must_equal 100.0
45
- @a.pic_score(@d, :radius => 0.01).must_equal 0.0
46
- # frozen:
47
- @a.pic_score(@b).must_be_close_to 68.4981684981685, 0.000001
45
+ it 'computes a pic score' do
46
+ @a.pic_score(@a, :radius => 0.01).is 100.0
47
+ @a.pic_score(@d, :radius => 0.01).is 0.0
48
+ # frozen:
49
+ @a.pic_score(@b).should.be.close 68.4981684981685, 0.000001
50
+ end
48
51
  end
49
52
  end
50
53
 
@@ -10,24 +10,26 @@ class Array
10
10
  end
11
11
  end
12
12
 
13
- class FilterSpec < MiniTest::Spec
13
+ class FilterSpec
14
14
  include Ms
15
15
 
16
- before do
17
- @a = Spectrum.new([[0,5,10, 15,16,17,18, 20.1], [0,1,2, 3,8,10,4, 0]])
18
- @null = Spectrum.new([[],[]])
19
- end
16
+ describe 'filtering spectra' do
17
+ before do
18
+ @a = Spectrum.new([[0,5,10, 15,16,17,18, 20.1], [0,1,2, 3,8,10,4, 0]])
19
+ @null = Spectrum.new([[],[]])
20
+ end
20
21
 
21
- it 'filters spectra' do
22
- spec = @a.filter(:bins, :bin_width => 10, :num_peaks => 2)
23
- spec.mzs.must_equal [5,10,16,17,20.1]
24
- spec.intensities.must_equal [1,2,8,10,0]
22
+ it 'filters spectra' do
23
+ spec = @a.filter(:bins, :bin_width => 10, :num_peaks => 2)
24
+ spec.mzs.enums [5,10,16,17,20.1]
25
+ spec.intensities.enums [1,2,8,10,0]
25
26
 
26
- @a.filter(:bins, :bin_width => 100, :num_peaks => 8).must_equal @a
27
- @a.filter(:bins, :bin_width => 1, :num_peaks => 1).must_equal @a
28
- @a.filter(:bins, :bin_width => 1, :num_peaks => 0).must_equal @null
29
- end
27
+ @a.filter(:bins, :bin_width => 100, :num_peaks => 8).is @a
28
+ @a.filter(:bins, :bin_width => 1, :num_peaks => 1).is @a
29
+ @a.filter(:bins, :bin_width => 1, :num_peaks => 0).is @null
30
+ end
30
31
 
32
+ end
31
33
  end
32
34
 
33
35
 
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'spec/more'
3
+
4
+ TESTFILES = File.expand_path(File.dirname(__FILE__)) + '/testfiles'
5
+
6
+ module Bacon
7
+ class Context
8
+ def hash_match(hash, obj)
9
+ hash.each do |k,v|
10
+ if v.is_a?(Hash)
11
+ hash_match(v, obj.send(k.to_sym))
12
+ else
13
+ puts "#{k}: #{v} but was #{obj.send(k.to_sym)}" if obj.send(k.to_sym) != v
14
+ obj.send(k.to_sym).should.equal v
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ Bacon.summary_on_exit
Binary file