rbbt-util 5.13.8 → 5.13.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7281b74a41b34bf9cc71d351b6ca175a40f8aeb
4
- data.tar.gz: 6f31f788281e74e00b594e9ff0303ccf0cddb491
3
+ metadata.gz: 7d7f9b2c2641577f41749304b67d7a7df205ba84
4
+ data.tar.gz: 0698c8200f48d6f115fef5730865b7421c49e1b5
5
5
  SHA512:
6
- metadata.gz: 7faad521cd49f6079fc8db95d49ad2d60dfda58f0ba99ee2f7249dcc519b3967df2c1a8cbe09f6de6af8d31c219233b3181ca7b70b859383885f335d7e13d80d
7
- data.tar.gz: c218eb43aaaee50d7fb41c08d55b99b5615243e7c9f38bf6d1c499ee1766486c0f4e1cd21edd01389525747714f50669c35d6a120aab7e01c1011dd1410fd216
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 Integer === field
121
- field
122
- when (field.nil? or field == :key)
119
+ case field
120
+ when nil
123
121
  :key
124
- when (String === field and not fields.nil?)
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
- Log.medium "Field #{ field } was not found. Options: #{fields * ", "}" if pos.nil?
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 "No fields specified in TSV.identify_field" if fields.nil?
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
- first.zip(*array[1..-1])
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
 
@@ -6,7 +6,7 @@ require 'rbbt/entity'
6
6
 
7
7
  class TestMisc < Test::Unit::TestCase
8
8
 
9
- def test_format_paragraph
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 test_format_dl
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 test_parse_cmd_params
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 test_fixutf8
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 test_colors_for
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 test_total_length
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 test_id_filename?
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 test_merge_sorted_arrays
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 test_intersect_sorted_arrays
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 test_sorted_array_matches
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 test_binary_include?
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 test_process_to_hash
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 test_pipe_fork
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 test_open_pipe
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 test_open_pipe_fork
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 test_open_pipe_fork_cascade
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 test_tee_stream
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 test_string2hash
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 test_named_array
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 test_path_relative_to
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 test_hash2string
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 test_merge
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 test_indiferent_hash
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 test_lockfile
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 test_positions2hash
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 test_mean
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 test_zip_fields
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 test_add_zipped
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 test_divide
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 test_ordered_divide
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 test_collapse_ranges
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 test_humanize
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 test_snake_case
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 test_correct_vcf_mutations
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 test_fingerprint
409
+ def _test_fingerprint
404
410
  assert_equal '{a=>1}', Misc.fingerprint({:a => 1})
405
411
  end
406
412
 
407
- def test_tarize
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 test_camel_case
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.8
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-09 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake