scout-gear 10.7.2 → 10.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +46 -32
  3. data/VERSION +1 -1
  4. data/lib/scout/association/index.rb +4 -0
  5. data/lib/scout/association/item.rb +1 -1
  6. data/lib/scout/association.rb +28 -9
  7. data/lib/scout/entity/identifiers.rb +2 -2
  8. data/lib/scout/entity/property.rb +1 -0
  9. data/lib/scout/knowledge_base/enrichment.rb +9 -0
  10. data/lib/scout/knowledge_base/entity.rb +143 -0
  11. data/lib/scout/knowledge_base/list.rb +95 -0
  12. data/lib/scout/knowledge_base/query.rb +96 -0
  13. data/lib/scout/knowledge_base/registry.rb +173 -0
  14. data/lib/scout/knowledge_base/traverse.rb +329 -0
  15. data/lib/scout/knowledge_base.rb +91 -0
  16. data/lib/scout/tsv/annotation.rb +4 -4
  17. data/lib/scout/tsv/index.rb +0 -2
  18. data/lib/scout/tsv/parser.rb +1 -1
  19. data/lib/scout/tsv/stream.rb +3 -3
  20. data/lib/scout/tsv.rb +2 -0
  21. data/lib/scout/workflow/step/info.rb +10 -1
  22. data/scout-gear.gemspec +24 -6
  23. data/scout_commands/kb/config +33 -0
  24. data/scout_commands/kb/entities +35 -0
  25. data/scout_commands/kb/list +39 -0
  26. data/scout_commands/{db → kb}/query +6 -11
  27. data/scout_commands/{db → kb}/register +9 -8
  28. data/scout_commands/{db → kb}/show +6 -16
  29. data/scout_commands/kb/traverse +66 -0
  30. data/test/data/person/brothers +1 -1
  31. data/test/scout/entity/test_identifiers.rb +3 -3
  32. data/test/scout/knowledge_base/test_enrichment.rb +0 -0
  33. data/test/scout/knowledge_base/test_entity.rb +38 -0
  34. data/test/scout/knowledge_base/test_list.rb +40 -0
  35. data/test/scout/knowledge_base/test_query.rb +39 -0
  36. data/test/scout/knowledge_base/test_registry.rb +16 -0
  37. data/test/scout/knowledge_base/test_traverse.rb +245 -0
  38. data/test/scout/test_association.rb +17 -3
  39. data/test/scout/test_entity.rb +0 -15
  40. data/test/scout/test_knowledge_base.rb +27 -0
  41. data/test/test_helper.rb +17 -0
  42. metadata +23 -5
@@ -0,0 +1,245 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/knowledge_base'
5
+ class TestKnowledgeBaseTraverse < Test::Unit::TestCase
6
+ def test_traverse_single
7
+ TmpFile.with_dir do |dir|
8
+ kb = KnowledgeBase.new dir
9
+ kb.entity_options = {"TestKnowledgeBaseQuery::Person" => {test: "Default"}}
10
+
11
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
12
+ kb.register :parents, datafile_test(:person).parents, entity_options: {"TestKnowledgeBaseQuery::Person" => {test: "Parents"}}
13
+
14
+ rules = []
15
+ rules << "Miki brothers ?1"
16
+ res = kb.traverse rules
17
+ assert_include res.first["?1"], "Isa"
18
+
19
+ rules = []
20
+ rules << "Miki parents ?1"
21
+ entities, paths = kb.traverse rules
22
+ assert_include paths.first.first.info, "Type of parent"
23
+
24
+ rules = []
25
+ rules << "?1 parents Domingo"
26
+ entities, paths = kb.traverse rules
27
+ assert_include entities["?1"], "Clei"
28
+ end
29
+ end
30
+
31
+ def test_traverse_multiple
32
+ TmpFile.with_dir do |dir|
33
+ kb = KnowledgeBase.new dir
34
+
35
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
36
+ kb.register :parents, datafile_test(:person).parents
37
+ kb.register :marriages, datafile_test(:person).marriages, source: "=>Alias", target: "=>Alias"
38
+
39
+ rules = []
40
+ rules << "Miki marriages ?1"
41
+ rules << "?1 brothers ?2"
42
+ res = kb.traverse rules
43
+ assert_include res.first["?2"], "Guille"
44
+ end
45
+ end
46
+
47
+ def test_traverse_condition
48
+ TmpFile.with_dir do |dir|
49
+ kb = KnowledgeBase.new dir
50
+
51
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
52
+ kb.register :parents, datafile_test(:person).parents
53
+ kb.register :marriages, datafile_test(:person).marriages, source: "=>Alias", target: "=>Alias"
54
+
55
+ rules = []
56
+ rules << "Miki parents ?1 - 'Type of parent=father'"
57
+ entities, paths = kb.traverse rules
58
+ assert_equal entities["?1"], ["Juan"]
59
+ end
60
+ end
61
+
62
+ def test_traverse_identify
63
+ TmpFile.with_dir do |dir|
64
+ kb = KnowledgeBase.new dir
65
+ kb.entity_options = {"TestKnowledgeBaseQuery::Person" => {test: "Default"}}
66
+
67
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
68
+ kb.register :parents, datafile_test(:person).parents, entity_options: {"TestKnowledgeBaseQuery::Person" => {test: "Parents"}}
69
+
70
+ rules = []
71
+ rules << "001 brothers ?1"
72
+ res = kb.traverse rules
73
+ assert_include res.first["?1"], "Isa"
74
+ end
75
+ end
76
+
77
+ def test_traverse_target
78
+ TmpFile.with_dir do |dir|
79
+ kb = KnowledgeBase.new dir
80
+
81
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
82
+ kb.register :parents, datafile_test(:person).parents
83
+
84
+ rules = []
85
+ rules << "?target =brothers 001"
86
+ rules << "?1 brothers ?target"
87
+ res = kb.traverse rules
88
+ assert_include res.first["?1"], "Isa"
89
+ assert_include res.first["?target"], "Miki"
90
+ end
91
+ end
92
+
93
+ def test_traverse_translate_multiple
94
+ TmpFile.with_dir do |dir|
95
+ kb = KnowledgeBase.new dir
96
+
97
+ kb.register :brothers, datafile_test(:person).brothers, undirected: true
98
+ kb.register :parents, datafile_test(:person).parents
99
+ kb.register :marriages, datafile_test(:person).marriages, undirected: true
100
+
101
+ rules = []
102
+ rules << "Guille brothers ?1"
103
+ rules << "?2 =marriages ?1"
104
+ rules << "?2 marriages ?3"
105
+ entities, paths = kb.traverse rules
106
+ assert_include entities["?3"], "001"
107
+ end
108
+ end
109
+ end
110
+
111
+
112
+
113
+ #require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
114
+ #require 'rbbt/knowledge_base/traverse'
115
+ #require 'rbbt/workflow'
116
+ #
117
+ #class TestKnowledgeBaseTraverse < Test::Unit::TestCase
118
+ # def with_kb(&block)
119
+ # keyword_test :organism do
120
+ # require 'rbbt/sources/organism'
121
+ # organism = Organism.default_code("Hsa")
122
+ # TmpFile.with_file do |tmpdir|
123
+ # kb = KnowledgeBase.new tmpdir
124
+ # kb.namespace = organism
125
+ # kb.format = {"Gene" => "Associated Gene Name"}
126
+ #
127
+ # kb.register :gene_ages, datadir_test.gene_ages, :source => "=>Associated Gene Name"
128
+ #
129
+ # kb.register :CollecTRI, datadir_test.CollecTRI,
130
+ # :source => "Transcription Factor=~Associated Gene Name",
131
+ # :target => "Target Gene=~Associated Gene Name",
132
+ # :fields => ["[ExTRI] Confidence", "[ExTRI] PMID"]
133
+ #
134
+ # yield kb
135
+ # end
136
+ # end
137
+ # end
138
+ #
139
+ # def test_traverse_simple
140
+ # with_kb do |kb|
141
+ # rules = []
142
+ # rules << "SMAD4 gene_ages ?1"
143
+ # res = kb.traverse rules
144
+ # assert_include res.first["?1"], "Bilateria"
145
+ # end
146
+ # end
147
+ #
148
+ # def test_traverse_CollecTRI
149
+ # with_kb do |kb|
150
+ # rules = []
151
+ # rules << "SMAD4 CollecTRI ?1 - '[ExTRI] Confidence=High'"
152
+ # res = kb.traverse rules
153
+ # assert res.last.any?
154
+ # end
155
+ # end
156
+ #
157
+ #
158
+ # def test_traverse
159
+ # with_kb do |kb|
160
+ # rules = []
161
+ # rules << "?1 CollecTRI SMAD7"
162
+ # rules << "?1 gene_ages ?2"
163
+ # rules << "SMAD4 gene_ages ?2"
164
+ # res = kb.traverse rules
165
+ # assert res.first["?1"].include? "MYC"
166
+ # end
167
+ # end
168
+ #
169
+ # def test_target
170
+ # with_kb do |kb|
171
+ # rules = []
172
+ # rules << "?target =CollecTRI SMAD7"
173
+ # rules << "?1 CollecTRI ?target"
174
+ # rules << "?1 gene_ages ?2"
175
+ # rules << "SMAD4 gene_ages ?2"
176
+ # res = kb.traverse rules
177
+ # assert res.first["?1"].include? "MYC"
178
+ # end
179
+ # end
180
+ #
181
+ # def test_target_translate
182
+ # with_kb do |kb|
183
+ # rules = []
184
+ # rules << "?target =CollecTRI ENSG00000101665"
185
+ # rules << "?1 CollecTRI ?target"
186
+ # res = kb.traverse rules
187
+ # assert res.first["?1"].include? "MYC"
188
+ # end
189
+ # end
190
+ #
191
+ # def test_target_attribute
192
+ # with_kb do |kb|
193
+ # rules = []
194
+ # rules << "?1 CollecTRI SMAD7"
195
+ # all = kb.traverse rules
196
+ #
197
+ # rules = []
198
+ # rules << "?1 CollecTRI SMAD7 - '[ExTRI] Confidence'=High"
199
+ # low = kb.traverse rules
200
+ #
201
+ # assert low.last.length < all.last.length
202
+ # end
203
+ # end
204
+ #
205
+ # def test_traverse_same_age
206
+ # with_kb do |kb|
207
+ # rules_str=<<-EOF
208
+ #?target1 =gene_ages SMAD7
209
+ #?target2 =gene_ages SMAD4
210
+ #?target1 gene_ages ?age
211
+ #?target2 gene_ages ?age
212
+ #?1 gene_ages ?age
213
+ # EOF
214
+ # rules = rules_str.split "\n"
215
+ # res = kb.traverse rules
216
+ # assert_include res.first["?1"], "MET"
217
+ # end
218
+ # end
219
+ #
220
+ # def test_traverse_same_age_acc
221
+ # with_kb do |kb|
222
+ # rules_str=<<-EOF
223
+ #?target1 =gene_ages SMAD7
224
+ #?target2 =gene_ages SMAD4
225
+ #?age{
226
+ # ?target1 gene_ages ?age
227
+ # ?target2 gene_ages ?age
228
+ #}
229
+ #?1 gene_ages ?age
230
+ # EOF
231
+ # rules = rules_str.split "\n"
232
+ # res = kb.traverse rules
233
+ # assert_include res.first["?1"], "MET"
234
+ # end
235
+ # end
236
+ #
237
+ # def test_wildcard_db
238
+ # with_kb do |kb|
239
+ # rules = []
240
+ # rules << "SMAD4 ?db ?1"
241
+ # res = kb.traverse rules
242
+ # end
243
+ # end
244
+ #end
245
+ #
@@ -4,12 +4,21 @@ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1
4
4
  require 'scout/tsv'
5
5
  class TestAssociation < Test::Unit::TestCase
6
6
 
7
- def test_marriages_simple
8
- database = Association.database(datadir_test.person.marriages, :source => "Wife", :target => "Husband")
7
+ def test_marriages_simple_no_persist
8
+ database = Association.database(datadir_test.person.marriages, :source => "Wife", :target => "Husband", persist: false)
9
9
  assert_equal "001", database["002"]["Husband"]
10
10
  assert_equal "2021", database["002"]["Date"]
11
+ refute database.respond_to?(:persistence_path)
11
12
  end
12
13
 
14
+ def test_marriages_simple_persist
15
+ database = Association.database(datadir_test.person.marriages, :source => "Wife", :target => "Husband", persist: true)
16
+ assert_equal "001", database["002"]["Husband"]
17
+ assert_equal "2021", database["002"]["Date"]
18
+ assert database.respond_to?(:persistence_path)
19
+ end
20
+
21
+
13
22
  def test_marriages_open
14
23
  database = Association.database(datadir_test.person.marriages, :source => "Wife (ID)=>Alias", :target => "Husband (ID)=>Name")
15
24
  assert_equal "Miguel", database["Clei"]["Husband"]
@@ -38,7 +47,7 @@ class TestAssociation < Test::Unit::TestCase
38
47
  end
39
48
 
40
49
  def test_brothers_rename
41
- database = Association.database(datadir_test.person.brothers, :source => "Older=~Older (Alias)=>Name")
50
+ database = Association.database(datadir_test.person.brothers, source: "Older=~Older (Alias)=>Name")
42
51
  assert_equal "Older (Name)", database.key_field
43
52
  end
44
53
 
@@ -47,5 +56,10 @@ class TestAssociation < Test::Unit::TestCase
47
56
  database = Association.database(tsv)
48
57
  assert_equal database["Miki"], %w(Juan Mariluz)
49
58
  end
59
+
60
+ def test_persist
61
+ database = Association.database(datadir_test.person.brothers, source: "Older=~Older (Alias)=>Name", persist: true)
62
+ assert database.respond_to?(:persistence_path)
63
+ end
50
64
  end
51
65
 
@@ -7,21 +7,6 @@ class TestEntity < Test::Unit::TestCase
7
7
  Entity.entity_property_cache = tmpdir.property_cache
8
8
  end
9
9
 
10
- module Person
11
- extend Entity
12
-
13
- annotation :language
14
-
15
- property :salutation do
16
- case language
17
- when 'es'
18
- "Hola #{self}"
19
- else
20
- "Hi #{self}"
21
- end
22
- end
23
- end
24
-
25
10
  module EmptyEntity
26
11
  extend Entity
27
12
  end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestKnowlegeBase < Test::Unit::TestCase
5
+ def test_no_namespace
6
+ TmpFile.with_dir do |dir|
7
+ kb = KnowledgeBase.new dir
8
+ assert_nil kb.namespace
9
+ kb.save
10
+
11
+ kb = KnowledgeBase.load dir
12
+ assert_nil kb.namespace
13
+ end
14
+ end
15
+
16
+ def test_namespace
17
+ TmpFile.with_dir do |dir|
18
+ kb = KnowledgeBase.new dir, "Hsa"
19
+ assert_equal "Hsa", kb.namespace
20
+ kb.save
21
+
22
+ kb = KnowledgeBase.load dir
23
+ assert_equal "Hsa", kb.namespace
24
+ end
25
+ end
26
+ end
27
+
data/test/test_helper.rb CHANGED
@@ -72,3 +72,20 @@ class Test::Unit::TestCase
72
72
  Test::Unit::TestCase.datafile_test(file)
73
73
  end
74
74
  end
75
+
76
+ module Object::Person
77
+ extend Entity
78
+
79
+ annotation :language
80
+
81
+ property :salutation do
82
+ case language
83
+ when 'es'
84
+ "Hola #{self}"
85
+ else
86
+ "Hi #{self}"
87
+ end
88
+ end
89
+ end
90
+
91
+ Object::Person.add_identifiers Test::Unit::TestCase.datafile_test(:person).identifiers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-gear
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.7.2
4
+ version: 10.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-10 00:00:00.000000000 Z
11
+ date: 2025-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scout-essentials
@@ -156,6 +156,13 @@ files:
156
156
  - lib/scout/entity/named_array.rb
157
157
  - lib/scout/entity/object.rb
158
158
  - lib/scout/entity/property.rb
159
+ - lib/scout/knowledge_base.rb
160
+ - lib/scout/knowledge_base/enrichment.rb
161
+ - lib/scout/knowledge_base/entity.rb
162
+ - lib/scout/knowledge_base/list.rb
163
+ - lib/scout/knowledge_base/query.rb
164
+ - lib/scout/knowledge_base/registry.rb
165
+ - lib/scout/knowledge_base/traverse.rb
159
166
  - lib/scout/offsite.rb
160
167
  - lib/scout/offsite/exceptions.rb
161
168
  - lib/scout/offsite/ssh.rb
@@ -234,12 +241,16 @@ files:
234
241
  - scout_commands/alias
235
242
  - scout_commands/batch/clean
236
243
  - scout_commands/batch/list
237
- - scout_commands/db/query
238
- - scout_commands/db/register
239
- - scout_commands/db/show
240
244
  - scout_commands/doc
241
245
  - scout_commands/find
242
246
  - scout_commands/glob
247
+ - scout_commands/kb/config
248
+ - scout_commands/kb/entities
249
+ - scout_commands/kb/list
250
+ - scout_commands/kb/query
251
+ - scout_commands/kb/register
252
+ - scout_commands/kb/show
253
+ - scout_commands/kb/traverse
243
254
  - scout_commands/log
244
255
  - scout_commands/offsite
245
256
  - scout_commands/rbbt
@@ -270,6 +281,12 @@ files:
270
281
  - test/scout/entity/test_named_array.rb
271
282
  - test/scout/entity/test_object.rb
272
283
  - test/scout/entity/test_property.rb
284
+ - test/scout/knowledge_base/test_enrichment.rb
285
+ - test/scout/knowledge_base/test_entity.rb
286
+ - test/scout/knowledge_base/test_list.rb
287
+ - test/scout/knowledge_base/test_query.rb
288
+ - test/scout/knowledge_base/test_registry.rb
289
+ - test/scout/knowledge_base/test_traverse.rb
273
290
  - test/scout/offsite/test_ssh.rb
274
291
  - test/scout/offsite/test_step.rb
275
292
  - test/scout/offsite/test_sync.rb
@@ -290,6 +307,7 @@ files:
290
307
  - test/scout/persist/tsv/test_serialize.rb
291
308
  - test/scout/test_association.rb
292
309
  - test/scout/test_entity.rb
310
+ - test/scout/test_knowledge_base.rb
293
311
  - test/scout/test_offsite.rb
294
312
  - test/scout/test_semaphore.rb
295
313
  - test/scout/test_tsv.rb