bioinform 0.1.6 → 0.1.7

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.
@@ -9,10 +9,10 @@ module Bioinform
9
9
  PCM.new([[1, 2.3, 3.2, 1],[4.4, 0.1, 1, 2]]).count.should == 7.5
10
10
  end
11
11
  end
12
-
12
+
13
13
  describe '#to_pwm' do
14
14
  it 'should return PWM' do
15
- PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_pwm.should be_kind_of(PWM)
15
+ PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_pwm.should be_kind_of(PWM)
16
16
  end
17
17
  it 'should make transformation: el --> log( (el + p_i*pseudocount) / (p_i*(count + pseudocount)) )' do
18
18
  PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_pwm(1).matrix.map{|line|line.map{|el| el.round(3)}}.should == [[-0.47, 0.118, 0.486, -0.47],[0.754, -2.079, -0.47, 0.118]]
@@ -26,10 +26,10 @@ module Bioinform
26
26
  PCM.new(matrix: [[1, 2, 3, 1],[4, 0, 1, 2]], name: 'Stub name').to_pwm.name.should == 'Stub name'
27
27
  end
28
28
  end
29
-
29
+
30
30
  describe '#to_ppm' do
31
31
  it 'should return PPM' do
32
- PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_ppm.should be_kind_of(PPM)
32
+ PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_ppm.should be_kind_of(PPM)
33
33
  end
34
34
  it 'should make transformation el --> el / count' do
35
35
  PCM.new([[1, 2, 3, 1],[4, 0, 1, 2]]).to_ppm.should == PPM.new([[1.0/7, 2.0/7, 3.0/7, 1.0/7],[4.0/7, 0.0/7, 1.0/7, 2.0/7]])
@@ -40,6 +40,6 @@ module Bioinform
40
40
  end
41
41
  end
42
42
 
43
-
43
+
44
44
  end
45
45
  end
@@ -2,8 +2,127 @@ require 'spec_helper'
2
2
  require 'bioinform/data_models/pm'
3
3
 
4
4
  module Bioinform
5
- describe PM do
5
+ describe PM do
6
+ {:to_pcm => PCM, :to_pwm => PWM, :to_ppm => PPM}.each do |converter_method, result_klass|
7
+ describe "##{converter_method}" do
8
+ before :each do
9
+ @collection = Collection.new(name: 'Collection 1')
10
+ @matrix = [[1,2,3,4],[5,6,7,8]]
11
+ @name = 'Motif name'
12
+ @background = [0.2,0.3,0.3,0.2]
13
+ @tags = [@collection, 'Collection 2']
14
+ @pm = PM.new(matrix: @matrix, name: @name, background: @background, tags: @tags)
15
+ @conv_motif = @pm.send converter_method
16
+ end
17
+ it "should return an instance of #{result_klass}" do
18
+ @conv_motif.should be_kind_of(result_klass)
19
+ end
20
+ it 'should return have the same matrix, name, background and tags' do
21
+ @conv_motif.matrix.should == @matrix
22
+ @conv_motif.name.should == @name
23
+ @conv_motif.background.should == @background
24
+ @conv_motif.tags.should == @tags
25
+ end
26
+ end
27
+ end
6
28
 
29
+ describe '#tagged?' do
30
+ context 'when PM marked with Collection object' do
31
+ context 'without collection-name' do
32
+ before :each do
33
+ @marking_collection = Collection.new
34
+ @nonmarking_collection = Collection.new
35
+ @pm = PM.new(matrix:[[1,1,1,1]], name:'Motif name')
36
+ @pm.mark(@marking_collection)
37
+ end
38
+ it 'should be true for marking collection' do
39
+ @pm.should be_tagged(@marking_collection)
40
+ end
41
+ it 'should be false for nonmarking collection' do
42
+ @pm.should_not be_tagged(@nonmarking_collection)
43
+ end
44
+ it 'should be false for nil-name' do
45
+ @pm.should_not be_tagged(nil)
46
+ end
47
+ it 'should be false for any string' do
48
+ @pm.should_not be_tagged('Another name')
49
+ end
50
+ end
51
+ context 'with collection-name' do
52
+ before :each do
53
+ @marking_collection = Collection.new(name: 'Collection name')
54
+ @nonmarking_collection = Collection.new(name: 'Another name')
55
+ @pm = PM.new(matrix:[[1,1,1,1]], name:'Motif name')
56
+ @pm.mark(@marking_collection)
57
+ end
58
+ it 'should be true for marking collection' do
59
+ @pm.should be_tagged(@marking_collection)
60
+ end
61
+ it 'should be false for nonmarking collection' do
62
+ @pm.should_not be_tagged(@nonmarking_collection)
63
+ end
64
+ it 'should be true for name of marking collection' do
65
+ @pm.should be_tagged('Collection name')
66
+ end
67
+ it 'should be false for string that is not name of marking collection' do
68
+ @pm.should_not be_tagged('Another name')
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'when PM marked with name' do
74
+ before :each do
75
+ @nonmarking_collection = Collection.new(name: 'Another name')
76
+ @pm = PM.new(matrix:[[1,1,1,1]], name:'Motif name')
77
+ @pm.mark('Mark name')
78
+ end
79
+ it 'should be true for marking name' do
80
+ @pm.should be_tagged('Mark name')
81
+ end
82
+ it 'should be false for string that is not marking name' do
83
+ @pm.should_not be_tagged('Another name')
84
+ end
85
+ it 'should be false for nonmarking collection' do
86
+ @pm.should_not be_tagged(@nonmarking_collection)
87
+ end
88
+ end
89
+
90
+ context 'when PM marked with several marks' do
91
+ before :each do
92
+ @collection_1 = Collection.new(name: 'First name')
93
+ @collection_2 = Collection.new(name: 'Second name')
94
+ @collection_3 = Collection.new(name: 'Nonmarking collection')
95
+ @pm = PM.new(matrix:[[1,1,1,1]], name:'Motif name')
96
+ @pm.mark(@collection_1)
97
+ @pm.mark(@collection_2)
98
+ @pm.mark('Stringy-name')
99
+ end
100
+ it 'should be true for each mark' do
101
+ @pm.should be_tagged(@collection_1)
102
+ @pm.should be_tagged(@collection_2)
103
+ @pm.should be_tagged('Stringy-name')
104
+ end
105
+ it 'should be false for not presented marks' do
106
+ @pm.should_not be_tagged(@collection_3)
107
+ @pm.should_not be_tagged('Bad stringy-name')
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#==' do
113
+ it 'should be true iff motifs have the same matrix, background and name' do
114
+ pm = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif')
115
+ pm_eq = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif')
116
+ pm_neq_matrix = PM.new(matrix: [[1,2,3,4],[15,16,17,18]], name: 'First motif')
117
+ pm_neq_name = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'Second motif')
118
+ pm_neq_background = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif').background!([1,2,2,1])
119
+
120
+ pm.should_not == pm_neq_matrix
121
+ pm.should_not == pm_neq_name
122
+ pm.should_not == pm_neq_background
123
+ pm.should == pm_eq
124
+ end
125
+ end
7
126
  describe '::valid_matrix?' do
8
127
  it 'should be true iff an argument is an array of arrays of 4 numerics in a column' do
9
128
  PM.valid_matrix?( [[1,2,3,4],[1,4,5,6.5]] ).should be_true
@@ -14,7 +133,7 @@ module Bioinform
14
133
  PM.valid_matrix?( [[1,2,'3','4'],[1,'4','5',6.5]] ).should be_false
15
134
  end
16
135
  end
17
-
136
+
18
137
  describe '#to_s' do
19
138
  before :each do
20
139
  @pm = PM.new( [[1,2,3,4],[1,4,5,6.5]] )
@@ -43,7 +162,7 @@ module Bioinform
43
162
  end
44
163
  end
45
164
  end
46
-
165
+
47
166
  describe '#pretty_string' do
48
167
  it 'should format string with 7-chars fields' do
49
168
  PM.new( [[1,2,3,4],[5,6,7,8]] ).pretty_string.should == " A C G T \n 1.0 2.0 3.0 4.0\n 5.0 6.0 7.0 8.0"
@@ -57,7 +176,7 @@ module Bioinform
57
176
  it 'should round floats upto 3 digits' do
58
177
  PM.new( [[1.1,2.22,3.333,4.4444],[5.5,6.66,7.777,8.8888]] ).pretty_string.should match(/1.1 +2.22 +3.333 +4.444 *\n *5.5 +6.66 +7.777 +8.889/)
59
178
  end
60
-
179
+
61
180
  context 'with name specified' do
62
181
  before :each do
63
182
  @pm = PM.new( [[1.1,2.22,3.333,4.4444],[5.5,6.66,7.777,8.8888]] )
@@ -86,14 +205,14 @@ module Bioinform
86
205
  end
87
206
  end
88
207
  end
89
-
208
+
90
209
  describe '#size' do
91
210
  it 'should return number of positions' do
92
211
  @pm = PM.new( [[1,2,3,4],[1,4,5,6.5]] )
93
212
  @pm.size.should == 2
94
213
  end
95
214
  end
96
-
215
+
97
216
  describe '#to_hash' do
98
217
  before :each do
99
218
  @pm = PM.new( [[1,2,3,4],[1,4,5,6.5]] )
@@ -116,7 +235,7 @@ module Bioinform
116
235
  @hsh['T'].should == @hsh[:T]
117
236
  end
118
237
  end
119
-
238
+
120
239
  describe '#background' do
121
240
  before :each do
122
241
  @pm = PM.new( [[1,2,3,4],[1,4,5,6.5]] )
@@ -144,7 +263,7 @@ module Bioinform
144
263
  end
145
264
  end
146
265
  end
147
-
266
+
148
267
  describe '#reverse_complement!' do
149
268
  before :each do
150
269
  @pm = PM.new( [[1, 2, 3, 4], [1, 4, 5, 6.5]] )
@@ -157,7 +276,7 @@ module Bioinform
157
276
  @pm.matrix.should == [[6.5, 5, 4, 1], [4, 3, 2, 1]]
158
277
  end
159
278
  end
160
-
279
+
161
280
  describe '#left_augment!' do
162
281
  before :each do
163
282
  @pm = PM.new( [[1, 2, 3, 4], [1, 4, 5, 6.5]] )
@@ -170,7 +289,7 @@ module Bioinform
170
289
  @pm.matrix.should == [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [1, 2, 3, 4], [1, 4, 5, 6.5]]
171
290
  end
172
291
  end
173
-
292
+
174
293
  describe '#right_augment!' do
175
294
  before :each do
176
295
  @pm = PM.new( [[1, 2, 3, 4], [1, 4, 5, 6.5]] )
@@ -183,20 +302,7 @@ module Bioinform
183
302
  @pm.matrix.should == [[1, 2, 3, 4], [1, 4, 5, 6.5], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]
184
303
  end
185
304
  end
186
-
187
- describe '#shift_to_zero!' do
188
- before :each do
189
- @pm = PM.new( [[1, 2, 3, 4], [5, 6.5, 3, 4]] )
190
- end
191
- it 'should return pm object itself' do
192
- @pm.shift_to_zero!.should be_equal(@pm)
193
- end
194
- it 'should make shift each column' do
195
- @pm.shift_to_zero!
196
- @pm.matrix.should == [[0, 1, 2, 3], [2, 3.5, 0, 1]]
197
- end
198
- end
199
-
305
+
200
306
  describe '#discrete!' do
201
307
  before :each do
202
308
  @pm = PM.new( [[1.3, 2.0, 3.2, 4.9], [6.51, 6.5, 3.25, 4.633]] )
@@ -215,7 +321,7 @@ module Bioinform
215
321
  @pm.matrix.should == [[13, 20, 32, 49], [66, 65, 33, 47]]
216
322
  end
217
323
  end
218
-
324
+
219
325
  describe '#vocabulary_volume' do
220
326
  before :each do
221
327
  @pm_2_positions = PM.new( [[1.3, 2.0, 3.2, 4.9], [5.0, 6.5, 3.2, 4.6]] )
@@ -231,13 +337,13 @@ module Bioinform
231
337
  it 'should be 1.0' do
232
338
  @pm_2_positions.background( [0.2, 0.3, 0.3, 0.2] )
233
339
  @pm_2_positions.vocabulary_volume.should == 1.0
234
-
340
+
235
341
  @pm_3_positions.background( [0.2, 0.3, 0.3, 0.2] )
236
342
  @pm_3_positions.vocabulary_volume.should == 1.0
237
343
  end
238
344
  end
239
345
  end
240
-
346
+
241
347
  describe '#best_score' do
242
348
  it 'should be equal to best score' do
243
349
  @pm = PM.new( [[1.3, 2.0, 4.9, 3.2], [7.13, 6.5, 3.25, 4.633], [-1.0, -1.0, -1.5, -1.0]] )
@@ -250,7 +356,7 @@ module Bioinform
250
356
  @pm.worst_score.should == 1.3 + 3.25 + (-1.5)
251
357
  end
252
358
  end
253
-
359
+
254
360
  describe '#best_suffix' do
255
361
  it 'should return maximal score of suffices from i-th position inclusively i.e. [i..end]' do
256
362
  @pm = PM.new( [[1.3, 2.0, 4.9, 3.2], [7.13, 6.5, 3.25, 4.633], [-1.0, -1.0, -1.5, -1.0]] )
@@ -276,7 +382,7 @@ module Bioinform
276
382
  end
277
383
  end
278
384
 
279
- [:shift_to_zero, :reverse_complement].each do |meth|
385
+ [:reverse_complement].each do |meth|
280
386
  describe "nonbang method #{meth}" do
281
387
  before :each do
282
388
  @pm = PM.new( [[1.3, 2.0, 4.9, 3.2], [7.13, 6.5, 3.25, 4.633], [-1.0, -1.0, -1.5, -1.0]] )
@@ -290,7 +396,7 @@ module Bioinform
290
396
  end
291
397
  end
292
398
  end
293
-
399
+
294
400
  [:discrete , :left_augment, :right_augment].each do |meth|
295
401
  describe "nonbang method #{meth}" do
296
402
  before :each do
@@ -3,6 +3,6 @@ require 'bioinform/data_models/pcm'
3
3
 
4
4
  module Bioinform
5
5
  describe PPM do
6
-
6
+
7
7
  end
8
8
  end
@@ -13,10 +13,10 @@ module Bioinform
13
13
  pwm.score_mean.should == ((0.2*1+0.3*2+0.3*1+0.2*2) + (0.2*4+0.3*6+0.3*8+0.2*6) + (0.2*2+0.3*2+0.3*2+0.2*2)) / (0.2+0.3+0.3+0.2)
14
14
  end
15
15
  end
16
-
16
+
17
17
  describe '#score_variance' do
18
18
  end
19
-
19
+
20
20
  describe '#gauss_estimation' do
21
21
  end
22
22
 
@@ -14,7 +14,7 @@ module Bioinform
14
14
  Parser.new([1,2,3,4]).parse.should == Parser.new([[1,2,3,4]]).parse
15
15
  end
16
16
  end
17
-
17
+
18
18
  context '::parse!' do
19
19
  it 'should behave like Parser.new(input).parse!' do
20
20
  Parser.parse!([1,2,3,4],[5,6,7,8]).should == Parser.new([1,2,3,4],[5,6,7,8]).parse!
@@ -27,7 +27,7 @@ module Bioinform
27
27
  Parser.parse([1,2,3],[4,5,6]).should be_nil
28
28
  end
29
29
  end
30
-
30
+
31
31
  context '::choose' do
32
32
  it 'should create parser of appropriate type' do
33
33
  Parser.choose([[1,2,3,4],[5,6,7,8]]).should be_kind_of(Parser)
@@ -37,16 +37,16 @@ module Bioinform
37
37
  Parser.choose("1 2 3 4\n5 6 7 8").should be_kind_of(StringParser)
38
38
  Parser.choose("1 2 3 4\n5 6 7 8").input.should == "1 2 3 4\n5 6 7 8"
39
39
  end
40
-
40
+
41
41
  end
42
42
 
43
-
43
+
44
44
  context '::normalize_hash_keys' do
45
45
  it 'should convert both symbolic and string keys, in both upcase and downcase to symbolic upcases' do
46
46
  Parser.normalize_hash_keys( {a: 1, C: 2, 'g' => 3, 'T' => 4} ).should == {A: 1, C: 2, G: 3, T: 4}
47
47
  end
48
48
  end
49
-
49
+
50
50
  context '::need_transpose?' do
51
51
  it 'should point whether matrix have positions(need not be transposed -- false) or letters(true) as first index' do
52
52
  Parser.need_tranpose?([[1,3,5,7], [2,4,6,8]]).should be_false
@@ -82,7 +82,7 @@ module Bioinform
82
82
  Parser.try_convert_to_array( {:A => [1,2,3], :c => [2,3,4], 'g' => [3,4,5], 'T' => [4,5,6]} ).should == [[1,2,3],[2,3,4],[3,4,5],[4,5,6]].transpose
83
83
  end
84
84
  end
85
-
85
+
86
86
  context '#parse' do
87
87
  it 'should give the same result as #parse!' do
88
88
  parser = Parser.new('stub parser')
@@ -95,61 +95,61 @@ module Bioinform
95
95
  parser.parse.should be_nil
96
96
  end
97
97
  end
98
-
98
+
99
99
  good_cases = {
100
- 'Array Nx4' => {input: [[0,1,2,3],[10,11,12,13]],
100
+ 'Array Nx4' => {input: [[0,1,2,3],[10,11,12,13]],
101
101
  matrix: [[0,1,2,3],[10,11,12,13]] },
102
-
102
+
103
103
  'Array 4xN' => {input: [[0,10],[1,11],[2,12],[3,13]],
104
104
  matrix: [[0,1,2,3],[10,11,12,13]] },
105
-
106
- 'Hash A,C,G,T => Arrays' => { input: {:A => [0,10], :c => [1,11],'g' => [2,12],'T' => [3,13]},
105
+
106
+ 'Hash A,C,G,T => Arrays' => { input: {:A => [0,10], :c => [1,11],'g' => [2,12],'T' => [3,13]},
107
107
  matrix: [[0,1,2,3],[10,11,12,13]] },
108
-
108
+
109
109
  'Hash array of hashes' => { input: [{:A => 0,:c => 1,'g' => 2,'T' => 3}, {:A => 10,:c => 11,'g' => 12,'T' => 13}],
110
110
  matrix: [[0,1,2,3],[10,11,12,13]] },
111
-
111
+
112
112
  'Array 4x4 (rows treated as positions, columns are treated as letter)' => { input: [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]],
113
113
  matrix: [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]] },
114
-
114
+
115
115
  'Hash A,C,G,T => 4-Arrays' => { input: {:A => [0,10,100,1000], :c => [1,11,101,1001],'g' => [2,12,102,1002],'T' => [3,13,103,1003]},
116
116
  matrix: [[0,1,2,3],[10,11,12,13],[100,101,102,103],[1000,1001,1002,1003]] },
117
-
117
+
118
118
  '4-Arrays of A,C,G,T hashes' => { input: [{:A => 0, :c => 1, 'g' => 2, 'T' => 3},
119
119
  {:A => 10, :c => 11, 'g' => 12, 'T' => 13},
120
120
  {:A => 100, :c => 101, 'g' => 102, 'T' => 103},
121
121
  {:A => 1000, :c => 1001, 'g' => 1002, 'T' => 1003}],
122
122
  matrix: [[0,1,2,3],[10,11,12,13],[100,101,102,103],[1000,1001,1002,1003]] }
123
123
  }
124
-
124
+
125
125
  bad_cases = {
126
126
  'Nil object on input' => {input: nil},
127
-
127
+
128
128
  'Empty array on input' => {input: []},
129
-
129
+
130
130
  'Different sizes of row arrays' => {input: [[1,2,3,4],[5,6,7,8,9]] },
131
-
131
+
132
132
  'Different sizes of column arrays' => {input: [[0,10],[1,11],[2,12],[3]] },
133
-
133
+
134
134
  'No one dimension have size 4' => {input: [[0,1,2,3,4],[10,11,12,13,14], [0,1,2,3,4]] },
135
-
135
+
136
136
  'Missing keys in column hashes' => {input: [{:A => 0, :c => 1, 'g' => 2, 'T' => 3},
137
137
  {:A => 10, :c => 11, 'g' => 12}] },
138
138
  'Bad keys in column hashes' => {input: [{:A => 0, :c => 1, 'g' => 2, 'T' => 3},
139
139
  {:A => 10, :c => 11, 'g' => 12, :X =>1000}] },
140
-
140
+
141
141
  'Excessing keys in column hashes' => { input: [{:A => 0,:c => 1,'g' => 2,'T' => 3},
142
142
  {:A => 10,:c => 11,'g' => 12,'T' => 13, :X => 1000}] },
143
143
 
144
144
  'Different sizes of row hashes' => {input: {:A => [0,10], :c => [1,11],'g' => [2,12],'T' => [3,13,14]} },
145
-
145
+
146
146
  'Missing keys in row hashes' => {input: {:A => [0,10], :c => [1,11],'g' => [2,12]} },
147
-
147
+
148
148
  'Wrong keys in row hashes' => {input: {:A => [0,10], :c => [1,11],'X' => [2,12]} },
149
-
149
+
150
150
  'Excessing keys in row hashes' => {input: {:A => [0,10], :c => [1,11],'g' => [2,12], 'T' => [3,12], :X => [4,14]} }
151
151
  }
152
-
152
+
153
153
  parser_specs(Parser, good_cases, bad_cases)
154
154
  context '#parser!' do
155
155
  it "should raise an exception on parsing empty list to parser" do