rbbt-util 5.21.121 → 5.21.122
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/tsv.rb +18 -2
- data/lib/rbbt/tsv/attach.rb +15 -2
- data/lib/rbbt/tsv/excel.rb +4 -2
- data/lib/rbbt/tsv/util.rb +12 -0
- data/lib/rbbt/util/R.rb +6 -1
- data/lib/rbbt/util/R/plot.rb +210 -4
- data/lib/rbbt/util/tmpfile.rb +3 -0
- data/share/Rlib/util.R +12 -2
- data/test/rbbt/test_tsv.rb +45 -7
- data/test/rbbt/util/R/test_plot.rb +40 -0
- data/test/rbbt/util/test_R.rb +6 -0
- data/test/rbbt/util/test_cmd.rb +5 -5
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e3570acbd38ac9c6559cabbfc3dae257ecae6dc0
|
|
4
|
+
data.tar.gz: f863e68d23369100f01c3d818aaecad50205afff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25abb01fe95848d99d5b20e3db8f00a03921377ea291fec3c4a938e1b73deb42650c068f2f3b1349e4dfc097515176f4d0bc8d87b096e8882076e3e187985a97
|
|
7
|
+
data.tar.gz: 3a1327e9286689eadfb6c6fc6725323dcb338eb7d9bc783e2dd8d80cf1998907346c764103777fbaad582ed38471dbc76c9cc860c9ec266247292fecd041eb97
|
data/lib/rbbt/tsv.rb
CHANGED
|
@@ -28,7 +28,22 @@ module TSV
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def self.
|
|
31
|
+
def self.str2options(str)
|
|
32
|
+
field_options, rest = str.split("#")
|
|
33
|
+
key, fields_str = field_options.split("~")
|
|
34
|
+
|
|
35
|
+
fields = fields_str.nil? ? [] : fields_str.split(/,\s*/)
|
|
36
|
+
rest_options = rest.nil? ? {} : Misc.string2hash(rest)
|
|
37
|
+
|
|
38
|
+
{:key_field => key, :fields => fields}.merge(rest_options)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.setup(hash, type = nil, options = nil)
|
|
42
|
+
type, options = nil, type if options.nil? and (Hash === type or (String === type and type.include? "~"))
|
|
43
|
+
options = TSV.str2options(options) if String === options and options.include? "~"
|
|
44
|
+
options ||= {}
|
|
45
|
+
options[:type] ||= type unless type.nil?
|
|
46
|
+
|
|
32
47
|
options = Misc.add_defaults options, :default_value => [], :unnamed => TSV.unnamed
|
|
33
48
|
default_value = Misc.process_options options, :default_value
|
|
34
49
|
hash = Misc.array2hash(hash, default_value) if Array === hash
|
|
@@ -47,7 +62,8 @@ module TSV
|
|
|
47
62
|
|
|
48
63
|
# options shift if type.nil?
|
|
49
64
|
def self.open(source, type = nil, options = nil)
|
|
50
|
-
type, options = nil, type if options.nil? and Hash === type
|
|
65
|
+
type, options = nil, type if options.nil? and (Hash === type or (String === type and type.include? "~"))
|
|
66
|
+
options = TSV.str2options(options) if String === options and options.include? "~"
|
|
51
67
|
options ||= {}
|
|
52
68
|
options[:type] ||= type unless type.nil?
|
|
53
69
|
|
data/lib/rbbt/tsv/attach.rb
CHANGED
|
@@ -215,6 +215,9 @@ module TSV
|
|
|
215
215
|
if complete
|
|
216
216
|
fill = TrueClass === complete ? nil : complete
|
|
217
217
|
field_length = self.fields.length
|
|
218
|
+
common_fields = (other.fields & self.fields)
|
|
219
|
+
other_common_pos = common_fields.collect{|f| other.fields.index f}
|
|
220
|
+
this_common_pos = common_fields.collect{|f| self.fields.index f}
|
|
218
221
|
missing = other.keys - self.keys
|
|
219
222
|
case type
|
|
220
223
|
when :single
|
|
@@ -223,11 +226,21 @@ module TSV
|
|
|
223
226
|
end
|
|
224
227
|
when :list
|
|
225
228
|
missing.each do |k|
|
|
226
|
-
|
|
229
|
+
values = [nil] * field_length
|
|
230
|
+
other_values = other[k]
|
|
231
|
+
other_common_pos.zip(this_common_pos).each do |o,t|
|
|
232
|
+
values[t] = other_values[o]
|
|
233
|
+
end
|
|
234
|
+
self[k] = values
|
|
227
235
|
end
|
|
228
236
|
when :double
|
|
229
237
|
missing.each do |k|
|
|
230
|
-
|
|
238
|
+
values = [[]] * field_length
|
|
239
|
+
other_values = other[k]
|
|
240
|
+
other_common_pos.zip(this_common_pos).each do |o,t|
|
|
241
|
+
values[t] = other_values[o]
|
|
242
|
+
end
|
|
243
|
+
self[k] = values
|
|
231
244
|
end
|
|
232
245
|
when :flat
|
|
233
246
|
missing.each do |k|
|
data/lib/rbbt/tsv/excel.rb
CHANGED
|
@@ -97,6 +97,7 @@ module TSV
|
|
|
97
97
|
options = Misc.add_defaults options, :sep2 => /[,|]\s?/
|
|
98
98
|
sheet = Misc.process_options options, :sheet
|
|
99
99
|
header = Misc.process_options options, :header
|
|
100
|
+
text = Misc.process_options options, :text
|
|
100
101
|
|
|
101
102
|
header = true unless header == false
|
|
102
103
|
sheet ||= 0
|
|
@@ -124,7 +125,7 @@ module TSV
|
|
|
124
125
|
end
|
|
125
126
|
end
|
|
126
127
|
|
|
127
|
-
TSV.open(filename, options)
|
|
128
|
+
text ? Open.read(filename) : TSV.open(filename, options)
|
|
128
129
|
end
|
|
129
130
|
end
|
|
130
131
|
|
|
@@ -152,6 +153,7 @@ module TSV
|
|
|
152
153
|
options = Misc.add_defaults options, :sep2 => /[,|]\s?/
|
|
153
154
|
sheet = Misc.process_options options, :sheet
|
|
154
155
|
header = Misc.process_options options, :header
|
|
156
|
+
text = Misc.process_options options, :text
|
|
155
157
|
|
|
156
158
|
header = true unless header == false
|
|
157
159
|
TmpFile.with_file do |filename|
|
|
@@ -178,7 +180,7 @@ module TSV
|
|
|
178
180
|
end
|
|
179
181
|
end
|
|
180
182
|
|
|
181
|
-
TSV.open(filename, options)
|
|
183
|
+
text ? Open.read(filename) : TSV.open(filename, options)
|
|
182
184
|
end
|
|
183
185
|
end
|
|
184
186
|
|
data/lib/rbbt/tsv/util.rb
CHANGED
|
@@ -334,6 +334,18 @@ module TSV
|
|
|
334
334
|
def marshal_dump
|
|
335
335
|
[info, to_hash]
|
|
336
336
|
end
|
|
337
|
+
|
|
338
|
+
def to_onehot(boolean = false)
|
|
339
|
+
all_values = values.flatten.uniq.collect{|v| v.to_s}.sort
|
|
340
|
+
index = TSV.setup({}, :key_field => key_field, :fields => all_values, :type => :list)
|
|
341
|
+
index.cast = :to_i unless boolean
|
|
342
|
+
through do |key,values|
|
|
343
|
+
v = all_values.collect{|_v| values.include?(_v)}
|
|
344
|
+
v = v.collect{|_v| _v ? 1 : 0 } unless boolean
|
|
345
|
+
index[key] = v
|
|
346
|
+
end
|
|
347
|
+
index
|
|
348
|
+
end
|
|
337
349
|
end
|
|
338
350
|
|
|
339
351
|
class Hash
|
data/lib/rbbt/util/R.rb
CHANGED
|
@@ -124,7 +124,6 @@ source(interactive.script.file)
|
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
|
|
128
127
|
def self.ruby2R(object)
|
|
129
128
|
case object
|
|
130
129
|
when Float::INFINITY
|
|
@@ -154,6 +153,12 @@ source(interactive.script.file)
|
|
|
154
153
|
end
|
|
155
154
|
end
|
|
156
155
|
|
|
156
|
+
def self.hash2Rargs(hash)
|
|
157
|
+
hash.collect do |k,v|
|
|
158
|
+
[k.to_s, ruby2R(v)] * "="
|
|
159
|
+
end * ", "
|
|
160
|
+
end
|
|
161
|
+
|
|
157
162
|
def self.tsv(file, options = {})
|
|
158
163
|
options = Misc.add_defaults :header_hash => '', :sep => / +/, :type => :list, :key_field => 'ID'
|
|
159
164
|
key_field = Misc.process_options options, :key_field
|
data/lib/rbbt/util/R/plot.rb
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module R
|
|
2
2
|
module SVG
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
def self.ggplotPNG(*args)
|
|
5
|
+
ggplot(*args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.ggplot(data, script = nil, width = nil, height = nil, options = {})
|
|
4
9
|
width ||= 3
|
|
5
10
|
height ||= 3
|
|
6
11
|
values = []
|
|
@@ -79,7 +84,27 @@ module R
|
|
|
79
84
|
end
|
|
80
85
|
|
|
81
86
|
module PNG
|
|
82
|
-
|
|
87
|
+
|
|
88
|
+
def self.eog(data, script = nil, width = nil, height = nil, options = {})
|
|
89
|
+
TmpFile.with_file :extension => 'png' do |filename|
|
|
90
|
+
ggplot(filename, data, script, width, height, options)
|
|
91
|
+
`eog #{ filename }`
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.eog_plot(data, script = nil, width = nil, height = nil, options = {})
|
|
96
|
+
TmpFile.with_file :extension => 'png' do |filename|
|
|
97
|
+
plot(filename, data, script, width, height, options)
|
|
98
|
+
`eog #{ filename }`
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def self.ggplotPNG(*args)
|
|
104
|
+
ggplot(*args)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def self.ggplot(filename, data, script = nil, width = nil, height = nil, options = {})
|
|
83
108
|
width ||= 3
|
|
84
109
|
height ||= 3
|
|
85
110
|
values = []
|
|
@@ -122,8 +147,8 @@ data = NULL
|
|
|
122
147
|
end
|
|
123
148
|
|
|
124
149
|
def self.plot(filename, data = nil, script = nil, width = nil, height = nil, options = {}, &block)
|
|
125
|
-
width ||=
|
|
126
|
-
height ||=
|
|
150
|
+
width ||= 600
|
|
151
|
+
height ||= 600
|
|
127
152
|
values = []
|
|
128
153
|
|
|
129
154
|
script ||= ""
|
|
@@ -210,4 +235,185 @@ data = NULL
|
|
|
210
235
|
end
|
|
211
236
|
end
|
|
212
237
|
end
|
|
238
|
+
|
|
239
|
+
module GIF
|
|
240
|
+
|
|
241
|
+
def self.eog(data, frames = nil, script = nil, width = nil, height = nil, options = {})
|
|
242
|
+
TmpFile.with_file :extension => 'gif' do |filename|
|
|
243
|
+
ggplot(filename, data, frames, script, width, height, options)
|
|
244
|
+
`eog #{ filename }`
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def self.eog_plot(data, frames = nil, script = nil, width = nil, height = nil, options = {})
|
|
249
|
+
TmpFile.with_file :extension => 'gif' do |filename|
|
|
250
|
+
plot(filename, data, frames, script, width, height, options)
|
|
251
|
+
`eog #{ filename }`
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def self.ggplot(filename, data, frames = nil, script = nil, width = nil, height = nil, options = {})
|
|
257
|
+
width ||= 3
|
|
258
|
+
height ||= 3
|
|
259
|
+
values = []
|
|
260
|
+
|
|
261
|
+
sources = [:plot, options[:source]].flatten.compact
|
|
262
|
+
|
|
263
|
+
data.each do |k,v|
|
|
264
|
+
v = Array === v ? v : [v]
|
|
265
|
+
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
|
266
|
+
values = v
|
|
267
|
+
break
|
|
268
|
+
end
|
|
269
|
+
values = [values] unless Array === values
|
|
270
|
+
field_classes = values.collect do |v|
|
|
271
|
+
case v
|
|
272
|
+
when FalseClass, TrueClass
|
|
273
|
+
"'logical'"
|
|
274
|
+
when Numeric
|
|
275
|
+
"'numeric'"
|
|
276
|
+
when String
|
|
277
|
+
if v.strip =~ /^[-+]?[\d\.]+$/
|
|
278
|
+
"'numeric'"
|
|
279
|
+
else
|
|
280
|
+
"'character'"
|
|
281
|
+
end
|
|
282
|
+
when Symbol
|
|
283
|
+
"'factor'"
|
|
284
|
+
else
|
|
285
|
+
":NA"
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
|
289
|
+
|
|
290
|
+
delay = options[:delay]
|
|
291
|
+
delay = 10 if delay.nil?
|
|
292
|
+
|
|
293
|
+
frames = data.keys if frames.nil?
|
|
294
|
+
frames = (1..frames).to_a if Integer === frames
|
|
295
|
+
|
|
296
|
+
data.R <<-EOF, :plot, options
|
|
297
|
+
frames = #{R.ruby2R frames}
|
|
298
|
+
for (frame in seq(1, length(frames))){
|
|
299
|
+
frame.value = frames[frame]
|
|
300
|
+
frame.str = sprintf("%06d", frame)
|
|
301
|
+
plot = { #{script} }
|
|
302
|
+
|
|
303
|
+
ggsave(paste('#{filename}', frame.str, 'tmp.png', sep="."), plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
|
|
304
|
+
}
|
|
305
|
+
data = NULL
|
|
306
|
+
EOF
|
|
307
|
+
|
|
308
|
+
CMD.cmd("convert #{filename}.*.tmp.png -set delay #{delay} -loop 0 #{filename} && rm #{filename}.*.tmp.png")
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def self.plot(filename, data = nil, frames = nil, script = nil, width = nil, height = nil, options = {}, &block)
|
|
312
|
+
width ||= 600
|
|
313
|
+
height ||= 600
|
|
314
|
+
values = []
|
|
315
|
+
|
|
316
|
+
script ||= ""
|
|
317
|
+
if block_given?
|
|
318
|
+
s = StringIO.new
|
|
319
|
+
class << s
|
|
320
|
+
def method_missing(name, *args)
|
|
321
|
+
name = name.to_s
|
|
322
|
+
if name[-1] == '='
|
|
323
|
+
arg = args.first
|
|
324
|
+
value = if String === arg
|
|
325
|
+
arg
|
|
326
|
+
else
|
|
327
|
+
R.ruby2R arg
|
|
328
|
+
end
|
|
329
|
+
add("" << name[0..-2] << "=" << value)
|
|
330
|
+
else
|
|
331
|
+
args_strs = []
|
|
332
|
+
args.each do |arg|
|
|
333
|
+
value = if String === arg
|
|
334
|
+
arg
|
|
335
|
+
else
|
|
336
|
+
R.ruby2R arg
|
|
337
|
+
end
|
|
338
|
+
args_strs << value
|
|
339
|
+
end
|
|
340
|
+
add("" << name << "(" << args_strs * ", " << ")")
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def add(line)
|
|
345
|
+
self.write line << "\n"
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
block.call(s)
|
|
349
|
+
s.rewind
|
|
350
|
+
script << "\n" << s.read
|
|
351
|
+
end
|
|
352
|
+
sources = [:plot, options[:source]].flatten.compact
|
|
353
|
+
|
|
354
|
+
delay = options[:delay]
|
|
355
|
+
delay = 10 if delay.nil?
|
|
356
|
+
|
|
357
|
+
frames = data.keys if frames.nil?
|
|
358
|
+
frames = (1..frames).to_a if Integer === frames
|
|
359
|
+
|
|
360
|
+
if data
|
|
361
|
+
data.each do |k,v|
|
|
362
|
+
v = Array === v ? v : [v]
|
|
363
|
+
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
|
364
|
+
values = v
|
|
365
|
+
break
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
values = [values] unless values.nil? or Array === values
|
|
369
|
+
|
|
370
|
+
field_classes = values.collect do |v|
|
|
371
|
+
case v
|
|
372
|
+
when FalseClass, TrueClass
|
|
373
|
+
"'logical'"
|
|
374
|
+
when Numeric
|
|
375
|
+
"'numeric'"
|
|
376
|
+
when String
|
|
377
|
+
if v.strip =~ /^[-+]?[\d\.]+$/
|
|
378
|
+
"'numeric'"
|
|
379
|
+
else
|
|
380
|
+
"'character'"
|
|
381
|
+
end
|
|
382
|
+
when Symbol
|
|
383
|
+
"'factor'"
|
|
384
|
+
else
|
|
385
|
+
":NA"
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')' if field_classes.any?
|
|
390
|
+
|
|
391
|
+
data.R <<-EOF, :plot, options
|
|
392
|
+
frames = #{R.ruby2R frames}
|
|
393
|
+
for (frame in seq(1, length(frames))){
|
|
394
|
+
frame.value = frames[frame]
|
|
395
|
+
frame.str = sprintf("%06d", frame)
|
|
396
|
+
plot = { #{script} }
|
|
397
|
+
|
|
398
|
+
png(paste('#{filename}', frame.str, 'tmp.png', sep="."), #{ width }, #{ height })
|
|
399
|
+
{ #{script} }
|
|
400
|
+
dev.off()
|
|
401
|
+
}
|
|
402
|
+
data = NULL
|
|
403
|
+
EOF
|
|
404
|
+
else
|
|
405
|
+
R.run <<-EOF, :plot, options
|
|
406
|
+
frames = #{R.ruby2R frames}
|
|
407
|
+
for (frame in seq(1, length(frames))){
|
|
408
|
+
frame.value = frames[frame]
|
|
409
|
+
frame.str = sprintf("%06d", frame)
|
|
410
|
+
png(paste('#{filename}', frame.str, 'tmp.png', sep="."), #{ width }, #{ height })
|
|
411
|
+
{ #{script} }
|
|
412
|
+
dev.off()
|
|
413
|
+
}
|
|
414
|
+
EOF
|
|
415
|
+
end
|
|
416
|
+
CMD.cmd("convert #{filename}.*.tmp.png -set delay #{delay} -loop 0 #{filename} && rm #{filename}.*.tmp.png")
|
|
417
|
+
end
|
|
418
|
+
end
|
|
213
419
|
end
|
data/lib/rbbt/util/tmpfile.rb
CHANGED
|
@@ -28,6 +28,9 @@ module TmpFile
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def self.with_file(content = nil, erase = true, options = {})
|
|
31
|
+
options, content, erase = content, nil, true if Hash === content
|
|
32
|
+
options, erase = erase, true if Hash === erase
|
|
33
|
+
|
|
31
34
|
prefix = options[:prefix] || ""
|
|
32
35
|
tmpfile = tmp_file prefix
|
|
33
36
|
if options[:extension]
|
data/share/Rlib/util.R
CHANGED
|
@@ -737,10 +737,20 @@ rbbt.psd <- function(m){
|
|
|
737
737
|
return(p)
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
+
rbbt.impute <- function(data){
|
|
741
|
+
m = as.matrix(data)
|
|
742
|
+
if (sum(is.na(m)) == 0){
|
|
743
|
+
return (m)
|
|
744
|
+
}else{
|
|
745
|
+
rbbt.require('Hmisc')
|
|
746
|
+
m.i = impute(m)
|
|
747
|
+
return(m.i)
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
740
751
|
rbbt.fix_distance <- function(data){
|
|
741
|
-
rbbt.require('Hmisc')
|
|
742
752
|
|
|
743
|
-
m = impute(
|
|
753
|
+
m = rbbt.impute(data)
|
|
744
754
|
|
|
745
755
|
p <- rbbt.psd(m)
|
|
746
756
|
p <- m
|
data/test/rbbt/test_tsv.rb
CHANGED
|
@@ -387,7 +387,7 @@ row2 A B Id3
|
|
|
387
387
|
end
|
|
388
388
|
end
|
|
389
389
|
|
|
390
|
-
def
|
|
390
|
+
def test_flat_merge2
|
|
391
391
|
content =<<-EOF
|
|
392
392
|
#Id ValueA ValueB OtherID
|
|
393
393
|
row1 a|aa|aaa b Id1|Id2
|
|
@@ -408,12 +408,39 @@ row1 a aa aaa
|
|
|
408
408
|
row2 b bbb bbbb bb
|
|
409
409
|
EOF
|
|
410
410
|
|
|
411
|
+
TmpFile.with_file(content) do |filename|
|
|
412
|
+
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :type => :flat)
|
|
413
|
+
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def test_flat_with_field
|
|
418
|
+
content =<<-EOF
|
|
419
|
+
#Id ValueA
|
|
420
|
+
row1 a aa aaa
|
|
421
|
+
row2 b bbb bbbb bb
|
|
422
|
+
EOF
|
|
423
|
+
|
|
411
424
|
TmpFile.with_file(content) do |filename|
|
|
412
425
|
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :type => :flat, :fields => ["ValueA"])
|
|
413
426
|
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
|
414
427
|
end
|
|
415
428
|
end
|
|
416
429
|
|
|
430
|
+
def test_flat_with_field_header
|
|
431
|
+
content =<<-EOF
|
|
432
|
+
#: :type=:flat
|
|
433
|
+
#Id ValueA
|
|
434
|
+
row1 a aa aaa
|
|
435
|
+
row2 b bbb bbbb bb
|
|
436
|
+
EOF
|
|
437
|
+
|
|
438
|
+
TmpFile.with_file(content) do |filename|
|
|
439
|
+
tsv = TSV.open(filename, :sep => /\s+/, :merge => false, :fields => ["ValueA"])
|
|
440
|
+
assert_equal ["a", "aa", "aaa"], tsv["row1"]
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
|
|
417
444
|
def test_flat_key
|
|
418
445
|
content =<<-EOF
|
|
419
446
|
#Id ValueA
|
|
@@ -525,10 +552,8 @@ row2 A B Id3
|
|
|
525
552
|
|
|
526
553
|
TmpFile.with_file(content) do |filename|
|
|
527
554
|
tsv = TSV.open(filename, :sep => /\s+/, :type => :flat, :key_field => "ValueA", :fields => ["OtherID"], :merge => true)
|
|
528
|
-
ppp tsv
|
|
529
555
|
assert tsv["aaa"].include? "Id1"
|
|
530
556
|
assert tsv["aaa"].include? "Id2"
|
|
531
|
-
|
|
532
557
|
end
|
|
533
558
|
end
|
|
534
559
|
|
|
@@ -554,10 +579,6 @@ row2 A AA AAA
|
|
|
554
579
|
assert_equal 10000, tsv.keys.length + 2
|
|
555
580
|
end
|
|
556
581
|
|
|
557
|
-
def test_merge_key_field
|
|
558
|
-
assert TSV.open('/home/mvazquezg/git/workflows/genomics/share/gene_ages', :key_field => "FamilyAge", :merge => true, :persist => false, :zipped => true, :type => :double).values.first.length > 1
|
|
559
|
-
end
|
|
560
|
-
|
|
561
582
|
def test_flat_merge
|
|
562
583
|
content =<<-EOF
|
|
563
584
|
#Id ValueA ValueB OtherID
|
|
@@ -600,4 +621,21 @@ row2 b bbb bbbb bb
|
|
|
600
621
|
assert tsv.include? 'aa'
|
|
601
622
|
end
|
|
602
623
|
end
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def test_string_options
|
|
627
|
+
content =<<-EOF
|
|
628
|
+
#Id ValueA ValueB OtherID
|
|
629
|
+
row1 a|aa|aaa b Id1|Id2
|
|
630
|
+
row2 A|aAa B Id3
|
|
631
|
+
row3 AA BB|BBB Id3|Id2
|
|
632
|
+
EOF
|
|
633
|
+
|
|
634
|
+
TmpFile.with_file(content) do |filename|
|
|
635
|
+
tsv = TSV.open(filename, :flat, 'Id~OtherID#:sep=/\s+/')
|
|
636
|
+
assert_equal %w(Id1 Id2), tsv["row1"]
|
|
637
|
+
|
|
638
|
+
end
|
|
639
|
+
end
|
|
603
640
|
end
|
|
641
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
|
|
2
|
+
require 'rbbt/util/R'
|
|
3
|
+
require 'rbbt/util/R/plot'
|
|
4
|
+
|
|
5
|
+
class TestRPlot < Test::Unit::TestCase
|
|
6
|
+
def __test_ggplotgif
|
|
7
|
+
|
|
8
|
+
Log.severity = 0
|
|
9
|
+
x = R.eval_a 'rnorm(100, 0, 1)'
|
|
10
|
+
data = TSV.setup(x, "Num~#:type=:single#:cast=:to_f")
|
|
11
|
+
|
|
12
|
+
data.add_field "Val" do |k,v|
|
|
13
|
+
k
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
R::GIF.eog(data, (0..10).to_a.collect{|i| 100.0 / 10**i}, <<-EOF, nil, nil, :delay => 100)
|
|
17
|
+
rbbt.require('reshape')
|
|
18
|
+
ggplot(data) + geom_density(bw=frame.value, aes(x=Val))
|
|
19
|
+
EOF
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_gif
|
|
24
|
+
|
|
25
|
+
Log.severity = 0
|
|
26
|
+
x = R.eval_a 'rnorm(100, 0, 1)'
|
|
27
|
+
data = TSV.setup(x, "Num~#:type=:single#:cast=:to_f")
|
|
28
|
+
|
|
29
|
+
data.add_field "Val" do |k,v|
|
|
30
|
+
k
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
R::GIF.eog_plot(data, (0..10).to_a.collect{|i| 100.0 / 10**i}, <<-EOF, 400, 400, :delay => 10)
|
|
34
|
+
rbbt.require('reshape')
|
|
35
|
+
plot(density(data$Val, bw=frame.value))
|
|
36
|
+
EOF
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
data/test/rbbt/util/test_R.rb
CHANGED
data/test/rbbt/util/test_cmd.rb
CHANGED
|
@@ -5,27 +5,27 @@ require 'test/unit'
|
|
|
5
5
|
class TestCmd < Test::Unit::TestCase
|
|
6
6
|
|
|
7
7
|
def test_cmd_option_string
|
|
8
|
-
assert_equal("--user-agent firefox", CMD.process_cmd_options("--user-agent" => "firefox"))
|
|
9
|
-
assert_equal("--user-agent=firefox", CMD.process_cmd_options("--user-agent=" => "firefox"))
|
|
8
|
+
assert_equal("--user-agent 'firefox'", CMD.process_cmd_options("--user-agent" => "firefox"))
|
|
9
|
+
assert_equal("--user-agent='firefox'", CMD.process_cmd_options("--user-agent=" => "firefox"))
|
|
10
10
|
assert_equal("-q", CMD.process_cmd_options("-q" => true))
|
|
11
11
|
assert_equal("", CMD.process_cmd_options("-q" => nil))
|
|
12
12
|
assert_equal("", CMD.process_cmd_options("-q" => false))
|
|
13
13
|
|
|
14
|
-
assert(CMD.process_cmd_options("--user-agent" => "firefox", "-q" => true) =~ /--user-agent firefox/)
|
|
14
|
+
assert(CMD.process_cmd_options("--user-agent" => "firefox", "-q" => true) =~ /--user-agent 'firefox'/)
|
|
15
15
|
assert(CMD.process_cmd_options("--user-agent" => "firefox", "-q" => true) =~ /-q/)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def test_cmd
|
|
19
19
|
assert_equal("test\n", CMD.cmd("echo '{opt}' test").read)
|
|
20
20
|
assert_equal("test", CMD.cmd("echo '{opt}' test", "-n" => true).read)
|
|
21
|
-
assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => '
|
|
21
|
+
assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => ' ', :in => "test1 test2").read)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def test_pipe
|
|
25
25
|
assert_equal("test\n", CMD.cmd("echo test", :pipe => true).read)
|
|
26
26
|
assert_equal("test\n", CMD.cmd("echo '{opt}' test", :pipe => true).read)
|
|
27
27
|
assert_equal("test", CMD.cmd("echo '{opt}' test", "-n" => true, :pipe => true).read)
|
|
28
|
-
assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => '
|
|
28
|
+
assert_equal("test2\n", CMD.cmd("cut", "-f" => 2, "-d" => ' ', :in => "test1 test2", :pipe => true).read)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def test_error
|
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.21.
|
|
4
|
+
version: 5.21.122
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miguel Vazquez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -452,6 +452,7 @@ files:
|
|
|
452
452
|
- test/rbbt/tsv/test_util.rb
|
|
453
453
|
- test/rbbt/util/R/test_eval.rb
|
|
454
454
|
- test/rbbt/util/R/test_model.rb
|
|
455
|
+
- test/rbbt/util/R/test_plot.rb
|
|
455
456
|
- test/rbbt/util/concurrency/processes/test_socket.rb
|
|
456
457
|
- test/rbbt/util/concurrency/test_processes.rb
|
|
457
458
|
- test/rbbt/util/concurrency/test_threads.rb
|
|
@@ -522,6 +523,7 @@ test_files:
|
|
|
522
523
|
- test/rbbt/util/misc/test_bgzf.rb
|
|
523
524
|
- test/rbbt/util/test_concurrency.rb
|
|
524
525
|
- test/rbbt/util/test_cmd.rb
|
|
526
|
+
- test/rbbt/util/R/test_plot.rb
|
|
525
527
|
- test/rbbt/util/R/test_eval.rb
|
|
526
528
|
- test/rbbt/util/R/test_model.rb
|
|
527
529
|
- test/rbbt/util/test_log.rb
|