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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 985a049f7bd611901dc77ac6fbb9f8529f9ed01c
4
- data.tar.gz: 653082e1984c57a177161f0e1f23e1a2c1f1506c
3
+ metadata.gz: 8809e7ff7afbc160340f326450273a14ca3ce286
4
+ data.tar.gz: 3de26d6f418fd60b21459b9cef3af0ed11844310
5
5
  SHA512:
6
- metadata.gz: d1ecb5c1fb2a9880b52003a0c20e137fc627ab9ed685dab911ce2f4c84e32bce7fbfad4c9abbb1c245872c325e2d388373ca4abc9e4167ed2887a9e8ed3d14a2
7
- data.tar.gz: 5e40f5ac11b3bbb015eb30742770821f6d434442b95aeb62c5afe8eccec0aec6d02601e317e2737d8b1eea0f5c66cc27f0b22df1ec31ee092a3215edb185a0aa
6
+ metadata.gz: 8f3d7b38e869e5b88aa3005a6cdb1ffb96ca9eb8c8ef96625892ed3ba8a038422b9c7172806bda50fd1e1bdf4e014d75607ad0c8c4fe33a806e0498d3e4e6b88
7
+ data.tar.gz: c56376cae5c4fc796fedef603179fd4e1129581b7c495e6101705fe939f5facd1c5a200e500d592df10c26ec91466c118b79ca38efc2ad2b14aa9b414cf61be3
@@ -209,8 +209,8 @@ module Annotated
209
209
  end
210
210
  end
211
211
 
212
- def marshal_dump(depth)
213
- clean_annotations
212
+ def marshal_dump
213
+ Annotated.purge(self).to_sym.to_s
214
214
  end
215
215
  end
216
216
 
data/lib/rbbt/tsv.rb CHANGED
@@ -160,7 +160,7 @@ module TSV
160
160
  data
161
161
  end
162
162
 
163
- def self.traverse(file, options, &block)
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)
@@ -1,104 +1,7 @@
1
1
  require 'rbbt/util/concurrency'
2
2
 
3
- module TSV
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
- def ppthrough(num_procs = 7, new_key_field = nil, new_fields = nil, uniq = false, zipped = false, &block)
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)
@@ -101,6 +101,7 @@ module Misc
101
101
  end
102
102
  str
103
103
  end
104
+
104
105
  def self.parse_cmd_params(str)
105
106
  return str if Array === str
106
107
  str.scan(/
@@ -125,6 +125,8 @@ class Step
125
125
  end
126
126
 
127
127
  def log(status, message = nil, &block)
128
+ self.status = status
129
+ self.message Log.uncolor(message)
128
130
  Step.log(status, message, path, &block)
129
131
  end
130
132
 
@@ -6,9 +6,8 @@ class TestClass < Test::Unit::TestCase
6
6
  a = "STRING"
7
7
  a.extend Annotated
8
8
 
9
+ assert !(Annotated === Marshal.load(Marshal.dump(a)))
9
10
  assert_equal a, Marshal.load(Marshal.dump(a))
10
- assert_equal Marshal.dump("STRING"), Marshal.dump(a)
11
-
12
11
  end
13
12
  end
14
13
 
@@ -12,12 +12,14 @@ end
12
12
 
13
13
  class TestPersistTSVCDB < Test::Unit::TestCase
14
14
 
15
- def test_organism
16
- require 'rbbt/sources/organism'
17
- TmpFile.with_file nil do |tmp_file|
18
- file = CMD.cmd("head -n 1000000", :in => Organism.identifiers("Hsa").open, :pipe => true)
19
- 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)
20
- assert_equal "ENSG00000141510", tsv["TP53"]
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
- def _test_organism_kch
16
- require 'rbbt/sources/organism'
17
- TmpFile.with_file do |tmp_file|
18
- 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
19
- assert_equal "ENSG00000141510", tsv["TP53"]
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
- def _test_organism_kct
25
- require 'rbbt/sources/organism'
26
- TmpFile.with_file do |tmp_file|
27
- 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
28
- assert_equal "ENSG00000141510", tsv["TP53"]
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
- def test_organism
16
- require 'rbbt/sources/organism'
17
- TmpFile.with_file do |tmp_file|
18
- 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
19
- assert_equal "ENSG00000141510", tsv["TP53"]
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
- TmpFile.with_file do |tmp_file|
18
- 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
19
- assert_equal "ENSG00000141510", tsv["TP53"]
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 test_double_array
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)
@@ -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, TestWF.jobs(:repeat2).first).done?
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
@@ -3,7 +3,7 @@ require 'rbbt/tsv'
3
3
  require 'rbbt/util/tmpfile'
4
4
  require 'test/unit'
5
5
 
6
- class TestTSV < Test::Unit::TestCase
6
+ class TestTSVAccessor < Test::Unit::TestCase
7
7
 
8
8
  def test_to_hash
9
9
  content =<<-EOF
@@ -476,7 +476,8 @@ A Id3
476
476
  end
477
477
 
478
478
  res = tsv1.attach tsv2, :fields => ["OtherID"]
479
- assert_equal "Id3", res["row2"]["OtherID"]
479
+ assert res["row2"].include? "Id3"
480
+ assert ! res["row2"].include?("b")
480
481
  end
481
482
  end
482
483
 
@@ -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 1
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 = 5_000_000
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 = 50000
28
+ times = 10000
31
29
  elems = (0..times-1).to_a
32
30
 
33
31
  TmpFile.with_file do |dir|
@@ -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 TestClass
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 = TestClass.new
21
+ @parser = TestSimpleDSLClass.new
22
22
  @parser.load_config(:action) do
23
23
  action1 "Hello"
24
24
  action2 "Good bye"
@@ -210,7 +210,5 @@ class TestStep < Test::Unit::TestCase
210
210
  RbbtSemaphore.delete_semaphore(semaphore)
211
211
  end
212
212
  end
213
-
214
213
  end
215
-
216
214
  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.8.10
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-18 00:00:00.000000000 Z
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