rbbt-util 5.13.8 → 5.13.9
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.
- checksums.yaml +4 -4
- data/lib/rbbt/tsv/util.rb +16 -11
- data/lib/rbbt/util/misc/objects.rb +6 -1
- data/share/rbbt_commands/tsv/unzip +1 -1
- data/test/rbbt/util/test_misc.rb +43 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d7f9b2c2641577f41749304b67d7a7df205ba84
|
4
|
+
data.tar.gz: 0698c8200f48d6f115fef5730865b7421c49e1b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30ccf37acc2676ce5a28c8237d96447d16b00b97d662dbd73cde7b3a9b9558dc6c9f710463eeb6b291a2a942c9bf6de3b9e662c7ae651e29d1c8d094cfc7c9f8
|
7
|
+
data.tar.gz: a3d39bafa0638bd682f18e3e1993538bb2ab812ea4a96da5e8d77f1c84bd52b9811e1617acc8fd90b1758bf83ee590c58f69e204664d6b002436283fc4ef045f
|
data/lib/rbbt/tsv/util.rb
CHANGED
@@ -116,23 +116,28 @@ module TSV
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def self.identify_field(key_field, fields, field)
|
119
|
-
case
|
120
|
-
when
|
121
|
-
field
|
122
|
-
when (field.nil? or field == :key)
|
119
|
+
case field
|
120
|
+
when nil
|
123
121
|
:key
|
124
|
-
when
|
122
|
+
when Symbol
|
123
|
+
field == :key ? field : identify_field(key_field, fields, field.to_s)
|
124
|
+
when Integer
|
125
|
+
field
|
126
|
+
when (fields.nil? and String)
|
127
|
+
raise "No field information available and specified field not numeric: #{ field }" unless field =~ /^\d+$/
|
128
|
+
identify_field(key_field, fields, field.to_i)
|
129
|
+
when String
|
130
|
+
return key if key_field == field
|
125
131
|
pos = fields.index field
|
126
132
|
pos ||= :key if key_field == field
|
127
|
-
|
128
|
-
pos
|
129
|
-
when key_field == field
|
130
|
-
:key
|
133
|
+
return identify_field(key_field, fields, field.to_i) if field =~ /^\d+$/
|
134
|
+
raise "Field #{ field } was not found. Options: #{fields * ", "}" if pos.nil?
|
131
135
|
else
|
132
|
-
raise "
|
133
|
-
Log.medium "Field #{ field } was not found. Options: (#{key_field}), #{fields * ", "}"
|
136
|
+
raise "Field #{ field } was not found. Options: (#{key_field || "NO_KEY_FIELD"}), #{(fields || ["NO_FIELDS"]) * ", "}"
|
134
137
|
end
|
135
138
|
end
|
139
|
+
|
140
|
+
|
136
141
|
|
137
142
|
def self.header_lines(key_field, fields, entry_hash = {})
|
138
143
|
sep = (Hash === entry_hash and entry_hash[:sep]) ? entry_hash[:sep] : "\t"
|
@@ -52,7 +52,12 @@ module Misc
|
|
52
52
|
|
53
53
|
def self.zip_fields(array)
|
54
54
|
return [] if array.empty? or (first = array.first).nil?
|
55
|
-
|
55
|
+
max = array[1..-1].collect{|l| l.length}.max
|
56
|
+
rest = array[1..-1].collect{|v|
|
57
|
+
v.length == 1 & max > 1 ? v * max : v
|
58
|
+
}
|
59
|
+
first = first * max if first.length == 1 and max > 1
|
60
|
+
first.zip(*rest)
|
56
61
|
end
|
57
62
|
|
58
63
|
def self.field_position(fields, field, quiet = false)
|
@@ -15,8 +15,8 @@ Display summary information. Works with Tokyocabinet HDB and BDB as well.
|
|
15
15
|
-tch--tokyocabinet File is a TC HDB
|
16
16
|
-tcb--tokyocabinet_bd File is a TC BDB
|
17
17
|
-hh--header_hash* Change the character used to mark the header line (defaults to #)
|
18
|
-
-m--merge* Merge lines
|
19
18
|
-f--field* Field to unzip
|
19
|
+
-m--merge Merge lines
|
20
20
|
-h--help Help
|
21
21
|
EOF
|
22
22
|
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rbbt/entity'
|
|
6
6
|
|
7
7
|
class TestMisc < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def
|
9
|
+
def _test_format_paragraph
|
10
10
|
p = <<-EOF
|
11
11
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
|
12
12
|
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
@@ -26,7 +26,7 @@ in culpa qui officia deserunt mollit anim id est laborum.
|
|
26
26
|
assert Misc.format_paragraph(p, 70, 10, 5) =~ /\n\s*\* two/sm
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def _test_format_dl
|
30
30
|
p1 = <<-EOF
|
31
31
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
|
32
32
|
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
@@ -56,13 +56,13 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
56
56
|
assert Misc.format_definition_list({:paragraph_first => p1, :paragraph_second => p2}) =~ / /
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def _test_parse_cmd_params
|
60
60
|
assert_equal ["workflow", "task", "Translation", "translate", "-f", "Associated Gene Name", "-l", "-"],
|
61
61
|
Misc.parse_cmd_params("workflow task Translation translate -f 'Associated Gene Name' -l -")
|
62
62
|
end
|
63
63
|
|
64
64
|
|
65
|
-
def
|
65
|
+
def _test_fixutf8
|
66
66
|
string = "abc\xffdef"
|
67
67
|
string = string.force_encoding("UTF-8") if string.respond_to? :force_encoding
|
68
68
|
assert(! string.valid_encoding?) if string.respond_to? :valid_encoding?
|
@@ -71,37 +71,37 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
71
71
|
assert( Misc.fixutf8(string).valid_encoding) if string.respond_to? :valid_encoding
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
74
|
+
def _test_colors_for
|
75
75
|
colors, used = Misc.colors_for([1,2,2,1,2,1,2,2,3,3,2,3,2])
|
76
76
|
assert_equal Misc::COLOR_LIST[1], used[2]
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def _test_total_length
|
80
80
|
ranges = [(0..100), (50..150), (120..160)]
|
81
81
|
ranges = [(0..100), (50..150), (120..160), (51..70)]
|
82
82
|
assert_equal 161, Misc.total_length(ranges)
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
85
|
+
def _test_id_filename?
|
86
86
|
TmpFile.with_file("") do |file|
|
87
87
|
assert Misc.is_filename?(file)
|
88
88
|
assert ! Misc.is_filename?("TEST STRING")
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def _test_merge_sorted_arrays
|
93
93
|
assert_equal [1,2,3,4], Misc.merge_sorted_arrays([1,3], [2,4])
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
96
|
+
def _test_intersect_sorted_arrays
|
97
97
|
assert_equal [2,4], Misc.intersect_sorted_arrays([1,2,3,4], [2,4])
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
100
|
+
def _test_sorted_array_matches
|
101
101
|
assert_equal [1,3], Misc.sorted_array_hits(%w(a b c d e), %w(b d))
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
104
|
+
def _test_binary_include?
|
105
105
|
a = %w(a b c d e).sort
|
106
106
|
assert Misc.binary_include?(a, "a")
|
107
107
|
assert(!Misc.binary_include?(a, "z"))
|
@@ -110,12 +110,12 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
110
110
|
assert(Misc.binary_include?(a, "d"))
|
111
111
|
end
|
112
112
|
|
113
|
-
def
|
113
|
+
def _test_process_to_hash
|
114
114
|
list = [1,2,3,4]
|
115
115
|
assert_equal 4, Misc.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
|
116
116
|
end
|
117
117
|
|
118
|
-
def
|
118
|
+
def _test_pipe_fork
|
119
119
|
sout, sin = Misc.pipe
|
120
120
|
pid = Process.fork do
|
121
121
|
Misc.purge_pipes(sin)
|
@@ -127,7 +127,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
127
127
|
Process.kill :INT, pid
|
128
128
|
end
|
129
129
|
|
130
|
-
def
|
130
|
+
def _test_open_pipe
|
131
131
|
t = 5
|
132
132
|
stream = Misc.open_pipe do |sin|
|
133
133
|
t.times do |i|
|
@@ -148,7 +148,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
148
148
|
assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }"}, lines
|
149
149
|
end
|
150
150
|
|
151
|
-
def
|
151
|
+
def _test_open_pipe_fork
|
152
152
|
t = 5
|
153
153
|
stream = Misc.open_pipe(true) do |sin|
|
154
154
|
t.times do |i|
|
@@ -169,7 +169,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
169
169
|
assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }"}, lines
|
170
170
|
end
|
171
171
|
|
172
|
-
def
|
172
|
+
def _test_open_pipe_fork_cascade
|
173
173
|
t = 500
|
174
174
|
sleep_time = 2.0 / t
|
175
175
|
time = Time.now
|
@@ -205,7 +205,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
205
205
|
assert_equal (0..t-1).to_a.collect{|i| "LINE #{ i }".reverse.downcase}, lines
|
206
206
|
end
|
207
207
|
|
208
|
-
def
|
208
|
+
def _test_tee_stream
|
209
209
|
t = 500
|
210
210
|
sleep_time = 2.0 / t
|
211
211
|
time = Time.now
|
@@ -255,7 +255,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
255
255
|
end
|
256
256
|
|
257
257
|
|
258
|
-
def
|
258
|
+
def _test_string2hash
|
259
259
|
assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
|
260
260
|
assert_equal(true, Misc.string2hash(":true")[:true])
|
261
261
|
assert_equal(true, Misc.string2hash("true")["true"])
|
@@ -266,16 +266,16 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
266
266
|
assert_equal(:j, Misc.string2hash("a=b#c=d#:h=:j")[:h])
|
267
267
|
end
|
268
268
|
|
269
|
-
def
|
269
|
+
def _test_named_array
|
270
270
|
a = NamedArray.setup([1,2,3,4], %w(a b c d))
|
271
271
|
assert_equal(1, a['a'])
|
272
272
|
end
|
273
273
|
|
274
|
-
def
|
274
|
+
def _test_path_relative_to
|
275
275
|
assert_equal "test/foo", Misc.path_relative_to('/test', '/test/test/foo')
|
276
276
|
end
|
277
277
|
|
278
|
-
def
|
278
|
+
def _test_hash2string
|
279
279
|
hash = {}
|
280
280
|
assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
|
281
281
|
|
@@ -293,14 +293,14 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
293
293
|
|
294
294
|
end
|
295
295
|
|
296
|
-
def
|
296
|
+
def _test_merge
|
297
297
|
a = [[1],[2]]
|
298
298
|
a = NamedArray.setup a, %w(1 2)
|
299
299
|
a.merge [3,4]
|
300
300
|
assert_equal [1,3], a[0]
|
301
301
|
end
|
302
302
|
|
303
|
-
def
|
303
|
+
def _test_indiferent_hash
|
304
304
|
a = {:a => 1, "b" => 2}
|
305
305
|
a.extend IndiferentHash
|
306
306
|
|
@@ -310,7 +310,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
310
310
|
assert_equal 2, a[:b]
|
311
311
|
end
|
312
312
|
|
313
|
-
def
|
313
|
+
def _test_lockfile
|
314
314
|
|
315
315
|
TmpFile.with_file do |tmpfile|
|
316
316
|
pids = []
|
@@ -334,7 +334,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
334
334
|
end
|
335
335
|
end
|
336
336
|
|
337
|
-
def
|
337
|
+
def _test_positions2hash
|
338
338
|
inputs = Misc.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
|
339
339
|
assert_equal 1, inputs[:one]
|
340
340
|
assert_equal 2, inputs[:two]
|
@@ -342,18 +342,24 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
342
342
|
assert_equal nil, inputs[:four]
|
343
343
|
end
|
344
344
|
|
345
|
-
def
|
345
|
+
def _test_mean
|
346
346
|
assert_equal 2, Misc.mean([1,2,3])
|
347
347
|
assert_equal 3, Misc.mean([1,2,3,4,5])
|
348
348
|
end
|
349
349
|
|
350
|
-
def
|
350
|
+
def _test_zip_fields
|
351
351
|
current = [[:a,1], [:b,2]]
|
352
352
|
assert_equal [[:a, :b],[1,2]], Misc.zip_fields(current)
|
353
353
|
assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
|
354
354
|
end
|
355
355
|
|
356
|
-
def
|
356
|
+
def test_zip_fields_comp
|
357
|
+
current = [[:a,1], [:b,2], [:c]]
|
358
|
+
assert_equal [[:a, :b, :c],[1,2,nil]], Misc.zip_fields(current)
|
359
|
+
assert_equal current, Misc.zip_fields(Misc.zip_fields(current)).collect{|v| v.compact }
|
360
|
+
end
|
361
|
+
|
362
|
+
def _test_add_zipped
|
357
363
|
current = [[:a,1], [:b,2]]
|
358
364
|
new = %w(A B)
|
359
365
|
Misc.append_zipped current, new
|
@@ -364,20 +370,20 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
364
370
|
assert_equal Math.sqrt(2), Misc.sd([1,3])
|
365
371
|
end
|
366
372
|
|
367
|
-
def
|
373
|
+
def _test_divide
|
368
374
|
assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
369
375
|
end
|
370
376
|
|
371
|
-
def
|
377
|
+
def _test_ordered_divide
|
372
378
|
assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
373
379
|
end
|
374
380
|
|
375
|
-
def
|
381
|
+
def _test_collapse_ranges
|
376
382
|
ranges = [(0..100), (50..150), (51..61),(200..250), (300..324),(320..350)]
|
377
383
|
assert_equal [(0..150),(200..250), (300..350)], Misc.collapse_ranges(ranges)
|
378
384
|
end
|
379
385
|
|
380
|
-
def
|
386
|
+
def _test_humanize
|
381
387
|
str1 = "test_string"
|
382
388
|
str2 = "TEST_string"
|
383
389
|
str3 = "test"
|
@@ -389,22 +395,22 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
389
395
|
assert_equal "mutation_enrichment", Misc.snake_case("MutationEnrichment")
|
390
396
|
end
|
391
397
|
|
392
|
-
def
|
398
|
+
def _test_snake_case
|
393
399
|
str1 = "ACRONIMTest"
|
394
400
|
str2 = "ACRONIM_test"
|
395
401
|
assert_equal "ACRONIM_test", Misc.snake_case(str1)
|
396
402
|
assert_equal "ACRONIM_test", Misc.snake_case(str2)
|
397
403
|
end
|
398
404
|
|
399
|
-
def
|
405
|
+
def _test_correct_vcf_mutations
|
400
406
|
assert_equal [737407, ["-----", "-----G", "-----GTTAAT"]], Misc.correct_vcf_mutation(737406, "GTTAAT", "G,GG,GGTTAAT")
|
401
407
|
end
|
402
408
|
|
403
|
-
def
|
409
|
+
def _test_fingerprint
|
404
410
|
assert_equal '{a=>1}', Misc.fingerprint({:a => 1})
|
405
411
|
end
|
406
412
|
|
407
|
-
def
|
413
|
+
def _test_tarize
|
408
414
|
path = File.expand_path('/home/mvazquezg/git/rbbt-util/lib')
|
409
415
|
stream = Misc.tarize(path)
|
410
416
|
TmpFile.with_file do |res|
|
@@ -414,7 +420,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
414
420
|
end
|
415
421
|
end
|
416
422
|
|
417
|
-
def
|
423
|
+
def _test_camel_case
|
418
424
|
assert_equal "DbSNP", Misc.camel_case("db_SNP")
|
419
425
|
assert_equal "D3Js", Misc.camel_case("D3Js")
|
420
426
|
assert_equal "Structure", Misc.camel_case("Structure")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.13.
|
4
|
+
version: 5.13.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|