bioinform 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/Gemfile +16 -16
- data/LICENSE +21 -21
- data/README.md +35 -35
- data/Rakefile +4 -4
- data/TODO.txt +37 -37
- data/bin/merge_into_collection +3 -3
- data/bin/pcm2pwm +3 -3
- data/bin/split_motifs +3 -3
- data/bioinform.gemspec +19 -19
- data/lib/bioinform/cli/convert_motif.rb +107 -107
- data/lib/bioinform/cli/merge_into_collection.rb +79 -79
- data/lib/bioinform/cli/pcm2pwm.rb +46 -46
- data/lib/bioinform/cli/split_motifs.rb +46 -46
- data/lib/bioinform/cli.rb +29 -29
- data/lib/bioinform/conversion_algorithms/pcm2ppm_converter.rb +18 -18
- data/lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb +19 -19
- data/lib/bioinform/data_models/collection.rb +74 -74
- data/lib/bioinform/data_models/motif.rb +55 -55
- data/lib/bioinform/data_models/pcm.rb +23 -23
- data/lib/bioinform/data_models/pm.rb +169 -169
- data/lib/bioinform/data_models/ppm.rb +9 -9
- data/lib/bioinform/data_models/pwm.rb +55 -55
- data/lib/bioinform/data_models.rb +10 -10
- data/lib/bioinform/formatters/raw_formatter.rb +40 -40
- data/lib/bioinform/formatters/transfac_formatter.rb +38 -38
- data/lib/bioinform/formatters.rb +1 -1
- data/lib/bioinform/parsers/jaspar_parser.rb +34 -34
- data/lib/bioinform/parsers/parser.rb +87 -87
- data/lib/bioinform/parsers/splittable_parser.rb +56 -56
- data/lib/bioinform/parsers/string_fantom_parser.rb +34 -34
- data/lib/bioinform/parsers/string_parser.rb +71 -71
- data/lib/bioinform/parsers/trivial_parser.rb +33 -33
- data/lib/bioinform/parsers/yaml_parser.rb +34 -34
- data/lib/bioinform/parsers.rb +6 -6
- data/lib/bioinform/support/array_product.rb +5 -5
- data/lib/bioinform/support/array_zip.rb +5 -5
- data/lib/bioinform/support/collect_hash.rb +6 -6
- data/lib/bioinform/support/deep_dup.rb +4 -4
- data/lib/bioinform/support/delete_many.rb +13 -13
- data/lib/bioinform/support/inverf.rb +12 -12
- data/lib/bioinform/support/multiline_squish.rb +5 -5
- data/lib/bioinform/support/parameters.rb +27 -27
- data/lib/bioinform/support/partial_sums.rb +15 -15
- data/lib/bioinform/support/same_by.rb +12 -12
- data/lib/bioinform/support/strip_doc.rb +8 -8
- data/lib/bioinform/support/third_part/active_support/hash_with_indifferent_access.rb +3 -0
- data/lib/bioinform/support.rb +17 -17
- data/lib/bioinform/version.rb +3 -3
- data/lib/bioinform.rb +10 -10
- data/spec/cli/cli_spec.rb +13 -13
- data/spec/cli/convert_motif_spec.rb +106 -106
- data/spec/cli/data/merge_into_collection/GABPA_f1.pwm +14 -14
- data/spec/cli/data/merge_into_collection/KLF4_f2.pwm +11 -11
- data/spec/cli/data/merge_into_collection/SP1_f1.pwm +12 -12
- data/spec/cli/data/merge_into_collection/collection.txt.result +40 -40
- data/spec/cli/data/merge_into_collection/collection.yaml.result +188 -188
- data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +188 -188
- data/spec/cli/data/merge_into_collection/pwm_folder/GABPA_f1.pwm +14 -14
- data/spec/cli/data/merge_into_collection/pwm_folder/KLF4_f2.pwm +11 -11
- data/spec/cli/data/merge_into_collection/pwm_folder/SP1_f1.pwm +12 -12
- data/spec/cli/data/pcm2pwm/KLF4 f2 spaced name.pcm +11 -11
- data/spec/cli/data/pcm2pwm/KLF4_f2.pcm +11 -11
- data/spec/cli/data/pcm2pwm/KLF4_f2.pwm.result +11 -11
- data/spec/cli/data/pcm2pwm/SP1_f1.pcm +12 -12
- data/spec/cli/data/pcm2pwm/SP1_f1.pwm.result +12 -12
- data/spec/cli/data/split_motifs/GABPA_f1.mat.result +14 -14
- data/spec/cli/data/split_motifs/KLF4_f2.mat.result +11 -11
- data/spec/cli/data/split_motifs/SP1_f1.mat.result +12 -12
- data/spec/cli/data/split_motifs/collection.yaml +188 -188
- data/spec/cli/data/split_motifs/plain_collection.txt +38 -38
- data/spec/cli/merge_into_collection_spec.rb +99 -99
- data/spec/cli/pcm2pwm_spec.rb +79 -79
- data/spec/cli/shared_examples/convert_motif/motif_list_empty.rb +17 -17
- data/spec/cli/shared_examples/convert_motif/several_motifs_specified.rb +14 -14
- data/spec/cli/shared_examples/convert_motif/single_motif_specified.rb +49 -49
- data/spec/cli/shared_examples/convert_motif/yield_help_string.rb +4 -4
- data/spec/cli/shared_examples/convert_motif/yield_motif_conversion_error.rb +3 -3
- data/spec/cli/split_motifs_spec.rb +76 -76
- data/spec/data_models/collection_spec.rb +97 -97
- data/spec/data_models/motif_spec.rb +223 -223
- data/spec/data_models/pcm_spec.rb +55 -55
- data/spec/data_models/pm_spec.rb +359 -359
- data/spec/data_models/ppm_spec.rb +7 -7
- data/spec/data_models/pwm_spec.rb +82 -82
- data/spec/fabricators/collection_fabricator.rb +7 -7
- data/spec/fabricators/motif_fabricator.rb +32 -32
- data/spec/fabricators/motif_formats_fabricator.rb +124 -124
- data/spec/fabricators/pcm_fabricator.rb +24 -24
- data/spec/fabricators/pm_fabricator.rb +51 -51
- data/spec/fabricators/ppm_fabricator.rb +13 -13
- data/spec/fabricators/pwm_fabricator.rb +16 -16
- data/spec/parsers/parser_spec.rb +152 -152
- data/spec/parsers/string_fantom_parser_spec.rb +69 -69
- data/spec/parsers/string_parser_spec.rb +76 -76
- data/spec/parsers/trivial_parser_spec.rb +63 -63
- data/spec/parsers/yaml_parser_spec.rb +50 -50
- data/spec/spec_helper.rb +10 -10
- data/spec/spec_helper_source.rb +59 -59
- data/spec/support/advanced_scan_spec.rb +31 -31
- data/spec/support/array_product_spec.rb +14 -14
- data/spec/support/array_zip_spec.rb +14 -14
- data/spec/support/collect_hash_spec.rb +14 -14
- data/spec/support/delete_many_spec.rb +43 -43
- data/spec/support/inverf_spec.rb +18 -18
- data/spec/support/multiline_squish_spec.rb +24 -24
- data/spec/support/partial_sums_spec.rb +30 -30
- data/spec/support/same_by_spec.rb +35 -35
- metadata +3 -3
@@ -1,77 +1,77 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/bioinform/parsers/string_parser'
|
3
|
-
|
4
|
-
module Bioinform
|
5
|
-
describe StringParser do
|
6
|
-
|
7
|
-
describe '#each' do
|
8
|
-
it 'should yield consequent results of #parse! while it returns result' do
|
9
|
-
parser = StringParser.new("1 2 3 4\n5 6 7 8\n\n1 2 3 4\n1 2 3 4\nName\n4 3 2 1\n1 1 1 1\n0 0 0 0")
|
10
|
-
expect{|b| parser.each(&b)}.to yield_successive_args(OpenStruct.new(matrix:[[1,2,3,4],[5,6,7,8]], name:nil),
|
11
|
-
OpenStruct.new(matrix:[[1,2,3,4],[1,2,3,4]], name:nil),
|
12
|
-
OpenStruct.new(matrix:[[4,3,2,1],[1,1,1,1],[0,0,0,0]], name:'Name') )
|
13
|
-
end
|
14
|
-
it 'should restart parser from the beginning each time' do
|
15
|
-
parser = StringParser.new("1 2 3 4\n5 6 7 8\n\n1 2 3 4\n1 2 3 4\nName\n4 3 2 1\n1 1 1 1\n0 0 0 0")
|
16
|
-
3.times do
|
17
|
-
expect{|b| parser.each(&b)}.to yield_successive_args(OpenStruct.new(matrix:[[1,2,3,4],[5,6,7,8]], name:nil),
|
18
|
-
OpenStruct.new(matrix:[[1,2,3,4],[1,2,3,4]], name:nil),
|
19
|
-
OpenStruct.new(matrix:[[4,3,2,1],[1,1,1,1],[0,0,0,0]], name:'Name') )
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context '::split_on_motifs' do
|
25
|
-
it 'should be able to get a single PM' do
|
26
|
-
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8").should == [ Fabricate(:pm_unnamed) ]
|
27
|
-
end
|
28
|
-
it 'should be able to split several PMs separated with an empty line' do
|
29
|
-
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n\n 15 16 17 18 \n 11 21 31 41").should ==
|
30
|
-
[ Fabricate(:pm_first, name: nil), Fabricate(:pm_second, name: nil) ]
|
31
|
-
end
|
32
|
-
it 'should be able to split several PMs separated with name' do
|
33
|
-
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \nPM_second\n 15 16 17 18 \n 11 21 31 41").should ==
|
34
|
-
[ Fabricate(:pm_first, name: nil), Fabricate(:pm_second) ]
|
35
|
-
end
|
36
|
-
it 'should be able to split several PMs separated with both name and empty line' do
|
37
|
-
StringParser.split_on_motifs("PM_first\n1 2 3 4 \n 5 6 7 8 \n\nPM_second\n 15 16 17 18 \n 11 21 31 41\n\n\n").should ==
|
38
|
-
[ Fabricate(:pm_first), Fabricate(:pm_second) ]
|
39
|
-
end
|
40
|
-
it 'should create PMs by default' do
|
41
|
-
result = StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n 9 10 11 12 \nName\n 9 10 11 12 \n 1 2 3 4 \n 5 6 7 8")
|
42
|
-
result.each{|pm| pm.class.should == PM}
|
43
|
-
end
|
44
|
-
it 'should create PM subclass when it\'s specified' do
|
45
|
-
result = StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n 9 10 11 12 \nName\n 9 10 11 12 \n 1 2 3 4 \n 5 6 7 8", PWM)
|
46
|
-
result.each{|pm| pm.class.should == PWM}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
good_cases = {
|
51
|
-
'Nx4 string' => {input: "1 2 3 4\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
52
|
-
'4xN string' => {input: "1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm_unnamed) },
|
53
|
-
'string with name' => {input: "PM_name\n1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm) },
|
54
|
-
'string with name (with introduction sign)' => {input: ">\t PM_name\n1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm) },
|
55
|
-
'string with name (with special characters)' => {input: "Testmatrix_first:subname+sub-subname\n1 5\n2 6\n3 7\n 4 8",
|
56
|
-
result: Fabricate(:pm, name: 'Testmatrix_first:subname+sub-subname') },
|
57
|
-
'string with float numerics' => {input: "1.23 4.56 7.8 9.0\n9 -8.7 6.54 -3210", result: Fabricate(:pm_with_floats) },
|
58
|
-
'string with exponents' => {input: "123e-2 0.456e+1 7.8 9.0\n9 -87000000000E-10 6.54 -3.210e3", result: Fabricate(:pm_with_floats) },
|
59
|
-
'string with multiple spaces and tabs' => {input: "1 \t\t 2 3 4\n 5 6 7 8", result: Fabricate(:pm_unnamed) },
|
60
|
-
'string with preceeding and terminating newlines' => {input: "\n\n\t 1 2 3 4\n5 6 7 8 \n\t\n", result: Fabricate(:pm_unnamed) },
|
61
|
-
'string with windows crlf' => {input: "1 2 3 4\r\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
62
|
-
'Nx4 string with acgt-header' => {input: "A C G T\n1 2 3 4\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
63
|
-
'Nx4 string with name and acgt-header' => {input: "PM_name\nA C G T\n1 2 3 4\n5 6 7 8", result: Fabricate(:pm)},
|
64
|
-
'Nx4 string with acgt-row-markers' => {input: "A 1 5\nC : 2 6\nG3 7\nT |4 8", result: Fabricate(:pm_unnamed) },
|
65
|
-
'4x4 string with acgt-header' => {input: "A C G T\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16", result: Fabricate(:pm_4x4_unnamed) },
|
66
|
-
'4x4 string with acgt-row-markers' => {input: "A|1 5 9 13\nC|2 6 10 14\nG|3 7 11 15\nT|4 8 12 16", result: Fabricate(:pm_4x4_unnamed) },
|
67
|
-
'4x4 string with name and acgt-row-markers' => {input: "PM_name\nA:1 5 9 13\nC:2 6 10 14\nG:3 7 11 15\nT:4 8 12 16", result: Fabricate(:pm_4x4) }
|
68
|
-
}
|
69
|
-
|
70
|
-
bad_cases = {
|
71
|
-
'string with non-numeric input' => {input: "1.23 4.56 78aaa 9.0\n9 -8.7 6.54 -3210" },
|
72
|
-
'string with empty exponent sign' => {input: "1.23 4.56 7.8 9.0\n 9e -8.7 6.54 3210" }
|
73
|
-
}
|
74
|
-
|
75
|
-
parser_specs(StringParser, good_cases, bad_cases)
|
76
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/bioinform/parsers/string_parser'
|
3
|
+
|
4
|
+
module Bioinform
|
5
|
+
describe StringParser do
|
6
|
+
|
7
|
+
describe '#each' do
|
8
|
+
it 'should yield consequent results of #parse! while it returns result' do
|
9
|
+
parser = StringParser.new("1 2 3 4\n5 6 7 8\n\n1 2 3 4\n1 2 3 4\nName\n4 3 2 1\n1 1 1 1\n0 0 0 0")
|
10
|
+
expect{|b| parser.each(&b)}.to yield_successive_args(OpenStruct.new(matrix:[[1,2,3,4],[5,6,7,8]], name:nil),
|
11
|
+
OpenStruct.new(matrix:[[1,2,3,4],[1,2,3,4]], name:nil),
|
12
|
+
OpenStruct.new(matrix:[[4,3,2,1],[1,1,1,1],[0,0,0,0]], name:'Name') )
|
13
|
+
end
|
14
|
+
it 'should restart parser from the beginning each time' do
|
15
|
+
parser = StringParser.new("1 2 3 4\n5 6 7 8\n\n1 2 3 4\n1 2 3 4\nName\n4 3 2 1\n1 1 1 1\n0 0 0 0")
|
16
|
+
3.times do
|
17
|
+
expect{|b| parser.each(&b)}.to yield_successive_args(OpenStruct.new(matrix:[[1,2,3,4],[5,6,7,8]], name:nil),
|
18
|
+
OpenStruct.new(matrix:[[1,2,3,4],[1,2,3,4]], name:nil),
|
19
|
+
OpenStruct.new(matrix:[[4,3,2,1],[1,1,1,1],[0,0,0,0]], name:'Name') )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '::split_on_motifs' do
|
25
|
+
it 'should be able to get a single PM' do
|
26
|
+
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8").should == [ Fabricate(:pm_unnamed) ]
|
27
|
+
end
|
28
|
+
it 'should be able to split several PMs separated with an empty line' do
|
29
|
+
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n\n 15 16 17 18 \n 11 21 31 41").should ==
|
30
|
+
[ Fabricate(:pm_first, name: nil), Fabricate(:pm_second, name: nil) ]
|
31
|
+
end
|
32
|
+
it 'should be able to split several PMs separated with name' do
|
33
|
+
StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \nPM_second\n 15 16 17 18 \n 11 21 31 41").should ==
|
34
|
+
[ Fabricate(:pm_first, name: nil), Fabricate(:pm_second) ]
|
35
|
+
end
|
36
|
+
it 'should be able to split several PMs separated with both name and empty line' do
|
37
|
+
StringParser.split_on_motifs("PM_first\n1 2 3 4 \n 5 6 7 8 \n\nPM_second\n 15 16 17 18 \n 11 21 31 41\n\n\n").should ==
|
38
|
+
[ Fabricate(:pm_first), Fabricate(:pm_second) ]
|
39
|
+
end
|
40
|
+
it 'should create PMs by default' do
|
41
|
+
result = StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n 9 10 11 12 \nName\n 9 10 11 12 \n 1 2 3 4 \n 5 6 7 8")
|
42
|
+
result.each{|pm| pm.class.should == PM}
|
43
|
+
end
|
44
|
+
it 'should create PM subclass when it\'s specified' do
|
45
|
+
result = StringParser.split_on_motifs("1 2 3 4 \n 5 6 7 8 \n 9 10 11 12 \nName\n 9 10 11 12 \n 1 2 3 4 \n 5 6 7 8", PWM)
|
46
|
+
result.each{|pm| pm.class.should == PWM}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
good_cases = {
|
51
|
+
'Nx4 string' => {input: "1 2 3 4\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
52
|
+
'4xN string' => {input: "1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm_unnamed) },
|
53
|
+
'string with name' => {input: "PM_name\n1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm) },
|
54
|
+
'string with name (with introduction sign)' => {input: ">\t PM_name\n1 5\n2 6\n3 7\n 4 8", result: Fabricate(:pm) },
|
55
|
+
'string with name (with special characters)' => {input: "Testmatrix_first:subname+sub-subname\n1 5\n2 6\n3 7\n 4 8",
|
56
|
+
result: Fabricate(:pm, name: 'Testmatrix_first:subname+sub-subname') },
|
57
|
+
'string with float numerics' => {input: "1.23 4.56 7.8 9.0\n9 -8.7 6.54 -3210", result: Fabricate(:pm_with_floats) },
|
58
|
+
'string with exponents' => {input: "123e-2 0.456e+1 7.8 9.0\n9 -87000000000E-10 6.54 -3.210e3", result: Fabricate(:pm_with_floats) },
|
59
|
+
'string with multiple spaces and tabs' => {input: "1 \t\t 2 3 4\n 5 6 7 8", result: Fabricate(:pm_unnamed) },
|
60
|
+
'string with preceeding and terminating newlines' => {input: "\n\n\t 1 2 3 4\n5 6 7 8 \n\t\n", result: Fabricate(:pm_unnamed) },
|
61
|
+
'string with windows crlf' => {input: "1 2 3 4\r\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
62
|
+
'Nx4 string with acgt-header' => {input: "A C G T\n1 2 3 4\n5 6 7 8", result: Fabricate(:pm_unnamed) },
|
63
|
+
'Nx4 string with name and acgt-header' => {input: "PM_name\nA C G T\n1 2 3 4\n5 6 7 8", result: Fabricate(:pm)},
|
64
|
+
'Nx4 string with acgt-row-markers' => {input: "A 1 5\nC : 2 6\nG3 7\nT |4 8", result: Fabricate(:pm_unnamed) },
|
65
|
+
'4x4 string with acgt-header' => {input: "A C G T\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16", result: Fabricate(:pm_4x4_unnamed) },
|
66
|
+
'4x4 string with acgt-row-markers' => {input: "A|1 5 9 13\nC|2 6 10 14\nG|3 7 11 15\nT|4 8 12 16", result: Fabricate(:pm_4x4_unnamed) },
|
67
|
+
'4x4 string with name and acgt-row-markers' => {input: "PM_name\nA:1 5 9 13\nC:2 6 10 14\nG:3 7 11 15\nT:4 8 12 16", result: Fabricate(:pm_4x4) }
|
68
|
+
}
|
69
|
+
|
70
|
+
bad_cases = {
|
71
|
+
'string with non-numeric input' => {input: "1.23 4.56 78aaa 9.0\n9 -8.7 6.54 -3210" },
|
72
|
+
'string with empty exponent sign' => {input: "1.23 4.56 7.8 9.0\n 9e -8.7 6.54 3210" }
|
73
|
+
}
|
74
|
+
|
75
|
+
parser_specs(StringParser, good_cases, bad_cases)
|
76
|
+
end
|
77
77
|
end
|
@@ -1,64 +1,64 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/bioinform/parsers/parser'
|
3
|
-
require_relative '../../lib/bioinform/data_models/collection'
|
4
|
-
|
5
|
-
module Bioinform
|
6
|
-
describe TrivialParser do
|
7
|
-
context '.new' do
|
8
|
-
it 'should take the only input argument' do
|
9
|
-
TrivialParser.instance_method(:initialize).arity.should == 1
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context '#parse!' do
|
14
|
-
it 'should return OpenStruct based on input of that was passed to initialize when input is a Hash' do
|
15
|
-
TrivialParser.new(matrix: 'stub matrix', name: 'stub name').parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should return OpenStruct based on input of that was passed to initialize when input is a OpenStruct' do
|
19
|
-
TrivialParser.new(OpenStruct.new(matrix: 'stub matrix', name: 'stub name')).parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context '.split_on_motifs' do
|
24
|
-
it 'should be able to get a single PM' do
|
25
|
-
TrivialParser.split_on_motifs({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, PM).should == [ PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name:'Name') ]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'can be used to create PM with {matrix: ..., name: ...} form' do
|
30
|
-
pm = PM.new({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, TrivialParser)
|
31
|
-
pm.matrix.should == [[1,2,3,4],[5,6,7,8]]
|
32
|
-
pm.name.should == 'Name'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'can be used to create PM from PM (make copy)' do
|
36
|
-
pm = Fabricate(:pm)
|
37
|
-
pm_copy = PM.new(pm, TrivialParser)
|
38
|
-
pm_copy.should == pm
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe TrivialCollectionParser do
|
43
|
-
let(:collection){ Fabricate(:three_elements_collection) }
|
44
|
-
let(:pm_1){ Fabricate(:pm_1) }
|
45
|
-
let(:pm_2){ Fabricate(:pm_2) }
|
46
|
-
let(:pm_3){ Fabricate(:pm_3) }
|
47
|
-
|
48
|
-
describe '#parse!' do
|
49
|
-
it 'can be used to obtain PMs from Collection' do
|
50
|
-
@parser = TrivialCollectionParser.new(collection)
|
51
|
-
@parser.parse!.should == pm_1
|
52
|
-
@parser.parse!.should == pm_2
|
53
|
-
@parser.parse!.should == pm_3
|
54
|
-
expect{ @parser.parse! }.to raise_error
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '.split_on_motifs' do
|
59
|
-
it 'should be able to split collection into PMs' do
|
60
|
-
TrivialCollectionParser.split_on_motifs(collection).should == [pm_1, pm_2, pm_3]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/bioinform/parsers/parser'
|
3
|
+
require_relative '../../lib/bioinform/data_models/collection'
|
4
|
+
|
5
|
+
module Bioinform
|
6
|
+
describe TrivialParser do
|
7
|
+
context '.new' do
|
8
|
+
it 'should take the only input argument' do
|
9
|
+
TrivialParser.instance_method(:initialize).arity.should == 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#parse!' do
|
14
|
+
it 'should return OpenStruct based on input of that was passed to initialize when input is a Hash' do
|
15
|
+
TrivialParser.new(matrix: 'stub matrix', name: 'stub name').parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return OpenStruct based on input of that was passed to initialize when input is a OpenStruct' do
|
19
|
+
TrivialParser.new(OpenStruct.new(matrix: 'stub matrix', name: 'stub name')).parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '.split_on_motifs' do
|
24
|
+
it 'should be able to get a single PM' do
|
25
|
+
TrivialParser.split_on_motifs({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, PM).should == [ PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name:'Name') ]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can be used to create PM with {matrix: ..., name: ...} form' do
|
30
|
+
pm = PM.new({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, TrivialParser)
|
31
|
+
pm.matrix.should == [[1,2,3,4],[5,6,7,8]]
|
32
|
+
pm.name.should == 'Name'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can be used to create PM from PM (make copy)' do
|
36
|
+
pm = Fabricate(:pm)
|
37
|
+
pm_copy = PM.new(pm, TrivialParser)
|
38
|
+
pm_copy.should == pm
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe TrivialCollectionParser do
|
43
|
+
let(:collection){ Fabricate(:three_elements_collection) }
|
44
|
+
let(:pm_1){ Fabricate(:pm_1) }
|
45
|
+
let(:pm_2){ Fabricate(:pm_2) }
|
46
|
+
let(:pm_3){ Fabricate(:pm_3) }
|
47
|
+
|
48
|
+
describe '#parse!' do
|
49
|
+
it 'can be used to obtain PMs from Collection' do
|
50
|
+
@parser = TrivialCollectionParser.new(collection)
|
51
|
+
@parser.parse!.should == pm_1
|
52
|
+
@parser.parse!.should == pm_2
|
53
|
+
@parser.parse!.should == pm_3
|
54
|
+
expect{ @parser.parse! }.to raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.split_on_motifs' do
|
59
|
+
it 'should be able to split collection into PMs' do
|
60
|
+
TrivialCollectionParser.split_on_motifs(collection).should == [pm_1, pm_2, pm_3]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
64
|
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
require_relative '../../lib/bioinform/parsers/yaml_parser'
|
4
|
-
require_relative '../../lib/bioinform/data_models/collection'
|
5
|
-
|
6
|
-
module Bioinform
|
7
|
-
describe YAMLParser do
|
8
|
-
context '#parse!' do
|
9
|
-
it 'should return PM that was encoded in YAML format' do
|
10
|
-
pm = Fabricate(:pm)
|
11
|
-
parser = YAMLParser.new(pm.to_yaml)
|
12
|
-
parser.parse!.should == pm
|
13
|
-
end
|
14
|
-
end
|
15
|
-
it 'can be used to create PM from yaml-string' do
|
16
|
-
pm = Fabricate(:pm)
|
17
|
-
pm_copy = PM.new(pm.to_yaml, YAMLParser)
|
18
|
-
pm_copy.should == pm
|
19
|
-
end
|
20
|
-
|
21
|
-
context '::split_on_motifs' do
|
22
|
-
it 'should be able to get a single PM' do
|
23
|
-
pm = Fabricate(:pm)
|
24
|
-
YAMLParser.split_on_motifs(pm.to_yaml, PM).should == [ pm ]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe YAMLCollectionParser do
|
30
|
-
let(:yamled_collection){ Fabricate(:three_elements_collection).to_yaml }
|
31
|
-
let(:pm_1){ Fabricate(:pm_1) }
|
32
|
-
let(:pm_2){ Fabricate(:pm_2) }
|
33
|
-
let(:pm_3){ Fabricate(:pm_3) }
|
34
|
-
|
35
|
-
context '::split_on_motifs' do
|
36
|
-
it 'should be able to split yamled collection into PMs' do
|
37
|
-
YAMLCollectionParser.split_on_motifs(yamled_collection).should == [pm_1, pm_2, pm_3]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
context '#parse!' do
|
41
|
-
it 'should return PMs which were in encoded YAML format' do
|
42
|
-
@parser = YAMLCollectionParser.new(yamled_collection)
|
43
|
-
@parser.parse!.should == pm_1
|
44
|
-
@parser.parse!.should == pm_2
|
45
|
-
@parser.parse!.should == pm_3
|
46
|
-
expect{ @parser.parse! }.to raise_error
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require_relative '../../lib/bioinform/parsers/yaml_parser'
|
4
|
+
require_relative '../../lib/bioinform/data_models/collection'
|
5
|
+
|
6
|
+
module Bioinform
|
7
|
+
describe YAMLParser do
|
8
|
+
context '#parse!' do
|
9
|
+
it 'should return PM that was encoded in YAML format' do
|
10
|
+
pm = Fabricate(:pm)
|
11
|
+
parser = YAMLParser.new(pm.to_yaml)
|
12
|
+
parser.parse!.should == pm
|
13
|
+
end
|
14
|
+
end
|
15
|
+
it 'can be used to create PM from yaml-string' do
|
16
|
+
pm = Fabricate(:pm)
|
17
|
+
pm_copy = PM.new(pm.to_yaml, YAMLParser)
|
18
|
+
pm_copy.should == pm
|
19
|
+
end
|
20
|
+
|
21
|
+
context '::split_on_motifs' do
|
22
|
+
it 'should be able to get a single PM' do
|
23
|
+
pm = Fabricate(:pm)
|
24
|
+
YAMLParser.split_on_motifs(pm.to_yaml, PM).should == [ pm ]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe YAMLCollectionParser do
|
30
|
+
let(:yamled_collection){ Fabricate(:three_elements_collection).to_yaml }
|
31
|
+
let(:pm_1){ Fabricate(:pm_1) }
|
32
|
+
let(:pm_2){ Fabricate(:pm_2) }
|
33
|
+
let(:pm_3){ Fabricate(:pm_3) }
|
34
|
+
|
35
|
+
context '::split_on_motifs' do
|
36
|
+
it 'should be able to split yamled collection into PMs' do
|
37
|
+
YAMLCollectionParser.split_on_motifs(yamled_collection).should == [pm_1, pm_2, pm_3]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context '#parse!' do
|
41
|
+
it 'should return PMs which were in encoded YAML format' do
|
42
|
+
@parser = YAMLCollectionParser.new(yamled_collection)
|
43
|
+
@parser.parse!.should == pm_1
|
44
|
+
@parser.parse!.should == pm_2
|
45
|
+
@parser.parse!.should == pm_3
|
46
|
+
expect{ @parser.parse! }.to raise_error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
-
|
4
|
-
require 'rspec'
|
5
|
-
require 'rspec-given'
|
6
|
-
|
7
|
-
require 'fileutils'
|
8
|
-
require 'stringio'
|
9
|
-
require 'fabrication'
|
10
|
-
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec-given'
|
6
|
+
|
7
|
+
require 'fileutils'
|
8
|
+
require 'stringio'
|
9
|
+
require 'fabrication'
|
10
|
+
|
11
11
|
require 'fakefs/spec_helpers'
|
12
12
|
require 'spec_helper_source'
|
13
13
|
Fabrication.clear_definitions
|
data/spec/spec_helper_source.rb
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
# from minitest (TODO: make use of minitest, not override it)
|
2
|
-
def capture_io(&block)
|
3
|
-
orig_stdout, orig_stderr = $stdout, $stderr
|
4
|
-
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
5
|
-
$stdout, $stderr = captured_stdout, captured_stderr
|
6
|
-
yield
|
7
|
-
return {stdout: captured_stdout.string, stderr: captured_stderr.string}
|
8
|
-
ensure
|
9
|
-
$stdout = orig_stdout
|
10
|
-
$stderr = orig_stderr
|
11
|
-
end
|
12
|
-
|
13
|
-
# Method stubs $stdin not STDIN !
|
14
|
-
def provide_stdin(input, tty = false, &block)
|
15
|
-
orig_stdin = $stdin
|
16
|
-
$stdin = StringIO.new(input)
|
17
|
-
$stdin.send(:define_singleton_method, :tty?){ tty } # Simulate that stdin is tty by default
|
18
|
-
yield
|
19
|
-
ensure
|
20
|
-
$stdin = orig_stdin
|
21
|
-
end
|
22
|
-
|
23
|
-
def capture_output(&block)
|
24
|
-
capture_io(&block)[:stdout]
|
25
|
-
end
|
26
|
-
def capture_stderr(&block)
|
27
|
-
capture_io(&block)[:stderr]
|
28
|
-
end
|
29
|
-
|
30
|
-
def parser_specs(parser_klass, good_cases, bad_cases)
|
31
|
-
context '#parse!' do
|
32
|
-
good_cases.each do |case_description, input_and_result|
|
33
|
-
it "should be able to parse #{case_description}" do
|
34
|
-
result = parser_klass.new(input_and_result[:input]).parse
|
35
|
-
Bioinform::PM.new(result).should == input_and_result[:result]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
bad_cases.each do |case_description, input|
|
40
|
-
it "should raise an exception on parsing #{case_description}" do
|
41
|
-
expect{ parser_klass.new(input[:input]).parse! }.to raise_error
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
##############################
|
48
|
-
|
49
|
-
def make_file(filename, content)
|
50
|
-
File.open(filename, 'w'){|f| f.puts content }
|
51
|
-
end
|
52
|
-
|
53
|
-
def motif_filename(motif, model_type)
|
54
|
-
"#{motif.name}.#{model_type}"
|
55
|
-
end
|
56
|
-
|
57
|
-
def make_model_file(motif, model_type)
|
58
|
-
make_file(motif_filename(motif, model_type), motif.send(model_type))
|
59
|
-
end
|
1
|
+
# from minitest (TODO: make use of minitest, not override it)
|
2
|
+
def capture_io(&block)
|
3
|
+
orig_stdout, orig_stderr = $stdout, $stderr
|
4
|
+
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
5
|
+
$stdout, $stderr = captured_stdout, captured_stderr
|
6
|
+
yield
|
7
|
+
return {stdout: captured_stdout.string, stderr: captured_stderr.string}
|
8
|
+
ensure
|
9
|
+
$stdout = orig_stdout
|
10
|
+
$stderr = orig_stderr
|
11
|
+
end
|
12
|
+
|
13
|
+
# Method stubs $stdin not STDIN !
|
14
|
+
def provide_stdin(input, tty = false, &block)
|
15
|
+
orig_stdin = $stdin
|
16
|
+
$stdin = StringIO.new(input)
|
17
|
+
$stdin.send(:define_singleton_method, :tty?){ tty } # Simulate that stdin is tty by default
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
$stdin = orig_stdin
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture_output(&block)
|
24
|
+
capture_io(&block)[:stdout]
|
25
|
+
end
|
26
|
+
def capture_stderr(&block)
|
27
|
+
capture_io(&block)[:stderr]
|
28
|
+
end
|
29
|
+
|
30
|
+
def parser_specs(parser_klass, good_cases, bad_cases)
|
31
|
+
context '#parse!' do
|
32
|
+
good_cases.each do |case_description, input_and_result|
|
33
|
+
it "should be able to parse #{case_description}" do
|
34
|
+
result = parser_klass.new(input_and_result[:input]).parse
|
35
|
+
Bioinform::PM.new(result).should == input_and_result[:result]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
bad_cases.each do |case_description, input|
|
40
|
+
it "should raise an exception on parsing #{case_description}" do
|
41
|
+
expect{ parser_klass.new(input[:input]).parse! }.to raise_error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##############################
|
48
|
+
|
49
|
+
def make_file(filename, content)
|
50
|
+
File.open(filename, 'w'){|f| f.puts content }
|
51
|
+
end
|
52
|
+
|
53
|
+
def motif_filename(motif, model_type)
|
54
|
+
"#{motif.name}.#{model_type}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_model_file(motif, model_type)
|
58
|
+
make_file(motif_filename(motif, model_type), motif.send(model_type))
|
59
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/bioinform/support/advanced_scan'
|
3
|
-
|
4
|
-
describe StringScanner do
|
5
|
-
context '#advanced_scan' do
|
6
|
-
before do
|
7
|
-
@scanner = StringScanner.new('abcde fghIJKLmnop')
|
8
|
-
end
|
9
|
-
it 'should return nil if text doesn\'t match. Pointer should not move' do
|
10
|
-
@scanner.advanced_scan(/\s\s\s/).should be_nil
|
11
|
-
@scanner.pos.should == 0
|
12
|
-
end
|
13
|
-
it 'should return MatchData if string Matches. Pointer should move' do
|
14
|
-
@scanner.advanced_scan(/\w\w\w/).should be_kind_of MatchData
|
15
|
-
@scanner.pos.should == 3
|
16
|
-
end
|
17
|
-
it 'should return have the same groups as regexp has' do
|
18
|
-
result = @scanner.advanced_scan(/(\w+)(\s+)([a-z]+)([A-Z]+)/)
|
19
|
-
result[0].should == 'abcde fghIJKL'
|
20
|
-
result[1].should == 'abcde'
|
21
|
-
result[2].should == ' '
|
22
|
-
result[3].should == 'fgh'
|
23
|
-
result[4].should == 'IJKL'
|
24
|
-
end
|
25
|
-
it 'should return have the same named groups as regexp has' do
|
26
|
-
result = @scanner.advanced_scan(/(\w+)(\s+)(?<word_downcase>[a-z]+)(?<word_upcase>[A-Z]+)/)
|
27
|
-
result[0].should == 'abcde fghIJKL'
|
28
|
-
result[:word_downcase].should == 'fgh'
|
29
|
-
result[:word_upcase].should == 'IJKL'
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/bioinform/support/advanced_scan'
|
3
|
+
|
4
|
+
describe StringScanner do
|
5
|
+
context '#advanced_scan' do
|
6
|
+
before do
|
7
|
+
@scanner = StringScanner.new('abcde fghIJKLmnop')
|
8
|
+
end
|
9
|
+
it 'should return nil if text doesn\'t match. Pointer should not move' do
|
10
|
+
@scanner.advanced_scan(/\s\s\s/).should be_nil
|
11
|
+
@scanner.pos.should == 0
|
12
|
+
end
|
13
|
+
it 'should return MatchData if string Matches. Pointer should move' do
|
14
|
+
@scanner.advanced_scan(/\w\w\w/).should be_kind_of MatchData
|
15
|
+
@scanner.pos.should == 3
|
16
|
+
end
|
17
|
+
it 'should return have the same groups as regexp has' do
|
18
|
+
result = @scanner.advanced_scan(/(\w+)(\s+)([a-z]+)([A-Z]+)/)
|
19
|
+
result[0].should == 'abcde fghIJKL'
|
20
|
+
result[1].should == 'abcde'
|
21
|
+
result[2].should == ' '
|
22
|
+
result[3].should == 'fgh'
|
23
|
+
result[4].should == 'IJKL'
|
24
|
+
end
|
25
|
+
it 'should return have the same named groups as regexp has' do
|
26
|
+
result = @scanner.advanced_scan(/(\w+)(\s+)(?<word_downcase>[a-z]+)(?<word_upcase>[A-Z]+)/)
|
27
|
+
result[0].should == 'abcde fghIJKL'
|
28
|
+
result[:word_downcase].should == 'fgh'
|
29
|
+
result[:word_upcase].should == 'IJKL'
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/bioinform/support/array_product'
|
3
|
-
|
4
|
-
describe Array do
|
5
|
-
context '::product' do
|
6
|
-
it 'should take any number of arrays and product them as if #product was made to first and others' do
|
7
|
-
Array.product([1,2,3]).should == [1,2,3].product()
|
8
|
-
Array.product([1,2,3],[4,5,6]).should == [1,2,3].product([4,5,6])
|
9
|
-
Array.product([1,2,3],[4,5,6],[7,8,9]).should == [1,2,3].product([4,5,6],[7,8,9])
|
10
|
-
end
|
11
|
-
it 'should return empty array if no arrays\'re given' do
|
12
|
-
Array.product().should == []
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/bioinform/support/array_product'
|
3
|
+
|
4
|
+
describe Array do
|
5
|
+
context '::product' do
|
6
|
+
it 'should take any number of arrays and product them as if #product was made to first and others' do
|
7
|
+
Array.product([1,2,3]).should == [1,2,3].product()
|
8
|
+
Array.product([1,2,3],[4,5,6]).should == [1,2,3].product([4,5,6])
|
9
|
+
Array.product([1,2,3],[4,5,6],[7,8,9]).should == [1,2,3].product([4,5,6],[7,8,9])
|
10
|
+
end
|
11
|
+
it 'should return empty array if no arrays\'re given' do
|
12
|
+
Array.product().should == []
|
13
|
+
end
|
14
|
+
end
|
15
15
|
end
|