rbbt-util 5.8.10 → 5.9.0
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/annotations/util.rb +2 -2
- data/lib/rbbt/tsv.rb +1 -1
- data/lib/rbbt/tsv/parallel.rb +3 -100
- data/lib/rbbt/tsv/parallel/through.rb +102 -0
- data/lib/rbbt/tsv/parallel/traverse.rb +138 -0
- data/lib/rbbt/util/concurrency/processes.rb +1 -0
- data/lib/rbbt/util/concurrency/threads.rb +2 -2
- data/lib/rbbt/util/misc.rb +1 -0
- data/lib/rbbt/workflow/accessor.rb +2 -0
- data/test/rbbt/annotations/test_util.rb +1 -2
- data/test/rbbt/persist/tsv/test_cdb.rb +8 -6
- data/test/rbbt/persist/tsv/test_kyotocabinet.rb +13 -11
- data/test/rbbt/persist/tsv/test_leveldb.rb +7 -5
- data/test/rbbt/persist/tsv/test_lmdb.rb +5 -3
- data/test/rbbt/test_annotations.rb +14 -14
- data/test/rbbt/test_workflow.rb +1 -1
- data/test/rbbt/tsv/parallel/test_through.rb +42 -0
- data/test/rbbt/tsv/parallel/test_traverse.rb +151 -0
- data/test/rbbt/tsv/test_accessor.rb +1 -1
- data/test/rbbt/tsv/test_attach.rb +2 -1
- data/test/rbbt/tsv/test_index.rb +3 -3
- data/test/rbbt/tsv/test_parallel.rb +0 -35
- data/test/rbbt/util/concurrency/test_processes.rb +1 -4
- data/test/rbbt/util/concurrency/test_threads.rb +2 -4
- data/test/rbbt/util/test_misc.rb +0 -22
- data/test/rbbt/util/test_simpleDSL.rb +2 -2
- data/test/rbbt/workflow/test_step.rb +0 -2
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8809e7ff7afbc160340f326450273a14ca3ce286
|
4
|
+
data.tar.gz: 3de26d6f418fd60b21459b9cef3af0ed11844310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f3d7b38e869e5b88aa3005a6cdb1ffb96ca9eb8c8ef96625892ed3ba8a038422b9c7172806bda50fd1e1bdf4e014d75607ad0c8c4fe33a806e0498d3e4e6b88
|
7
|
+
data.tar.gz: c56376cae5c4fc796fedef603179fd4e1129581b7c495e6101705fe939f5facd1c5a200e500d592df10c26ec91466c118b79ca38efc2ad2b14aa9b414cf61be3
|
data/lib/rbbt/tsv.rb
CHANGED
@@ -160,7 +160,7 @@ module TSV
|
|
160
160
|
data
|
161
161
|
end
|
162
162
|
|
163
|
-
def self.
|
163
|
+
def self.traverse_old(file, options, &block)
|
164
164
|
return file.through(options[:key_field], options[:fields], &block) if TSV === file
|
165
165
|
|
166
166
|
TSV::Parser.traverse(TSV.get_stream(file), options, &block)
|
data/lib/rbbt/tsv/parallel.rb
CHANGED
@@ -1,104 +1,7 @@
|
|
1
1
|
require 'rbbt/util/concurrency'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
def pthrough(num_threads = 10, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
|
6
|
-
q = RbbtThreadQueue.new num_threads
|
7
|
-
|
8
|
-
q.init(true, &block)
|
9
|
-
|
10
|
-
begin
|
11
|
-
res = through(new_key_field, new_fields, uniq, zipped) do |*p|
|
12
|
-
q.process p
|
13
|
-
end
|
14
|
-
q.join
|
15
|
-
ensure
|
16
|
-
q.clean
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def ppthrough_callback(&block)
|
22
|
-
@ppthrough_callback = block
|
23
|
-
end
|
24
|
-
|
25
|
-
def ppthrough(num_procs = 7, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
|
26
|
-
|
27
|
-
q = RbbtProcessQueue.new num_procs
|
28
|
-
|
29
|
-
q.callback &@ppthrough_callback
|
30
|
-
@ppthrough_callback = nil
|
31
|
-
|
32
|
-
q.init do |k,v|
|
33
|
-
block.call k,v
|
34
|
-
end
|
35
|
-
|
36
|
-
begin
|
37
|
-
res = through(new_key_field, new_fields, uniq, zipped) do |*p|
|
38
|
-
q.process q
|
39
|
-
end
|
40
|
-
q.join
|
41
|
-
ensure
|
42
|
-
q.clean
|
43
|
-
end
|
44
|
-
|
45
|
-
res
|
46
|
-
end
|
3
|
+
require 'rbbt/tsv/parallel/through'
|
4
|
+
require 'rbbt/tsv/parallel/traverse'
|
47
5
|
|
48
|
-
|
49
|
-
|
50
|
-
q = RbbtProcessQueue.new num_procs
|
51
|
-
|
52
|
-
q.callback &@ppthrough_callback
|
53
|
-
@ppthrough_callback = nil
|
54
|
-
|
55
|
-
_pat_size = 20
|
56
|
-
_pat = "A" << _pat_size.to_s
|
57
|
-
|
58
|
-
num_fields = fields.length
|
59
|
-
pattern = case type
|
60
|
-
when :single, :flat
|
61
|
-
_pat * 2
|
62
|
-
when :list, :double
|
63
|
-
_pat * (num_fields + 1)
|
64
|
-
end
|
65
|
-
|
66
|
-
q.init do |str|
|
67
|
-
_parts = str.unpack(pattern)
|
68
|
-
|
69
|
-
case type
|
70
|
-
when :single
|
71
|
-
k, v = _parts
|
72
|
-
when :list
|
73
|
-
k, *v = _parts
|
74
|
-
when :flat
|
75
|
-
k, v = _parts
|
76
|
-
v = v.split "|"
|
77
|
-
when :double
|
78
|
-
k, *v = _parts
|
79
|
-
v = v.collect{|l| l.split "|" }
|
80
|
-
end
|
81
|
-
|
82
|
-
block.call k,v
|
83
|
-
end
|
84
|
-
|
85
|
-
begin
|
86
|
-
res = through(new_key_field, new_fields, uniq, zipped) do |k,v|
|
87
|
-
case type
|
88
|
-
when :flat
|
89
|
-
v = v * "|"
|
90
|
-
when :double
|
91
|
-
v = v.collect{|l| l * "|" } if type == :double
|
92
|
-
end
|
93
|
-
|
94
|
-
str = [k,v].flatten.pack(pattern)
|
95
|
-
q.process str
|
96
|
-
end
|
97
|
-
q.join
|
98
|
-
ensure
|
99
|
-
q.clean
|
100
|
-
end
|
101
|
-
|
102
|
-
res
|
103
|
-
end
|
6
|
+
module TSV
|
104
7
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module TSV
|
2
|
+
|
3
|
+
def pthrough(num_threads = 10, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
|
4
|
+
q = RbbtThreadQueue.new num_threads
|
5
|
+
|
6
|
+
q.init(true, &block)
|
7
|
+
|
8
|
+
begin
|
9
|
+
res = through(new_key_field, new_fields, uniq, zipped) do |*p|
|
10
|
+
q.process p
|
11
|
+
end
|
12
|
+
q.join
|
13
|
+
ensure
|
14
|
+
q.clean
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def ppthrough_callback(&block)
|
20
|
+
@ppthrough_callback = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def ppthrough(num_procs = 7, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
|
24
|
+
|
25
|
+
q = RbbtProcessQueue.new num_procs
|
26
|
+
|
27
|
+
q.callback &@ppthrough_callback
|
28
|
+
@ppthrough_callback = nil
|
29
|
+
|
30
|
+
q.init do |k,v|
|
31
|
+
block.call k,v
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
res = through(new_key_field, new_fields, uniq, zipped) do |*p|
|
36
|
+
q.process q
|
37
|
+
end
|
38
|
+
q.join
|
39
|
+
ensure
|
40
|
+
q.clean
|
41
|
+
end
|
42
|
+
|
43
|
+
res
|
44
|
+
end
|
45
|
+
|
46
|
+
def ppthrough(num_procs = 7, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
|
47
|
+
|
48
|
+
q = RbbtProcessQueue.new num_procs
|
49
|
+
|
50
|
+
q.callback &@ppthrough_callback
|
51
|
+
@ppthrough_callback = nil
|
52
|
+
|
53
|
+
_pat_size = 20
|
54
|
+
_pat = "A" << _pat_size.to_s
|
55
|
+
|
56
|
+
num_fields = fields.length
|
57
|
+
pattern = case type
|
58
|
+
when :single, :flat
|
59
|
+
_pat * 2
|
60
|
+
when :list, :double
|
61
|
+
_pat * (num_fields + 1)
|
62
|
+
end
|
63
|
+
|
64
|
+
q.init do |str|
|
65
|
+
_parts = str.unpack(pattern)
|
66
|
+
|
67
|
+
case type
|
68
|
+
when :single
|
69
|
+
k, v = _parts
|
70
|
+
when :list
|
71
|
+
k, *v = _parts
|
72
|
+
when :flat
|
73
|
+
k, v = _parts
|
74
|
+
v = v.split "|"
|
75
|
+
when :double
|
76
|
+
k, *v = _parts
|
77
|
+
v = v.collect{|l| l.split "|" }
|
78
|
+
end
|
79
|
+
|
80
|
+
block.call k,v
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
res = through(new_key_field, new_fields, uniq, zipped) do |k,v|
|
85
|
+
case type
|
86
|
+
when :flat
|
87
|
+
v = v * "|"
|
88
|
+
when :double
|
89
|
+
v = v.collect{|l| l * "|" } if type == :double
|
90
|
+
end
|
91
|
+
|
92
|
+
str = [k,v].flatten.pack(pattern)
|
93
|
+
q.process str
|
94
|
+
end
|
95
|
+
q.join
|
96
|
+
ensure
|
97
|
+
q.clean
|
98
|
+
end
|
99
|
+
|
100
|
+
res
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module TSV
|
2
|
+
|
3
|
+
def self.traverse_tsv(tsv, options = {}, &block)
|
4
|
+
callback = Misc.process_options options, :callback
|
5
|
+
|
6
|
+
if callback
|
7
|
+
tsv.through options[:key_field], options[:fields] do |k,v|
|
8
|
+
callback.call yield(k,v)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
tsv.through options[:key_field], options[:fields] do |k,v|
|
12
|
+
yield k,v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.traverse_array(array, options = {}, &block)
|
18
|
+
callback = Misc.process_options options, :callback
|
19
|
+
|
20
|
+
if callback
|
21
|
+
array.each do |e|
|
22
|
+
res = yield(e)
|
23
|
+
callback.call res
|
24
|
+
end
|
25
|
+
else
|
26
|
+
array.each do |e|
|
27
|
+
yield e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.traverse_obj(obj, options = {}, &block)
|
33
|
+
if options[:type] == :keys
|
34
|
+
options[:fields] = []
|
35
|
+
options[:type] = :single
|
36
|
+
end
|
37
|
+
|
38
|
+
case obj
|
39
|
+
when TSV
|
40
|
+
traverse_tsv(obj, options, &block)
|
41
|
+
when IO
|
42
|
+
callback = Misc.process_options options, :callback
|
43
|
+
if callback
|
44
|
+
TSV::Parser.traverse(obj, options) do |k,v|
|
45
|
+
res = yield k, v
|
46
|
+
callback.call res
|
47
|
+
end
|
48
|
+
else
|
49
|
+
TSV::Parser.traverse(obj, options, &block)
|
50
|
+
end
|
51
|
+
when Array
|
52
|
+
traverse_array(obj, options, &block)
|
53
|
+
else
|
54
|
+
raise "Unknown object for traversal: #{Misc.fingerprint obj }"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.traverse_threads(num, obj, options, &block)
|
59
|
+
callback = Misc.process_options options, :callback
|
60
|
+
|
61
|
+
q = RbbtThreadQueue.new num
|
62
|
+
|
63
|
+
|
64
|
+
if callback
|
65
|
+
block = Proc.new do |k,v,mutex|
|
66
|
+
v, mutex = nil, v if mutex.nil?
|
67
|
+
res = yield k, v
|
68
|
+
mutex.synchronize do
|
69
|
+
callback.call res
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
q.init true, &block
|
75
|
+
|
76
|
+
traverse_obj(obj, options) do |*p|
|
77
|
+
q.process p
|
78
|
+
end
|
79
|
+
|
80
|
+
q.join
|
81
|
+
q.clean
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.traverse_cpus(num, obj, options, &block)
|
86
|
+
callback = Misc.process_options options, :callback
|
87
|
+
|
88
|
+
q = RbbtProcessQueue.new num
|
89
|
+
|
90
|
+
q.callback &callback
|
91
|
+
q.init &block
|
92
|
+
|
93
|
+
traverse_obj(obj, options) do |*p|
|
94
|
+
q.process p
|
95
|
+
end
|
96
|
+
|
97
|
+
q.join
|
98
|
+
q.clean
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.store_into(obj, value)
|
103
|
+
case obj
|
104
|
+
when Hash
|
105
|
+
if Hash === value
|
106
|
+
obj.merge! value
|
107
|
+
else
|
108
|
+
k,v = value
|
109
|
+
obj[k] = v
|
110
|
+
end
|
111
|
+
else
|
112
|
+
obj << value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.traverse(obj, options = {}, &block)
|
117
|
+
threads = Misc.process_options options, :threads
|
118
|
+
cpus = Misc.process_options options, :cpus
|
119
|
+
into = Misc.process_options options, :into
|
120
|
+
|
121
|
+
if into
|
122
|
+
callback = Proc.new do |*v|
|
123
|
+
store_into into, *v
|
124
|
+
end
|
125
|
+
options[:callback] = callback
|
126
|
+
end
|
127
|
+
|
128
|
+
if threads.nil? and cpus.nil?
|
129
|
+
traverse_obj obj, options, &block
|
130
|
+
else
|
131
|
+
if threads
|
132
|
+
traverse_threads threads, obj, options, &block
|
133
|
+
else
|
134
|
+
traverse_cpus cpus, obj, options, &block
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -50,6 +50,7 @@ class RbbtProcessQueue
|
|
50
50
|
while @processes.any? do
|
51
51
|
pid = Process.wait -1, Process::WNOHANG
|
52
52
|
if pid
|
53
|
+
next unless @processes.collect{|p| p.pid }.include? pid
|
53
54
|
@processes.delete_if{|p| p.pid == pid}
|
54
55
|
raise "Process #{pid} failed" unless $?.success?
|
55
56
|
else
|
@@ -19,7 +19,8 @@ class RbbtThreadQueue
|
|
19
19
|
begin
|
20
20
|
loop do
|
21
21
|
p = queue.pop
|
22
|
-
p << mutex
|
22
|
+
p = Array === p ? p << mutex : [p,mutex]
|
23
|
+
p = [p, mutex].flatten(1)
|
23
24
|
block.call *p
|
24
25
|
end
|
25
26
|
rescue Exception
|
@@ -66,7 +67,6 @@ class RbbtThreadQueue
|
|
66
67
|
queue << e
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
70
|
def self.each(list, num = 3, &block)
|
71
71
|
q = RbbtThreadQueue.new num
|
72
72
|
q.init(&block)
|
data/lib/rbbt/util/misc.rb
CHANGED
@@ -12,12 +12,14 @@ end
|
|
12
12
|
|
13
13
|
class TestPersistTSVCDB < Test::Unit::TestCase
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
if Persist.respond_to? :open_cbd
|
16
|
+
def test_organism
|
17
|
+
require 'rbbt/sources/organism'
|
18
|
+
TmpFile.with_file nil do |tmp_file|
|
19
|
+
file = CMD.cmd("head -n 1000000", :in => Organism.identifiers("Hsa").open, :pipe => true)
|
20
|
+
tsv = Organism.identifiers("Hsa").tsv(:key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "CDB", :persist_dir => tmp_file)
|
21
|
+
assert_equal "ENSG00000141510", tsv["TP53"]
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -12,20 +12,22 @@ module TestAnnotation
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class TestPersistTSVKC < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
if Persist.respond_to? :open_kyotocabinet
|
16
|
+
def _test_organism_kch
|
17
|
+
require 'rbbt/sources/organism'
|
18
|
+
TmpFile.with_file do |tmp_file|
|
19
|
+
tsv = Organism.identifiers("Hsa").tsv :key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "kch", :persist_dir => tmp_file
|
20
|
+
assert_equal "ENSG00000141510", tsv["TP53"]
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def _test_organism_kct
|
26
|
+
require 'rbbt/sources/organism'
|
27
|
+
TmpFile.with_file do |tmp_file|
|
28
|
+
tsv = Organism.identifiers("Hsa").tsv :key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "kct", :persist_dir => tmp_file
|
29
|
+
assert_equal "ENSG00000141510", tsv["TP53"]
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -12,11 +12,13 @@ end
|
|
12
12
|
|
13
13
|
class TestPersistTSVLevelDB < Test::Unit::TestCase
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
if Persist.respond_to? :open_leveldb
|
16
|
+
def test_organism
|
17
|
+
require 'rbbt/sources/organism'
|
18
|
+
TmpFile.with_file do |tmp_file|
|
19
|
+
tsv = Organism.identifiers("Hsa").tsv :key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "LevelDB", :persist_dir => tmp_file
|
20
|
+
assert_equal "ENSG00000141510", tsv["TP53"]
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -14,9 +14,11 @@ class TestPersistTSVLMDB < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
def test_organism
|
16
16
|
require 'rbbt/sources/organism'
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if Persist.respond_to? :open_lmdb
|
18
|
+
TmpFile.with_file do |tmp_file|
|
19
|
+
tsv = Organism.identifiers("Hsa").tsv :key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "LMDB", :persist_dir => tmp_file
|
20
|
+
assert_equal "ENSG00000141510", tsv["TP53"]
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -42,19 +42,6 @@ class TestAnnotations < Test::Unit::TestCase
|
|
42
42
|
assert_equal annotation_str, ary[0].annotation_str
|
43
43
|
end
|
44
44
|
|
45
|
-
def test_double_array
|
46
|
-
ary = ["string"]
|
47
|
-
annotation_str = "Annotation String"
|
48
|
-
ary.extend AnnotatedArray
|
49
|
-
ary_ary = [ary]
|
50
|
-
ary_ary.extend AnnotatedArray
|
51
|
-
AnnotatedString.setup(ary, annotation_str)
|
52
|
-
AnnotatedString.setup(ary_ary, annotation_str)
|
53
|
-
assert_equal [AnnotatedString], ary.annotation_types
|
54
|
-
assert_equal annotation_str, ary.annotation_str
|
55
|
-
assert_equal annotation_str, ary[0].annotation_str
|
56
|
-
end
|
57
|
-
|
58
45
|
|
59
46
|
def test_info
|
60
47
|
ary = ["string"]
|
@@ -145,7 +132,20 @@ class TestAnnotations < Test::Unit::TestCase
|
|
145
132
|
assert_equal str + annotation_str, str.add_annot
|
146
133
|
end
|
147
134
|
|
148
|
-
def
|
135
|
+
def test_double_array_1
|
136
|
+
ary = ["string"]
|
137
|
+
annotation_str = "Annotation String"
|
138
|
+
ary.extend AnnotatedArray
|
139
|
+
ary_ary = [ary]
|
140
|
+
ary_ary.extend AnnotatedArray
|
141
|
+
AnnotatedString.setup(ary, annotation_str)
|
142
|
+
AnnotatedString.setup(ary_ary, annotation_str)
|
143
|
+
assert_equal [AnnotatedString], ary.annotation_types
|
144
|
+
assert_equal annotation_str, ary.annotation_str
|
145
|
+
assert_equal annotation_str, ary[0].annotation_str
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_double_array_2
|
149
149
|
a = ["a"]
|
150
150
|
b = AnnotatedString.setup([AnnotatedString.setup(["a"])])
|
151
151
|
AnnotatedString.setup(a)
|
data/test/rbbt/test_workflow.rb
CHANGED
@@ -106,7 +106,7 @@ class TestWorkflow < Test::Unit::TestCase
|
|
106
106
|
assert TestWF.jobs(:repeat2).include?(job1.name)
|
107
107
|
assert TestWF.jobs(:repeat2).include?(job2.name)
|
108
108
|
assert TestWF.jobs(:repeat2).include?(job3.name)
|
109
|
-
assert TestWF.load_name(:repeat2,
|
109
|
+
assert TestWF.load_name(:repeat2, job3.name).done?
|
110
110
|
assert_equal "TEST\nTEST\nTEST\nTEST\nTEST\nTEST", TestWF.load_name(:repeat2, TestWF.jobs(:repeat2).first).load
|
111
111
|
end
|
112
112
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
|
2
|
+
require 'rbbt/tsv'
|
3
|
+
require 'rbbt/tsv/parallel'
|
4
|
+
|
5
|
+
class TestTSVParallelThrough < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_pthrough
|
8
|
+
require 'rbbt/sources/organism'
|
9
|
+
tsv = Organism.identifiers("Hsa").tsv :unnamed => true, :persist => false, :fields => ["Associated Gene Name"]
|
10
|
+
|
11
|
+
h = {}
|
12
|
+
tsv.monitor = true
|
13
|
+
tsv.unnamed = true
|
14
|
+
tsv.pthrough do |k,v|
|
15
|
+
h[k] = v.first
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal tsv.size, h.size
|
19
|
+
assert_equal tsv.keys.sort, h.keys.sort
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def test_ppthrough
|
24
|
+
require 'rbbt/sources/organism'
|
25
|
+
tsv = Organism.identifiers("Hsa").tsv :unnamed => true, :persist => false, :fields => ["Associated Gene Name"]
|
26
|
+
|
27
|
+
h = {}
|
28
|
+
|
29
|
+
tsv.ppthrough_callback do |k,v|
|
30
|
+
h[k] = v
|
31
|
+
end
|
32
|
+
|
33
|
+
tsv.unnamed = true
|
34
|
+
tsv.monitor = true
|
35
|
+
tsv.ppthrough(3) do |k,v|
|
36
|
+
[k,v.first]
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal tsv.size, h.size
|
40
|
+
assert_equal tsv.keys.sort, h.keys.sort
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
|
2
|
+
require 'rbbt/tsv'
|
3
|
+
require 'rbbt/tsv/parallel'
|
4
|
+
|
5
|
+
class TestTSVParallelThrough < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def _test_traverse_tsv
|
8
|
+
require 'rbbt/sources/organism'
|
9
|
+
|
10
|
+
head = 100
|
11
|
+
|
12
|
+
tsv = Organism.identifiers("Hsa").tsv :head => head
|
13
|
+
res = {}
|
14
|
+
TSV.traverse tsv do |k,v|
|
15
|
+
res[k] = v
|
16
|
+
end
|
17
|
+
assert_equal head, res.keys.compact.sort.length
|
18
|
+
|
19
|
+
tsv = Organism.identifiers("Hsa").tsv :head => head
|
20
|
+
TSV.traverse tsv, :into => res do |k,v|
|
21
|
+
[k,v]
|
22
|
+
end
|
23
|
+
assert_equal head, res.keys.compact.sort.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def _test_traverse_stream
|
27
|
+
require 'rbbt/sources/organism'
|
28
|
+
|
29
|
+
head = 100
|
30
|
+
|
31
|
+
tsv = Organism.identifiers("Hsa").open
|
32
|
+
res = {}
|
33
|
+
TSV.traverse tsv, :head => head do |k,v|
|
34
|
+
res[k] = v
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal head, res.keys.compact.sort.length
|
38
|
+
tsv = Organism.identifiers("Hsa").open
|
39
|
+
res = {}
|
40
|
+
TSV.traverse tsv, :head => head, :into => res do |k,v|
|
41
|
+
[k,v]
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_equal head, res.keys.compact.sort.length
|
45
|
+
end
|
46
|
+
|
47
|
+
def _test_traverse_stream_keys
|
48
|
+
require 'rbbt/sources/organism'
|
49
|
+
|
50
|
+
head = 100
|
51
|
+
|
52
|
+
tsv = Organism.identifiers("Hsa").open
|
53
|
+
res = []
|
54
|
+
|
55
|
+
TSV.traverse tsv, :head => head, :type => :keys do |v|
|
56
|
+
res << v
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal res, Organism.identifiers("Hsa").tsv(:head => 100).keys
|
60
|
+
|
61
|
+
tsv = Organism.identifiers("Hsa").open
|
62
|
+
res = []
|
63
|
+
|
64
|
+
TSV.traverse tsv, :head => head, :type => :keys, :into => res do |v|
|
65
|
+
v
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_equal res, Organism.identifiers("Hsa").tsv(:head => 100).keys
|
69
|
+
end
|
70
|
+
|
71
|
+
def _test_traverse_array
|
72
|
+
require 'rbbt/sources/organism'
|
73
|
+
|
74
|
+
array = []
|
75
|
+
100.times do array << rand(10).to_i end
|
76
|
+
|
77
|
+
res = []
|
78
|
+
TSV.traverse array do |v|
|
79
|
+
res << v
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_equal array, res
|
83
|
+
|
84
|
+
|
85
|
+
res = []
|
86
|
+
TSV.traverse array, :into => res do |v|
|
87
|
+
v
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal array, res
|
91
|
+
end
|
92
|
+
|
93
|
+
def _test_traverse_array_threads
|
94
|
+
require 'rbbt/sources/organism'
|
95
|
+
|
96
|
+
array = []
|
97
|
+
100.times do array << rand(10).to_i end
|
98
|
+
|
99
|
+
res = []
|
100
|
+
TSV.traverse array, :threads => 5 do |v|
|
101
|
+
res << v
|
102
|
+
end
|
103
|
+
|
104
|
+
assert_equal array.sort, res.sort
|
105
|
+
|
106
|
+
res = []
|
107
|
+
TSV.traverse array, :threads => 5, :into => res do |v|
|
108
|
+
v
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_equal array.sort, res.sort
|
112
|
+
end
|
113
|
+
|
114
|
+
def _test_traverse_array_cpus
|
115
|
+
require 'rbbt/sources/organism'
|
116
|
+
|
117
|
+
array = []
|
118
|
+
100.times do array << rand(10).to_i end
|
119
|
+
|
120
|
+
res = []
|
121
|
+
|
122
|
+
TSV.traverse array, :cpus => 5, :into => res do |v|
|
123
|
+
v
|
124
|
+
end
|
125
|
+
|
126
|
+
assert_equal array.sort, res.sort
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_traverse_benchmark
|
130
|
+
require 'rbbt/sources/organism'
|
131
|
+
|
132
|
+
head = 80_000
|
133
|
+
|
134
|
+
tsv = Organism.identifiers("Hsa").open
|
135
|
+
Misc.benchmark do
|
136
|
+
res = {}
|
137
|
+
TSV.traverse tsv, :head => head do |k,v|
|
138
|
+
res[k] = v
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
tsv = Organism.identifiers("Hsa").open
|
143
|
+
Misc.benchmark do
|
144
|
+
res = {}
|
145
|
+
TSV.traverse tsv, :head => head, :cpus => 5, :into => res do |k,v|
|
146
|
+
[k,v]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
data/test/rbbt/tsv/test_index.rb
CHANGED
@@ -190,8 +190,8 @@ row2 A B 30 35
|
|
190
190
|
|
191
191
|
def test_range_index2
|
192
192
|
data =<<-EOF
|
193
|
+
# 012345678901234567890
|
193
194
|
#ID:Range
|
194
|
-
#:012345678901234567890
|
195
195
|
a: ______
|
196
196
|
b: ______
|
197
197
|
c: _______
|
@@ -215,8 +215,8 @@ g: ____
|
|
215
215
|
|
216
216
|
def test_range_index_persistent
|
217
217
|
data =<<-EOF
|
218
|
+
# 012345678901234567890
|
218
219
|
#ID:Range
|
219
|
-
#:012345678901234567890
|
220
220
|
a: ______
|
221
221
|
b: ______
|
222
222
|
c: _______
|
@@ -259,8 +259,8 @@ g: ____
|
|
259
259
|
|
260
260
|
def test_range_index_persistent_with_filter
|
261
261
|
data =<<-EOF
|
262
|
+
# 012345678901234567890
|
262
263
|
#ID:Range
|
263
|
-
#:012345678901234567890
|
264
264
|
a: ______
|
265
265
|
b: ______
|
266
266
|
c: _______
|
@@ -4,39 +4,4 @@ require 'rbbt/tsv/parallel'
|
|
4
4
|
|
5
5
|
class TestTSVParallel < Test::Unit::TestCase
|
6
6
|
|
7
|
-
def _test_pthrough
|
8
|
-
require 'rbbt/sources/organism'
|
9
|
-
tsv = Organism.identifiers("Hsa").tsv :unnamed => true, :persist => false, :fields => ["Associated Gene Name"]
|
10
|
-
|
11
|
-
h = {}
|
12
|
-
tsv.monitor = true
|
13
|
-
tsv.unnamed = true
|
14
|
-
tsv.pthrough do |k,v|
|
15
|
-
h[k] = v.first
|
16
|
-
end
|
17
|
-
|
18
|
-
assert_equal tsv.size, h.size
|
19
|
-
assert_equal tsv.keys.sort, h.keys.sort
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def test_ppthrough
|
24
|
-
require 'rbbt/sources/organism'
|
25
|
-
tsv = Organism.identifiers("Hsa").tsv :unnamed => true, :persist => false, :fields => ["Associated Gene Name"]
|
26
|
-
|
27
|
-
h = {}
|
28
|
-
|
29
|
-
tsv.ppthrough_callback do |k,v|
|
30
|
-
h[k] = v
|
31
|
-
end
|
32
|
-
|
33
|
-
tsv.unnamed = true
|
34
|
-
tsv.monitor = true
|
35
|
-
tsv.ppthrough(3) do |k,v|
|
36
|
-
[k,v.first]
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_equal tsv.size, h.size
|
40
|
-
assert_equal tsv.keys.sort, h.keys.sort
|
41
|
-
end
|
42
7
|
end
|
@@ -7,7 +7,7 @@ require 'rbbt/util/concurrency/processes'
|
|
7
7
|
class TestConcurrencyProcess < Test::Unit::TestCase
|
8
8
|
|
9
9
|
def test_process
|
10
|
-
q = RbbtProcessQueue.new
|
10
|
+
q = RbbtProcessQueue.new 10
|
11
11
|
|
12
12
|
res = []
|
13
13
|
|
@@ -22,18 +22,15 @@ class TestConcurrencyProcess < Test::Unit::TestCase
|
|
22
22
|
times = 500
|
23
23
|
t = TSV.setup({"a" => 1}, :type => :single)
|
24
24
|
|
25
|
-
Misc.benchmark do
|
26
25
|
times.times do |i|
|
27
26
|
q.process i
|
28
27
|
end
|
29
28
|
|
30
29
|
q.join
|
31
30
|
q.clean
|
32
|
-
end
|
33
31
|
|
34
32
|
assert_equal times, res.length
|
35
33
|
assert_equal [0, 2, 4], res.sort[0..2]
|
36
|
-
|
37
34
|
end
|
38
35
|
|
39
36
|
def test_each
|
@@ -11,12 +11,10 @@ class TestConcurrencyThreads < Test::Unit::TestCase
|
|
11
11
|
res << v
|
12
12
|
end
|
13
13
|
|
14
|
-
times =
|
15
|
-
Misc.benchmark do
|
14
|
+
times = 1_000_000
|
16
15
|
times.times do |i|
|
17
16
|
q.process [i*2]
|
18
17
|
end
|
19
|
-
end
|
20
18
|
|
21
19
|
q.join
|
22
20
|
q.clean
|
@@ -27,7 +25,7 @@ class TestConcurrencyThreads < Test::Unit::TestCase
|
|
27
25
|
end
|
28
26
|
|
29
27
|
def test_each
|
30
|
-
times =
|
28
|
+
times = 10000
|
31
29
|
elems = (0..times-1).to_a
|
32
30
|
|
33
31
|
TmpFile.with_file do |dir|
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -145,30 +145,8 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
145
145
|
|
146
146
|
def test_path_relative_to
|
147
147
|
assert_equal "test/foo", Misc.path_relative_to('/test', '/test/test/foo')
|
148
|
-
|
149
|
-
Misc.profile do
|
150
|
-
Misc.benchmark(45_000) do
|
151
|
-
Misc.path_relative_to('/test', '/test/test/foo')
|
152
|
-
end
|
153
|
-
end
|
154
148
|
end
|
155
149
|
|
156
|
-
# def test_chunk
|
157
|
-
# test =<<-EOF
|
158
|
-
#This is an example file. Entries are separated by Entry
|
159
|
-
#-- Entry
|
160
|
-
#1
|
161
|
-
#2
|
162
|
-
#3
|
163
|
-
#-- Entry
|
164
|
-
#4
|
165
|
-
#5
|
166
|
-
#6
|
167
|
-
# EOF
|
168
|
-
#
|
169
|
-
# assert_equal "1\n2\n3", Misc.chunk(test, /^-- Entry/).first.strip
|
170
|
-
# end
|
171
|
-
|
172
150
|
def test_hash2string
|
173
151
|
hash = {}
|
174
152
|
assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
2
2
|
require 'rbbt/util/simpleDSL'
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestSimpleDSLClass
|
6
6
|
include SimpleDSL
|
7
7
|
|
8
8
|
def action(name, *args, &block)
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
class TestDSL < Test::Unit::TestCase
|
20
20
|
def setup
|
21
|
-
@parser =
|
21
|
+
@parser = TestSimpleDSLClass.new
|
22
22
|
@parser.load_config(:action) do
|
23
23
|
action1 "Hello"
|
24
24
|
action2 "Good bye"
|
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.
|
4
|
+
version: 5.9.0
|
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-03-
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -153,6 +153,8 @@ files:
|
|
153
153
|
- lib/rbbt/tsv/index.rb
|
154
154
|
- lib/rbbt/tsv/manipulate.rb
|
155
155
|
- lib/rbbt/tsv/parallel.rb
|
156
|
+
- lib/rbbt/tsv/parallel/through.rb
|
157
|
+
- lib/rbbt/tsv/parallel/traverse.rb
|
156
158
|
- lib/rbbt/tsv/parser.rb
|
157
159
|
- lib/rbbt/tsv/serializers.rb
|
158
160
|
- lib/rbbt/tsv/util.rb
|
@@ -260,6 +262,8 @@ files:
|
|
260
262
|
- test/rbbt/test_resource.rb
|
261
263
|
- test/rbbt/test_tsv.rb
|
262
264
|
- test/rbbt/test_workflow.rb
|
265
|
+
- test/rbbt/tsv/parallel/test_through.rb
|
266
|
+
- test/rbbt/tsv/parallel/test_traverse.rb
|
263
267
|
- test/rbbt/tsv/test_accessor.rb
|
264
268
|
- test/rbbt/tsv/test_attach.rb
|
265
269
|
- test/rbbt/tsv/test_change_id.rb
|
@@ -370,5 +374,7 @@ test_files:
|
|
370
374
|
- test/rbbt/tsv/test_filter.rb
|
371
375
|
- test/rbbt/tsv/test_attach.rb
|
372
376
|
- test/rbbt/tsv/test_manipulate.rb
|
377
|
+
- test/rbbt/tsv/parallel/test_through.rb
|
378
|
+
- test/rbbt/tsv/parallel/test_traverse.rb
|
373
379
|
- test/rbbt/test_fix_width_table.rb
|
374
380
|
- test/test_helper.rb
|