rbbt-util 5.20.12 → 5.20.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/persist/tsv.rb +1 -0
- data/lib/rbbt/tsv/parser.rb +0 -1
- data/lib/rbbt/tsv/stream.rb +60 -1
- data/lib/rbbt/tsv/util.rb +0 -42
- data/lib/rbbt/util/misc/omics.rb +1 -1
- data/lib/rbbt/util/misc/pipes.rb +0 -5
- data/lib/rbbt/workflow/step/dependencies.rb +1 -2
- data/test/rbbt/tsv/test_stream.rb +16 -0
- 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: 841046995ec2cd9dda2e965c39eb088c77460d72
|
4
|
+
data.tar.gz: 5f07ff9767eaf96377ff5dc1ed222599e111486d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f2f171aedb529a94e7d972859f8dcc6b2c152a74e0bbc37e8d3816f1274f9df3e2bbc593d633be412cea27b47c7dcae47e29f2ae8c4d019812b4492a5eea59
|
7
|
+
data.tar.gz: 19e701161b6b0c8b7cf74e508b18365d94c53af2783441145afda1673dd38f45c16a17ef64527a5d99484246c9e80a64ec780edefbe95ed39028812abdd145ca
|
data/lib/rbbt/persist/tsv.rb
CHANGED
data/lib/rbbt/tsv/parser.rb
CHANGED
data/lib/rbbt/tsv/stream.rb
CHANGED
@@ -10,7 +10,7 @@ module TSV
|
|
10
10
|
|
11
11
|
sorted_input_stream = Misc.sort_stream input_stream, header_hash, cmd_args
|
12
12
|
|
13
|
-
parser = TSV::Parser.new
|
13
|
+
parser = TSV::Parser.new(sorted_input_stream, options.dup)
|
14
14
|
dumper = TSV::Dumper.new parser
|
15
15
|
header = TSV.header_lines(parser.key_field, parser.fields, parser.options)
|
16
16
|
dumper.close_in
|
@@ -232,4 +232,63 @@ module TSV
|
|
232
232
|
end
|
233
233
|
dumper
|
234
234
|
end
|
235
|
+
|
236
|
+
|
237
|
+
def self.reorder_stream(stream, positions, sep = "\t")
|
238
|
+
Misc.open_pipe do |sin|
|
239
|
+
line = stream.gets
|
240
|
+
line.strip! unless line.nil?
|
241
|
+
|
242
|
+
while line =~ /^#\:/
|
243
|
+
sin.puts line
|
244
|
+
line = stream.gets
|
245
|
+
line.strip! unless line.nil?
|
246
|
+
end
|
247
|
+
|
248
|
+
while line =~ /^#/
|
249
|
+
if Hash === positions
|
250
|
+
new = (0..line.split(sep).length-1).to_a
|
251
|
+
positions.each do |k,v|
|
252
|
+
new[k] = v
|
253
|
+
new[v] = k
|
254
|
+
end
|
255
|
+
positions = new
|
256
|
+
end
|
257
|
+
sin.puts "#" + line.sub(/^#/,'').strip.split(sep).values_at(*positions).compact * sep
|
258
|
+
line = stream.gets
|
259
|
+
line.strip! unless line.nil?
|
260
|
+
end
|
261
|
+
|
262
|
+
while line
|
263
|
+
if Hash === positions
|
264
|
+
new = (0..line.split(sep).length-1).to_a
|
265
|
+
positions.each do |k,v|
|
266
|
+
new[k] = v
|
267
|
+
new[v] = k
|
268
|
+
end
|
269
|
+
positions = new
|
270
|
+
end
|
271
|
+
values = line.split(sep)
|
272
|
+
new_values = values.values_at(*positions)
|
273
|
+
sin.puts new_values * sep
|
274
|
+
line = stream.gets
|
275
|
+
line.strip! unless line.nil?
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
def self.reorder_stream_tsv(stream, key_field, fields)
|
282
|
+
parser = TSV::Parser.new TSV.get_stream(stream), :key_field => key_field, :fields => fields
|
283
|
+
dumper_options = parser.options
|
284
|
+
dumper = TSV::Dumper.new dumper_options
|
285
|
+
dumper.init
|
286
|
+
TSV.traverse parser, :into => dumper do |key,values|
|
287
|
+
key = key.first if Array === key
|
288
|
+
values = [values] unless Array === values
|
289
|
+
[key, values]
|
290
|
+
end
|
291
|
+
dumper
|
292
|
+
end
|
293
|
+
|
235
294
|
end
|
data/lib/rbbt/tsv/util.rb
CHANGED
@@ -6,48 +6,6 @@ module TSV
|
|
6
6
|
field_matches.sort_by{|field, count| count.to_i}.last
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.reorder_stream(stream, positions, sep = "\t")
|
10
|
-
Misc.open_pipe do |sin|
|
11
|
-
line = stream.gets
|
12
|
-
line.strip! unless line.nil?
|
13
|
-
|
14
|
-
while line =~ /^#\:/
|
15
|
-
sin.puts line
|
16
|
-
line = stream.gets
|
17
|
-
line.strip! unless line.nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
while line =~ /^#/
|
21
|
-
if Hash === positions
|
22
|
-
new = (0..line.split(sep).length-1).to_a
|
23
|
-
positions.each do |k,v|
|
24
|
-
new[k] = v
|
25
|
-
new[v] = k
|
26
|
-
end
|
27
|
-
positions = new
|
28
|
-
end
|
29
|
-
sin.puts "#" + line.sub(/^#/,'').strip.split(sep).values_at(*positions).compact * sep
|
30
|
-
line = stream.gets
|
31
|
-
line.strip! unless line.nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
while line
|
35
|
-
if Hash === positions
|
36
|
-
new = (0..line.split(sep).length-1).to_a
|
37
|
-
positions.each do |k,v|
|
38
|
-
new[k] = v
|
39
|
-
new[v] = k
|
40
|
-
end
|
41
|
-
positions = new
|
42
|
-
end
|
43
|
-
values = line.split(sep)
|
44
|
-
new_values = values.values_at(*positions)
|
45
|
-
sin.puts new_values * sep
|
46
|
-
line = stream.gets
|
47
|
-
line.strip! unless line.nil?
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
9
|
|
52
10
|
def self.field_match_counts(file, values, options = {})
|
53
11
|
options = Misc.add_defaults options, :persist_prefix => "Field_Matches"
|
data/lib/rbbt/util/misc/omics.rb
CHANGED
data/lib/rbbt/util/misc/pipes.rb
CHANGED
@@ -398,11 +398,6 @@ module Misc
|
|
398
398
|
def self.sort_stream(stream, header_hash = "#", cmd_args = "-u")
|
399
399
|
Misc.open_pipe do |sin|
|
400
400
|
begin
|
401
|
-
#if defined? Step and Step === stream
|
402
|
-
# step = stream
|
403
|
-
# stream = stream.get_stream || stream.path.open
|
404
|
-
#end
|
405
|
-
|
406
401
|
stream = TSV.get_stream stream
|
407
402
|
|
408
403
|
line = stream.gets
|
@@ -153,8 +153,7 @@ class Step
|
|
153
153
|
Log.error "Interrupted while in dep. #{Log.color :red, dependency.task_name.to_s}"
|
154
154
|
raise $!
|
155
155
|
rescue Exception
|
156
|
-
Log.error "Exception in dep. #{ Log.color :red, dependency.task_name.to_s }"
|
157
|
-
Log.exception $!
|
156
|
+
Log.error "Exception in dep. #{ Log.color :red, dependency.task_name.to_s } -- #{$!.message}"
|
158
157
|
raise $!
|
159
158
|
end
|
160
159
|
end
|
@@ -217,4 +217,20 @@ row2 a|aa|aaa
|
|
217
217
|
assert_equal text2, s2.stream.read
|
218
218
|
end
|
219
219
|
|
220
|
+
def test_reorder_stream
|
221
|
+
text=<<-EOF
|
222
|
+
#: :sep=" "
|
223
|
+
#Row LabelA LabelB LabelC
|
224
|
+
row1 A B C
|
225
|
+
row1 a b c
|
226
|
+
row2 AA BB CC
|
227
|
+
row2 aa bb cc
|
228
|
+
row4 BBB CC
|
229
|
+
EOF
|
230
|
+
|
231
|
+
s = StringIO.new text
|
232
|
+
dumper = TSV.reorder_stream_tsv(s, "LabelC", %w(Row LabelA))
|
233
|
+
tsv = TSV.open TSV.collapse_stream(dumper.stream).stream.read
|
234
|
+
assert_equal %w(row2 row4), tsv["CC"]["Row"]
|
235
|
+
end
|
220
236
|
end
|
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.20.
|
4
|
+
version: 5.20.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|