rbbt-util 5.17.0 → 5.17.1
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/open.rb +1 -1
- data/lib/rbbt/knowledge_base/traverse.rb +71 -1
- data/lib/rbbt/persist.rb +1 -1
- data/lib/rbbt/tsv/accessor.rb +9 -2
- data/lib/rbbt/tsv/manipulate.rb +2 -0
- data/lib/rbbt/tsv/parallel/traverse.rb +6 -4
- data/lib/rbbt/tsv/parser.rb +13 -9
- data/lib/rbbt/util/R.rb +8 -1
- data/lib/rbbt/util/log/progress.rb +3 -3
- data/lib/rbbt/workflow.rb +6 -1
- data/test/rbbt/knowledge_base/test_traverse.rb +25 -3
- 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: 1ac03b5ef9630246419ee1b188f942ce49b51b5c
|
4
|
+
data.tar.gz: 7334d42c5ca19a5927a0ffb842b2cbac3f75517e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a74c22d7618b91ae8d8ea1e1eea99f05cb667aee28fecc0b66ce426f73bb112a844cb1509b7ad8af4d87bf6ea3005d148a817427c7470b4cba9a73d149ee3d
|
7
|
+
data.tar.gz: 88954c0d848fafd43e5c2defc0b8d490ebb1b3d21d3ab2a5a4dae54cc45dd23a3b9d2e457cc4854b640045006df255cbb0de49bde84f05baf7fcae7b91668424
|
@@ -20,7 +20,7 @@ module Association
|
|
20
20
|
|
21
21
|
data = Persist.persist_tsv(file, "Association Database", options, persist_options) do |data|
|
22
22
|
options = options.dup
|
23
|
-
tsv = Association.database(file, options.merge(:persist => persist))
|
23
|
+
tsv = Association.database(file, options.merge(:persist => persist, :unnamed => true))
|
24
24
|
tsv = tsv.to_double unless tsv.type == :double
|
25
25
|
|
26
26
|
tsv.annotate data
|
@@ -46,11 +46,12 @@ class KnowledgeBase
|
|
46
46
|
assignments[target] = (matches.any? ? matches.target.uniq : []) if is_wildcard? target
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
49
|
+
def clean_matches(rules, all_matches, assignments)
|
50
50
|
paths = {}
|
51
51
|
|
52
52
|
rules.zip(all_matches).each do |rule, matches|
|
53
53
|
source, db, target = rule.split /\s+/
|
54
|
+
|
54
55
|
if is_wildcard? source
|
55
56
|
assigned = assignments[source]
|
56
57
|
matches = matches.select{|m| assigned.include? m.source }
|
@@ -63,11 +64,78 @@ class KnowledgeBase
|
|
63
64
|
|
64
65
|
paths[rule] = matches
|
65
66
|
end
|
67
|
+
|
66
68
|
paths
|
67
69
|
end
|
68
70
|
|
71
|
+
def _fp(rules, clean_matches, assignments)
|
72
|
+
return true if rules.empty?
|
73
|
+
|
74
|
+
rule, *rest = rules
|
75
|
+
source, db, target = rule.split /\s+/
|
76
|
+
|
77
|
+
paths = {}
|
78
|
+
matches = clean_matches[rule]
|
79
|
+
Annotated.purge(matches).each do |match|
|
80
|
+
new_assignments = nil
|
81
|
+
match_source, _sep, match_target = match.partition "~"
|
82
|
+
|
83
|
+
if is_wildcard? source
|
84
|
+
next if assignments[source] and assignments[source] != match_source
|
85
|
+
new_assignments ||= assignments.dup
|
86
|
+
new_assignments[source] = match_source
|
87
|
+
end
|
88
|
+
|
89
|
+
if is_wildcard? target
|
90
|
+
next if assignments[target] and assignments[target] != match_target
|
91
|
+
new_assignments ||= assignments.dup
|
92
|
+
new_assignments[target] = match_target
|
93
|
+
end
|
94
|
+
|
95
|
+
new_paths = _fp(rest, clean_matches, new_assignments)
|
96
|
+
next unless new_paths
|
97
|
+
paths[match] = new_paths
|
98
|
+
end
|
99
|
+
|
100
|
+
return false if paths.empty?
|
101
|
+
|
102
|
+
paths
|
103
|
+
end
|
104
|
+
|
105
|
+
def _ep(paths)
|
106
|
+
found = []
|
107
|
+
paths.each do |match,_next|
|
108
|
+
case _next
|
109
|
+
when TrueClass
|
110
|
+
found << [match]
|
111
|
+
when FalseClass
|
112
|
+
next
|
113
|
+
else
|
114
|
+
_ep(_next).each do |_n|
|
115
|
+
found << [match] + _n
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
found
|
120
|
+
end
|
121
|
+
|
122
|
+
def find_paths(rules, all_matches, assignments)
|
123
|
+
clean_matches = clean_matches(rules, all_matches, assignments)
|
124
|
+
|
125
|
+
path_hash = _fp(rules, clean_matches, {})
|
126
|
+
|
127
|
+
return [] unless path_hash
|
128
|
+
_ep(path_hash).collect do |path|
|
129
|
+
path.zip(clean_matches.values_at(*rules)).collect do |item, matches|
|
130
|
+
matches.first.annotate item.dup
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
69
136
|
def traverse
|
70
137
|
all_matches = []
|
138
|
+
|
71
139
|
rules.each do |rule|
|
72
140
|
rule = rule.strip
|
73
141
|
next if rule.empty?
|
@@ -76,6 +144,7 @@ class KnowledgeBase
|
|
76
144
|
source_entities, target_entities = identify db, source, target
|
77
145
|
|
78
146
|
matches = kb.subset(db, :source => source_entities, :target => target_entities)
|
147
|
+
|
79
148
|
if conditions
|
80
149
|
conditions.split(/\s+/).each do |condition|
|
81
150
|
if condition.index "="
|
@@ -88,6 +157,7 @@ class KnowledgeBase
|
|
88
157
|
end
|
89
158
|
|
90
159
|
reassign matches, source, target
|
160
|
+
|
91
161
|
all_matches << matches
|
92
162
|
end
|
93
163
|
|
data/lib/rbbt/persist.rb
CHANGED
@@ -72,7 +72,7 @@ module Persist
|
|
72
72
|
Path.setup(persistence_dir) unless Path === persistence_dir
|
73
73
|
|
74
74
|
filename = perfile.gsub(/\s/,'_').gsub(/\//,'>')
|
75
|
-
clean_options = options
|
75
|
+
clean_options = options.dup
|
76
76
|
clean_options.delete :unnamed
|
77
77
|
clean_options.delete "unnamed"
|
78
78
|
|
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -252,9 +252,16 @@ module TSV
|
|
252
252
|
if self.include? key
|
253
253
|
new = []
|
254
254
|
self[key, true].each_with_index do |v,i|
|
255
|
-
|
255
|
+
_v = values[i]
|
256
|
+
case _v
|
257
|
+
when Array
|
258
|
+
_n = v + _v
|
259
|
+
else
|
260
|
+
_n = v << _v
|
261
|
+
end
|
262
|
+
new << _n
|
256
263
|
end
|
257
|
-
self[key]
|
264
|
+
self[key] = new
|
258
265
|
else
|
259
266
|
self[key] = Array === values.first ? values.dup : values.collect{|v| [v] }
|
260
267
|
end
|
data/lib/rbbt/tsv/manipulate.rb
CHANGED
@@ -284,6 +284,8 @@ module TSV
|
|
284
284
|
|
285
285
|
data.extend TSV unless TSV === data
|
286
286
|
self.annotate(data)
|
287
|
+
data.entity_options = self.entity_options
|
288
|
+
data.entity_templates = self.entity_templates
|
287
289
|
|
288
290
|
data.key_field = new_key_field_name
|
289
291
|
data.fields = new_field_names
|
@@ -535,9 +535,6 @@ module TSV
|
|
535
535
|
bar = Misc.process_options options, :bar
|
536
536
|
bar ||= Misc.process_options options, :progress
|
537
537
|
options[:bar] = case bar
|
538
|
-
when Step
|
539
|
-
max = guess_max(obj)
|
540
|
-
Log::ProgressBar.new_bar(max, {:desc => bar.status, :file => bar.file(:progress)})
|
541
538
|
when String
|
542
539
|
max = guess_max(obj)
|
543
540
|
Log::ProgressBar.new_bar(max, {:desc => bar})
|
@@ -554,7 +551,12 @@ module TSV
|
|
554
551
|
bar.max ||= guess_max(obj)
|
555
552
|
bar
|
556
553
|
else
|
557
|
-
bar
|
554
|
+
if (defined? Step and Step === bar)
|
555
|
+
max = guess_max(obj)
|
556
|
+
Log::ProgressBar.new_bar(max, {:desc => bar.status, :file => bar.file(:progress)})
|
557
|
+
else
|
558
|
+
bar
|
559
|
+
end
|
558
560
|
end
|
559
561
|
|
560
562
|
if into
|
data/lib/rbbt/tsv/parser.rb
CHANGED
@@ -284,6 +284,8 @@ module TSV
|
|
284
284
|
|
285
285
|
def cast_values_single(value)
|
286
286
|
case
|
287
|
+
when (value.nil? or value.empty?)
|
288
|
+
nil
|
287
289
|
when Symbol === cast
|
288
290
|
value.send(cast)
|
289
291
|
when Proc === cast
|
@@ -294,27 +296,27 @@ module TSV
|
|
294
296
|
def cast_values_list(values)
|
295
297
|
case
|
296
298
|
when Symbol === cast
|
297
|
-
values.collect{|v| v.send(cast)}
|
299
|
+
values.collect{|v| v.nil? or v.empty? ? nil : v.send(cast)}
|
298
300
|
when Proc === cast
|
299
|
-
values.collect{|v| cast.call
|
301
|
+
values.collect{|v| v.nil? or v.empty? ? nil : cast.call(v)}
|
300
302
|
end
|
301
303
|
end
|
302
304
|
|
303
305
|
def cast_values_flat(values)
|
304
306
|
case
|
305
307
|
when Symbol === cast
|
306
|
-
values.collect{|v| v.send(cast)}
|
308
|
+
values.collect{|v| v.nil? or v.empty? ? nil : v.send(cast)}
|
307
309
|
when Proc === cast
|
308
|
-
values.collect{|v| cast.call
|
310
|
+
values.collect{|v| v.nil? or v.empty? ? nil : cast.call(v) }
|
309
311
|
end
|
310
312
|
end
|
311
313
|
|
312
314
|
def cast_values_double(values)
|
313
315
|
case
|
314
316
|
when Symbol === cast
|
315
|
-
values.collect{|list| list.collect{|v| v.send(cast)}}
|
317
|
+
values.collect{|list| list.collect{|v| v.nil? or v.empty? ? nil : v.send(cast)}}
|
316
318
|
when Proc === cast
|
317
|
-
values.collect{|list| list.collect{|v| cast.call
|
319
|
+
values.collect{|list| list.collect{|v| v.nil? or v.empty? ? nil : cast.call(v) }}
|
318
320
|
end
|
319
321
|
end
|
320
322
|
|
@@ -539,7 +541,7 @@ module TSV
|
|
539
541
|
desc = monitor[:desc] if monitor.include? :desc
|
540
542
|
step = monitor[:step] if monitor.include? :step
|
541
543
|
end
|
542
|
-
progress_monitor = Log::ProgressBar.
|
544
|
+
progress_monitor = Log::ProgressBar.new_bar(size, :desc => desc)
|
543
545
|
end
|
544
546
|
|
545
547
|
# parser
|
@@ -548,8 +550,9 @@ module TSV
|
|
548
550
|
|
549
551
|
while not line.nil?
|
550
552
|
begin
|
551
|
-
|
552
|
-
|
553
|
+
if progress_monitor
|
554
|
+
progress_monitor.tick(line.bytesize)
|
555
|
+
end
|
553
556
|
|
554
557
|
raise SKIP_LINE if line.empty?
|
555
558
|
|
@@ -588,6 +591,7 @@ module TSV
|
|
588
591
|
end
|
589
592
|
end
|
590
593
|
ensure
|
594
|
+
Log::ProgressBar.remove_bar(progress_monitor)
|
591
595
|
stream.close unless stream.closed?
|
592
596
|
stream.join if stream.respond_to? :join and not stream.joined?
|
593
597
|
end
|
data/lib/rbbt/util/R.rb
CHANGED
@@ -8,13 +8,20 @@ module R
|
|
8
8
|
UTIL = File.join(LIB_DIR, 'util.R')
|
9
9
|
PLOT = File.join(LIB_DIR, 'plot.R')
|
10
10
|
|
11
|
-
def self.run(command, options = {})
|
11
|
+
def self.run(command, source = nil, options = {})
|
12
12
|
cmd =<<-EOF
|
13
13
|
# Loading basic rbbt environment
|
14
14
|
source('#{UTIL}');
|
15
15
|
|
16
16
|
EOF
|
17
17
|
|
18
|
+
require_sources = source.collect{|source|
|
19
|
+
source = R::LIB_DIR["plot.R"] if source == :plot
|
20
|
+
"source('#{source}')"
|
21
|
+
} * ";\n" if Array === source and source.any?
|
22
|
+
|
23
|
+
cmd << require_sources + "\n\n" if require_sources
|
24
|
+
|
18
25
|
case
|
19
26
|
when IO === command
|
20
27
|
cmd << command.read
|
@@ -16,7 +16,7 @@ module Log
|
|
16
16
|
@last_count = nil
|
17
17
|
@last_percent = nil
|
18
18
|
@depth = depth
|
19
|
-
@desc = desc
|
19
|
+
@desc = desc.nil? ? nil : desc.gsub(/\n/,' ')
|
20
20
|
@file = file
|
21
21
|
end
|
22
22
|
|
@@ -24,9 +24,9 @@ module Log
|
|
24
24
|
(@ticks * 100) / @max
|
25
25
|
end
|
26
26
|
|
27
|
-
def tick(step =
|
27
|
+
def tick(step = 1)
|
28
28
|
return if ENV["RBBT_NO_PROGRESS"] == "true"
|
29
|
-
@ticks +=
|
29
|
+
@ticks += step
|
30
30
|
|
31
31
|
begin
|
32
32
|
time = Time.now
|
data/lib/rbbt/workflow.rb
CHANGED
@@ -41,7 +41,12 @@ module Workflow
|
|
41
41
|
|
42
42
|
def self.load_workflow_file(filename)
|
43
43
|
begin
|
44
|
-
|
44
|
+
workflow_lib_dir = File.join(File.dirname(File.expand_path(filename)), 'lib')
|
45
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(filename)), 'lib'))
|
46
|
+
if File.directory? workflow_lib_dir
|
47
|
+
Log.debug "Adding workflow lib directory to LOAD_PATH: #{workflow_lib_dir}"
|
48
|
+
$LOAD_PATH.unshift(workflow_lib_dir)
|
49
|
+
end
|
45
50
|
|
46
51
|
filename = File.expand_path(filename)
|
47
52
|
|
@@ -8,12 +8,34 @@ class TestKnowledgeBaseTraverse < Test::Unit::TestCase
|
|
8
8
|
Genomics.knowledge_base
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def _test_traverse
|
12
12
|
rules = []
|
13
|
-
rules << "
|
14
|
-
rules << "TP53 pina ?
|
13
|
+
rules << "?1 pina SF3B1 - Method=MI:0006"
|
14
|
+
rules << "TP53 pina ?2"
|
15
|
+
rules << "?2 pina ?1"
|
15
16
|
res = kb.traverse rules
|
17
|
+
iii res
|
16
18
|
assert res.first.include? "?1"
|
17
19
|
end
|
20
|
+
|
21
|
+
def _test_path
|
22
|
+
rules = []
|
23
|
+
rules << "?1 pina ARPC2"
|
24
|
+
rules << "ARPC3 pina ?2"
|
25
|
+
rules << "?2 pina ?1"
|
26
|
+
res = kb.traverse rules
|
27
|
+
assert res.first.include? "?1"
|
28
|
+
iii res.last.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_path2
|
32
|
+
rules = []
|
33
|
+
rules << "?1 pina SF3B1"
|
34
|
+
rules << "?2 pina SF3B1"
|
35
|
+
rules << "?1 pina ?2"
|
36
|
+
res = kb.traverse rules
|
37
|
+
assert res.first.include? "?1"
|
38
|
+
iii res.last.first.first.source
|
39
|
+
end
|
18
40
|
end
|
19
41
|
|
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.17.
|
4
|
+
version: 5.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|