rbbt-util 5.14.26 → 5.14.28
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/etc/app.d/grid_system.rb +3 -1
- data/lib/rbbt/annotations/annotated_array.rb +4 -0
- data/lib/rbbt/association.rb +44 -18
- data/lib/rbbt/association/index.rb +1 -0
- data/lib/rbbt/association/item.rb +42 -4
- data/lib/rbbt/knowledge_base.rb +60 -32
- data/lib/rbbt/resource.rb +14 -3
- data/lib/rbbt/resource/path.rb +8 -4
- data/lib/rbbt/tsv.rb +3 -2
- data/lib/rbbt/tsv/accessor.rb +3 -3
- data/lib/rbbt/tsv/parser.rb +1 -1
- data/lib/rbbt/util/R.rb +48 -1
- data/lib/rbbt/util/log.rb +8 -1
- data/lib/rbbt/util/misc/development.rb +2 -1
- data/share/Rlib/util.R +0 -2
- data/test/rbbt/test_knowledge_base.rb +1 -1
- data/test/rbbt/test_resource.rb +15 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46848d2c59e5582f44b698be77f427d886682c4f
|
4
|
+
data.tar.gz: c3ae39b55c1f9d44975679aa2916cdcb198cd7e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fe50e3bb01ed9b718f71a19f29b5697af0aacbc9ce602b93f802ba1400074491782f32774cb56d832c50befd99386566732e8a9941ba2500957e2f66ef1d9b5
|
7
|
+
data.tar.gz: 600ac43a4bd563779943a3061a151d3dacb5b3d2cfa5ff98d7f90f600bc29578bd34c3161af06d8d97ec7d32f1c9896f21518ff0cd2837f00f569d2348894d6c
|
data/etc/app.d/grid_system.rb
CHANGED
data/lib/rbbt/association.rb
CHANGED
@@ -11,17 +11,36 @@ module Association
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.add_reciprocal(tsv)
|
14
|
-
|
15
|
-
new = tsv.
|
14
|
+
tsv = tsv.type == :double ? tsv : tsv.to_double
|
15
|
+
new = TSV.open(tsv.dumper_stream)
|
16
16
|
tsv.with_unnamed do
|
17
17
|
tsv.through do |source, values|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
next if values.flatten.compact.empty?
|
19
|
+
if values.length > 1
|
20
|
+
Misc.zip_fields(values).each do |_target_values|
|
21
|
+
target, *target_values = _target_values
|
22
|
+
if new[target].nil?
|
23
|
+
new_values = [[source]] + target_values.collect{|v| [v] }
|
24
|
+
new[target] = new_values
|
25
|
+
else
|
26
|
+
new_values = new[target].collect{|l| l.dup }
|
27
|
+
targets = new_values.shift
|
28
|
+
targets << source
|
29
|
+
rest = new_values.zip(target_values).collect do |o,n|
|
30
|
+
o << n
|
31
|
+
o
|
32
|
+
end
|
33
|
+
new_values = [targets] + rest
|
34
|
+
new[target] = new_values
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
values.first.each do |target|
|
39
|
+
if new[target].nil?
|
40
|
+
new[target] = [[source]]
|
41
|
+
else
|
42
|
+
new[target] = [new[target][0] + [source]]
|
43
|
+
end
|
25
44
|
end
|
26
45
|
end
|
27
46
|
end
|
@@ -61,7 +80,7 @@ module Association
|
|
61
80
|
end
|
62
81
|
|
63
82
|
#{{{ Open
|
64
|
-
|
83
|
+
|
65
84
|
def self.open_tsv(file, source, source_header, target, target_header, all_fields, options)
|
66
85
|
fields = Misc.process_options options, :fields
|
67
86
|
fields ||= all_fields.dup
|
@@ -74,7 +93,6 @@ module Association
|
|
74
93
|
:persist => false,
|
75
94
|
:key_field => all_fields.index(source),
|
76
95
|
:fields => fields.collect{|f| String === f ? all_fields.index(f): f },
|
77
|
-
#:type => (options[:type] and options[:type].to_sym == :flat) ? :flat : nil,
|
78
96
|
:unnamed => true,
|
79
97
|
:merge => (options[:merge] or (options[:type] and options[:type].to_sym == :flat) ? false : true)
|
80
98
|
})
|
@@ -88,7 +106,6 @@ module Association
|
|
88
106
|
if file.fields == field_headers
|
89
107
|
file
|
90
108
|
else
|
91
|
-
iii :reorder
|
92
109
|
file.reorder(source, field_headers)
|
93
110
|
end
|
94
111
|
else
|
@@ -200,7 +217,7 @@ module Association
|
|
200
217
|
end
|
201
218
|
|
202
219
|
def self.load_tsv(file, options)
|
203
|
-
undirected =
|
220
|
+
undirected = options[:undirected]
|
204
221
|
|
205
222
|
case file
|
206
223
|
when Proc
|
@@ -261,7 +278,7 @@ module Association
|
|
261
278
|
|
262
279
|
def self.index(file, options = {}, persist_options = nil)
|
263
280
|
options = {} if options.nil?
|
264
|
-
options = Misc.add_defaults options, :persist => true
|
281
|
+
options = Misc.add_defaults options, :persist => true, :undirected => false
|
265
282
|
persist_options = Misc.pull_keys options, persist_options if persist_options.nil?
|
266
283
|
|
267
284
|
Persist.persist_tsv(file, nil, options, {:persist => true, :prefix => "Association Index"}.merge(persist_options).merge(:engine => TokyoCabinet::BDB, :serializer => :clean)) do |assocs|
|
@@ -270,7 +287,10 @@ module Association
|
|
270
287
|
tsv = TSV === file ? file : Association.open(file, options, persist_options.merge(:persist => false))
|
271
288
|
|
272
289
|
fields = tsv.fields
|
273
|
-
|
290
|
+
source_field = tsv.key_field
|
291
|
+
target_field = fields.first.split(":").last
|
292
|
+
|
293
|
+
key_field = [source_field, target_field, undirected ? "undirected" : nil].compact * "~"
|
274
294
|
|
275
295
|
TSV.setup(assocs, :key_field => key_field, :fields => fields[1..-1], :type => :list, :serializer => :list)
|
276
296
|
|
@@ -299,7 +319,7 @@ module Association
|
|
299
319
|
when :double
|
300
320
|
tsv.through do |source, values|
|
301
321
|
next if values.empty?
|
302
|
-
next if source.nil?
|
322
|
+
next if source.nil? or source.empty?
|
303
323
|
next if values.empty?
|
304
324
|
targets = values.first
|
305
325
|
rest = Misc.zip_fields values[1..-1]
|
@@ -309,9 +329,15 @@ module Association
|
|
309
329
|
targets.zip(rest * targets.length)
|
310
330
|
|
311
331
|
annotations.each do |target, info|
|
312
|
-
next if target.nil?
|
332
|
+
next if target.nil? or target.empty?
|
313
333
|
key = [source, target] * "~"
|
314
|
-
assocs[key]
|
334
|
+
if assocs[key].nil? or info.nil?
|
335
|
+
assocs[key] = info
|
336
|
+
else
|
337
|
+
old_info = assocs[key]
|
338
|
+
info = old_info.zip(info).collect{|p| p * ";;" }
|
339
|
+
assocs[key] = info
|
340
|
+
end
|
315
341
|
end
|
316
342
|
end
|
317
343
|
else
|
@@ -7,6 +7,21 @@ module AssociationItem
|
|
7
7
|
annotation :database
|
8
8
|
annotation :reverse
|
9
9
|
|
10
|
+
property :name => :single do
|
11
|
+
[source_entity, target_entity].collect{|e| e.respond_to?(:name)? e.name || e : e } * "~"
|
12
|
+
end
|
13
|
+
|
14
|
+
property :full_name => :single do
|
15
|
+
database ? [database, name] * ":" : name
|
16
|
+
end
|
17
|
+
|
18
|
+
property :invert => :single do
|
19
|
+
s,_sep,t= self.partition "~"
|
20
|
+
inverted = self.annotate([t,s] * _sep)
|
21
|
+
inverted.reverse = ! reverse
|
22
|
+
inverted
|
23
|
+
end
|
24
|
+
|
10
25
|
property :namespace => :both do
|
11
26
|
knowledge_base.namespace
|
12
27
|
end
|
@@ -44,6 +59,10 @@ module AssociationItem
|
|
44
59
|
knowledge_base.annotate self.target, type, database #if self.target.any?
|
45
60
|
end
|
46
61
|
|
62
|
+
property :undirected => :both do
|
63
|
+
knowledge_base.undirected(database)
|
64
|
+
end
|
65
|
+
|
47
66
|
property :source_entity => :array2single do
|
48
67
|
type = reverse ? knowledge_base.target(database) : knowledge_base.source(database)
|
49
68
|
knowledge_base.annotate self.source, type #if self.source.any?
|
@@ -84,18 +103,25 @@ module AssociationItem
|
|
84
103
|
tsv
|
85
104
|
end
|
86
105
|
|
87
|
-
def self.incidence(pairs, key_field = nil)
|
106
|
+
def self.incidence(pairs, key_field = nil, &block)
|
88
107
|
matrix = {}
|
89
108
|
targets = []
|
90
109
|
sources = []
|
91
110
|
matches = {}
|
92
111
|
|
93
|
-
pairs.each do |p|
|
112
|
+
pairs.inject([]){|acc,m| acc << m; acc << m.invert if m.respond_to?(:undirected) and m.undirected; acc }.each do |p|
|
94
113
|
s, sep, t = p.partition "~"
|
114
|
+
|
95
115
|
sources << s
|
96
116
|
targets << t
|
97
|
-
|
98
|
-
|
117
|
+
if block_given?
|
118
|
+
matches[s] ||= Hash.new{nil}
|
119
|
+
value = block.call p
|
120
|
+
matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
|
121
|
+
else
|
122
|
+
matches[s] ||= Hash.new{true}
|
123
|
+
matches[s][t] ||= true
|
124
|
+
end
|
99
125
|
end
|
100
126
|
|
101
127
|
sources.uniq!
|
@@ -108,6 +134,18 @@ module AssociationItem
|
|
108
134
|
defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
|
109
135
|
end
|
110
136
|
|
137
|
+
def self.adjacency(pairs, key_field = nil, &block)
|
138
|
+
incidence = incidence(pairs, key_field, &block)
|
139
|
+
|
140
|
+
targets = incidence.fields
|
141
|
+
adjacency = TSV.setup({}, :key_field => incidence.key_field, :fields => ["Target"], :type => :double)
|
142
|
+
TSV.traverse incidence, :into => adjacency, :unnamed => true do |k,values|
|
143
|
+
target_values = targets.zip(values).reject{|t,v| v.nil? }.collect{|t,v| [t,v]}
|
144
|
+
next if target_values.empty?
|
145
|
+
[k, Misc.zip_fields(target_values)]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
111
149
|
def self._select_match(orig, elem)
|
112
150
|
if Array === orig and Array === elem
|
113
151
|
(orig & elem).any?
|
data/lib/rbbt/knowledge_base.rb
CHANGED
@@ -260,26 +260,32 @@ class KnowledgeBase
|
|
260
260
|
|
261
261
|
#{{{ Identify
|
262
262
|
|
263
|
+
|
264
|
+
def database_identify_index(database, target)
|
265
|
+
if database.identifier_files.any?
|
266
|
+
id_file = database.identifier_files.first
|
267
|
+
identifier_fields = TSV.parse_header(id_file).all_fields
|
268
|
+
if identifier_fields.include? target
|
269
|
+
TSV.index(database.identifiers, :target => target, :persist => true, :order => true)
|
270
|
+
else
|
271
|
+
{}
|
272
|
+
end
|
273
|
+
else
|
274
|
+
if TSV.parse_header(Organism.identifiers(namespace)).all_fields.include? target
|
275
|
+
Organism.identifiers(namespace).index(:target => target, :persist => true, :order => true)
|
276
|
+
else
|
277
|
+
{}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
263
282
|
def identify_source(name, entity)
|
264
283
|
database = get_database(name, :persist => true)
|
265
284
|
return entity if Symbol === entity or (String === entity and database.include? entity)
|
266
285
|
source = source(name)
|
267
286
|
@identifiers[name] ||= {}
|
268
287
|
@identifiers[name]['source'] ||= begin
|
269
|
-
|
270
|
-
identifier_fields = TSV.parse_header(database.identifier_files.first).all_fields
|
271
|
-
if identifier_fields.include? source
|
272
|
-
TSV.index(database.identifiers, :target => source, :persist => true, :order => true)
|
273
|
-
else
|
274
|
-
{}
|
275
|
-
end
|
276
|
-
else
|
277
|
-
if TSV.parse_header(Organism.identifiers(namespace)).all_fields.include? source
|
278
|
-
Organism.identifiers(namespace).index(:target => source, :persist => true, :order => true)
|
279
|
-
else
|
280
|
-
{}
|
281
|
-
end
|
282
|
-
end
|
288
|
+
database_identify_index(database, source)
|
283
289
|
end
|
284
290
|
|
285
291
|
if Array === entity
|
@@ -287,37 +293,25 @@ class KnowledgeBase
|
|
287
293
|
p.compact.first
|
288
294
|
}
|
289
295
|
else
|
290
|
-
@identifiers[name]['source'][entity]
|
296
|
+
@identifiers[name]['source'][entity]
|
291
297
|
end
|
292
298
|
end
|
293
299
|
|
294
300
|
def identify_target(name, entity)
|
295
301
|
database = get_database(name, :persist => true)
|
296
|
-
return entity if Symbol === entity
|
302
|
+
return entity if Symbol === entity or (String === entity and database.values.collect{|v| v.first}.compact.flatten.include?(entity))
|
297
303
|
target = target(name)
|
298
304
|
|
299
305
|
@identifiers[name] ||= {}
|
300
306
|
@identifiers[name]['target'] ||= begin
|
301
|
-
|
302
|
-
if TSV.parse_header(database.identifier_files.first).all_fields.include? target
|
303
|
-
TSV.index(database.identifiers, :target => target, :persist => true)
|
304
|
-
else
|
305
|
-
{}
|
306
|
-
end
|
307
|
-
else
|
308
|
-
if TSV.parse_header(Organism.identifiers(namespace)).all_fields.include? target
|
309
|
-
Organism.identifiers(namespace).index(:target => target, :persist => true)
|
310
|
-
else
|
311
|
-
database.index(:target => database.fields.first, :fields => [database.fields.first], :persist => true)
|
312
|
-
end
|
313
|
-
end
|
307
|
+
database_identify_index(database, target)
|
314
308
|
end
|
315
309
|
if Array === entity
|
316
310
|
@identifiers[name]['target'].chunked_values_at(entity).zip(entity).collect{|p|
|
317
311
|
p.compact.first
|
318
312
|
}
|
319
313
|
else
|
320
|
-
@identifiers[name]['target'][entity]
|
314
|
+
@identifiers[name]['target'][entity]
|
321
315
|
end
|
322
316
|
end
|
323
317
|
|
@@ -325,8 +319,22 @@ class KnowledgeBase
|
|
325
319
|
identify_source(name, entity) || identify_target(name, entity)
|
326
320
|
end
|
327
321
|
|
322
|
+
def normalize(entity)
|
323
|
+
source_matches = all_databases.collect{|d|
|
324
|
+
identify_source(d, entity)
|
325
|
+
}.flatten.compact.uniq
|
326
|
+
return entity if source_matches.include? entity
|
327
|
+
|
328
|
+
target_matches = all_databases.collect{|d|
|
329
|
+
identify_target(d, entity)
|
330
|
+
}.flatten.compact.uniq
|
331
|
+
return entity if target_matches.include? entity
|
332
|
+
|
333
|
+
(source_matches + target_matches).first
|
334
|
+
end
|
335
|
+
|
328
336
|
#{{{ Query
|
329
|
-
|
337
|
+
|
330
338
|
def all(name, options={})
|
331
339
|
repo = get_index name, options
|
332
340
|
setup name, repo.keys
|
@@ -343,7 +351,7 @@ class KnowledgeBase
|
|
343
351
|
end
|
344
352
|
|
345
353
|
def neighbours(name, entity)
|
346
|
-
if undirected(name)
|
354
|
+
if undirected(name) and source(name) == target(name)
|
347
355
|
IndiferentHash.setup({:children => children(name, entity)})
|
348
356
|
else
|
349
357
|
IndiferentHash.setup({:parents => parents(name, entity), :children => children(name, entity)})
|
@@ -387,4 +395,24 @@ class KnowledgeBase
|
|
387
395
|
entities
|
388
396
|
end
|
389
397
|
end
|
398
|
+
|
399
|
+
def pair_matches(source, target, undirected = nil)
|
400
|
+
all_databases.inject([]){|acc,database|
|
401
|
+
match = [source, target] * "~"
|
402
|
+
index = get_index(database)
|
403
|
+
|
404
|
+
if index.include? match
|
405
|
+
acc << setup(database, match)
|
406
|
+
|
407
|
+
elsif undirected or undirected(database)
|
408
|
+
inv = [target, source] * "~"
|
409
|
+
if index.include? inv
|
410
|
+
setup(database, inv)
|
411
|
+
acc << inv
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
acc
|
416
|
+
}
|
417
|
+
end
|
390
418
|
end
|
data/lib/rbbt/resource.rb
CHANGED
@@ -28,7 +28,7 @@ module Resource
|
|
28
28
|
base
|
29
29
|
end
|
30
30
|
|
31
|
-
attr_accessor :pkgdir, :subdir, :resources, :rake_dirs, :remote_server
|
31
|
+
attr_accessor :pkgdir, :subdir, :resources, :rake_dirs, :remote_server, :search_paths
|
32
32
|
|
33
33
|
def root()
|
34
34
|
Path.setup @subdir || "", @pkgdir, self
|
@@ -122,11 +122,12 @@ module Resource
|
|
122
122
|
raise "Resource is missing and does not seem to be claimed: #{ self } -- #{ path } "
|
123
123
|
end
|
124
124
|
|
125
|
-
final_path = path.respond_to?(:find) ? (force ? path.find(:
|
125
|
+
final_path = path.respond_to?(:find) ? (force ? path.find(:default) : path.find) : path
|
126
126
|
if not File.exists? final_path or force
|
127
127
|
Log.medium "Producing: #{ final_path }"
|
128
128
|
lock_filename = Persist.persistence_path(final_path, {:dir => Resource.lock_dir})
|
129
129
|
Misc.lock lock_filename do
|
130
|
+
FileUtils.rm_rf final_path if force and File.exists? final_path
|
130
131
|
if not File.exists? final_path or force
|
131
132
|
(remote_server and get_from_server(path, final_path)) or
|
132
133
|
begin
|
@@ -142,7 +143,17 @@ module Resource
|
|
142
143
|
when 1
|
143
144
|
content.call final_path
|
144
145
|
end
|
145
|
-
|
146
|
+
case data
|
147
|
+
when String, IO
|
148
|
+
Misc.sensiblewrite(final_path, data)
|
149
|
+
when Array
|
150
|
+
Misc.sensiblewrite(final_path, data * "\n")
|
151
|
+
when TSV
|
152
|
+
Misc.sensiblewrite(final_path, data.dumper_stream)
|
153
|
+
when nil
|
154
|
+
else
|
155
|
+
raise "Unkown object produced: #{Misc.fingerprint data}"
|
156
|
+
end
|
146
157
|
when :rake
|
147
158
|
run_rake(path, content, rake_dir)
|
148
159
|
when :install
|
data/lib/rbbt/resource/path.rb
CHANGED
@@ -91,9 +91,10 @@ module Path
|
|
91
91
|
|
92
92
|
def find(where = nil, caller_lib = nil, paths = nil)
|
93
93
|
@path ||= {}
|
94
|
-
|
94
|
+
rsearch_paths = (resource and resource.respond_to?(:search_paths)) ? resource.search_paths : nil
|
95
|
+
key = Misc.digest([where, caller_lib, rsearch_paths, paths].inspect)
|
95
96
|
@path[key] ||= begin
|
96
|
-
paths =
|
97
|
+
paths = [paths, rsearch_paths, self.search_paths, SEARCH_PATHS].reverse.compact.inject({}){|acc,h| acc.merge! h; acc }
|
97
98
|
where = paths[:default] if where == :default
|
98
99
|
return self if located?
|
99
100
|
if self.match(/(.*?)\/(.*)/)
|
@@ -131,11 +132,14 @@ module Path
|
|
131
132
|
libdir = "NOLIBDIR"
|
132
133
|
end
|
133
134
|
pwd = FileUtils.pwd
|
134
|
-
path = paths[where]
|
135
|
+
path = paths[where]
|
136
|
+
path = File.join(path, "{PATH}") unless path.include? "PATH}" or path.include? "{BASENAME}"
|
137
|
+
path = path.
|
135
138
|
sub('{PKGDIR}', pkgdir).
|
136
139
|
sub('{PWD}', pwd).
|
137
140
|
sub('{TOPLEVEL}', toplevel).
|
138
141
|
sub('{SUBPATH}', subpath).
|
142
|
+
sub('{BASENAME}', File.basename(self)).
|
139
143
|
sub('{PATH}', self).
|
140
144
|
sub('{LIBDIR}', libdir) #, @pkgdir, @resource, @search_paths
|
141
145
|
|
@@ -223,7 +227,7 @@ module Path
|
|
223
227
|
end
|
224
228
|
|
225
229
|
def tsv(*args)
|
226
|
-
TSV.open(self.produce, *args)
|
230
|
+
TSV.open(self.produce.find, *args)
|
227
231
|
end
|
228
232
|
|
229
233
|
def tsv_options(options = {})
|
data/lib/rbbt/tsv.rb
CHANGED
@@ -73,12 +73,13 @@ module TSV
|
|
73
73
|
|
74
74
|
open_options = Misc.pull_keys options, :open
|
75
75
|
|
76
|
-
stream = get_stream source, open_options
|
76
|
+
stream = get_stream source, options.merge(open_options)
|
77
77
|
parse stream, data, options
|
78
78
|
|
79
79
|
data.filename = filename.to_s unless filename.nil?
|
80
|
+
|
80
81
|
if data.identifiers.nil? and Path === filename and filename.identifier_file_path
|
81
|
-
data.identifiers = filename.identifier_file_path.
|
82
|
+
data.identifiers = filename.identifier_file_path.find if filename.identifier_file_path.exists?
|
82
83
|
end
|
83
84
|
|
84
85
|
data
|
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -493,10 +493,10 @@ module TSV
|
|
493
493
|
when (TSV === identifiers.first or identifiers.empty?)
|
494
494
|
identifiers
|
495
495
|
else
|
496
|
-
identifiers.collect{|f| Path === f ? f : Path.setup(f
|
496
|
+
identifiers.collect{|f| Path === f ? f : Path.setup(f)}
|
497
497
|
end
|
498
498
|
when identifiers
|
499
|
-
[ Path === identifiers ? identifiers : Path.setup(identifiers
|
499
|
+
[ Path === identifiers ? identifiers : Path.setup(identifiers) ]
|
500
500
|
when Path === filename
|
501
501
|
filename.identifier_files
|
502
502
|
when filename
|
@@ -662,7 +662,7 @@ Example:
|
|
662
662
|
self.through do |key,values|
|
663
663
|
field_values = values.delete_at field_pos
|
664
664
|
next if field_values.nil?
|
665
|
-
zipped =
|
665
|
+
zipped = Misc.zip_fields(values)
|
666
666
|
field_values.zip(zipped).each do |field_value,rest|
|
667
667
|
k = [key,field_value]*":"
|
668
668
|
if new.include? k
|
data/lib/rbbt/tsv/parser.rb
CHANGED
data/lib/rbbt/util/R.rb
CHANGED
@@ -49,6 +49,41 @@ source('#{UTIL}');
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def self.console(script, options = {})
|
53
|
+
TmpFile.with_file do |init_file|
|
54
|
+
Open.write(init_file) do |f|
|
55
|
+
f.puts "# Loading basic rbbt environment"
|
56
|
+
f.puts "library(utils);\n"
|
57
|
+
f.puts "source('#{R::UTIL}');\n"
|
58
|
+
f.puts
|
59
|
+
f.puts script
|
60
|
+
end
|
61
|
+
|
62
|
+
pid = Process.fork do |ppid|
|
63
|
+
ENV["R_PROFILE"] = init_file
|
64
|
+
exec("R")
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
Process.waitpid pid
|
69
|
+
rescue Interrupt
|
70
|
+
if Misc.pid_exists? pid
|
71
|
+
Process.kill "INT", pid
|
72
|
+
retry
|
73
|
+
else
|
74
|
+
raise $!
|
75
|
+
end
|
76
|
+
rescue Exception
|
77
|
+
Process.kill 9, pid if Misc.pid_exists? pid
|
78
|
+
raise $!
|
79
|
+
ensure
|
80
|
+
Process.waitpid pid if Misc.pid_exists? pid
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
52
87
|
def self.ruby2R(object)
|
53
88
|
case object
|
54
89
|
when nil
|
@@ -114,7 +149,7 @@ if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
|
|
114
149
|
|
115
150
|
def R_interactive(pre_script = nil)
|
116
151
|
TmpFile.with_file do |f|
|
117
|
-
Log.debug{"R
|
152
|
+
Log.debug{"R Interactive:\n" << pre_script } if pre_script
|
118
153
|
TmpFile.with_file(pre_script) do |script_file|
|
119
154
|
Open.write(f, self.to_s)
|
120
155
|
script = "data_file = '#{f}';\n"
|
@@ -123,4 +158,16 @@ if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
|
|
123
158
|
end
|
124
159
|
end
|
125
160
|
end
|
161
|
+
|
162
|
+
def R_console(pre_script = nil)
|
163
|
+
TmpFile.with_file do |f|
|
164
|
+
Log.debug{"R Console:\n" << pre_script } if pre_script
|
165
|
+
TmpFile.with_file(pre_script) do |script_file|
|
166
|
+
Open.write(f, self.to_s)
|
167
|
+
script = "data_file = '#{f}';\n"
|
168
|
+
script << "\n#\{{{Pre-script:\n\n" << pre_script << "\n#}}}Pre-script\n\n"
|
169
|
+
R.console(script)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
126
173
|
end
|
data/lib/rbbt/util/log.rb
CHANGED
@@ -26,7 +26,8 @@ module Log
|
|
26
26
|
|
27
27
|
def self.last_caller(stack)
|
28
28
|
line = nil
|
29
|
-
|
29
|
+
pos ||= 0
|
30
|
+
while line.nil? or line =~ /util\/log\.rb/ and stack.any?
|
30
31
|
line = stack.shift
|
31
32
|
end
|
32
33
|
line ||= caller.first
|
@@ -217,6 +218,12 @@ module Log
|
|
217
218
|
error("BACKTRACE: " << Log.last_caller(caller) << "\n" + color_stack(e.backtrace)*"\n")
|
218
219
|
end
|
219
220
|
|
221
|
+
def self.deprecated(m)
|
222
|
+
stack = caller
|
223
|
+
warn("DEPRECATED: " << Log.last_caller(caller))
|
224
|
+
warn("* " << (m || "").to_s)
|
225
|
+
end
|
226
|
+
|
220
227
|
def self.color_stack(stack)
|
221
228
|
stack.collect do |line|
|
222
229
|
line = line.sub('`',"'")
|
data/share/Rlib/util.R
CHANGED
@@ -170,8 +170,6 @@ rbbt.png_plot <- function(filename, width, height, p, ...){
|
|
170
170
|
}
|
171
171
|
|
172
172
|
rbbt.heatmap <- function(filename, width, height, data, take_log=FALSE, ...){
|
173
|
-
require(gplots, quietly = TRUE, warn.conflicts = FALSE)
|
174
|
-
library(pls, quietly = TRUE, warn.conflicts = FALSE)
|
175
173
|
opar = par()
|
176
174
|
png(filename=filename, width=width, height=height);
|
177
175
|
|
data/test/rbbt/test_resource.rb
CHANGED
@@ -24,20 +24,30 @@ end
|
|
24
24
|
|
25
25
|
class TestTSV < Test::Unit::TestCase
|
26
26
|
|
27
|
-
def
|
27
|
+
def test_tsv
|
28
|
+
require 'rbbt/tsv'
|
29
|
+
TestResource.claim TestResource.tmp.test.test_tsv, :proc do
|
30
|
+
tsv = {"a" => 1, "b" => 2}
|
31
|
+
TSV.setup(tsv, :key_field => "Letter", :fields => ["Value"], :type => :single)
|
32
|
+
end
|
33
|
+
iii TestResource.tmp.test.test_tsv.produce
|
34
|
+
Log.tsv TestResource.tmp.test.test_tsv.tsv
|
35
|
+
end
|
36
|
+
|
37
|
+
def _test_rake
|
28
38
|
TestResource.tmp.test.work.footest.foo.read == "TEST"
|
29
39
|
assert TestResource.tmp.test.work.footest.foo.read == "TEST"
|
30
40
|
end
|
31
41
|
|
32
|
-
def
|
42
|
+
def _test_proc
|
33
43
|
assert TestResource.tmp.test.proc.read == "PROC TEST"
|
34
44
|
end
|
35
45
|
|
36
|
-
def
|
46
|
+
def _test_string
|
37
47
|
assert TestResource.tmp.test.string.read == "TEST"
|
38
48
|
end
|
39
49
|
|
40
|
-
def
|
50
|
+
def _test_url
|
41
51
|
assert TestResource[].tmp.test.google.read =~ /google/
|
42
52
|
end
|
43
53
|
|
@@ -59,7 +69,7 @@ class TestTSV < Test::Unit::TestCase
|
|
59
69
|
assert_equal File.join(ENV['HOME'], '.phgx/etc/foo'), Path.setup('etc/foo', 'phgx').find()
|
60
70
|
end
|
61
71
|
|
62
|
-
def
|
72
|
+
def _test_libdir
|
63
73
|
assert File.exists? TestResource[].share.Rlib["util.R"].find :lib
|
64
74
|
assert File.exists? TestResource[].share.Rlib["util.R"].find
|
65
75
|
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.14.
|
4
|
+
version: 5.14.28
|
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-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|