bioinform 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. data/TODO.txt +7 -2
  2. data/bin/merge_into_collection +4 -0
  3. data/bin/pcm2pwm +1 -1
  4. data/bin/split_motifs +1 -1
  5. data/bioinform.gemspec +2 -0
  6. data/lib/bioinform/cli/merge_into_collection.rb +76 -0
  7. data/lib/bioinform/cli/pcm2pwm.rb +20 -20
  8. data/lib/bioinform/cli/split_motifs.rb +21 -20
  9. data/lib/bioinform/cli.rb +16 -2
  10. data/lib/bioinform/data_models/collection.rb +13 -10
  11. data/lib/bioinform/data_models/pcm.rb +2 -2
  12. data/lib/bioinform/data_models/pm.rb +24 -37
  13. data/lib/bioinform/data_models/ppm.rb +2 -2
  14. data/lib/bioinform/data_models/pwm.rb +2 -2
  15. data/lib/bioinform/data_models.rb +8 -8
  16. data/lib/bioinform/parsers/parser.rb +10 -5
  17. data/lib/bioinform/parsers/splittable_parser.rb +57 -0
  18. data/lib/bioinform/parsers/string_fantom_parser.rb +3 -3
  19. data/lib/bioinform/parsers/string_parser.rb +5 -24
  20. data/lib/bioinform/parsers/trivial_parser.rb +19 -3
  21. data/lib/bioinform/parsers/yaml_parser.rb +35 -0
  22. data/lib/bioinform/parsers.rb +6 -4
  23. data/lib/bioinform/support/parameters.rb +19 -0
  24. data/lib/bioinform/support/partial_sums.rb +1 -1
  25. data/lib/bioinform/support.rb +11 -10
  26. data/lib/bioinform/version.rb +1 -1
  27. data/lib/bioinform.rb +5 -5
  28. data/spec/cli/cli_spec.rb +8 -7
  29. data/spec/cli/data/merge_into_collection/GABPA_f1.pwm +14 -0
  30. data/spec/cli/data/{KLF4_f2.pwm.result → merge_into_collection/KLF4_f2.pwm} +0 -0
  31. data/spec/cli/data/{SP1_f1.pwm.result → merge_into_collection/SP1_f1.pwm} +0 -0
  32. data/spec/cli/data/merge_into_collection/collection.txt.result +40 -0
  33. data/spec/cli/data/merge_into_collection/collection.yaml.result +185 -0
  34. data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +185 -0
  35. data/spec/cli/data/merge_into_collection/pwm_folder/GABPA_f1.pwm +14 -0
  36. data/spec/cli/data/merge_into_collection/pwm_folder/KLF4_f2.pwm +11 -0
  37. data/spec/cli/data/merge_into_collection/pwm_folder/SP1_f1.pwm +12 -0
  38. data/spec/cli/data/{KLF4 f2 spaced name.pcm → pcm2pwm/KLF4 f2 spaced name.pcm} +0 -0
  39. data/spec/cli/data/{KLF4_f2.pcm → pcm2pwm/KLF4_f2.pcm} +0 -0
  40. data/spec/cli/data/pcm2pwm/KLF4_f2.pwm.result +11 -0
  41. data/spec/cli/data/{SP1_f1.pcm → pcm2pwm/SP1_f1.pcm} +0 -0
  42. data/spec/cli/data/pcm2pwm/SP1_f1.pwm.result +12 -0
  43. data/spec/cli/data/split_motifs/GABPA_f1.mat.result +14 -0
  44. data/spec/cli/data/split_motifs/KLF4_f2.mat.result +11 -0
  45. data/spec/cli/data/split_motifs/SP1_f1.mat.result +12 -0
  46. data/spec/cli/data/split_motifs/collection.yaml +197 -0
  47. data/spec/cli/data/split_motifs/plain_collection.txt +38 -0
  48. data/spec/cli/merge_into_collection_spec.rb +100 -0
  49. data/spec/cli/pcm2pwm_spec.rb +3 -3
  50. data/spec/cli/split_motifs_spec.rb +74 -3
  51. data/spec/data_models/collection_spec.rb +2 -2
  52. data/spec/data_models/pcm_spec.rb +2 -2
  53. data/spec/data_models/pm_spec.rb +10 -27
  54. data/spec/data_models/ppm_spec.rb +2 -2
  55. data/spec/data_models/pwm_spec.rb +3 -3
  56. data/spec/fabricators/collection_fabricator.rb +8 -0
  57. data/spec/fabricators/pm_fabricator.rb +43 -0
  58. data/spec/parsers/parser_spec.rb +29 -37
  59. data/spec/parsers/string_fantom_parser_spec.rb +38 -35
  60. data/spec/parsers/string_parser_spec.rb +33 -66
  61. data/spec/parsers/trivial_parser_spec.rb +48 -6
  62. data/spec/parsers/yaml_parser_spec.rb +50 -0
  63. data/spec/spec_helper.rb +2 -6
  64. data/spec/support/advanced_scan_spec.rb +2 -2
  65. data/spec/support/array_product_spec.rb +2 -2
  66. data/spec/support/array_zip_spec.rb +2 -2
  67. data/spec/support/collect_hash_spec.rb +2 -2
  68. data/spec/support/delete_many_spec.rb +2 -2
  69. data/spec/support/inverf_spec.rb +2 -2
  70. data/spec/support/multiline_squish_spec.rb +2 -2
  71. data/spec/support/partial_sums_spec.rb +2 -2
  72. data/spec/support/same_by_spec.rb +2 -2
  73. metadata +86 -12
@@ -0,0 +1,12 @@
1
+ SP1_f1
2
+ -0.24435707885585292 -0.674823404693731 0.8657012535789866 -1.1060188862599287
3
+ -1.0631255752097797 -2.111925969423868 1.0960627561110403 -0.6138563775211977
4
+ -0.3872276234760535 -2.9739851913218045 1.1807800242010378 -4.338927525031566
5
+ -4.563896055436894 -2.9161633002532277 1.3684371349982638 -5.077972423609655
6
+ -2.2369752892820083 -3.7196436313301846 1.3510439136452734 -4.889930670508233
7
+ -0.07473964149330865 0.944919654762011 -2.6246857648086044 -0.8510983487822436
8
+ -1.9643526491643322 -2.978402770880115 1.3113096718240573 -2.324334259499025
9
+ -4.0155484139655835 -3.1384268078096667 1.3387488589788057 -2.084673903537648
10
+ -0.44509385828355363 -2.2510053061629702 1.1265431574368685 -1.7780413702431372
11
+ -1.1896356092245048 -1.2251832285630027 1.1636760063747527 -1.6080243648157353
12
+ -0.5166047365590571 0.7641033353626657 -0.2862677570028208 -0.68254820978656
@@ -0,0 +1,14 @@
1
+ GABPA_f1
2
+ -0.1106670158341858 0.013801606113892391 0.6054596108973699 -1.3518085041421573
3
+ 0.37030668921643345 0.15761121480429963 0.009069314183831202 -0.9888619717703562
4
+ 0.47526546359546684 -0.3011678534572083 0.4031522994412777 -1.8638752827041059
5
+ -1.5544255540164373 1.1082369687811506 -0.2814091552834454 -5.30708531823271
6
+ -0.6362037835776368 1.235338189985594 -3.5801322928552253 -5.717323067092849
7
+ -5.852906870733575 -5.852906870733575 1.3841383838057746 -5.852906870733575
8
+ -5.852906870733575 -5.852906870733575 1.3841383838057746 -5.852906870733575
9
+ 1.3835219739184708 -5.2341956006430985 -5.852906870733575 -5.852906870733575
10
+ 1.3756340514956562 -5.394962755562375 -5.394962755562375 -3.401117964959733
11
+ -1.2176198315414444 -3.109079898175411 1.2964067931472216 -5.717323067092849
12
+ -1.3716559438167257 -0.2761401935045069 -1.8504445165866068 1.0404320473626856
13
+ -0.5440863133031895 -0.48103682561971345 0.907381908447086 -1.1280642594012078
14
+ 0.10557340209290218 -0.01814819455289191 0.4381106695354074 -1.0304105539540915
@@ -0,0 +1,11 @@
1
+ KLF4_f2
2
+ 0.30861857265872605 -2.254321000121579 0.13505703522674192 0.3285194224375633
3
+ -1.227018967707036 -4.814127713368663 1.3059890687390967 -4.908681463544344
4
+ -2.443469374521196 -4.648238485031404 1.3588686548279805 -4.441801801188402
5
+ -2.7177827948276123 -3.8073538975356565 1.356272809724262 -3.504104725510225
6
+ -0.5563232977367343 0.5340697765121405 -3.61417723090579 0.5270259776377405
7
+ -1.8687622060887386 -4.381483976582316 1.337932245336098 -3.815629658877517
8
+ -2.045671123823928 -2.384975142213679 0.7198551207724355 0.5449254135616948
9
+ -1.373157530374372 -3.0063112097748217 1.285188335493552 -2.5026044231773543
10
+ -2.1030513122772208 -1.8941348100402244 1.249265758393991 -1.4284210948906104
11
+ -1.3277128628152939 0.8982415633049462 -0.8080773665408135 -0.18161647647456935
@@ -0,0 +1,12 @@
1
+ SP1_f1
2
+ -0.24435707885585292 -0.674823404693731 0.8657012535789866 -1.1060188862599287
3
+ -1.0631255752097797 -2.111925969423868 1.0960627561110403 -0.6138563775211977
4
+ -0.3872276234760535 -2.9739851913218045 1.1807800242010378 -4.338927525031566
5
+ -4.563896055436894 -2.9161633002532277 1.3684371349982638 -5.077972423609655
6
+ -2.2369752892820083 -3.7196436313301846 1.3510439136452734 -4.889930670508233
7
+ -0.07473964149330865 0.944919654762011 -2.6246857648086044 -0.8510983487822436
8
+ -1.9643526491643322 -2.978402770880115 1.3113096718240573 -2.324334259499025
9
+ -4.0155484139655835 -3.1384268078096667 1.3387488589788057 -2.084673903537648
10
+ -0.44509385828355363 -2.2510053061629702 1.1265431574368685 -1.7780413702431372
11
+ -1.1896356092245048 -1.2251832285630027 1.1636760063747527 -1.6080243648157353
12
+ -0.5166047365590571 0.7641033353626657 -0.2862677570028208 -0.68254820978656
@@ -0,0 +1,197 @@
1
+ --- &14005248 !ruby/object:Bioinform::Collection
2
+ collection:
3
+ - - !ruby/object:Bioinform::PWM
4
+ parameters: !ruby/object:OpenStruct
5
+ table:
6
+ :name: GABPA_f1
7
+ :tags:
8
+ - *14005248
9
+ :background: &14005452
10
+ - 1
11
+ - 1
12
+ - 1
13
+ - 1
14
+ :max_hash_size: 1000000
15
+ modifiable: true
16
+ matrix:
17
+ - - -0.1106670158341858
18
+ - 0.013801606113892391
19
+ - 0.6054596108973699
20
+ - -1.3518085041421573
21
+ - - 0.37030668921643345
22
+ - 0.15761121480429963
23
+ - 0.009069314183831202
24
+ - -0.9888619717703562
25
+ - - 0.47526546359546684
26
+ - -0.3011678534572083
27
+ - 0.4031522994412777
28
+ - -1.8638752827041059
29
+ - - -1.5544255540164373
30
+ - 1.1082369687811506
31
+ - -0.2814091552834454
32
+ - -5.30708531823271
33
+ - - -0.6362037835776368
34
+ - 1.235338189985594
35
+ - -3.5801322928552253
36
+ - -5.717323067092849
37
+ - - -5.852906870733575
38
+ - -5.852906870733575
39
+ - 1.3841383838057746
40
+ - -5.852906870733575
41
+ - - -5.852906870733575
42
+ - -5.852906870733575
43
+ - 1.3841383838057746
44
+ - -5.852906870733575
45
+ - - 1.3835219739184708
46
+ - -5.2341956006430985
47
+ - -5.852906870733575
48
+ - -5.852906870733575
49
+ - - 1.3756340514956562
50
+ - -5.394962755562375
51
+ - -5.394962755562375
52
+ - -3.401117964959733
53
+ - - -1.2176198315414444
54
+ - -3.109079898175411
55
+ - 1.2964067931472216
56
+ - -5.717323067092849
57
+ - - -1.3716559438167257
58
+ - -0.2761401935045069
59
+ - -1.8504445165866068
60
+ - 1.0404320473626856
61
+ - - -0.5440863133031895
62
+ - -0.48103682561971345
63
+ - 0.907381908447086
64
+ - -1.1280642594012078
65
+ - - 0.10557340209290218
66
+ - -0.01814819455289191
67
+ - 0.4381106695354074
68
+ - -1.0304105539540915
69
+ - !ruby/object:OpenStruct
70
+ table:
71
+ :rough:
72
+ 0.0005: 12.1
73
+ :precise:
74
+ 0.0005: 4.51
75
+ - - !ruby/object:Bioinform::PWM
76
+ parameters: !ruby/object:OpenStruct
77
+ table:
78
+ :name: KLF4_f2
79
+ :tags:
80
+ - *14005248
81
+ :background: *14005452
82
+ :max_hash_size: 1000000
83
+ modifiable: true
84
+ matrix:
85
+ - - 0.30861857265872605
86
+ - -2.254321000121579
87
+ - 0.13505703522674192
88
+ - 0.3285194224375633
89
+ - - -1.227018967707036
90
+ - -4.814127713368663
91
+ - 1.3059890687390967
92
+ - -4.908681463544344
93
+ - - -2.443469374521196
94
+ - -4.648238485031404
95
+ - 1.3588686548279805
96
+ - -4.441801801188402
97
+ - - -2.7177827948276123
98
+ - -3.8073538975356565
99
+ - 1.356272809724262
100
+ - -3.504104725510225
101
+ - - -0.5563232977367343
102
+ - 0.5340697765121405
103
+ - -3.61417723090579
104
+ - 0.5270259776377405
105
+ - - -1.8687622060887386
106
+ - -4.381483976582316
107
+ - 1.337932245336098
108
+ - -3.815629658877517
109
+ - - -2.045671123823928
110
+ - -2.384975142213679
111
+ - 0.7198551207724355
112
+ - 0.5449254135616948
113
+ - - -1.373157530374372
114
+ - -3.0063112097748217
115
+ - 1.285188335493552
116
+ - -2.5026044231773543
117
+ - - -2.1030513122772208
118
+ - -1.8941348100402244
119
+ - 1.249265758393991
120
+ - -1.4284210948906104
121
+ - - -1.3277128628152939
122
+ - 0.8982415633049462
123
+ - -0.8080773665408135
124
+ - -0.18161647647456935
125
+ - !ruby/object:OpenStruct
126
+ table:
127
+ :rough:
128
+ 0.0005: 11.1
129
+ :precise:
130
+ 0.0005: 5.8100000000000005
131
+ - - !ruby/object:Bioinform::PWM
132
+ parameters: !ruby/object:OpenStruct
133
+ table:
134
+ :name: SP1_f1
135
+ :tags:
136
+ - *14005248
137
+ :background: *14005452
138
+ :max_hash_size: 1000000
139
+ modifiable: true
140
+ matrix:
141
+ - - -0.24435707885585292
142
+ - -0.674823404693731
143
+ - 0.8657012535789866
144
+ - -1.1060188862599287
145
+ - - -1.0631255752097797
146
+ - -2.111925969423868
147
+ - 1.0960627561110403
148
+ - -0.6138563775211977
149
+ - - -0.3872276234760535
150
+ - -2.9739851913218045
151
+ - 1.1807800242010378
152
+ - -4.338927525031566
153
+ - - -4.563896055436894
154
+ - -2.9161633002532277
155
+ - 1.3684371349982638
156
+ - -5.077972423609655
157
+ - - -2.2369752892820083
158
+ - -3.7196436313301846
159
+ - 1.3510439136452734
160
+ - -4.889930670508233
161
+ - - -0.07473964149330865
162
+ - 0.944919654762011
163
+ - -2.6246857648086044
164
+ - -0.8510983487822436
165
+ - - -1.9643526491643322
166
+ - -2.978402770880115
167
+ - 1.3113096718240573
168
+ - -2.324334259499025
169
+ - - -4.0155484139655835
170
+ - -3.1384268078096667
171
+ - 1.3387488589788057
172
+ - -2.084673903537648
173
+ - - -0.44509385828355363
174
+ - -2.2510053061629702
175
+ - 1.1265431574368685
176
+ - -1.7780413702431372
177
+ - - -1.1896356092245048
178
+ - -1.2251832285630027
179
+ - 1.1636760063747527
180
+ - -1.6080243648157353
181
+ - - -0.5166047365590571
182
+ - 0.7641033353626657
183
+ - -0.2862677570028208
184
+ - -0.68254820978656
185
+ - !ruby/object:OpenStruct
186
+ table:
187
+ :rough:
188
+ 0.0005: 11.1
189
+ :precise:
190
+ 0.0005: 5.61
191
+ parameters: !ruby/object:OpenStruct
192
+ table:
193
+ :rough_discretization: 1
194
+ :precise_discretization: 10
195
+ :background: *14005452
196
+ :pvalues:
197
+ - 0.0005
@@ -0,0 +1,38 @@
1
+ > SP1_f1
2
+ -0.24435707885585292 -0.674823404693731 0.8657012535789866 -1.1060188862599287
3
+ -1.0631255752097797 -2.111925969423868 1.0960627561110403 -0.6138563775211977
4
+ -0.3872276234760535 -2.9739851913218045 1.1807800242010378 -4.338927525031566
5
+ -4.563896055436894 -2.9161633002532277 1.3684371349982638 -5.077972423609655
6
+ -2.2369752892820083 -3.7196436313301846 1.3510439136452734 -4.889930670508233
7
+ -0.07473964149330865 0.944919654762011 -2.6246857648086044 -0.8510983487822436
8
+ -1.9643526491643322 -2.978402770880115 1.3113096718240573 -2.324334259499025
9
+ -4.0155484139655835 -3.1384268078096667 1.3387488589788057 -2.084673903537648
10
+ -0.44509385828355363 -2.2510053061629702 1.1265431574368685 -1.7780413702431372
11
+ -1.1896356092245048 -1.2251832285630027 1.1636760063747527 -1.6080243648157353
12
+ -0.5166047365590571 0.7641033353626657 -0.2862677570028208 -0.68254820978656
13
+
14
+ KLF4_f2
15
+ 0.30861857265872605 -2.254321000121579 0.13505703522674192 0.3285194224375633
16
+ -1.227018967707036 -4.814127713368663 1.3059890687390967 -4.908681463544344
17
+ -2.443469374521196 -4.648238485031404 1.3588686548279805 -4.441801801188402
18
+ -2.7177827948276123 -3.8073538975356565 1.356272809724262 -3.504104725510225
19
+ -0.5563232977367343 0.5340697765121405 -3.61417723090579 0.5270259776377405
20
+ -1.8687622060887386 -4.381483976582316 1.337932245336098 -3.815629658877517
21
+ -2.045671123823928 -2.384975142213679 0.7198551207724355 0.5449254135616948
22
+ -1.373157530374372 -3.0063112097748217 1.285188335493552 -2.5026044231773543
23
+ -2.1030513122772208 -1.8941348100402244 1.249265758393991 -1.4284210948906104
24
+ -1.3277128628152939 0.8982415633049462 -0.8080773665408135 -0.18161647647456935
25
+ GABPA_f1
26
+ -0.1106670158341858 0.013801606113892391 0.6054596108973699 -1.3518085041421573
27
+ 0.37030668921643345 0.15761121480429963 0.009069314183831202 -0.9888619717703562
28
+ 0.47526546359546684 -0.3011678534572083 0.4031522994412777 -1.8638752827041059
29
+ -1.5544255540164373 1.1082369687811506 -0.2814091552834454 -5.30708531823271
30
+ -0.6362037835776368 1.235338189985594 -3.5801322928552253 -5.717323067092849
31
+ -5.852906870733575 -5.852906870733575 1.3841383838057746 -5.852906870733575
32
+ -5.852906870733575 -5.852906870733575 1.3841383838057746 -5.852906870733575
33
+ 1.3835219739184708 -5.2341956006430985 -5.852906870733575 -5.852906870733575
34
+ 1.3756340514956562 -5.394962755562375 -5.394962755562375 -3.401117964959733
35
+ -1.2176198315414444 -3.109079898175411 1.2964067931472216 -5.717323067092849
36
+ -1.3716559438167257 -0.2761401935045069 -1.8504445165866068 1.0404320473626856
37
+ -0.5440863133031895 -0.48103682561971345 0.907381908447086 -1.1280642594012078
38
+ 0.10557340209290218 -0.01814819455289191 0.4381106695354074 -1.0304105539540915
@@ -0,0 +1,100 @@
1
+ require 'shellwords'
2
+ require 'yaml'
3
+ require_relative '../spec_helper'
4
+ require_relative '../../lib/bioinform/cli/merge_into_collection'
5
+ require_relative '../../lib/bioinform/data_models/collection'
6
+
7
+
8
+ def run_merge_into_collection(cmd)
9
+ Bioinform::CLI::MergeIntoCollection.main(cmd.shellsplit)
10
+ end
11
+
12
+ describe Bioinform::CLI::MergeIntoCollection do
13
+ before :each do
14
+ @start_dir = Dir.pwd
15
+ Dir.chdir File.join(File.dirname(__FILE__), 'data', 'merge_into_collection')
16
+ end
17
+ after :each do
18
+ File.delete('collection.yaml') if File.exist?('collection.yaml')
19
+ File.delete('collection.txt') if File.exist?('collection.txt')
20
+ File.delete('my_collection.yaml') if File.exist?('my_collection.yaml')
21
+ File.delete('my_collection.txt') if File.exist?('my_collection.txt')
22
+ File.delete('result.out') if File.exist?('result.out')
23
+ Dir.chdir(@start_dir)
24
+ end
25
+
26
+ context 'without --plain option' do
27
+ context 'when name not specified' do
28
+ it 'collects motifs into file collection.yaml' do
29
+ run_merge_into_collection('GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
30
+ File.exist?('collection.yaml').should be_true
31
+ YAML.load(File.read('collection.yaml')).should == YAML.load(File.read('collection.yaml.result'))
32
+ end
33
+ end
34
+
35
+ context 'when name specified' do
36
+ it 'collects motifs into file <collection name>.yaml' do
37
+ run_merge_into_collection('--name my_collection GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
38
+ File.exist?('my_collection.yaml').should be_true
39
+ YAML.load(File.read('my_collection.yaml')).should == YAML.load(File.read('collection.yaml.result')).set_parameters(name: 'my_collection')
40
+ end
41
+ end
42
+
43
+ context 'with --data-model option' do
44
+ it 'treat motifs as specified data model' do
45
+ run_merge_into_collection('--data-model pwm GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
46
+ File.exist?('collection.yaml').should be_true
47
+ YAML.load(File.read('collection.yaml')).should == YAML.load(File.read('collection_pwm.yaml.result'))
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'with --plain option' do
53
+ context 'when name not specified' do
54
+ it 'should collect motifs into file collection.txt in plain-text format' do
55
+ run_merge_into_collection('--plain GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
56
+ File.exist?('collection.txt').should be_true
57
+ YAML.load(File.read('collection.txt')).should == YAML.load(File.read('collection.txt.result'))
58
+ end
59
+ end
60
+
61
+ context 'when name specified' do
62
+ it 'should collect motifs into file <collection name>.txt in plain-text format' do
63
+ run_merge_into_collection('--name my_collection --plain GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
64
+ File.exist?('my_collection.txt').should be_true
65
+ YAML.load(File.read('my_collection.txt')).should == YAML.load(File.read('collection.txt.result'))
66
+ end
67
+ end
68
+
69
+ context 'with --data-model option' do
70
+ it 'generate usual txt file' do
71
+ run_merge_into_collection('--data-model pwm --plain GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
72
+ File.exist?('collection.txt').should be_true
73
+ YAML.load(File.read('collection.txt')).should == YAML.load(File.read('collection.txt.result'))
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'when --output-file specified' do
79
+ it 'collects motifs into specified file' do
80
+ run_merge_into_collection('--output-file result.out GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm')
81
+ File.exist?('result.out').should be_true
82
+ YAML.load(File.read('result.out')).should == YAML.load(File.read('collection.yaml.result'))
83
+ end
84
+ end
85
+
86
+ context 'when filelist is empty' do
87
+ it 'takes filelist from stdin' do
88
+ provide_stdin('GABPA_f1.pwm KLF4_f2.pwm SP1_f1.pwm'){ run_merge_into_collection('') }
89
+ File.exist?('collection.yaml').should be_true
90
+ YAML.load(File.read('collection.yaml')).should == YAML.load(File.read('collection.yaml.result'))
91
+ end
92
+ end
93
+ context 'when filelist contain folder name' do
94
+ it 'takes filelist as files from folder' do
95
+ run_merge_into_collection('pwm_folder')
96
+ File.exist?('collection.yaml').should be_true
97
+ YAML.load(File.read('collection.yaml')).should == YAML.load(File.read('collection.yaml.result'))
98
+ end
99
+ end
100
+ end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
2
1
  require 'shellwords'
3
- require 'bioinform/cli/pcm2pwm'
2
+ require_relative '../spec_helper'
3
+ require_relative '../../lib/bioinform/cli/pcm2pwm'
4
4
 
5
5
 
6
6
  def run_pcm2pwm(cmd)
@@ -10,7 +10,7 @@ end
10
10
  describe Bioinform::CLI::PCM2PWM do
11
11
  before :each do
12
12
  @start_dir = Dir.pwd
13
- Dir.chdir File.join(File.dirname(__FILE__), 'data')
13
+ Dir.chdir File.join(File.dirname(__FILE__), 'data', 'pcm2pwm')
14
14
  end
15
15
  after :each do
16
16
  File.delete('KLF4_f2.pwm') if File.exist?('KLF4_f2.pwm')
@@ -1,6 +1,77 @@
1
- require 'spec_helper'
2
- require 'bioinform/cli/split_motifs'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/cli/split_motifs'
3
3
 
4
- describe Bioinform::CLI::SplitMotifs do
4
+ def run_split_motifs(cmd)
5
+ Bioinform::CLI::SplitMotifs.main(cmd.shellsplit)
6
+ end
5
7
 
8
+ describe Bioinform::CLI::SplitMotifs do
9
+ before :each do
10
+ @start_dir = Dir.pwd
11
+ @motifs_in_collection = %w[KLF4_f2 SP1_f1 GABPA_f1]
12
+ Dir.chdir File.join(File.dirname(__FILE__), 'data', 'split_motifs')
13
+ end
14
+ after :each do
15
+ @motifs_in_collection.each do |motif_name|
16
+ File.delete("#{motif_name}.mat") if File.exist?("#{motif_name}.mat")
17
+ File.delete("#{motif_name}.pwm") if File.exist?("#{motif_name}.pwm")
18
+ File.delete("#{motif_name}.pat") if File.exist?("#{motif_name}.pat")
19
+ end
20
+ FileUtils.rm_rf('result_folder') if Dir.exist?('result_folder')
21
+ Dir.chdir(@start_dir)
22
+ end
23
+ it 'splits plain text into separate files' do
24
+ run_split_motifs('plain_collection.txt')
25
+ @motifs_in_collection.each do |motif_name|
26
+ File.exist?("#{motif_name}.mat").should be_true
27
+ File.read("#{motif_name}.mat") == File.read("#{motif_name}.mat.result")
28
+ end
29
+ end
30
+ it 'create files with specified extension' do
31
+ run_split_motifs('plain_collection.txt -e pwm')
32
+ @motifs_in_collection.each do |motif_name|
33
+ File.exist?("#{motif_name}.pwm").should be_true
34
+ File.read("#{motif_name}.pwm") == File.read("#{motif_name}.mat.result")
35
+ end
36
+ end
37
+
38
+ context 'when specified folder exist' do
39
+ before :each do
40
+ Dir.mkdir('result_folder') unless Dir.exist?('result_folder')
41
+ end
42
+ it 'create files in specified folder' do
43
+ run_split_motifs('plain_collection.txt -f result_folder')
44
+ @motifs_in_collection.each do |motif_name|
45
+ File.exist?(File.join('result_folder', "#{motif_name}.mat")).should be_true
46
+ File.read(File.join('result_folder', "#{motif_name}.mat")) == File.read("#{motif_name}.mat.result")
47
+ end
48
+ end
49
+ end
50
+ context 'when specified folder not exist' do
51
+ before :each do
52
+ FileUtils.rm_rf('result_folder') if Dir.exist?('result_folder')
53
+ end
54
+ it 'create files in specified folder' do
55
+ run_split_motifs('plain_collection.txt -f result_folder')
56
+ @motifs_in_collection.each do |motif_name|
57
+ File.exist?(File.join('result_folder', "#{motif_name}.mat")).should be_true
58
+ File.read(File.join('result_folder', "#{motif_name}.mat")) == File.read("#{motif_name}.mat.result")
59
+ end
60
+ end
61
+ end
62
+
63
+ it 'splits motifs from Collections (yamled Bioinform::Collection instances) with appropriate extension' do
64
+ run_split_motifs('collection.yaml')
65
+ @motifs_in_collection.each do |motif_name|
66
+ File.exist?("#{motif_name}.pwm").should be_true
67
+ File.read("#{motif_name}.pwm") == File.read("#{motif_name}.mat.result")
68
+ end
69
+ end
70
+ it 'splits motifs from Collections with specified extension' do
71
+ run_split_motifs('collection.yaml -e pat')
72
+ @motifs_in_collection.each do |motif_name|
73
+ File.exist?("#{motif_name}.pat").should be_true
74
+ File.read("#{motif_name}.pat") == File.read("#{motif_name}.mat.result")
75
+ end
76
+ end
6
77
  end
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'bioinform/data_models/collection'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/collection'
3
3
 
4
4
  module Bioinform
5
5
  describe Collection do
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'bioinform/data_models/pcm'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/pcm'
3
3
 
4
4
  module Bioinform
5
5
  describe PCM do
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'bioinform/data_models/pm'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/pm'
3
3
 
4
4
  module Bioinform
5
5
  describe PM do
@@ -8,7 +8,7 @@ module Bioinform
8
8
  before :each do
9
9
  @collection = Collection.new(name: 'Collection 1')
10
10
  @matrix = [[1,2,3,4],[5,6,7,8]]
11
- @name = 'Motif name'
11
+ @name = 'PM_motif'
12
12
  @background = [0.2,0.3,0.3,0.2]
13
13
  @tags = [@collection, 'Collection 2']
14
14
  @pm = PM.new(matrix: @matrix, name: @name, background: @background, tags: @tags)
@@ -25,7 +25,7 @@ module Bioinform
25
25
  end
26
26
  end
27
27
  end
28
-
28
+
29
29
  describe '#tagged?' do
30
30
  context 'when PM marked with Collection object' do
31
31
  context 'without collection-name' do
@@ -115,7 +115,7 @@ module Bioinform
115
115
  pm_eq = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif')
116
116
  pm_neq_matrix = PM.new(matrix: [[1,2,3,4],[15,16,17,18]], name: 'First motif')
117
117
  pm_neq_name = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'Second motif')
118
- pm_neq_background = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif').background!([1,2,2,1])
118
+ pm_neq_background = PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'First motif').set_parameters(background: [1,2,2,1])
119
119
 
120
120
  pm.should_not == pm_neq_matrix
121
121
  pm.should_not == pm_neq_name
@@ -240,26 +240,9 @@ module Bioinform
240
240
  before :each do
241
241
  @pm = PM.new( [[1,2,3,4],[1,4,5,6.5]] )
242
242
  end
243
- context 'when none arguments passed' do
244
- context 'when pm just created' do
245
- it 'should be [1,1,1,1]' do
246
- @pm.background.should == [1,1,1,1]
247
- end
248
- end
249
- it 'should return background' do
250
- @pm.background = [0.2, 0.3, 0.3, 0.2]
251
- @pm.background.should == [0.2, 0.3, 0.3, 0.2]
252
- end
253
- end
254
- context 'when one argument passed' do
255
- it 'should set background' do
256
- @pm.background([0.2,0.3,0.3,0.2])
257
- @pm.background.should == [0.2, 0.3, 0.3, 0.2]
258
- end
259
- end
260
- context 'when more than one argument passed' do
261
- it 'should raise an ArgumentError' do
262
- expect { @pm.background(:first, :second) }.to raise_error ArgumentError
243
+ context 'when pm just created' do
244
+ it 'should be [1,1,1,1]' do
245
+ @pm.background.should == [1,1,1,1]
263
246
  end
264
247
  end
265
248
  end
@@ -335,10 +318,10 @@ module Bioinform
335
318
  end
336
319
  context 'when background is normalized probabilities' do
337
320
  it 'should be 1.0' do
338
- @pm_2_positions.background( [0.2, 0.3, 0.3, 0.2] )
321
+ @pm_2_positions.background = [0.2, 0.3, 0.3, 0.2]
339
322
  @pm_2_positions.vocabulary_volume.should == 1.0
340
323
 
341
- @pm_3_positions.background( [0.2, 0.3, 0.3, 0.2] )
324
+ @pm_3_positions.background = [0.2, 0.3, 0.3, 0.2]
342
325
  @pm_3_positions.vocabulary_volume.should == 1.0
343
326
  end
344
327
  end
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'bioinform/data_models/pcm'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/pcm'
3
3
 
4
4
  module Bioinform
5
5
  describe PPM do
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'bioinform/data_models/pwm'
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/data_models/pwm'
3
3
 
4
4
  module Bioinform
5
5
  describe PWM do
@@ -9,7 +9,7 @@ module Bioinform
9
9
  pwm.score_mean.should == 1.5 + 6 + 2
10
10
  end
11
11
  it 'should be equal to a mean score of pwm by measure induced from background probability mean' do
12
- pwm = PWM.new( [[1,2,1,2],[4,6,8,6],[2,2,2,2]] ).background([0.2, 0.3, 0.3, 0.2])
12
+ pwm = PWM.new( [[1,2,1,2],[4,6,8,6],[2,2,2,2]] ).set_parameters(background: [0.2, 0.3, 0.3, 0.2])
13
13
  pwm.score_mean.should == ((0.2*1+0.3*2+0.3*1+0.2*2) + (0.2*4+0.3*6+0.3*8+0.2*6) + (0.2*2+0.3*2+0.3*2+0.2*2)) / (0.2+0.3+0.3+0.2)
14
14
  end
15
15
  end
@@ -0,0 +1,8 @@
1
+ Fabricator(:pm_collection, from: Bioinform::Collection, aliases: [:two_elements_collection]) do
2
+ name 'PM_collection'
3
+ after_build{|collection| collection << Fabricate(:pm_first) << Fabricate(:pm_second) }
4
+ end
5
+
6
+ Fabricator(:unnamed_pm_collection, from: :pm_collection) do
7
+ name nil
8
+ end
@@ -0,0 +1,43 @@
1
+ Fabricator(:pm, from: Bioinform::PM) do
2
+ initialize_with{ Bioinform::PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name: 'PM_name') }
3
+ end
4
+
5
+ Fabricator(:pm_unnamed, from: :pm) do
6
+ name nil
7
+ end
8
+
9
+
10
+ Fabricator(:pm_first, from: :pm) do
11
+ name 'PM_first'
12
+ end
13
+
14
+ Fabricator(:pm_second, from: :pm) do
15
+ matrix [[15,16,17,18],[11,21,31,41]]
16
+ name 'PM_second'
17
+ end
18
+
19
+
20
+ Fabricator(:pm_4x4, from: :pm) do
21
+ matrix [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
22
+ end
23
+
24
+ Fabricator(:pm_4x4_unnamed, from: :pm_4x4) do
25
+ name nil
26
+ end
27
+
28
+ Fabricator(:pm_with_floats, from: :pm_unnamed) do
29
+ matrix [[1.23, 4.56, 7.8, 9.0], [9, -8.7, 6.54, -3210]]
30
+ end
31
+
32
+ Fabricator(:pm_1, from: :pm) do
33
+ matrix [[0,1,2,3],[4,5,6,7]]
34
+ name 'motif_1'
35
+ end
36
+ Fabricator(:pm_2, from: :pm) do
37
+ matrix [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
38
+ name 'motif_2'
39
+ end
40
+ Fabricator(:pm_3, from: :pm) do
41
+ matrix [[2,3,4,5],[6,7,8,9]]
42
+ name 'motif_3'
43
+ end