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,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
@@ -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