rbbt-util 5.43.0 → 5.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/association/util.rb +1 -1
- data/lib/rbbt/hpc/batch.rb +19 -17
- data/lib/rbbt/tsv/accessor.rb +6 -11
- data/lib/rbbt/tsv/dumper.rb +21 -10
- data/lib/rbbt/tsv/index.rb +2 -1
- data/lib/rbbt/util/misc/math.rb +0 -1
- data/lib/rbbt/util/open.rb +1 -1
- data/lib/rbbt/workflow/step/info.rb +1 -0
- data/lib/rbbt/workflow/step.rb +2 -1
- data/python/rbbt/__init__.py +2 -2
- data/share/rbbt_commands/workflow/task +1 -1
- metadata +4 -220
- data/test/rbbt/annotations/test_util.rb +0 -43
- data/test/rbbt/association/test_database.rb +0 -87
- data/test/rbbt/association/test_index.rb +0 -127
- data/test/rbbt/association/test_item.rb +0 -15
- data/test/rbbt/association/test_open.rb +0 -63
- data/test/rbbt/association/test_util.rb +0 -108
- data/test/rbbt/entity/test_identifiers.rb +0 -34
- data/test/rbbt/hpc/orchestrate/test_batches.rb +0 -70
- data/test/rbbt/hpc/orchestrate/test_chains.rb +0 -108
- data/test/rbbt/hpc/orchestrate/test_rules.rb +0 -59
- data/test/rbbt/hpc/test_batch.rb +0 -64
- data/test/rbbt/hpc/test_hpc_test_workflows.rb +0 -0
- data/test/rbbt/hpc/test_orchestrate.rb +0 -144
- data/test/rbbt/hpc/test_pbs.rb +0 -43
- data/test/rbbt/hpc/test_slurm.rb +0 -28
- data/test/rbbt/knowledge_base/test_enrichment.rb +0 -50
- data/test/rbbt/knowledge_base/test_entity.rb +0 -62
- data/test/rbbt/knowledge_base/test_query.rb +0 -46
- data/test/rbbt/knowledge_base/test_registry.rb +0 -74
- data/test/rbbt/knowledge_base/test_syndicate.rb +0 -48
- data/test/rbbt/knowledge_base/test_traverse.rb +0 -133
- data/test/rbbt/persist/test_tsv.rb +0 -88
- data/test/rbbt/persist/tsv/test_cdb.rb +0 -18
- data/test/rbbt/persist/tsv/test_kyotocabinet.rb +0 -27
- data/test/rbbt/persist/tsv/test_leveldb.rb +0 -18
- data/test/rbbt/persist/tsv/test_lmdb.rb +0 -20
- data/test/rbbt/persist/tsv/test_sharder.rb +0 -164
- data/test/rbbt/persist/tsv/test_tokyocabinet.rb +0 -262
- data/test/rbbt/resource/test_path.rb +0 -49
- data/test/rbbt/test_annotations.rb +0 -167
- data/test/rbbt/test_association.rb +0 -103
- data/test/rbbt/test_entity.rb +0 -252
- data/test/rbbt/test_fix_width_table.rb +0 -135
- data/test/rbbt/test_knowledge_base.rb +0 -226
- data/test/rbbt/test_monitor.rb +0 -11
- data/test/rbbt/test_packed_index.rb +0 -68
- data/test/rbbt/test_persist.rb +0 -85
- data/test/rbbt/test_resource.rb +0 -110
- data/test/rbbt/test_tsv.rb +0 -669
- data/test/rbbt/test_workflow.rb +0 -609
- data/test/rbbt/tsv/parallel/test_through.rb +0 -40
- data/test/rbbt/tsv/parallel/test_traverse.rb +0 -456
- data/test/rbbt/tsv/test_accessor.rb +0 -319
- data/test/rbbt/tsv/test_attach.rb +0 -715
- data/test/rbbt/tsv/test_change_id.rb +0 -61
- data/test/rbbt/tsv/test_csv.rb +0 -49
- data/test/rbbt/tsv/test_excel.rb +0 -171
- data/test/rbbt/tsv/test_field_index.rb +0 -19
- data/test/rbbt/tsv/test_filter.rb +0 -187
- data/test/rbbt/tsv/test_index.rb +0 -308
- data/test/rbbt/tsv/test_manipulate.rb +0 -334
- data/test/rbbt/tsv/test_marshal.rb +0 -24
- data/test/rbbt/tsv/test_matrix.rb +0 -20
- data/test/rbbt/tsv/test_parallel.rb +0 -7
- data/test/rbbt/tsv/test_parser.rb +0 -101
- data/test/rbbt/tsv/test_stream.rb +0 -253
- data/test/rbbt/tsv/test_util.rb +0 -52
- data/test/rbbt/util/R/test_eval.rb +0 -43
- data/test/rbbt/util/R/test_model.rb +0 -128
- data/test/rbbt/util/R/test_plot.rb +0 -38
- data/test/rbbt/util/concurrency/processes/test_socket.rb +0 -70
- data/test/rbbt/util/concurrency/test_processes.rb +0 -192
- data/test/rbbt/util/concurrency/test_threads.rb +0 -40
- data/test/rbbt/util/log/test_progress.rb +0 -111
- data/test/rbbt/util/misc/test_bgzf.rb +0 -48
- data/test/rbbt/util/misc/test_communication.rb +0 -13
- data/test/rbbt/util/misc/test_development.rb +0 -26
- data/test/rbbt/util/misc/test_format.rb +0 -10
- data/test/rbbt/util/misc/test_indiferent_hash.rb +0 -14
- data/test/rbbt/util/misc/test_lock.rb +0 -77
- data/test/rbbt/util/misc/test_multipart_payload.rb +0 -202
- data/test/rbbt/util/misc/test_omics.rb +0 -116
- data/test/rbbt/util/misc/test_pipes.rb +0 -343
- data/test/rbbt/util/misc/test_serialize.rb +0 -24
- data/test/rbbt/util/python/test_util.rb +0 -25
- data/test/rbbt/util/simpleopt/test_get.rb +0 -12
- data/test/rbbt/util/simpleopt/test_parse.rb +0 -10
- data/test/rbbt/util/simpleopt/test_setup.rb +0 -76
- data/test/rbbt/util/test_R.rb +0 -37
- data/test/rbbt/util/test_chain_methods.rb +0 -22
- data/test/rbbt/util/test_cmd.rb +0 -87
- data/test/rbbt/util/test_colorize.rb +0 -22
- data/test/rbbt/util/test_concurrency.rb +0 -6
- data/test/rbbt/util/test_config.rb +0 -69
- data/test/rbbt/util/test_excel2tsv.rb +0 -10
- data/test/rbbt/util/test_filecache.rb +0 -36
- data/test/rbbt/util/test_log.rb +0 -52
- data/test/rbbt/util/test_migrate.rb +0 -34
- data/test/rbbt/util/test_misc.rb +0 -728
- data/test/rbbt/util/test_open.rb +0 -200
- data/test/rbbt/util/test_procpath.rb +0 -23
- data/test/rbbt/util/test_python.rb +0 -144
- data/test/rbbt/util/test_semaphore.rb +0 -36
- data/test/rbbt/util/test_simpleDSL.rb +0 -55
- data/test/rbbt/util/test_simpleopt.rb +0 -11
- data/test/rbbt/util/test_ssh.rb +0 -10
- data/test/rbbt/util/test_tmpfile.rb +0 -32
- data/test/rbbt/workflow/step/test_dependencies.rb +0 -295
- data/test/rbbt/workflow/step/test_save_load_inputs.rb +0 -136
- data/test/rbbt/workflow/test_doc.rb +0 -30
- data/test/rbbt/workflow/test_remote_workflow.rb +0 -99
- data/test/rbbt/workflow/test_schedule.rb +0 -0
- data/test/rbbt/workflow/test_step.rb +0 -231
- data/test/rbbt/workflow/test_task.rb +0 -85
- data/test/rbbt/workflow/util/test_archive.rb +0 -27
- data/test/rbbt/workflow/util/test_data.rb +0 -67
- data/test/rbbt/workflow/util/test_orchestrator.rb +0 -263
- data/test/test_helper.rb +0 -114
data/test/rbbt/test_tsv.rb
DELETED
@@ -1,669 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
require 'rbbt/tsv'
|
3
|
-
require 'rbbt/util/tmpfile'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
class TestTSV < Test::Unit::TestCase
|
7
|
-
|
8
|
-
def test_extend
|
9
|
-
a = {
|
10
|
-
"one" => "1",
|
11
|
-
"two" => "2"
|
12
|
-
}
|
13
|
-
|
14
|
-
a.extend TSV
|
15
|
-
|
16
|
-
a.key_field = "Number"
|
17
|
-
|
18
|
-
assert_equal "1", a["one"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_tsv_1
|
22
|
-
content =<<-EOF
|
23
|
-
#Id ValueA ValueB OtherID
|
24
|
-
row1 a|aa|aaa b Id1|Id2
|
25
|
-
row2 A B Id3
|
26
|
-
EOF
|
27
|
-
|
28
|
-
TmpFile.with_file(content) do |filename|
|
29
|
-
tsv = TSV.open(filename, :sep => /\s+/)
|
30
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
31
|
-
assert_equal ["ValueA", "ValueB", "OtherID"], tsv.fields
|
32
|
-
assert_equal :double, tsv.type
|
33
|
-
assert_equal "Id", tsv.key_field
|
34
|
-
|
35
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "Id")
|
36
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
37
|
-
assert_equal ["ValueA", "ValueB", "OtherID"], tsv.fields
|
38
|
-
assert_equal :double, tsv.type
|
39
|
-
assert_equal "Id", tsv.key_field
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_headerless
|
45
|
-
content =<<-EOF
|
46
|
-
row1 a|aa|aaa b Id1|Id2
|
47
|
-
row2 A B Id3
|
48
|
-
EOF
|
49
|
-
|
50
|
-
TmpFile.with_file(content) do |filename|
|
51
|
-
tsv = TSV.open(filename, :sep => /\s+/)
|
52
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
53
|
-
assert_equal :double, tsv.type
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_headerless_fields
|
58
|
-
content =<<-EOF
|
59
|
-
row1 a|aa|aaa b Id1|Id2
|
60
|
-
row2 A B Id3
|
61
|
-
EOF
|
62
|
-
|
63
|
-
TmpFile.with_file(content) do |filename|
|
64
|
-
tsv = TSV.open(filename, :sep => /\s+/, :fields => [1])
|
65
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
66
|
-
assert_equal :double, tsv.type
|
67
|
-
assert_equal [%w(a aa aaa)], tsv["row1"]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_tsv_persistence
|
72
|
-
content =<<-EOF
|
73
|
-
#Id ValueA ValueB OtherID
|
74
|
-
row1 a|aa|aaa b Id1|Id2
|
75
|
-
row2 A B Id3
|
76
|
-
EOF
|
77
|
-
|
78
|
-
TmpFile.with_file(content) do |filename|
|
79
|
-
tsv = TSV.open(filename, :sep => /\s+/, :persist => true)
|
80
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
81
|
-
assert_equal ["ValueA", "ValueB", "OtherID"], tsv.fields
|
82
|
-
assert_equal :double, tsv.type
|
83
|
-
assert_equal "Id", tsv.key_field
|
84
|
-
assert TokyoCabinet::HDB === tsv
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_tsv_field_selection
|
89
|
-
content =<<-EOF
|
90
|
-
#Id ValueA ValueB OtherID
|
91
|
-
row1 a|aa|aaa b Id1|Id2
|
92
|
-
row2 A B Id3
|
93
|
-
EOF
|
94
|
-
|
95
|
-
TmpFile.with_file(content) do |filename|
|
96
|
-
tsv = TSV.open(filename, :sep => /\s+/, :type => :single)
|
97
|
-
assert_equal tsv.fields, ["ValueA"]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_tsv_field_selection2
|
102
|
-
content =<<-EOF
|
103
|
-
#Id ValueA ValueB OtherID
|
104
|
-
row1 a|aa|aaa b Id1|Id2
|
105
|
-
row2 A B Id3
|
106
|
-
EOF
|
107
|
-
|
108
|
-
TmpFile.with_file(content) do |filename|
|
109
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => 0)
|
110
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
111
|
-
|
112
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "Id")
|
113
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
114
|
-
|
115
|
-
tsv = TSV.open(filename, :sep => /\s+/, :fields => 1)
|
116
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"].first
|
117
|
-
|
118
|
-
tsv = TSV.open(filename, :sep => /\s+/, :fields => 2)
|
119
|
-
assert_equal ["b"], tsv["row1"].first
|
120
|
-
|
121
|
-
tsv = TSV.open(filename, :sep => /\s+/, :fields => [1,2])
|
122
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"].first
|
123
|
-
assert_equal ["b"], tsv["row1"].last
|
124
|
-
|
125
|
-
tsv = TSV.open(filename, :sep => /\s+/, :fields => [1,3])
|
126
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"].first
|
127
|
-
assert_equal ["Id1", "Id2"], tsv["row1"].last
|
128
|
-
|
129
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "OtherID")
|
130
|
-
assert_equal ["row1"], tsv["Id1"].first
|
131
|
-
assert_equal tsv["Id2"], tsv["Id1"]
|
132
|
-
|
133
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "OtherID", :fields => "Id")
|
134
|
-
assert_equal ["row1"], tsv["Id1"].first
|
135
|
-
assert_equal tsv["Id2"], tsv["Id1"]
|
136
|
-
|
137
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "OtherID", :fields => ["ValueA",2])
|
138
|
-
assert_equal ["a", "aa", "aaa"], tsv["Id1"].first
|
139
|
-
assert_equal tsv["Id2"], tsv["Id1"]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_tsv_cast
|
144
|
-
content =<<-EOF
|
145
|
-
#Id Value
|
146
|
-
row1 1|2|3
|
147
|
-
row2 4
|
148
|
-
EOF
|
149
|
-
|
150
|
-
TmpFile.with_file(content) do |filename|
|
151
|
-
tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_i)
|
152
|
-
assert_equal [1,2,3], tsv["row1"][0]
|
153
|
-
tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_f)
|
154
|
-
assert_equal [1.0,2.0,3.0], tsv["row1"][0]
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_tsv_single
|
159
|
-
content =<<-EOF
|
160
|
-
#Id Value
|
161
|
-
row1 1
|
162
|
-
row2 4
|
163
|
-
EOF
|
164
|
-
|
165
|
-
TmpFile.with_file(content) do |filename|
|
166
|
-
tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_i, :type => :single, :fields => "Value")
|
167
|
-
assert_equal 1, tsv["row1"]
|
168
|
-
tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_i, :type => :single, :fields => ["Value"])
|
169
|
-
assert_equal 1, tsv["row1"]
|
170
|
-
tsv = TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value", :fields => ["Id"])
|
171
|
-
assert_equal "row1", tsv["1"]
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_tsv_single_from_flat
|
176
|
-
content =<<-EOF
|
177
|
-
#: :type=:flat
|
178
|
-
#Id Value
|
179
|
-
row1 1 2
|
180
|
-
row2 4
|
181
|
-
EOF
|
182
|
-
|
183
|
-
TmpFile.with_file(content) do |filename|
|
184
|
-
tsv = TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value", :fields => ["Id"])
|
185
|
-
assert_equal "row1", tsv["1"]
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
|
190
|
-
def test_tsv_serializer
|
191
|
-
content =<<-EOF
|
192
|
-
#Id Value
|
193
|
-
row1 1
|
194
|
-
row2 4
|
195
|
-
EOF
|
196
|
-
|
197
|
-
TmpFile.with_file(content) do |filename|
|
198
|
-
tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_i, :type => :single, :serializer => :integer)
|
199
|
-
assert_equal 1, tsv["row1"]
|
200
|
-
assert String === tsv.send(:[], "row1", true)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_tsv_header_options
|
205
|
-
content =<<-EOF
|
206
|
-
#: :sep=/\\s+/
|
207
|
-
#Id Value
|
208
|
-
1 a
|
209
|
-
2 b
|
210
|
-
EOF
|
211
|
-
|
212
|
-
TmpFile.with_file(content) do |filename|
|
213
|
-
tsv = TSV.open(filename)
|
214
|
-
assert_equal [["a"]], tsv["1"]
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_tsv_fastimport
|
219
|
-
content =<<-EOF
|
220
|
-
#Id ValueA ValueB OtherID
|
221
|
-
row1 a|aa|aaa b Id1|Id2
|
222
|
-
row2 A B Id3
|
223
|
-
row3 AA B Id3
|
224
|
-
EOF
|
225
|
-
|
226
|
-
TmpFile.with_file(content.gsub(/ +/,"\t")) do |filename|
|
227
|
-
tsv = TSV.open(filename, :persist => true)
|
228
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"][0]
|
229
|
-
assert_equal ["ValueA", "ValueB", "OtherID"], tsv.fields
|
230
|
-
assert_equal :double, tsv.type
|
231
|
-
assert_equal "Id", tsv.key_field
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_header_type
|
236
|
-
content =<<-EOF
|
237
|
-
#: :sep=/\\s+/#:type=:single
|
238
|
-
#Id Value
|
239
|
-
1 a
|
240
|
-
2 b
|
241
|
-
EOF
|
242
|
-
|
243
|
-
TmpFile.with_file(content) do |filename|
|
244
|
-
tsv = TSV.open(filename)
|
245
|
-
assert_equal :single, tsv.type
|
246
|
-
assert_equal "a", tsv["1"]
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_single_cast
|
252
|
-
content =<<-EOF
|
253
|
-
#: :sep=/\\s+/#:type=:single#:cast=:to_i
|
254
|
-
#Id Value
|
255
|
-
a 1
|
256
|
-
b 2
|
257
|
-
EOF
|
258
|
-
|
259
|
-
TmpFile.with_file(content) do |filename|
|
260
|
-
tsv = TSV.open(filename)
|
261
|
-
assert_equal :single, tsv.type
|
262
|
-
assert_equal 1, tsv["a"]
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_key_field
|
267
|
-
content =<<-EOF
|
268
|
-
#: :sep=/\\s+/#:type=:single
|
269
|
-
#Id Value
|
270
|
-
a 1
|
271
|
-
b 2
|
272
|
-
EOF
|
273
|
-
|
274
|
-
TmpFile.with_file(content) do |filename|
|
275
|
-
tsv = TSV.open(filename, :key_field => "Value")
|
276
|
-
assert_equal %w(Id), tsv.fields
|
277
|
-
assert_equal "Value", tsv.key_field
|
278
|
-
assert_equal "a", tsv["1"]
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_fix
|
283
|
-
content =<<-EOF
|
284
|
-
#: :sep=/\\s+/#:type=:single
|
285
|
-
#Id Value
|
286
|
-
a 1
|
287
|
-
b 2
|
288
|
-
EOF
|
289
|
-
|
290
|
-
TmpFile.with_file(content) do |filename|
|
291
|
-
tsv = TSV.open(filename, :key_field => "Value", :fix => Proc.new{|l| if l =~ /1/;then "a 3" else l end})
|
292
|
-
assert_equal "a", tsv["3"]
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def test_select
|
297
|
-
content =<<-EOF
|
298
|
-
#: :sep=/\\s+/#:type=:single
|
299
|
-
#Id Value
|
300
|
-
a 1
|
301
|
-
b 2
|
302
|
-
EOF
|
303
|
-
|
304
|
-
TmpFile.with_file(content) do |filename|
|
305
|
-
tsv = TSV.open(filename, :key_field => "Value", :select => Proc.new{|l| l !~ /1/})
|
306
|
-
assert(! tsv.include?("3"))
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def test_grep
|
311
|
-
content =<<-EOF
|
312
|
-
#: :sep=/\\s+/#:type=:single
|
313
|
-
#Id Value
|
314
|
-
a 1
|
315
|
-
b 2
|
316
|
-
EOF
|
317
|
-
|
318
|
-
TmpFile.with_file(content) do |filename|
|
319
|
-
tsv = TSV.open(filename, :key_field => "Value", :grep => "#\\|2")
|
320
|
-
assert(! tsv.include?("3"))
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
def test_tsv_grep
|
325
|
-
content =<<-EOF
|
326
|
-
#: :sep=/\\s+/#:type=:single
|
327
|
-
#Id Value
|
328
|
-
a 1
|
329
|
-
b 2
|
330
|
-
b 3
|
331
|
-
d 22
|
332
|
-
EOF
|
333
|
-
|
334
|
-
TmpFile.with_file(content) do |filename|
|
335
|
-
tsv = TSV.open(filename, :key_field => "Value", :grep => "2")
|
336
|
-
assert(tsv.include?("2"))
|
337
|
-
assert(! tsv.include?("3"))
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_grep_invert
|
342
|
-
content =<<-EOF
|
343
|
-
#: :sep=/\\s+/#:type=:single
|
344
|
-
#Id Value
|
345
|
-
a 1
|
346
|
-
b 2
|
347
|
-
EOF
|
348
|
-
|
349
|
-
TmpFile.with_file(content) do |filename|
|
350
|
-
tsv = TSV.open(filename, :key_field => "Value", :tsv_grep => "2", :invert_grep => true)
|
351
|
-
assert(! tsv.include?("2"))
|
352
|
-
assert(tsv.include?("1"))
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
def test_grep_header
|
357
|
-
content =<<-EOF
|
358
|
-
#: :sep=/\\s+/#:type=:single#:namespace=Test
|
359
|
-
#Id Value
|
360
|
-
a 7
|
361
|
-
a 1
|
362
|
-
b 2
|
363
|
-
EOF
|
364
|
-
|
365
|
-
TmpFile.with_file(content) do |filename|
|
366
|
-
tsv = TSV.open(filename, :key_field => "Value", :grep => '2')
|
367
|
-
assert(tsv.include?("2"))
|
368
|
-
assert(! tsv.include?("7"))
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
def test_json
|
373
|
-
content =<<-EOF
|
374
|
-
#: :sep=/\\s+/#:type=:single
|
375
|
-
#Id Value
|
376
|
-
a 1
|
377
|
-
b 2
|
378
|
-
EOF
|
379
|
-
|
380
|
-
require 'json'
|
381
|
-
TmpFile.with_file(content) do |filename|
|
382
|
-
tsv = TSV.open(filename, :key_field => "Value", :grep => "#\\|2")
|
383
|
-
end
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
def test_flat_no_merge
|
388
|
-
content =<<-EOF
|
389
|
-
#Id ValueA ValueB OtherID
|
390
|
-
row1 a|aa|aaa b Id1|Id2
|
391
|
-
row2 A B Id3
|
392
|
-
EOF
|
393
|
-
|
394
|
-
TmpFile.with_file(content) do |filename|
|
395
|
-
tsv = TSV.open(filename, :sep => /\s+/, :type => :flat, :fields => ["ValueA"])
|
396
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
397
|
-
assert_equal ["ValueA"], tsv.fields
|
398
|
-
assert_equal :flat, tsv.type
|
399
|
-
assert_equal "Id", tsv.key_field
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_flat_merge2
|
404
|
-
content =<<-EOF
|
405
|
-
#Id ValueA ValueB OtherID
|
406
|
-
row1 a|aa|aaa b Id1|Id2
|
407
|
-
row1 aaaa b Id1|Id2
|
408
|
-
row2 A B Id3
|
409
|
-
EOF
|
410
|
-
|
411
|
-
TmpFile.with_file(content) do |filename|
|
412
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => true, :type => :flat, :fields => ["ValueA"])
|
413
|
-
assert_equal ["a", "aa", "aaa", "aaaa"], tsv["row1"]
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
def test_flat
|
418
|
-
content =<<-EOF
|
419
|
-
#Id ValueA
|
420
|
-
row1 a aa aaa
|
421
|
-
row2 b bbb bbbb bb
|
422
|
-
EOF
|
423
|
-
|
424
|
-
TmpFile.with_file(content) do |filename|
|
425
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :type => :flat)
|
426
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
def test_flat_with_field
|
431
|
-
content =<<-EOF
|
432
|
-
#Id ValueA
|
433
|
-
row1 a aa aaa
|
434
|
-
row2 b bbb bbbb bb
|
435
|
-
EOF
|
436
|
-
|
437
|
-
TmpFile.with_file(content) do |filename|
|
438
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :type => :flat, :fields => ["ValueA"])
|
439
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
def test_flat_with_field_header
|
444
|
-
content =<<-EOF
|
445
|
-
#: :type=:flat
|
446
|
-
#Id ValueA
|
447
|
-
row1 a aa aaa
|
448
|
-
row2 b bbb bbbb bb
|
449
|
-
EOF
|
450
|
-
|
451
|
-
TmpFile.with_file(content) do |filename|
|
452
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :fields => ["ValueA"])
|
453
|
-
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
def test_flat_key
|
458
|
-
content =<<-EOF
|
459
|
-
#Id ValueA
|
460
|
-
row1 a aa aaa
|
461
|
-
row2 b bbb bbbb bb aa
|
462
|
-
EOF
|
463
|
-
|
464
|
-
TmpFile.with_file(content) do |filename|
|
465
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => true, :type => :flat, :key_field => "ValueA")
|
466
|
-
assert_equal ["row1"], tsv["a"]
|
467
|
-
assert_equal ["row1", "row2"], tsv["aa"]
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
def test_zipped
|
474
|
-
content =<<-EOF
|
475
|
-
#Id ValueA ValueB
|
476
|
-
row1 a|aa|aaa b|bb|bbb
|
477
|
-
row2 a|aa|aaa c|cc|ccc
|
478
|
-
EOF
|
479
|
-
|
480
|
-
TmpFile.with_file(content) do |filename|
|
481
|
-
tsv = TSV.open(filename, :sep => /\s+/, :merge => true, :type => :double, :key_field => "ValueA", :zipped => true)
|
482
|
-
assert_equal [["row1", "row2"], ["b", "c"]], tsv["a"]
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
def test_named_array_key
|
487
|
-
content =<<-EOF
|
488
|
-
#Id ValueA ValueB OtherID
|
489
|
-
row1 a|aa|aaa b Id1|Id2
|
490
|
-
row2 A B Id3
|
491
|
-
EOF
|
492
|
-
|
493
|
-
TmpFile.with_file(content) do |filename|
|
494
|
-
tsv = TSV.open(filename, :sep => /\s+/)
|
495
|
-
assert_equal "row1", tsv["row1"].key
|
496
|
-
|
497
|
-
end
|
498
|
-
|
499
|
-
end
|
500
|
-
|
501
|
-
def test_unnamed_key
|
502
|
-
content =<<-EOF
|
503
|
-
row1 a|aa|aaa b Id1|Id2
|
504
|
-
row2 A B Id3
|
505
|
-
EOF
|
506
|
-
|
507
|
-
TmpFile.with_file(content) do |filename|
|
508
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => 1)
|
509
|
-
assert tsv.keys.include? "a"
|
510
|
-
end
|
511
|
-
|
512
|
-
end
|
513
|
-
|
514
|
-
def test_float_array
|
515
|
-
content =<<-EOF
|
516
|
-
#Id ValueA ValueB OtherID
|
517
|
-
row1 0.2 0.3 0
|
518
|
-
row2 0.1 4.5 0
|
519
|
-
EOF
|
520
|
-
|
521
|
-
TmpFile.with_file(content) do |filename|
|
522
|
-
tsv = TSV.open(filename, :sep => /\s+/, :persist => true, :type => :list, :cast => :to_f)
|
523
|
-
assert_equal [0.2, 0.3, 0], tsv["row1"]
|
524
|
-
assert_equal :float_array, tsv.serializer
|
525
|
-
end
|
526
|
-
|
527
|
-
end
|
528
|
-
|
529
|
-
def test_flat_field_select
|
530
|
-
content =<<-EOF
|
531
|
-
#: :type=:flat
|
532
|
-
#Id Value
|
533
|
-
row1 a aa aaa
|
534
|
-
row2 b bb bbb
|
535
|
-
EOF
|
536
|
-
|
537
|
-
TmpFile.with_file(content) do |filename|
|
538
|
-
assert TSV.open(filename, :sep => /\s+/, :key_field => "Value").include? "aa"
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
def test_flat2
|
543
|
-
content =<<-EOF
|
544
|
-
#: :type=:flat
|
545
|
-
#Id Value
|
546
|
-
row1 a|aa|aaa
|
547
|
-
row2 A|AA|AAA
|
548
|
-
EOF
|
549
|
-
|
550
|
-
TmpFile.with_file(content) do |filename|
|
551
|
-
assert TSV.open(filename, :sep => /\s+/, :type => :flat).include? "row1"
|
552
|
-
assert TSV.open(filename, :sep => /\s+/, :type => :flat)["row1"].include? "a"
|
553
|
-
assert TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "Id")["row1"].include? "a"
|
554
|
-
assert TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "Id", :fields => ["Value"])["row1"].include? "a"
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
|
559
|
-
def test_tsv_flat_double
|
560
|
-
content =<<-EOF
|
561
|
-
#Id ValueA ValueB OtherID
|
562
|
-
row1 a|aa|aaa b Id1|Id2
|
563
|
-
row2 A B Id3
|
564
|
-
EOF
|
565
|
-
|
566
|
-
TmpFile.with_file(content) do |filename|
|
567
|
-
tsv = TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "ValueA", :fields => ["OtherID"], :merge => true)
|
568
|
-
assert tsv["aaa"].include? "Id1"
|
569
|
-
assert tsv["aaa"].include? "Id2"
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
def test_flat2single
|
574
|
-
content =<<-EOF
|
575
|
-
#: :type=:flat
|
576
|
-
#Id Value
|
577
|
-
row1 a aa aaa
|
578
|
-
row2 A AA AAA
|
579
|
-
EOF
|
580
|
-
|
581
|
-
TmpFile.with_file(content) do |filename|
|
582
|
-
assert TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value").include? "aaa"
|
583
|
-
end
|
584
|
-
|
585
|
-
end
|
586
|
-
|
587
|
-
def test_shard
|
588
|
-
shard_function = Proc.new do |key|
|
589
|
-
key[-1]
|
590
|
-
end
|
591
|
-
tsv = datafile_test('identifiers').tsv :persist => true, :shard_function => shard_function
|
592
|
-
assert_equal 10000, tsv.keys.length + 2
|
593
|
-
end
|
594
|
-
|
595
|
-
def test_flat_merge
|
596
|
-
content =<<-EOF
|
597
|
-
#Id ValueA ValueB OtherID
|
598
|
-
row1 a|aa|aaa b Id1|Id2
|
599
|
-
row2 A|aAa B Id3
|
600
|
-
row3 AA BB|BBB Id3|Id2
|
601
|
-
EOF
|
602
|
-
|
603
|
-
TmpFile.with_file(content) do |filename|
|
604
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "OtherID", :fields => ["ValueA"], :type => :flat, :merge => true)
|
605
|
-
assert_equal %w(A aAa AA).sort, tsv["Id3"].sort
|
606
|
-
assert_equal %w(a aa aaa AA).sort, tsv["Id2"].sort
|
607
|
-
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
def test_flat_key_field_double
|
612
|
-
content =<<-EOF
|
613
|
-
#Id ValueA
|
614
|
-
row1 a|aa|aaa
|
615
|
-
row2 b|bbb|bbbb|bb
|
616
|
-
EOF
|
617
|
-
|
618
|
-
TmpFile.with_file(content) do |filename|
|
619
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "ValueA", :fields => ["Id"], :type => :flat)
|
620
|
-
assert tsv.include? 'aa'
|
621
|
-
end
|
622
|
-
end
|
623
|
-
|
624
|
-
def test_flat_key_field
|
625
|
-
content =<<-EOF
|
626
|
-
#: :type=:flat
|
627
|
-
#Id ValueA
|
628
|
-
row1 a aa aaa
|
629
|
-
row2 b bbb bbbb bb
|
630
|
-
EOF
|
631
|
-
|
632
|
-
TmpFile.with_file(content) do |filename|
|
633
|
-
tsv = TSV.open(filename, :sep => /\s+/, :key_field => "ValueA", :fields => ["Id"], :type => :flat)
|
634
|
-
assert tsv.include? 'aa'
|
635
|
-
end
|
636
|
-
end
|
637
|
-
|
638
|
-
|
639
|
-
def test_string_options
|
640
|
-
content =<<-EOF
|
641
|
-
#Id ValueA ValueB OtherID
|
642
|
-
row1 a|aa|aaa b Id1|Id2
|
643
|
-
row2 A|aAa B Id3
|
644
|
-
row3 AA BB|BBB Id3|Id2
|
645
|
-
EOF
|
646
|
-
|
647
|
-
TmpFile.with_file(content) do |filename|
|
648
|
-
tsv = TSV.open(filename, :flat, 'Id~OtherID#:sep=/\s+/')
|
649
|
-
assert_equal %w(Id1 Id2), tsv["row1"]
|
650
|
-
|
651
|
-
end
|
652
|
-
end
|
653
|
-
|
654
|
-
def __test_benchmark
|
655
|
-
num = 10_000
|
656
|
-
txt = num.times.inject(nil) do |acc,i|
|
657
|
-
(acc.nil? ? "" : acc << "\n") << (0..10).collect{|v| v == 0 ? i : [v,v] * "|" } * "\t"
|
658
|
-
end
|
659
|
-
|
660
|
-
txt = StringIO.new(([txt] * (10))*"\n")
|
661
|
-
#Misc.profile do
|
662
|
-
Misc.benchmark(1) do
|
663
|
-
data = TSV.open(txt, type: :double, bar: true, merge: true)
|
664
|
-
assert_equal num, data.size
|
665
|
-
end
|
666
|
-
end
|
667
|
-
|
668
|
-
end
|
669
|
-
|