bioinform 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +12 -0
- data/Guardfile +9 -0
- data/README.md +7 -1
- data/TODO.txt +8 -0
- data/bioinform.gemspec +7 -5
- data/lib/bioinform.rb +1 -0
- data/lib/bioinform/cli.rb +12 -3
- data/lib/bioinform/cli/convert_motif.rb +108 -0
- data/lib/bioinform/cli/merge_into_collection.rb +6 -2
- data/lib/bioinform/cli/pcm2pwm.rb +1 -1
- data/lib/bioinform/cli/split_motifs.rb +1 -1
- data/lib/bioinform/conversion_algorithms/pcm2ppm_converter.rb +19 -0
- data/lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb +20 -0
- data/lib/bioinform/conversion_algorithms/pcm2pwm_mara_converter.rb +0 -0
- data/lib/bioinform/conversion_algorithms/ppm2pcm_converter.rb +0 -0
- data/lib/bioinform/conversion_algorithms/ppm2pwm_converter.rb +0 -0
- data/lib/bioinform/data_models/collection.rb +21 -35
- data/lib/bioinform/data_models/motif.rb +56 -0
- data/lib/bioinform/data_models/pcm.rb +4 -8
- data/lib/bioinform/data_models/pm.rb +19 -48
- data/lib/bioinform/data_models/pwm.rb +16 -0
- data/lib/bioinform/formatters.rb +2 -0
- data/lib/bioinform/formatters/raw_formatter.rb +41 -0
- data/lib/bioinform/formatters/transfac_formatter.rb +39 -0
- data/lib/bioinform/parsers.rb +2 -1
- data/lib/bioinform/parsers/jaspar_parser.rb +35 -0
- data/lib/bioinform/parsers/string_parser.rb +1 -1
- data/lib/bioinform/parsers/trivial_parser.rb +2 -1
- data/lib/bioinform/parsers/yaml_parser.rb +1 -1
- data/lib/bioinform/support.rb +2 -1
- data/lib/bioinform/support/parameters.rb +27 -18
- data/lib/bioinform/support/strip_doc.rb +9 -0
- data/lib/bioinform/version.rb +1 -1
- data/spec/cli/convert_motif_spec.rb +107 -0
- data/spec/cli/data/merge_into_collection/collection.yaml.result +186 -183
- data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +186 -183
- data/spec/cli/data/split_motifs/collection.yaml +184 -193
- data/spec/cli/shared_examples/convert_motif/motif_list_empty.rb +18 -0
- data/spec/cli/shared_examples/convert_motif/several_motifs_specified.rb +14 -0
- data/spec/cli/shared_examples/convert_motif/single_motif_specified.rb +50 -0
- data/spec/cli/shared_examples/convert_motif/yield_help_string.rb +5 -0
- data/spec/cli/shared_examples/convert_motif/yield_motif_conversion_error.rb +4 -0
- data/spec/data_models/collection_spec.rb +36 -34
- data/spec/data_models/motif_spec.rb +224 -0
- data/spec/data_models/pcm_spec.rb +28 -17
- data/spec/data_models/pm_spec.rb +83 -121
- data/spec/data_models/pwm_spec.rb +38 -0
- data/spec/fabricators/collection_fabricator.rb +2 -2
- data/spec/fabricators/motif_fabricator.rb +33 -0
- data/spec/fabricators/motif_formats_fabricator.rb +125 -0
- data/spec/fabricators/pcm_fabricator.rb +25 -0
- data/spec/fabricators/pm_fabricator.rb +10 -1
- data/spec/fabricators/ppm_fabricator.rb +14 -0
- data/spec/fabricators/pwm_fabricator.rb +16 -0
- data/spec/parsers/trivial_parser_spec.rb +12 -12
- data/spec/parsers/yaml_parser_spec.rb +11 -11
- data/spec/spec_helper.rb +19 -49
- data/spec/spec_helper_source.rb +59 -0
- metadata +78 -7
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require_relative 'yield_help_string'
|
3
|
+
|
4
|
+
shared_examples 'motif list is empty' do
|
5
|
+
context 'motif list is empty' do
|
6
|
+
Given(:motif_list) { [] }
|
7
|
+
|
8
|
+
context 'with options' do
|
9
|
+
Given(:options) { '--formatter default --silent' }
|
10
|
+
include_examples 'yield help string'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'without options' do
|
14
|
+
Given(:options){ '' }
|
15
|
+
include_examples 'yield help string'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'several motifs specified' do
|
4
|
+
context 'several motifs specified' do
|
5
|
+
Given {
|
6
|
+
make_model_file(sp1_f1, 'pcm')
|
7
|
+
make_model_file(klf4_f2, 'pcm')
|
8
|
+
}
|
9
|
+
Given(:motif_list) { [sp1_f1, klf4_f2] }
|
10
|
+
Given(:model_from) { 'pcm' }
|
11
|
+
Given(:model_to) { 'pwm' }
|
12
|
+
Then { resulting_stdout.should == [sp1_f1.pwm, klf4_f2.pwm].join("\n") }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'single motif specified' do
|
4
|
+
context 'single motif specified' do
|
5
|
+
Given {
|
6
|
+
make_model_file(sp1_f1, model_from)
|
7
|
+
}
|
8
|
+
Given(:motif_list) { [sp1_f1] }
|
9
|
+
|
10
|
+
context 'when input is a pcm' do
|
11
|
+
Given(:model_from) { 'pcm' }
|
12
|
+
|
13
|
+
context 'pwm conversion invoked' do
|
14
|
+
Given(:model_to) { 'pwm' }
|
15
|
+
Then { resulting_stdout.should == sp1_f1.pwm }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'ppm conversion invoked' do
|
19
|
+
Given(:model_to) { 'ppm' }
|
20
|
+
Then { resulting_stdout.should == sp1_f1.ppm }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when input is a pwm' do
|
25
|
+
Given(:model_from) { 'pwm' }
|
26
|
+
|
27
|
+
context 'pcm conversion invoked' do
|
28
|
+
Given(:model_to) { 'pcm' }
|
29
|
+
include_examples 'yields motif conversion error'
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'ppm conversion invoked' do
|
33
|
+
Given(:model_to) { 'ppm' }
|
34
|
+
include_examples 'yields motif conversion error'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'if there exist other files in current folder' do
|
39
|
+
Given {
|
40
|
+
make_model_file(sp1_f1, model_from)
|
41
|
+
make_model_file(klf4_f2, model_from)
|
42
|
+
}
|
43
|
+
Given(:model_from) { 'pcm' }
|
44
|
+
Given(:model_to) { 'pwm' }
|
45
|
+
Then { resulting_stdout.should == sp1_f1.pwm }
|
46
|
+
Then { resulting_stdout.should_not match(klf4_f2.pwm) }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -5,9 +5,9 @@ module Bioinform
|
|
5
5
|
describe Collection do
|
6
6
|
before :each do
|
7
7
|
@collection = Collection.new(name: 'Main collection')
|
8
|
-
@pm_1 =
|
9
|
-
@pm_2 =
|
10
|
-
@pm_3 =
|
8
|
+
@pm_1 = Fabricate(:pm_1)
|
9
|
+
@pm_2 = Fabricate(:pm_2)
|
10
|
+
@pm_3 = Fabricate(:pm_3)
|
11
11
|
end
|
12
12
|
describe '#size' do
|
13
13
|
it 'should return size of collection' do
|
@@ -20,51 +20,52 @@ module Bioinform
|
|
20
20
|
@collection << @pm_1
|
21
21
|
@collection << @pm_2
|
22
22
|
@collection << @pm_3
|
23
|
-
@collection.
|
23
|
+
@collection.should include(Motif.new(pm: @pm_1), Motif.new(pm: @pm_2), Motif.new(pm: @pm_3))
|
24
24
|
end
|
25
25
|
it 'should be chainable' do
|
26
26
|
@collection << @pm_1 << @pm_2 << @pm_3
|
27
|
-
@collection.
|
28
|
-
end
|
29
|
-
it 'should mark motif with name' do
|
30
|
-
@collection << @pm_1 << @pm_2
|
31
|
-
@pm_1.should be_tagged('Main collection')
|
32
|
-
@pm_2.should be_tagged('Main collection')
|
33
|
-
end
|
34
|
-
it 'should mark motif with self' do
|
35
|
-
@collection << @pm_1 << @pm_2
|
36
|
-
@pm_1.should be_tagged(@collection)
|
37
|
-
@pm_2.should be_tagged(@collection)
|
27
|
+
@collection.should include(Motif.new(pm: @pm_1), Motif.new(pm: @pm_2), Motif.new(pm: @pm_3))
|
38
28
|
end
|
29
|
+
# it 'should mark motif with name' do
|
30
|
+
# @collection << @pm_1 << @pm_2
|
31
|
+
# @pm_1.should be_tagged('Main collection')
|
32
|
+
# @pm_2.should be_tagged('Main collection')
|
33
|
+
# end
|
34
|
+
# it 'should mark motif with self' do
|
35
|
+
# @collection << @pm_1 << @pm_2
|
36
|
+
# @pm_1.should be_tagged(@collection)
|
37
|
+
# @pm_2.should be_tagged(@collection)
|
38
|
+
# end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe '#
|
41
|
+
describe '#each' do
|
42
42
|
before :each do
|
43
43
|
@collection << @pm_1 << @pm_2 << @pm_3
|
44
44
|
end
|
45
45
|
context 'with block given' do
|
46
|
-
it 'should yield
|
47
|
-
expect{|b| @collection.
|
46
|
+
it 'should yield Motifs' do
|
47
|
+
expect{|b| @collection.each(&b)}.to yield_successive_args(Motif,Motif,Motif)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
context 'with block given' do
|
51
51
|
it 'return an Enumerator' do
|
52
|
-
@collection.
|
52
|
+
@collection.each.should be_kind_of(Enumerator)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
|
+
describe '#each(:pcm)' do
|
57
58
|
before :each do
|
58
|
-
@collection << @pm_1 << @pm_2 << @pm_3
|
59
|
+
@collection << @pm_1.as_pcm << @pm_2 << @pm_3.as_pcm
|
59
60
|
end
|
60
61
|
context 'with block given' do
|
61
62
|
it 'should yield elements of collecton converted to pcm' do
|
62
|
-
expect{|b| @collection.
|
63
|
+
expect{|b| @collection.each(:pcm, &b)}.to yield_successive_args(PCM, nil, PCM)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
context 'with block given' do
|
66
67
|
it 'return an Enumerator' do
|
67
|
-
@collection.
|
68
|
+
@collection.each(:pcm).should be_kind_of(Enumerator)
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end
|
@@ -72,8 +73,8 @@ module Bioinform
|
|
72
73
|
describe '#+' do
|
73
74
|
before :each do
|
74
75
|
@collection << @pm_1 << @pm_2 << @pm_3
|
75
|
-
@pm_sec_1 =
|
76
|
-
@pm_sec_2 =
|
76
|
+
@pm_sec_1 = Fabricate(:pm_4)
|
77
|
+
@pm_sec_2 = Fabricate(:pm_5)
|
77
78
|
@secondary_collection = Collection.new(name: 'Secondary collection')
|
78
79
|
@secondary_collection << @pm_sec_1 << @pm_sec_2
|
79
80
|
@summary_collection = @collection + @secondary_collection
|
@@ -81,16 +82,17 @@ module Bioinform
|
|
81
82
|
it 'should create a collection consisting of all elements of both collections' do
|
82
83
|
@summary_collection.should be_kind_of(Collection)
|
83
84
|
@summary_collection.size.should == (@collection.size + @secondary_collection.size)
|
84
|
-
@summary_collection.
|
85
|
-
|
86
|
-
it 'should leave marks on motifs' do
|
87
|
-
@pm_1.should be_tagged('Main collection')
|
88
|
-
@pm_sec_1.should be_tagged('Secondary collection')
|
89
|
-
end
|
90
|
-
it 'should not mix marks of motifs in different collections' do
|
91
|
-
@pm_1.should_not be_tagged('Secondary collection')
|
92
|
-
@pm_sec_1.should_not be_tagged('Main collection')
|
85
|
+
@summary_collection.should include(Motif.new(pm: @pm_1), Motif.new(pm: @pm_2), Motif.new(pm: @pm_3),
|
86
|
+
Motif.new(pm: @pm_sec_1), Motif.new(pm: @pm_sec_2))
|
93
87
|
end
|
88
|
+
# it 'should leave marks on motifs' do
|
89
|
+
# @pm_1.should be_tagged('Main collection')
|
90
|
+
# @pm_sec_1.should be_tagged('Secondary collection')
|
91
|
+
# end
|
92
|
+
# it 'should not mix marks of motifs in different collections' do
|
93
|
+
# @pm_1.should_not be_tagged('Secondary collection')
|
94
|
+
# @pm_sec_1.should_not be_tagged('Main collection')
|
95
|
+
# end
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
@@ -0,0 +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
|
224
|
+
end
|
@@ -5,38 +5,49 @@ module Bioinform
|
|
5
5
|
describe PCM do
|
6
6
|
describe '#count' do
|
7
7
|
it 'should be equal to sum of elements at position' do
|
8
|
-
|
9
|
-
|
8
|
+
Fabricate(:pcm).count.should == 7
|
9
|
+
Fabricate(:pcm_with_floats).count.should == 7.5
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#to_pwm' do
|
14
|
+
subject{ Fabricate(:pcm) }
|
14
15
|
it 'should return PWM' do
|
15
|
-
|
16
|
+
Fabricate(:pcm).to_pwm.should be_kind_of(PWM)
|
16
17
|
end
|
17
18
|
it 'should make transformation: el --> log( (el + p_i*pseudocount) / (p_i*(count + pseudocount)) )' do
|
18
|
-
|
19
|
-
|
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
|
20
21
|
end
|
21
22
|
it 'should use default pseudocount equal to log(count)' do
|
22
|
-
|
23
|
+
Fabricate(:pcm).to_pwm.should == Fabricate(:pcm).to_pwm(Math.log(7))
|
23
24
|
end
|
24
25
|
it 'should preserve name' do
|
25
|
-
|
26
|
-
|
26
|
+
Fabricate(:pcm, name: nil).to_pwm.name.should be_nil
|
27
|
+
Fabricate(:pcm, name: 'Stub name').to_pwm.name.should == 'Stub name'
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
describe '#to_ppm' do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|