bioinform 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/Gemfile +16 -16
  4. data/LICENSE +21 -21
  5. data/README.md +35 -35
  6. data/Rakefile +4 -4
  7. data/TODO.txt +37 -37
  8. data/bin/merge_into_collection +3 -3
  9. data/bin/pcm2pwm +3 -3
  10. data/bin/split_motifs +3 -3
  11. data/bioinform.gemspec +19 -19
  12. data/lib/bioinform/cli/convert_motif.rb +107 -107
  13. data/lib/bioinform/cli/merge_into_collection.rb +79 -79
  14. data/lib/bioinform/cli/pcm2pwm.rb +46 -46
  15. data/lib/bioinform/cli/split_motifs.rb +46 -46
  16. data/lib/bioinform/cli.rb +29 -29
  17. data/lib/bioinform/conversion_algorithms/pcm2ppm_converter.rb +18 -18
  18. data/lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb +19 -19
  19. data/lib/bioinform/data_models/collection.rb +74 -74
  20. data/lib/bioinform/data_models/motif.rb +55 -55
  21. data/lib/bioinform/data_models/pcm.rb +23 -23
  22. data/lib/bioinform/data_models/pm.rb +169 -169
  23. data/lib/bioinform/data_models/ppm.rb +9 -9
  24. data/lib/bioinform/data_models/pwm.rb +55 -55
  25. data/lib/bioinform/data_models.rb +10 -10
  26. data/lib/bioinform/formatters/raw_formatter.rb +40 -40
  27. data/lib/bioinform/formatters/transfac_formatter.rb +38 -38
  28. data/lib/bioinform/formatters.rb +1 -1
  29. data/lib/bioinform/parsers/jaspar_parser.rb +34 -34
  30. data/lib/bioinform/parsers/parser.rb +87 -87
  31. data/lib/bioinform/parsers/splittable_parser.rb +56 -56
  32. data/lib/bioinform/parsers/string_fantom_parser.rb +34 -34
  33. data/lib/bioinform/parsers/string_parser.rb +71 -71
  34. data/lib/bioinform/parsers/trivial_parser.rb +33 -33
  35. data/lib/bioinform/parsers/yaml_parser.rb +34 -34
  36. data/lib/bioinform/parsers.rb +6 -6
  37. data/lib/bioinform/support/array_product.rb +5 -5
  38. data/lib/bioinform/support/array_zip.rb +5 -5
  39. data/lib/bioinform/support/collect_hash.rb +6 -6
  40. data/lib/bioinform/support/deep_dup.rb +4 -4
  41. data/lib/bioinform/support/delete_many.rb +13 -13
  42. data/lib/bioinform/support/inverf.rb +12 -12
  43. data/lib/bioinform/support/multiline_squish.rb +5 -5
  44. data/lib/bioinform/support/parameters.rb +27 -27
  45. data/lib/bioinform/support/partial_sums.rb +15 -15
  46. data/lib/bioinform/support/same_by.rb +12 -12
  47. data/lib/bioinform/support/strip_doc.rb +8 -8
  48. data/lib/bioinform/support/third_part/active_support/hash_with_indifferent_access.rb +3 -0
  49. data/lib/bioinform/support.rb +17 -17
  50. data/lib/bioinform/version.rb +3 -3
  51. data/lib/bioinform.rb +10 -10
  52. data/spec/cli/cli_spec.rb +13 -13
  53. data/spec/cli/convert_motif_spec.rb +106 -106
  54. data/spec/cli/data/merge_into_collection/GABPA_f1.pwm +14 -14
  55. data/spec/cli/data/merge_into_collection/KLF4_f2.pwm +11 -11
  56. data/spec/cli/data/merge_into_collection/SP1_f1.pwm +12 -12
  57. data/spec/cli/data/merge_into_collection/collection.txt.result +40 -40
  58. data/spec/cli/data/merge_into_collection/collection.yaml.result +188 -188
  59. data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +188 -188
  60. data/spec/cli/data/merge_into_collection/pwm_folder/GABPA_f1.pwm +14 -14
  61. data/spec/cli/data/merge_into_collection/pwm_folder/KLF4_f2.pwm +11 -11
  62. data/spec/cli/data/merge_into_collection/pwm_folder/SP1_f1.pwm +12 -12
  63. data/spec/cli/data/pcm2pwm/KLF4 f2 spaced name.pcm +11 -11
  64. data/spec/cli/data/pcm2pwm/KLF4_f2.pcm +11 -11
  65. data/spec/cli/data/pcm2pwm/KLF4_f2.pwm.result +11 -11
  66. data/spec/cli/data/pcm2pwm/SP1_f1.pcm +12 -12
  67. data/spec/cli/data/pcm2pwm/SP1_f1.pwm.result +12 -12
  68. data/spec/cli/data/split_motifs/GABPA_f1.mat.result +14 -14
  69. data/spec/cli/data/split_motifs/KLF4_f2.mat.result +11 -11
  70. data/spec/cli/data/split_motifs/SP1_f1.mat.result +12 -12
  71. data/spec/cli/data/split_motifs/collection.yaml +188 -188
  72. data/spec/cli/data/split_motifs/plain_collection.txt +38 -38
  73. data/spec/cli/merge_into_collection_spec.rb +99 -99
  74. data/spec/cli/pcm2pwm_spec.rb +79 -79
  75. data/spec/cli/shared_examples/convert_motif/motif_list_empty.rb +17 -17
  76. data/spec/cli/shared_examples/convert_motif/several_motifs_specified.rb +14 -14
  77. data/spec/cli/shared_examples/convert_motif/single_motif_specified.rb +49 -49
  78. data/spec/cli/shared_examples/convert_motif/yield_help_string.rb +4 -4
  79. data/spec/cli/shared_examples/convert_motif/yield_motif_conversion_error.rb +3 -3
  80. data/spec/cli/split_motifs_spec.rb +76 -76
  81. data/spec/data_models/collection_spec.rb +97 -97
  82. data/spec/data_models/motif_spec.rb +223 -223
  83. data/spec/data_models/pcm_spec.rb +55 -55
  84. data/spec/data_models/pm_spec.rb +359 -359
  85. data/spec/data_models/ppm_spec.rb +7 -7
  86. data/spec/data_models/pwm_spec.rb +82 -82
  87. data/spec/fabricators/collection_fabricator.rb +7 -7
  88. data/spec/fabricators/motif_fabricator.rb +32 -32
  89. data/spec/fabricators/motif_formats_fabricator.rb +124 -124
  90. data/spec/fabricators/pcm_fabricator.rb +24 -24
  91. data/spec/fabricators/pm_fabricator.rb +51 -51
  92. data/spec/fabricators/ppm_fabricator.rb +13 -13
  93. data/spec/fabricators/pwm_fabricator.rb +16 -16
  94. data/spec/parsers/parser_spec.rb +152 -152
  95. data/spec/parsers/string_fantom_parser_spec.rb +69 -69
  96. data/spec/parsers/string_parser_spec.rb +76 -76
  97. data/spec/parsers/trivial_parser_spec.rb +63 -63
  98. data/spec/parsers/yaml_parser_spec.rb +50 -50
  99. data/spec/spec_helper.rb +10 -10
  100. data/spec/spec_helper_source.rb +59 -59
  101. data/spec/support/advanced_scan_spec.rb +31 -31
  102. data/spec/support/array_product_spec.rb +14 -14
  103. data/spec/support/array_zip_spec.rb +14 -14
  104. data/spec/support/collect_hash_spec.rb +14 -14
  105. data/spec/support/delete_many_spec.rb +43 -43
  106. data/spec/support/inverf_spec.rb +18 -18
  107. data/spec/support/multiline_squish_spec.rb +24 -24
  108. data/spec/support/partial_sums_spec.rb +30 -30
  109. data/spec/support/same_by_spec.rb +35 -35
  110. metadata +3 -3
@@ -1,224 +1,224 @@
1
- require_relative '../../lib/bioinform/data_models/motif'
2
-
3
- shared_examples 'when pm is PM' do
4
- context 'when pm-value is a PCM' do
5
- let(:pm) { Fabricate(:pcm) }
6
- it 'sets pcm-attribute to specified PM' do
7
- subject.pcm.should == Fabricate(:pcm)
8
- end
9
- end
10
- context 'when pm-value is a PWM' do
11
- let(:pm) { Fabricate(:pwm) }
12
- it 'sets pwm-attribute to specified PM' do
13
- subject.pwm.should == Fabricate(:pwm)
14
- end
15
- end
16
- context 'when pm-value is a PPM' do
17
- let(:pm) { Fabricate(:ppm) }
18
- it 'sets ppm-attribute to specified PM' do
19
- subject.ppm.should == Fabricate(:ppm)
20
- end
21
- end
22
- context 'when pm-value is a PM' do
23
- let(:pm) { Fabricate(:pm) }
24
- it 'sets only parameter pm attribute to specified PM' do
25
- subject.parameters.pm.should == Fabricate(:pm)
26
- subject.pcm.should be_nil
27
- subject.pwm.should be_nil
28
- subject.ppm.should be_nil
29
- end
30
- end
31
- end
32
-
33
-
34
- module Bioinform
35
- describe Motif do
36
- describe '.new' do
37
- it 'accepts empty argument list' do
38
- expect{ described_class.new }.to_not raise_error
39
- end
40
-
41
- context 'when argument is a Hash' do
42
- subject{ described_class.new(hash) }
43
- context 'which contains usual symbolic parameters' do
44
- let(:hash){ {:a => 123, :key => 'value', :threshold => {0.1 => 15} } }
45
- it 'sets its content as parameters' do
46
- subject.parameters.a.should == 123
47
- subject.parameters.key.should == 'value'
48
- subject.parameters.threshold.should == {0.1 => 15}
49
- end
50
- end
51
- context 'which contains any combination of :pwm, :pcm and :ppm keys' do
52
- let(:hash) { {pcm: 'my_pcm', ppm: 'my_ppm'} }
53
- it 'sets corresponding attributes to specified values' do
54
- subject.pcm.should == 'my_pcm'
55
- subject.ppm.should == 'my_ppm'
56
- end
57
- end
58
- end
59
-
60
- context 'when argument is a Hash with pm-key' do
61
- subject{ described_class.new(pm: pm) }
62
-
63
- include_examples 'when pm is PM'
64
-
65
- context 'when pm-value is a usual object' do
66
- let(:pm) { 'stub pm' }
67
- it 'sets only parameter pm attribute to specified value' do
68
- subject.parameters.pm.should == 'stub pm'
69
- subject.pcm.should be_nil
70
- subject.pwm.should be_nil
71
- subject.ppm.should be_nil
72
- end
73
- end
74
- end
75
- context 'when argument is neither PM nor Hash' do
76
- it 'raises ArgumentError' do
77
- expect{ described_class.new('stub pm') }.to raise_error(ArgumentError)
78
- end
79
- end
80
- end
81
-
82
- ########################################################
83
- describe '#pcm' do
84
- subject { motif.pcm }
85
- context 'when pcm is set' do
86
- context 'when pwm and ppm aren\'t setted' do
87
- let(:motif) { Fabricate(:motif_pcm) }
88
- it 'returns setted pcm' do
89
- subject.should == Fabricate(:pcm)
90
- end
91
- end
92
- context 'when ppm also setted' do
93
- let(:motif) { Fabricate(:motif_pcm_and_ppm) }
94
- it 'returns setted pcm' do
95
- subject.should == Fabricate(:pcm)
96
- end
97
- end
98
- context 'when pwm also setted' do
99
- let(:motif) { Fabricate(:motif_pcm_and_pwm) }
100
- it 'returns setted pcm' do
101
- subject.should == Fabricate(:pcm)
102
- end
103
- end
104
- end
105
-
106
- context 'when pcm isn\'t set' do
107
- context 'when nothing set' do
108
- let(:motif) { Fabricate(:motif) }
109
- it 'returns nil' do
110
- subject.should be_nil
111
- end
112
- end
113
- context 'when pwm setted' do
114
- let(:motif) { Fabricate(:motif_pwm) }
115
- it 'returns nil' do
116
- subject.should be_nil
117
- end
118
- end
119
- context 'when ppm setted' do
120
- let(:motif) { Fabricate(:motif_ppm) }
121
- it 'returns nil' do
122
- subject.should be_nil
123
- end
124
- end
125
- end
126
- end
127
- ############################################
128
- describe '#pwm' do
129
- subject { motif.pwm }
130
- context 'when pwm is set' do
131
- context 'when pcm and ppm aren\'t setted' do
132
- let(:motif) { Fabricate(:motif_pwm) }
133
- it 'returns setted pwm' do
134
- subject.should == Fabricate(:pwm)
135
- end
136
- end
137
- context 'when ppm also setted' do
138
- let(:motif) { Fabricate(:motif_pwm_and_ppm) }
139
- it 'returns setted pwm' do
140
- subject.should == Fabricate(:pwm)
141
- end
142
- end
143
- context 'when pcm also setted' do
144
- let(:motif) { Fabricate(:motif_pcm_and_pwm) }
145
- it 'returns setted pwm' do
146
- subject.should == Fabricate(:pwm)
147
- end
148
- end
149
- end
150
-
151
- context 'when pwm isn\'t set' do
152
- context 'when nothing set' do
153
- let(:motif) { Fabricate(:motif) }
154
- it 'returns nil' do
155
- subject.should be_nil
156
- end
157
- end
158
- context 'when pcm setted' do
159
- let(:motif) { Fabricate(:motif_pcm) }
160
- it 'returns pcm converted to pwm' do
161
- subject.should == Fabricate(:pwm_by_pcm)
162
- end
163
- end
164
- context 'when ppm setted' do
165
- let(:motif) { Fabricate(:motif_ppm) }
166
- it 'returns nil' do
167
- subject.should be_nil
168
- end
169
- end
170
- end
171
- end
172
-
173
- ############################################
174
- describe '#ppm' do
175
- subject { motif.ppm }
176
- context 'when ppm is set' do
177
- context 'when pcm and pwm aren\'t setted' do
178
- let(:motif) { Fabricate(:motif_ppm) }
179
- it 'returns setted ppm' do
180
- subject.should == Fabricate(:ppm)
181
- end
182
- end
183
- context 'when pcm also setted' do
184
- let(:motif) { Fabricate(:motif_pcm_and_ppm) }
185
- it 'returns setted ppm' do
186
- subject.should == Fabricate(:ppm)
187
- end
188
- end
189
- context 'when pwm also setted' do
190
- let(:motif) { Fabricate(:motif_pwm_and_ppm) }
191
- it 'returns setted ppm' do
192
- subject.should == Fabricate(:ppm)
193
- end
194
- end
195
- end
196
-
197
- context 'when ppm isn\'t set' do
198
- context 'when nothing set' do
199
- let(:motif) { Fabricate(:motif) }
200
- it 'returns nil' do
201
- subject.should be_nil
202
- end
203
- end
204
- context 'when pcm setted' do
205
- let(:motif) { Fabricate(:motif_pcm) }
206
- it 'returns pcm converted to ppm' do
207
- subject.should == Fabricate(:ppm_by_pcm)
208
- end
209
- end
210
- context 'when pwm setted' do
211
- let(:motif) { Fabricate(:motif_pwm) }
212
- it 'returns nil' do
213
- subject.should be_nil
214
- end
215
- end
216
- end
217
- end
218
-
219
-
220
-
221
-
222
-
223
- end
1
+ require_relative '../../lib/bioinform/data_models/motif'
2
+
3
+ shared_examples 'when pm is PM' do
4
+ context 'when pm-value is a PCM' do
5
+ let(:pm) { Fabricate(:pcm) }
6
+ it 'sets pcm-attribute to specified PM' do
7
+ subject.pcm.should == Fabricate(:pcm)
8
+ end
9
+ end
10
+ context 'when pm-value is a PWM' do
11
+ let(:pm) { Fabricate(:pwm) }
12
+ it 'sets pwm-attribute to specified PM' do
13
+ subject.pwm.should == Fabricate(:pwm)
14
+ end
15
+ end
16
+ context 'when pm-value is a PPM' do
17
+ let(:pm) { Fabricate(:ppm) }
18
+ it 'sets ppm-attribute to specified PM' do
19
+ subject.ppm.should == Fabricate(:ppm)
20
+ end
21
+ end
22
+ context 'when pm-value is a PM' do
23
+ let(:pm) { Fabricate(:pm) }
24
+ it 'sets only parameter pm attribute to specified PM' do
25
+ subject.parameters.pm.should == Fabricate(:pm)
26
+ subject.pcm.should be_nil
27
+ subject.pwm.should be_nil
28
+ subject.ppm.should be_nil
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ module Bioinform
35
+ describe Motif do
36
+ describe '.new' do
37
+ it 'accepts empty argument list' do
38
+ expect{ described_class.new }.to_not raise_error
39
+ end
40
+
41
+ context 'when argument is a Hash' do
42
+ subject{ described_class.new(hash) }
43
+ context 'which contains usual symbolic parameters' do
44
+ let(:hash){ {:a => 123, :key => 'value', :threshold => {0.1 => 15} } }
45
+ it 'sets its content as parameters' do
46
+ subject.parameters.a.should == 123
47
+ subject.parameters.key.should == 'value'
48
+ subject.parameters.threshold.should == {0.1 => 15}
49
+ end
50
+ end
51
+ context 'which contains any combination of :pwm, :pcm and :ppm keys' do
52
+ let(:hash) { {pcm: 'my_pcm', ppm: 'my_ppm'} }
53
+ it 'sets corresponding attributes to specified values' do
54
+ subject.pcm.should == 'my_pcm'
55
+ subject.ppm.should == 'my_ppm'
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'when argument is a Hash with pm-key' do
61
+ subject{ described_class.new(pm: pm) }
62
+
63
+ include_examples 'when pm is PM'
64
+
65
+ context 'when pm-value is a usual object' do
66
+ let(:pm) { 'stub pm' }
67
+ it 'sets only parameter pm attribute to specified value' do
68
+ subject.parameters.pm.should == 'stub pm'
69
+ subject.pcm.should be_nil
70
+ subject.pwm.should be_nil
71
+ subject.ppm.should be_nil
72
+ end
73
+ end
74
+ end
75
+ context 'when argument is neither PM nor Hash' do
76
+ it 'raises ArgumentError' do
77
+ expect{ described_class.new('stub pm') }.to raise_error(ArgumentError)
78
+ end
79
+ end
80
+ end
81
+
82
+ ########################################################
83
+ describe '#pcm' do
84
+ subject { motif.pcm }
85
+ context 'when pcm is set' do
86
+ context 'when pwm and ppm aren\'t setted' do
87
+ let(:motif) { Fabricate(:motif_pcm) }
88
+ it 'returns setted pcm' do
89
+ subject.should == Fabricate(:pcm)
90
+ end
91
+ end
92
+ context 'when ppm also setted' do
93
+ let(:motif) { Fabricate(:motif_pcm_and_ppm) }
94
+ it 'returns setted pcm' do
95
+ subject.should == Fabricate(:pcm)
96
+ end
97
+ end
98
+ context 'when pwm also setted' do
99
+ let(:motif) { Fabricate(:motif_pcm_and_pwm) }
100
+ it 'returns setted pcm' do
101
+ subject.should == Fabricate(:pcm)
102
+ end
103
+ end
104
+ end
105
+
106
+ context 'when pcm isn\'t set' do
107
+ context 'when nothing set' do
108
+ let(:motif) { Fabricate(:motif) }
109
+ it 'returns nil' do
110
+ subject.should be_nil
111
+ end
112
+ end
113
+ context 'when pwm setted' do
114
+ let(:motif) { Fabricate(:motif_pwm) }
115
+ it 'returns nil' do
116
+ subject.should be_nil
117
+ end
118
+ end
119
+ context 'when ppm setted' do
120
+ let(:motif) { Fabricate(:motif_ppm) }
121
+ it 'returns nil' do
122
+ subject.should be_nil
123
+ end
124
+ end
125
+ end
126
+ end
127
+ ############################################
128
+ describe '#pwm' do
129
+ subject { motif.pwm }
130
+ context 'when pwm is set' do
131
+ context 'when pcm and ppm aren\'t setted' do
132
+ let(:motif) { Fabricate(:motif_pwm) }
133
+ it 'returns setted pwm' do
134
+ subject.should == Fabricate(:pwm)
135
+ end
136
+ end
137
+ context 'when ppm also setted' do
138
+ let(:motif) { Fabricate(:motif_pwm_and_ppm) }
139
+ it 'returns setted pwm' do
140
+ subject.should == Fabricate(:pwm)
141
+ end
142
+ end
143
+ context 'when pcm also setted' do
144
+ let(:motif) { Fabricate(:motif_pcm_and_pwm) }
145
+ it 'returns setted pwm' do
146
+ subject.should == Fabricate(:pwm)
147
+ end
148
+ end
149
+ end
150
+
151
+ context 'when pwm isn\'t set' do
152
+ context 'when nothing set' do
153
+ let(:motif) { Fabricate(:motif) }
154
+ it 'returns nil' do
155
+ subject.should be_nil
156
+ end
157
+ end
158
+ context 'when pcm setted' do
159
+ let(:motif) { Fabricate(:motif_pcm) }
160
+ it 'returns pcm converted to pwm' do
161
+ subject.should == Fabricate(:pwm_by_pcm)
162
+ end
163
+ end
164
+ context 'when ppm setted' do
165
+ let(:motif) { Fabricate(:motif_ppm) }
166
+ it 'returns nil' do
167
+ subject.should be_nil
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ ############################################
174
+ describe '#ppm' do
175
+ subject { motif.ppm }
176
+ context 'when ppm is set' do
177
+ context 'when pcm and pwm aren\'t setted' do
178
+ let(:motif) { Fabricate(:motif_ppm) }
179
+ it 'returns setted ppm' do
180
+ subject.should == Fabricate(:ppm)
181
+ end
182
+ end
183
+ context 'when pcm also setted' do
184
+ let(:motif) { Fabricate(:motif_pcm_and_ppm) }
185
+ it 'returns setted ppm' do
186
+ subject.should == Fabricate(:ppm)
187
+ end
188
+ end
189
+ context 'when pwm also setted' do
190
+ let(:motif) { Fabricate(:motif_pwm_and_ppm) }
191
+ it 'returns setted ppm' do
192
+ subject.should == Fabricate(:ppm)
193
+ end
194
+ end
195
+ end
196
+
197
+ context 'when ppm isn\'t set' do
198
+ context 'when nothing set' do
199
+ let(:motif) { Fabricate(:motif) }
200
+ it 'returns nil' do
201
+ subject.should be_nil
202
+ end
203
+ end
204
+ context 'when pcm setted' do
205
+ let(:motif) { Fabricate(:motif_pcm) }
206
+ it 'returns pcm converted to ppm' do
207
+ subject.should == Fabricate(:ppm_by_pcm)
208
+ end
209
+ end
210
+ context 'when pwm setted' do
211
+ let(:motif) { Fabricate(:motif_pwm) }
212
+ it 'returns nil' do
213
+ subject.should be_nil
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+
220
+
221
+
222
+
223
+ end
224
224
  end
@@ -1,56 +1,56 @@
1
- require_relative '../spec_helper'
2
- require_relative '../../lib/bioinform/data_models/pcm'
3
-
4
- module Bioinform
5
- describe PCM do
6
- describe '#count' do
7
- it 'should be equal to sum of elements at position' do
8
- Fabricate(:pcm).count.should == 7
9
- Fabricate(:pcm_with_floats).count.should == 7.5
10
- end
11
- end
12
-
13
- describe '#to_pwm' do
14
- subject{ Fabricate(:pcm) }
15
- it 'should return PWM' do
16
- Fabricate(:pcm).to_pwm.should be_kind_of(PWM)
17
- end
18
- it 'should make transformation: el --> log( (el + p_i*pseudocount) / (p_i*(count + pseudocount)) )' do
19
- subject.to_pwm(1).matrix.map{|line|line.map{|el| el.round(3)}}.should == Fabricate(:rounded_upto_3_digits_pwm_by_pcm_with_pseudocount_1).matrix
20
- subject.to_pwm(10).matrix.map{|line|line.map{|el| el.round(3)}}.should == Fabricate(:rounded_upto_3_digits_pwm_by_pcm_with_pseudocount_10).matrix
21
- end
22
- it 'should use default pseudocount equal to log(count)' do
23
- Fabricate(:pcm).to_pwm.should == Fabricate(:pcm).to_pwm(Math.log(7))
24
- end
25
- it 'should preserve name' do
26
- Fabricate(:pcm, name: nil).to_pwm.name.should be_nil
27
- Fabricate(:pcm, name: 'Stub name').to_pwm.name.should == 'Stub name'
28
- end
29
- end
30
-
31
- describe '#to_ppm' do
32
- let(:pcm_motif) { Fabricate(:pcm) }
33
- context 'returned object' do
34
- subject{ pcm_motif.to_ppm }
35
- it { should be_kind_of(PPM)}
36
- it 'should have matrix transformed with el --> el / count' do
37
- subject.matrix.should == Fabricate(:ppm_pcm_divided_by_count).matrix
38
- end
39
- context 'when source PCM name is absent' do
40
- let(:pcm_motif) { Fabricate(:pcm, name: nil) }
41
- it 'should have no name' do
42
- subject.name.should be_nil
43
- end
44
- end
45
- context 'when source PCM has name' do
46
- let(:pcm_motif) { Fabricate(:pcm, name: 'Stub-name') }
47
- it 'should has the same name' do
48
- subject.name.should == 'Stub-name'
49
- end
50
- end
51
- end
52
- end
53
-
54
-
55
- end
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/pcm'
3
+
4
+ module Bioinform
5
+ describe PCM do
6
+ describe '#count' do
7
+ it 'should be equal to sum of elements at position' do
8
+ Fabricate(:pcm).count.should == 7
9
+ Fabricate(:pcm_with_floats).count.should == 7.5
10
+ end
11
+ end
12
+
13
+ describe '#to_pwm' do
14
+ subject{ Fabricate(:pcm) }
15
+ it 'should return PWM' do
16
+ Fabricate(:pcm).to_pwm.should be_kind_of(PWM)
17
+ end
18
+ it 'should make transformation: el --> log( (el + p_i*pseudocount) / (p_i*(count + pseudocount)) )' do
19
+ subject.to_pwm(1).matrix.map{|line|line.map{|el| el.round(3)}}.should == Fabricate(:rounded_upto_3_digits_pwm_by_pcm_with_pseudocount_1).matrix
20
+ subject.to_pwm(10).matrix.map{|line|line.map{|el| el.round(3)}}.should == Fabricate(:rounded_upto_3_digits_pwm_by_pcm_with_pseudocount_10).matrix
21
+ end
22
+ it 'should use default pseudocount equal to log(count)' do
23
+ Fabricate(:pcm).to_pwm.should == Fabricate(:pcm).to_pwm(Math.log(7))
24
+ end
25
+ it 'should preserve name' do
26
+ Fabricate(:pcm, name: nil).to_pwm.name.should be_nil
27
+ Fabricate(:pcm, name: 'Stub name').to_pwm.name.should == 'Stub name'
28
+ end
29
+ end
30
+
31
+ describe '#to_ppm' do
32
+ let(:pcm_motif) { Fabricate(:pcm) }
33
+ context 'returned object' do
34
+ subject{ pcm_motif.to_ppm }
35
+ it { should be_kind_of(PPM)}
36
+ it 'should have matrix transformed with el --> el / count' do
37
+ subject.matrix.should == Fabricate(:ppm_pcm_divided_by_count).matrix
38
+ end
39
+ context 'when source PCM name is absent' do
40
+ let(:pcm_motif) { Fabricate(:pcm, name: nil) }
41
+ it 'should have no name' do
42
+ subject.name.should be_nil
43
+ end
44
+ end
45
+ context 'when source PCM has name' do
46
+ let(:pcm_motif) { Fabricate(:pcm, name: 'Stub-name') }
47
+ it 'should has the same name' do
48
+ subject.name.should == 'Stub-name'
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ end
56
56
  end