rbbt-util 5.5.6 → 5.5.7
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 +8 -8
- data/lib/rbbt/association.rb +19 -12
- data/lib/rbbt/knowledge_base.rb +15 -2
- data/lib/rbbt/util/log.rb +1 -1
- data/test/rbbt/test_knowledge_base.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTU3NGViM2M2ODk0ODA1MzA2OTU4ZDUyYzg4ODAxNWU2YzdmYTY1NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzhkMWQwMmZlMjA1MjQ5YTQwM2QzN2M2NWNlZmE1OGVmYzg3NDM2ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGZlMWVlODIxN2M4NjQ0MTJiYTIzNWE3MGFjZThmMmJjY2M5OWMwMmZjNWE1
|
10
|
+
ODllNjA3NDZlZGRhOTBmYTY0ZGVjOGRlZWNkM2Y2MWE0YzQyNGEzYTk3NWYx
|
11
|
+
MzQ4MTk4NDlhZWU4ZTY2YTIzZWM2MjUwMjUzNDI3NzdlMmZlODE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmRhY2QyOGIyZjRjZTYwNzY4OThhNjUyZGM2ZWZiOTA0MmI2OTVhYWE4MmM1
|
14
|
+
OTA5NGU2OGYxODYzODZjMDk0MTU4ZDczYTdhZjljODU0ZmM5MzcwYTBhM2Qz
|
15
|
+
MTczYWYwYjg4MDNjYjU2NWQ2MWI0YjljNTFlNzY1OTUxMWM3ODU=
|
data/lib/rbbt/association.rb
CHANGED
@@ -68,7 +68,7 @@ module Association
|
|
68
68
|
|
69
69
|
def self.open_tsv(file, source, source_header, target, target_header, all_fields, options)
|
70
70
|
fields = all_fields.dup
|
71
|
-
fields.delete source
|
71
|
+
fields.delete source
|
72
72
|
fields.delete target
|
73
73
|
fields.unshift target
|
74
74
|
|
@@ -87,9 +87,11 @@ module Association
|
|
87
87
|
|
88
88
|
tsv = case file
|
89
89
|
when TSV
|
90
|
-
file.fields == field_headers
|
91
|
-
file
|
90
|
+
if file.fields == field_headers
|
91
|
+
file
|
92
|
+
else
|
92
93
|
file.reorder(source, field_headers)
|
94
|
+
end
|
93
95
|
else
|
94
96
|
TSV.open(file, open_options)
|
95
97
|
end
|
@@ -169,7 +171,7 @@ module Association
|
|
169
171
|
|
170
172
|
target, target_header, orig_target_format = calculate_headers(key_field, fields, target_spec)
|
171
173
|
target_format ||= orig_target_format
|
172
|
-
target = (([key_field] + fields) - [source]).first if target.nil?
|
174
|
+
target = (key_field == source ? fields.first : (([key_field] + fields) - [source]).first) if target.nil?
|
173
175
|
target = key_field if target == :key
|
174
176
|
target_header ||= target
|
175
177
|
|
@@ -201,9 +203,9 @@ module Association
|
|
201
203
|
|
202
204
|
source, source_header, source_format, target, target_header, target_format = specs(all_fields, options)
|
203
205
|
|
204
|
-
Log.
|
205
|
-
Log.
|
206
|
-
Log.
|
206
|
+
Log.low("Loading associations from: #{ Misc.fingerprint file }")
|
207
|
+
Log.low("sources: #{ [source, source_header, source_format].join(", ") }")
|
208
|
+
Log.low("targets: #{ [target, target_header, target_format].join(", ") }")
|
207
209
|
|
208
210
|
tsv = open_tsv(file, source, source_header, target, target_header, all_fields, options)
|
209
211
|
|
@@ -229,8 +231,13 @@ module Association
|
|
229
231
|
|
230
232
|
tsv.annotate(data)
|
231
233
|
data.serializer = tsv.type if TokyoCabinet::HDB === data
|
232
|
-
|
233
|
-
tsv.
|
234
|
+
|
235
|
+
tsv.with_unnamed do
|
236
|
+
tsv.each do |k,v|
|
237
|
+
next if v.nil?
|
238
|
+
data[k] = v
|
239
|
+
end
|
240
|
+
end
|
234
241
|
|
235
242
|
data
|
236
243
|
end
|
@@ -238,9 +245,9 @@ module Association
|
|
238
245
|
|
239
246
|
#{{{ Index
|
240
247
|
|
241
|
-
def self.get_index(index_file, write = false)
|
242
|
-
|
243
|
-
end
|
248
|
+
#def self.get_index(index_file, write = false)
|
249
|
+
# Persist.open_tokyocabinet(index_file, write, :list, TokyoCabinet::BDB).tap{|r| r.unnamed = true; Association::Index.setup r }
|
250
|
+
#end
|
244
251
|
|
245
252
|
def self.index(file, options = {}, persist_options = {})
|
246
253
|
options = {} if options.nil?
|
data/lib/rbbt/knowledge_base.rb
CHANGED
@@ -45,6 +45,7 @@ class KnowledgeBase
|
|
45
45
|
|
46
46
|
def register(name, file = nil, options = {}, &block)
|
47
47
|
if block_given?
|
48
|
+
block.define_singleton_method(:filename) do name.to_s end
|
48
49
|
Log.debug("Registering #{ name } from code block")
|
49
50
|
@registry[name] = [block, options]
|
50
51
|
else
|
@@ -53,10 +54,20 @@ class KnowledgeBase
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
def syndicate(kb, name)
|
58
|
+
kb.all_databases.each do |database|
|
59
|
+
db_name = [database, name] * "@"
|
60
|
+
register(db_name) do
|
61
|
+
kb.get_database(database)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
56
66
|
def all_databases
|
57
67
|
(@indices.keys + @registry.keys).uniq
|
58
68
|
end
|
59
69
|
|
70
|
+
|
60
71
|
def description(name)
|
61
72
|
@descriptions[name] ||= get_index(name).key_field.split("~")
|
62
73
|
end
|
@@ -100,6 +111,7 @@ class KnowledgeBase
|
|
100
111
|
end
|
101
112
|
|
102
113
|
def get_database(name, options = {})
|
114
|
+
options = Misc.add_defaults options, :persist_dir => dir.databases
|
103
115
|
persist_options = Misc.pull_keys options, :persist
|
104
116
|
|
105
117
|
file, registered_options = registry[name]
|
@@ -107,7 +119,7 @@ class KnowledgeBase
|
|
107
119
|
raise "Repo #{ name } not found and not registered" if file.nil?
|
108
120
|
|
109
121
|
@databases[name] ||= begin
|
110
|
-
Log.
|
122
|
+
Log.low "Opening database #{ name } from #{ Misc.fingerprint file }. #{options}"
|
111
123
|
Association.open(file, options, persist_options).
|
112
124
|
tap{|tsv| tsv.namespace = self.namespace}
|
113
125
|
end
|
@@ -115,6 +127,7 @@ class KnowledgeBase
|
|
115
127
|
|
116
128
|
|
117
129
|
def get_index(name, options = {})
|
130
|
+
options = Misc.add_defaults options, :persist_dir => dir.indices
|
118
131
|
persist_options = Misc.pull_keys options, :persist
|
119
132
|
|
120
133
|
file, registered_options = registry[name]
|
@@ -122,7 +135,7 @@ class KnowledgeBase
|
|
122
135
|
raise "Repo #{ name } not found and not registered" if file.nil?
|
123
136
|
|
124
137
|
@indices[name] ||= begin
|
125
|
-
Log.
|
138
|
+
Log.low "Opening index #{ name } from #{ Misc.fingerprint file }. #{options}"
|
126
139
|
Association.index(file, options, persist_options).
|
127
140
|
tap{|tsv| tsv.namespace = self.namespace}
|
128
141
|
end
|
data/lib/rbbt/util/log.rb
CHANGED
@@ -19,7 +19,7 @@ module Log
|
|
19
19
|
|
20
20
|
WHITE, DARK, GREEN, YELLOW, RED = ["0;37m", "0m", "0;32m", "0;33m", "0;31m"].collect{|e| "\033[#{e}"}
|
21
21
|
|
22
|
-
SEVERITY_COLOR = [WHITE, GREEN, YELLOW, RED,
|
22
|
+
SEVERITY_COLOR = [WHITE, GREEN, YELLOW, RED, GREEN, YELLOW, ERROR].collect{|e| "\033[#{e}"}
|
23
23
|
|
24
24
|
def self.log(message = nil, severity = MEDIUM, &block)
|
25
25
|
message ||= block
|
@@ -91,7 +91,6 @@ class TestKnowledgeBase < Test::Unit::TestCase
|
|
91
91
|
found = Genomics.knowledge_base.identify :pina, gene
|
92
92
|
p53_interactors = Misc.profile{ Genomics.knowledge_base.children(:pina, found).target_entity }
|
93
93
|
|
94
|
-
ddd p53_interactors.length
|
95
94
|
|
96
95
|
Misc.profile do
|
97
96
|
puts Genomics.knowledge_base.subset(:pina,{"Gene" => p53_interactors}).length
|
@@ -100,5 +99,13 @@ class TestKnowledgeBase < Test::Unit::TestCase
|
|
100
99
|
#assert Genomics.knowledge_base.subset(:pina,{"Gene" => p53_interactors}).target_entities.name.include? "MDM2"
|
101
100
|
end
|
102
101
|
|
102
|
+
def test_syndication
|
103
|
+
kb = KnowledgeBase.new Rbbt.tmp.test.kb2, "Hsa/jan2013"
|
104
|
+
kb.syndicate @kb, :genomics
|
105
|
+
|
106
|
+
gene = "TP53"
|
107
|
+
found = kb.identify "pina@genomics", gene
|
108
|
+
assert found =~ /ENSG/
|
109
|
+
end
|
103
110
|
end
|
104
111
|
|