rbbt-util 5.43.0 → 5.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rbbt/association/util.rb +1 -1
  3. data/lib/rbbt/hpc/batch.rb +19 -17
  4. data/lib/rbbt/tsv/accessor.rb +6 -11
  5. data/lib/rbbt/tsv/dumper.rb +21 -10
  6. data/lib/rbbt/tsv/index.rb +2 -1
  7. data/lib/rbbt/util/misc/math.rb +0 -1
  8. data/lib/rbbt/util/open.rb +1 -1
  9. data/lib/rbbt/workflow/step/info.rb +1 -0
  10. data/lib/rbbt/workflow/step.rb +2 -1
  11. data/python/rbbt/__init__.py +2 -2
  12. data/share/rbbt_commands/workflow/task +1 -1
  13. metadata +4 -220
  14. data/test/rbbt/annotations/test_util.rb +0 -43
  15. data/test/rbbt/association/test_database.rb +0 -87
  16. data/test/rbbt/association/test_index.rb +0 -127
  17. data/test/rbbt/association/test_item.rb +0 -15
  18. data/test/rbbt/association/test_open.rb +0 -63
  19. data/test/rbbt/association/test_util.rb +0 -108
  20. data/test/rbbt/entity/test_identifiers.rb +0 -34
  21. data/test/rbbt/hpc/orchestrate/test_batches.rb +0 -70
  22. data/test/rbbt/hpc/orchestrate/test_chains.rb +0 -108
  23. data/test/rbbt/hpc/orchestrate/test_rules.rb +0 -59
  24. data/test/rbbt/hpc/test_batch.rb +0 -64
  25. data/test/rbbt/hpc/test_hpc_test_workflows.rb +0 -0
  26. data/test/rbbt/hpc/test_orchestrate.rb +0 -144
  27. data/test/rbbt/hpc/test_pbs.rb +0 -43
  28. data/test/rbbt/hpc/test_slurm.rb +0 -28
  29. data/test/rbbt/knowledge_base/test_enrichment.rb +0 -50
  30. data/test/rbbt/knowledge_base/test_entity.rb +0 -62
  31. data/test/rbbt/knowledge_base/test_query.rb +0 -46
  32. data/test/rbbt/knowledge_base/test_registry.rb +0 -74
  33. data/test/rbbt/knowledge_base/test_syndicate.rb +0 -48
  34. data/test/rbbt/knowledge_base/test_traverse.rb +0 -133
  35. data/test/rbbt/persist/test_tsv.rb +0 -88
  36. data/test/rbbt/persist/tsv/test_cdb.rb +0 -18
  37. data/test/rbbt/persist/tsv/test_kyotocabinet.rb +0 -27
  38. data/test/rbbt/persist/tsv/test_leveldb.rb +0 -18
  39. data/test/rbbt/persist/tsv/test_lmdb.rb +0 -20
  40. data/test/rbbt/persist/tsv/test_sharder.rb +0 -164
  41. data/test/rbbt/persist/tsv/test_tokyocabinet.rb +0 -262
  42. data/test/rbbt/resource/test_path.rb +0 -49
  43. data/test/rbbt/test_annotations.rb +0 -167
  44. data/test/rbbt/test_association.rb +0 -103
  45. data/test/rbbt/test_entity.rb +0 -252
  46. data/test/rbbt/test_fix_width_table.rb +0 -135
  47. data/test/rbbt/test_knowledge_base.rb +0 -226
  48. data/test/rbbt/test_monitor.rb +0 -11
  49. data/test/rbbt/test_packed_index.rb +0 -68
  50. data/test/rbbt/test_persist.rb +0 -85
  51. data/test/rbbt/test_resource.rb +0 -110
  52. data/test/rbbt/test_tsv.rb +0 -669
  53. data/test/rbbt/test_workflow.rb +0 -609
  54. data/test/rbbt/tsv/parallel/test_through.rb +0 -40
  55. data/test/rbbt/tsv/parallel/test_traverse.rb +0 -456
  56. data/test/rbbt/tsv/test_accessor.rb +0 -319
  57. data/test/rbbt/tsv/test_attach.rb +0 -715
  58. data/test/rbbt/tsv/test_change_id.rb +0 -61
  59. data/test/rbbt/tsv/test_csv.rb +0 -49
  60. data/test/rbbt/tsv/test_excel.rb +0 -171
  61. data/test/rbbt/tsv/test_field_index.rb +0 -19
  62. data/test/rbbt/tsv/test_filter.rb +0 -187
  63. data/test/rbbt/tsv/test_index.rb +0 -308
  64. data/test/rbbt/tsv/test_manipulate.rb +0 -334
  65. data/test/rbbt/tsv/test_marshal.rb +0 -24
  66. data/test/rbbt/tsv/test_matrix.rb +0 -20
  67. data/test/rbbt/tsv/test_parallel.rb +0 -7
  68. data/test/rbbt/tsv/test_parser.rb +0 -101
  69. data/test/rbbt/tsv/test_stream.rb +0 -253
  70. data/test/rbbt/tsv/test_util.rb +0 -52
  71. data/test/rbbt/util/R/test_eval.rb +0 -43
  72. data/test/rbbt/util/R/test_model.rb +0 -128
  73. data/test/rbbt/util/R/test_plot.rb +0 -38
  74. data/test/rbbt/util/concurrency/processes/test_socket.rb +0 -70
  75. data/test/rbbt/util/concurrency/test_processes.rb +0 -192
  76. data/test/rbbt/util/concurrency/test_threads.rb +0 -40
  77. data/test/rbbt/util/log/test_progress.rb +0 -111
  78. data/test/rbbt/util/misc/test_bgzf.rb +0 -48
  79. data/test/rbbt/util/misc/test_communication.rb +0 -13
  80. data/test/rbbt/util/misc/test_development.rb +0 -26
  81. data/test/rbbt/util/misc/test_format.rb +0 -10
  82. data/test/rbbt/util/misc/test_indiferent_hash.rb +0 -14
  83. data/test/rbbt/util/misc/test_lock.rb +0 -77
  84. data/test/rbbt/util/misc/test_multipart_payload.rb +0 -202
  85. data/test/rbbt/util/misc/test_omics.rb +0 -116
  86. data/test/rbbt/util/misc/test_pipes.rb +0 -343
  87. data/test/rbbt/util/misc/test_serialize.rb +0 -24
  88. data/test/rbbt/util/python/test_util.rb +0 -25
  89. data/test/rbbt/util/simpleopt/test_get.rb +0 -12
  90. data/test/rbbt/util/simpleopt/test_parse.rb +0 -10
  91. data/test/rbbt/util/simpleopt/test_setup.rb +0 -76
  92. data/test/rbbt/util/test_R.rb +0 -37
  93. data/test/rbbt/util/test_chain_methods.rb +0 -22
  94. data/test/rbbt/util/test_cmd.rb +0 -87
  95. data/test/rbbt/util/test_colorize.rb +0 -22
  96. data/test/rbbt/util/test_concurrency.rb +0 -6
  97. data/test/rbbt/util/test_config.rb +0 -69
  98. data/test/rbbt/util/test_excel2tsv.rb +0 -10
  99. data/test/rbbt/util/test_filecache.rb +0 -36
  100. data/test/rbbt/util/test_log.rb +0 -52
  101. data/test/rbbt/util/test_migrate.rb +0 -34
  102. data/test/rbbt/util/test_misc.rb +0 -728
  103. data/test/rbbt/util/test_open.rb +0 -200
  104. data/test/rbbt/util/test_procpath.rb +0 -23
  105. data/test/rbbt/util/test_python.rb +0 -144
  106. data/test/rbbt/util/test_semaphore.rb +0 -36
  107. data/test/rbbt/util/test_simpleDSL.rb +0 -55
  108. data/test/rbbt/util/test_simpleopt.rb +0 -11
  109. data/test/rbbt/util/test_ssh.rb +0 -10
  110. data/test/rbbt/util/test_tmpfile.rb +0 -32
  111. data/test/rbbt/workflow/step/test_dependencies.rb +0 -295
  112. data/test/rbbt/workflow/step/test_save_load_inputs.rb +0 -136
  113. data/test/rbbt/workflow/test_doc.rb +0 -30
  114. data/test/rbbt/workflow/test_remote_workflow.rb +0 -99
  115. data/test/rbbt/workflow/test_schedule.rb +0 -0
  116. data/test/rbbt/workflow/test_step.rb +0 -231
  117. data/test/rbbt/workflow/test_task.rb +0 -85
  118. data/test/rbbt/workflow/util/test_archive.rb +0 -27
  119. data/test/rbbt/workflow/util/test_data.rb +0 -67
  120. data/test/rbbt/workflow/util/test_orchestrator.rb +0 -263
  121. data/test/test_helper.rb +0 -114
@@ -1,728 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
- require 'rbbt/util/misc'
3
- require 'test/unit'
4
- require 'rbbt/tsv'
5
- require 'rbbt/entity'
6
-
7
- class TestMisc < Test::Unit::TestCase
8
-
9
- def test_object_delta
10
- a = []
11
- b = nil
12
- d = Misc.object_delta(String) do
13
- a << rand.to_s
14
- end
15
- assert_equal 1, a.length
16
- assert_match /^0\.\d+$/, a.first
17
- end
18
-
19
- def test_format_seconds
20
- t = 61.3232
21
- assert_equal "00:01:01", Misc.format_seconds(t)
22
- assert_equal "00:01:01.32", Misc.format_seconds(t, true)
23
- end
24
-
25
- def test_format_paragraph
26
- p = <<-EOF
27
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
28
- incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
29
- nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
30
-
31
- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
32
- fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
33
- in culpa qui officia deserunt mollit anim id est laborum.
34
-
35
-
36
- * one
37
- * two
38
- * three
39
-
40
- EOF
41
-
42
- assert Misc.format_paragraph(p, 70, 10, 5) =~ /\n\s*\* two/sm
43
- end
44
-
45
- def test_format_dl
46
- p1 = <<-EOF
47
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
48
- incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
49
- nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
50
- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
51
- fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
52
- in culpa qui officia deserunt mollit anim id est laborum.
53
- EOF
54
-
55
- p2 = <<-EOF
56
-
57
- Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
58
- doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
59
- veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim
60
- ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia
61
- consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
62
-
63
- Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
64
- adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
65
- dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis
66
- nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex
67
- ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea
68
- voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem
69
- eum fugiat quo voluptas nulla pariatur?"
70
- EOF
71
-
72
- assert Misc.format_definition_list({:paragraph_first => p1, :paragraph_second => p2}) =~ / /
73
- end
74
-
75
- def test_parse_cmd_params
76
- assert_equal ["workflow", "task", "Translation", "translate", "-f", "Associated Gene Name", "-l", "-"],
77
- Misc.parse_cmd_params("workflow task Translation translate -f 'Associated Gene Name' -l -")
78
- end
79
-
80
-
81
- def test_fixutf8
82
- string = "abc\xffdef"
83
- string = string.force_encoding("UTF-8") if string.respond_to? :force_encoding
84
- assert(! string.valid_encoding?) if string.respond_to? :valid_encoding?
85
- assert(! string.valid_encoding) if string.respond_to? :valid_encoding
86
- assert( Misc.fixutf8(string).valid_encoding?) if string.respond_to? :valid_encoding?
87
- assert( Misc.fixutf8(string).valid_encoding) if string.respond_to? :valid_encoding
88
- end
89
-
90
- def test_colors_for
91
- colors, used = Misc.colors_for([1,2,2,1,2,1,2,2,3,3,2,3,2])
92
- assert_equal Misc::COLOR_LIST[1], used[2]
93
- end
94
-
95
- def test_total_length
96
- ranges = [(0..100), (50..150), (120..160)]
97
- ranges = [(0..100), (50..150), (120..160), (51..70)]
98
- assert_equal 161, Misc.total_length(ranges)
99
- end
100
-
101
- def test_id_filename?
102
- TmpFile.with_file("") do |file|
103
- assert Misc.is_filename?(file)
104
- assert ! Misc.is_filename?("TEST STRING")
105
- end
106
- end
107
-
108
- def test_merge_sorted_arrays
109
- assert_equal [1,2,3,4], Misc.merge_sorted_arrays([1,3], [2,4])
110
- end
111
-
112
- def test_intersect_sorted_arrays
113
- assert_equal [2,4], Misc.intersect_sorted_arrays([1,2,3,4], [2,4])
114
- end
115
-
116
- def test_sorted_array_matches
117
- assert_equal [1,3], Misc.sorted_array_hits(%w(a b c d e), %w(b d))
118
- end
119
-
120
- def test_binary_include?
121
- a = %w(a b c d e).sort
122
- assert Misc.binary_include?(a, "a")
123
- assert(!Misc.binary_include?(a, "z"))
124
- assert(Misc.binary_include?(a, "b"))
125
- assert(Misc.binary_include?(a, "c"))
126
- assert(Misc.binary_include?(a, "d"))
127
- end
128
-
129
- def test_process_to_hash
130
- list = [1,2,3,4]
131
- assert_equal 4, Misc.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
132
- end
133
-
134
- def test_pipe_fork
135
- sout, sin = Misc.pipe
136
- pid = Process.fork do
137
- Misc.purge_pipes(sin)
138
- sleep 2
139
- sin.close
140
- end
141
- sin.close
142
- assert sout.eof?
143
- Process.kill :INT, pid
144
- end
145
-
146
- def test_open_pipe
147
- t = 5
148
- stream = Misc.open_pipe do |sin|
149
- t.times do |i|
150
- sleep 0.5
151
- sin.puts "LINE #{ i }"
152
- end
153
- end
154
-
155
- time = Time.now
156
- lines = []
157
- while line = stream.gets
158
- lines << line.strip
159
- end
160
- time_spent = Time.new - time
161
-
162
- assert time_spent >= t * 0.5
163
- assert time_spent <= (t+1) * 0.5
164
- assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }"}, lines
165
- end
166
-
167
- def test_open_pipe_fork
168
- t = 5
169
- stream = Misc.open_pipe(true) do |sin|
170
- t.times do |i|
171
- sleep 0.5
172
- sin.puts "LINE #{ i }"
173
- end
174
- sin.close
175
- end
176
-
177
- time = Time.now
178
- lines = []
179
- while line = stream.gets
180
- lines << line.strip
181
- end
182
- time_spent = Time.new - time
183
-
184
- assert time_spent >= t * 0.5
185
- assert time_spent <= (t+1) * 0.5
186
- assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }"}, lines
187
- end
188
-
189
- def test_open_pipe_fork_cascade
190
- t = 500
191
- sleep_time = 2.0 / t
192
- time = Time.now
193
-
194
- stream1 = Misc.open_pipe(true) do |sin|
195
- t.times do |i|
196
- sleep sleep_time
197
- sin.puts "LINE #{ i }"
198
- end
199
- end
200
-
201
- stream2 = Misc.open_pipe(true) do |sin|
202
- while line = stream1.gets
203
- sin.puts line.strip.reverse
204
- end
205
- end
206
-
207
- stream3 = Misc.open_pipe(true) do |sin|
208
- while line = stream2.gets
209
- sin.puts line.downcase
210
- end
211
- end
212
-
213
- lines = []
214
- while line = stream3.gets
215
- lines << line.strip
216
- end
217
-
218
- time_spent = Time.new - time
219
-
220
- assert time_spent >= t * sleep_time
221
- assert time_spent <= t * 1.2 * sleep_time
222
- assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }".reverse.downcase}, lines
223
- end
224
-
225
- def test_tee_stream
226
- t = 500
227
- sleep_time = 2.0 / t
228
- time = Time.now
229
-
230
- stream1 = Misc.open_pipe(true) do |sin|
231
- t.times do |i|
232
- sleep sleep_time
233
- sin.puts "LINE #{ i }"
234
- end
235
- end
236
-
237
- stream2, stream3 = Misc.tee_stream stream1
238
-
239
- stream4 = Misc.open_pipe(true) do |sin|
240
- while line = stream2.gets
241
- sin.puts line.strip.reverse
242
- end
243
- end
244
- stream2.close
245
-
246
- stream5 = Misc.open_pipe(true) do |sin|
247
- while line = stream3.gets
248
- sin.puts line.strip.downcase
249
- end
250
- end
251
- stream3.close
252
-
253
- lines1 = []
254
- th1 = Thread.new do
255
- while line = stream4.gets
256
- lines1 << line.strip
257
- end
258
- end
259
-
260
- lines2 = []
261
- th2 = Thread.new do
262
- while line = stream5.gets
263
- lines2 << line.strip
264
- end
265
- end
266
- th1.join and th2.join
267
-
268
- time_spent = Time.new - time
269
-
270
- assert time_spent >= t * sleep_time
271
- assert time_spent <= t * 1.5 * sleep_time
272
- assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }".reverse}, lines1
273
- assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }".downcase}, lines2
274
- end
275
-
276
-
277
- def test_string2hash
278
- assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
279
- assert_equal(true, Misc.string2hash(":true")[:true])
280
- assert_equal(true, Misc.string2hash("true")["true"])
281
- assert_equal(1, Misc.string2hash("a=1")["a"])
282
- assert_equal('b', Misc.string2hash("a=b")["a"])
283
- assert_equal('d', Misc.string2hash("a=b#c=d#:h='j'")["c"])
284
- assert_equal('j', Misc.string2hash("a=b#c=d#:h='j'")[:h])
285
- assert_equal(:j, Misc.string2hash("a=b#c=d#:h=:j")[:h])
286
- end
287
-
288
- def test_named_array
289
- a = NamedArray.setup([1,2,3,4], %w(a b c d))
290
- assert_equal(1, a['a'])
291
- end
292
-
293
- def test_path_relative_to
294
- assert_equal "test/foo", Misc.path_relative_to('/test', '/test/test/foo')
295
- end
296
-
297
- def test_hash2string
298
- hash = {}
299
- assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
300
-
301
- hash = {:a => 1}
302
- assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
303
-
304
- hash = {:a => true}
305
- assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
306
-
307
- hash = {:a => :b}
308
- assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
309
-
310
- hash = {:a => /test/}
311
- assert_equal({}, Misc.string2hash(Misc.hash2string(hash)))
312
-
313
- end
314
-
315
- def test_merge
316
- a = [[1],[2]]
317
- a = NamedArray.setup a, %w(1 2)
318
- a.merge [3,4]
319
- assert_equal [1,3], a[0]
320
- end
321
-
322
- def test_indiferent_hash
323
- a = {:a => 1, "b" => 2}
324
- a.extend IndiferentHash
325
-
326
- assert_equal 1, a[:a]
327
- assert_equal 1, a["a"]
328
- assert_equal 2, a["b"]
329
- assert_equal 2, a[:b]
330
- end
331
-
332
- def test_lockfile
333
-
334
- TmpFile.with_file do |tmpfile|
335
- pids = []
336
- 4.times do |i|
337
- pids << Process.fork do
338
- status = Misc.lock(tmpfile) do
339
- pid = Process.pid.to_s
340
- Open.write(tmpfile, pid)
341
- sleep rand * 1
342
- if pid == Open.read(tmpfile)
343
- 0
344
- else
345
- 1
346
- end
347
- end
348
- exit(status)
349
- end
350
-
351
- end
352
- pids.each do |pid| Process.waitpid pid; assert $?.success? end
353
- end
354
- end
355
-
356
- def test_positions2hash
357
- inputs = Misc.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
358
- assert_equal 1, inputs[:one]
359
- assert_equal 2, inputs[:two]
360
- assert_equal nil, inputs[:three]
361
- assert_equal nil, inputs[:four]
362
- end
363
-
364
- def test_mean
365
- assert_equal 2, Misc.mean([1,2,3])
366
- assert_equal 3, Misc.mean([1,2,3,4,5])
367
- end
368
-
369
- def test_zip_fields
370
- current = [[:a,1], [:b,2]]
371
- assert_equal [[:a, :b],[1,2]], Misc.zip_fields(current)
372
- assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
373
- end
374
-
375
- def test_zip_fields_large
376
- current = (1..1500).to_a.collect{|i| ["A#{i}", "B#{i}"]}
377
- assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
378
- current = (1..150000).to_a.collect{|i| ["A#{i}", "B#{i}"]}
379
- assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
380
- end
381
-
382
- def test_zip_fields_comp
383
- current = [[:a,1], [:b,2], [:c]]
384
- assert_equal [[:a, :b, :c],[1,2,nil]], Misc.zip_fields(current)
385
- assert_equal current, Misc.zip_fields(Misc.zip_fields(current)).collect{|v| v.compact }
386
- end
387
-
388
- def test_add_zipped
389
- current = [[:a,1], [:b,2]]
390
- new = %w(A B)
391
- Misc.append_zipped current, new
392
- assert_equal [[:a,1,"A"], [:b,2,"B"]], current
393
- end
394
-
395
- def test_divide
396
- assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
397
- end
398
-
399
- def test_ordered_divide
400
- assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
401
- end
402
-
403
- def test_collapse_ranges
404
- ranges = [(0..100), (50..150), (51..61),(200..250), (300..324),(320..350)]
405
- assert_equal [(0..150),(200..250), (300..350)], Misc.collapse_ranges(ranges)
406
- end
407
-
408
- def test_humanize
409
- str1 = "test_string"
410
- str2 = "TEST_string"
411
- str3 = "test"
412
-
413
- assert_equal "Test string", Misc.humanize(str1)
414
- assert_equal "TEST string", Misc.humanize(str2)
415
- assert_equal "Test", Misc.humanize(str3)
416
-
417
- assert_equal "mutation_enrichment", Misc.snake_case("MutationEnrichment")
418
- end
419
-
420
- def test_snake_case
421
- str1 = "ACRONIMTest"
422
- str2 = "ACRONIM_test"
423
- assert_equal "ACRONIM_test", Misc.snake_case(str1)
424
- assert_equal "ACRONIM_test", Misc.snake_case(str2)
425
- end
426
-
427
- def test_correct_vcf_mutations
428
- assert_equal [737407, ["-----", "-----G", "-----GTTAAT"]], Misc.correct_vcf_mutation(737406, "GTTAAT", "G,GG,GGTTAAT")
429
- end
430
-
431
-
432
- def test_fingerprint
433
- assert_equal '{:a=>1}', Misc.fingerprint({:a => 1})
434
- end
435
-
436
- def test_tarize
437
- dir = Path.caller_lib_dir(__FILE__)
438
- path = File.expand_path(dir)
439
- stream = Misc.tarize(path)
440
- TmpFile.with_file do |res|
441
- Misc.in_dir(res) do
442
- CMD.cmd("tar xvfz - ", :in => stream)
443
- end
444
- end
445
- end
446
-
447
- def test_camel_case
448
- assert_equal "DbSNP", Misc.camel_case("db_SNP")
449
- assert_equal "D3Js", Misc.camel_case("D3Js")
450
- assert_equal "Structure", Misc.camel_case("Structure")
451
- assert_equal "MutEval", Misc.camel_case("mut_eval")
452
- assert_equal "COSMIC", Misc.camel_case("COSMIC")
453
- end
454
-
455
- def test_texar
456
- ppp Misc.html_tag('textarea', "hola\nadios\nagain")
457
- end
458
-
459
- def test_link_title
460
- ppp Misc.html_tag('a', "hola\nadios\nagain", :title => "Hola adios")
461
- end
462
-
463
- def __test_lock_fd
464
- require 'rbbt/workflow'
465
- Rbbt.var.jobs.Structure.neighbour_map.glob("*")[0..1000].each do |file|
466
- next if file =~ /\.info$/
467
- step = Step.new file
468
- TSV.open step.path
469
- end
470
- puts `ls -l /proc/#{ Process.pid }/fd`
471
- end
472
-
473
- def test_snake_case
474
- assert_equal "kinase_SAR_fari", Misc.snake_case("KinaseSARFari")
475
- end
476
-
477
- def test_bootstrap
478
- res = Misc.bootstrap((1..10).to_a, 2, :bar => "Test bootstrap ticks", :respawn => :always, :into => []) do |num|
479
- sleep 1 + rand(2)
480
- num
481
- end
482
- end
483
-
484
- def test_obj2md5
485
- str = "string" * 1000000
486
- obj1 = [1,2,"test_str", 0.3, [1,2,3], {:a => [1,2], :b => str}]
487
-
488
- obj2 = [1,2,"test_str", 0.3, [1,2,3], {:a => [1,2,3], :b => str}]
489
- obj3 = [1,2,:test_str, 0.3, [1,2,3], {:a => [1,2,"3"], :b => str}]
490
-
491
- assert_not_equal Misc.obj2md5(obj1), Misc.obj2md5(obj2)
492
- assert_equal Misc.obj2md5(obj2), Misc.obj2md5(obj3)
493
- hash = Hash[*(0..obj1.length).zip(obj1).flatten]
494
-
495
- Misc.benchmark(1000) do
496
- Misc.hash2md5(hash)
497
- end
498
- Misc.benchmark(1000) do
499
- Misc.obj2md5(obj1)
500
- end
501
- Misc.profile do
502
- 10.times do
503
- Misc.hash2md5(hash)
504
- end
505
- end
506
- Misc.profile do
507
- 10.times do
508
- Misc.obj2md5(obj1)
509
- end
510
- end
511
- end
512
-
513
- def test_obj2md5_str_float
514
- assert_equal Misc.obj2md5([1,2]), Misc.obj2md5(["1","2"])
515
- end
516
-
517
- def test_sample_large_string
518
- str = "string" * 1000000
519
-
520
- max = 100
521
- assert_equal Misc.sample_large_obj(str, max).length, max+51
522
-
523
- max = 1000
524
- assert_equal Misc.sample_large_obj(str, max).length, max+51
525
- end
526
-
527
- def test_sample_large_array
528
- str = (0..1000000).to_a
529
-
530
- max = 100
531
- assert_equal Misc.sample_large_obj(str, max).length, max+29
532
-
533
- max = 1000
534
- assert_equal Misc.sample_large_obj(str, max).length, max+29
535
- end
536
-
537
- def test_match_value
538
- assert Misc.match_value("10", "10")
539
- assert Misc.match_value("Hi", /hi/i)
540
- assert Misc.match_value("Hi", /Hi/)
541
- assert Misc.match_value("Hi", "/Hi/")
542
- assert Misc.match_value("Hi", "/hi/i")
543
- assert Misc.match_value("15", "<=20")
544
- assert Misc.match_value("15", ">14")
545
- assert Misc.match_value("15", "! >15")
546
- assert Misc.match_value("15", "! >15")
547
- assert Misc.match_value("15", [14, 15, 25])
548
- assert ! Misc.match_value("15", [14, 25])
549
- end
550
-
551
- def __test_bench_log
552
- Misc.benchmark(1000) do
553
- Log.info { "Hola" }
554
- end
555
- Misc.benchmark(1000) do
556
- Log.debug { "Hola" }
557
- end
558
- Misc.benchmark(1000) do
559
- Log.debug "Hola"
560
- end
561
- p = Misc.pipe
562
- Misc.benchmark(1000) do
563
- Log.debug "Hola #{[p.first.inspect, p.last.inspect] * "=>"}"
564
- end
565
- end
566
-
567
- def test_sanitize_filename
568
- text = "This is a very long line that needs to be split in several lines"
569
- assert Misc.break_lines(text, 10).split("\n").length == 1 + text.length / 10
570
- assert Misc.break_lines(text, 10).split("\n").select{|l| l.length > 10 }.empty?
571
- end
572
-
573
- def test_parse_sql_values
574
- str=<<'EOF'
575
- (xxx,yyy,zzz),(aaa,'bb(,)b',ccc)
576
- EOF
577
- assert Misc.parse_sql_values(str)[1][1] == "bb(,)b"
578
- end
579
-
580
- def test_match_fields
581
- f1 = "Target (Associated Gene Name)"
582
- f2 = "Source (Associated Gene Name)"
583
- f3 = "Associated Gene Name"
584
-
585
- assert Misc.match_fields(f1, f2)
586
- assert Misc.match_fields(f1, f3)
587
- assert Misc.match_fields(f3, f1)
588
- end
589
-
590
- def test_case_insensitive
591
- hash = {"A" => 1, :b => 2, "c" => 3}
592
- CaseInsensitiveHash.setup hash
593
-
594
- assert_equal 1, hash["A"]
595
- assert_equal 1, hash[:A]
596
- assert_equal 1, hash[:a]
597
- assert_equal 2, hash["B"]
598
- assert_equal 2, hash["b"]
599
- assert_equal 1, hash[:A]
600
- assert_equal 3, hash[:C]
601
- end
602
-
603
- def test_time_stamp
604
- assert_equal 10, Misc.timespan('10')
605
- assert_equal 10, Misc.timespan('10s')
606
- assert_equal 60, Misc.timespan('1min')
607
- assert_equal 60, Misc.timespan('00:01:00')
608
- assert_equal 60, Misc.timespan('01:00')
609
- assert_equal 60, Misc.timespan('0:1:00')
610
- assert_equal 60*60*24, Misc.timespan('1d')
611
- assert_equal 60*60*24, Misc.timespan('1d')
612
- assert_equal 60*60*24, Misc.timespan('24:00:00')
613
-
614
- assert_equal Misc.timespan('1min'), - Misc.timespan('-1min')
615
- end
616
-
617
- def test_remove_long_items
618
- tsv = TSV.setup({}, "key~value1,value2#:type=:list")
619
- tsv["a"] = [2,3]
620
- tsv["b"] = [6,7]
621
- iii Misc.remove_long_items(tsv)
622
- 1000.times do |n|
623
- tsv[n] = [n*2, n*3]
624
- end
625
- iii Misc.remove_long_items(tsv)
626
- end
627
-
628
- def test_digest_file
629
- TmpFile.with_file("FILE CONTENT") do |file|
630
- assert_match /^[0-9a-z]{10,}$/, Misc.file2md5(file)
631
- end
632
- end
633
-
634
- def test_scan_version_text
635
- txt =<<-EOF
636
- Program: bcftools (Tools for variant calling and manipulating VCFs and BCFs)
637
- Version: 1.10.2-dirty (using htslib 1.10.2-12-gd807564-dirty)
638
-
639
- Usage: bcftools [--version|--version-only] [--help] <command> <argument>
640
-
641
- Commands:
642
-
643
- -- Indexing
644
- index index VCF/BCF files
645
-
646
- -- VCF/BCF manipulation
647
- annotate annotate and edit VCF/BCF files
648
- concat concatenate VCF/BCF files from the same set of samples
649
- convert convert VCF/BCF files to different formats and back
650
- isec intersections of VCF/BCF files
651
- merge merge VCF/BCF files files from non-overlapping sample sets
652
- norm left-align and normalize indels
653
- plugin user-defined plugins
654
- query transform VCF/BCF into user-defined formats
655
- reheader modify VCF/BCF header, change sample names
656
- sort sort VCF/BCF file
657
- view VCF/BCF conversion, view, subset and filter VCF/BCF files
658
-
659
- -- VCF/BCF analysis
660
- call SNP/indel calling
661
- consensus create consensus sequence by applying VCF variants
662
- cnv HMM CNV calling
663
- csq call variation consequences
664
- filter filter VCF/BCF files using fixed thresholds
665
- gtcheck check sample concordance, detect sample swaps and contamination
666
- mpileup multi-way pileup producing genotype likelihoods
667
- roh identify runs of autozygosity (HMM)
668
- stats produce VCF/BCF stats
669
-
670
- Most commands accept VCF, bgzipped VCF, and BCF with the file type detected
671
- automatically even when streaming from a pipe. Indexed VCF and BCF will work
672
- in all situations. Un-indexed VCF and BCF and streams will work in most but
673
- not all situations.
674
- EOF
675
-
676
- assert_equal "1.10.2-dirty", Misc.scan_version_text(txt, "bcftools")
677
-
678
- txt =<<-EOF
679
- The Genome Analysis Toolkit (GATK) 4.1.4.1
680
- HTSJDK Version: 2.21.0
681
- Picard Version: 2.21.2
682
- EOF
683
- assert_equal "4.1.4.1", Misc.scan_version_text(txt, "gatk")
684
-
685
-
686
- txt =<<-EOF
687
- grep (GNU grep) 3.1
688
- Copyright (C) 2017 Free Software Foundation, Inc.
689
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
690
- This is free software: you are free to change and redistribute it.
691
- There is NO WARRANTY, to the extent permitted by law.
692
-
693
- Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
694
- EOF
695
- assert_equal "3.1", Misc.scan_version_text(txt, "grep")
696
- end
697
-
698
- def test_bootstrap_current_only_once
699
-
700
-
701
- max = Etc.nprocessors * 10
702
- TmpFile.with_file do |f|
703
- RbbtSemaphore.with_semaphore(1) do |sem|
704
- Misc.bootstrap (1..max).to_a do
705
- Open.open(f, :mode => 'a') do |sin|
706
- sin.puts Process.pid.to_s
707
- end
708
- Misc.bootstrap (1..10).to_a do
709
- RbbtSemaphore.synchronize(sem) do
710
- Open.open(f, :mode => 'a') do |sin|
711
- sin.puts [Process.ppid.to_s, Process.pid.to_s] * ":"
712
- end
713
- end
714
- end
715
- end
716
- end
717
- assert_equal max * 10 + max, Open.read(f).split("\n").length
718
- assert_equal Etc.nprocessors * 2, Open.read(f).split("\n").uniq.length
719
- end
720
-
721
- end
722
-
723
- def test_tokenize
724
- iii Misc.tokenize("One Two 'this is Three'")
725
- iii Misc.tokenize("some - 'Ex t=tr'")
726
- end
727
- end
728
-