rbbt-util 5.14.35 → 5.14.36
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/database.rb +15 -10
- data/lib/rbbt/association/index.rb +69 -41
- data/lib/rbbt/association/item.rb +12 -8
- data/lib/rbbt/association/open.rb +7 -4
- data/lib/rbbt/association/util.rb +1 -1
- data/lib/rbbt/entity.rb +14 -10
- data/lib/rbbt/entity/identifiers.rb +9 -6
- data/lib/rbbt/knowledge_base/entity.rb +14 -10
- data/lib/rbbt/knowledge_base/registry.rb +20 -2
- data/lib/rbbt/resource/path.rb +1 -0
- data/lib/rbbt/resource/rake.rb +1 -0
- data/lib/rbbt/tsv/accessor.rb +1 -3
- data/lib/rbbt/tsv/change_id.rb +2 -2
- data/lib/rbbt/tsv/manipulate.rb +6 -5
- data/lib/rbbt/tsv/parser.rb +1 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +1 -1
- data/lib/rbbt/util/misc/pipes.rb +1 -0
- data/lib/rbbt/workflow/step/run.rb +3 -1
- data/share/rbbt_commands/tsv/info +1 -1
- data/test/rbbt/association/test_index.rb +7 -0
- data/test/rbbt/association/test_open.rb +1 -1
- data/test/rbbt/knowledge_base/test_entity.rb +41 -0
- data/test/rbbt/knowledge_base/test_registry.rb +2 -1
- data/test/rbbt/knowledge_base/test_syndicate.rb +48 -0
- data/test/rbbt/test_entity.rb +23 -15
- data/test/test_helper.rb +9 -3
- 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: 795e7afaaeccea346ef27ef5a13ccc114072207e
|
4
|
+
data.tar.gz: e8cb3fd1d85d3c30d2970ec75f63d8ce408f471d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94cac0c82c60c0759be8bf32296b016666b2408751eab32d32b7b2e97e059374c3ff33ed427ac05b696169e8ce71c15839a4eedd7a7573ae7bc0add452a257e8
|
7
|
+
data.tar.gz: f7e41b218c3809e5048fbf94121e93192c28a1ab11e1c9c423d8bb0d585d3aea62e72d371e09f9421a58d4fe42f8c3f21a482a146ae198fb2edc84413fda567c
|
@@ -71,6 +71,7 @@ module Association
|
|
71
71
|
info_fields = field_pos.collect{|f| f == :key ? :key : all_fields[f]}
|
72
72
|
options = options.merge({:key_field => source_field, :fields => info_fields})
|
73
73
|
|
74
|
+
|
74
75
|
tsv = tsv.reorder source_field, fields if true or source_field != tsv.key_field or (fields and tsv.fields != fields)
|
75
76
|
|
76
77
|
tsv.key_field = source_header
|
@@ -136,16 +137,20 @@ module Association
|
|
136
137
|
end
|
137
138
|
|
138
139
|
def self.database(file, options = {})
|
139
|
-
case file
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
140
|
+
database = case file
|
141
|
+
when TSV
|
142
|
+
file = file.to_double unless file.type == :double
|
143
|
+
reorder_tsv(file, options.dup)
|
144
|
+
when IO
|
145
|
+
open_stream(file, options.dup)
|
146
|
+
else
|
147
|
+
stream = TSV.get_stream(file)
|
148
|
+
open_stream(stream, options.dup)
|
149
|
+
end
|
150
|
+
|
151
|
+
database.entity_options = options[:entity_options] if options[:entity_options]
|
152
|
+
|
153
|
+
database
|
149
154
|
end
|
150
155
|
|
151
156
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rbbt/tsv'
|
2
2
|
require 'rbbt/association/open'
|
3
|
+
require 'rbbt/association/item'
|
3
4
|
|
4
5
|
module Association
|
5
6
|
def self.index(file, options = nil, persist_options = nil)
|
@@ -16,13 +17,16 @@ module Association
|
|
16
17
|
undirected = options[:undirected]
|
17
18
|
|
18
19
|
persist_options[:file] = persist_options[:file] + '.database' if persist_options[:file]
|
20
|
+
|
19
21
|
database = open(file, options, persist_options.dup.merge(:engine => "HDB"))
|
20
22
|
|
21
|
-
|
23
|
+
source_field = database.key_field
|
22
24
|
|
23
25
|
fields = database.fields
|
24
|
-
source_field = database.key_field
|
25
26
|
target_field = fields.first.split(":").last
|
27
|
+
|
28
|
+
undirected = true if undirected.nil? and source_field == target_field
|
29
|
+
|
26
30
|
key_field = [source_field, target_field, undirected ? "undirected" : nil].compact * "~"
|
27
31
|
|
28
32
|
TSV.setup(data, :key_field => key_field, :fields => fields[1..-1], :type => :list, :serializer => :list)
|
@@ -33,46 +37,48 @@ module Association
|
|
33
37
|
data.serializer = :list
|
34
38
|
|
35
39
|
database.with_unnamed do
|
36
|
-
database.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
next if values.empty?
|
46
|
-
next if source.nil? or source.empty?
|
47
|
-
next if values.empty?
|
48
|
-
|
49
|
-
targets, *rest = values
|
50
|
-
|
51
|
-
size = targets ? targets.length : 0
|
52
|
-
|
53
|
-
rest.each_with_index do |list,i|
|
54
|
-
list.replace [list.first] * size if list.length == 1
|
55
|
-
end if recycle and size > 1
|
56
|
-
|
57
|
-
rest = Misc.zip_fields rest
|
58
|
-
|
59
|
-
annotations = rest.length > 1 ?
|
60
|
-
targets.zip(rest) :
|
61
|
-
targets.zip(rest * targets.length)
|
62
|
-
|
63
|
-
annotations.each do |target, info|
|
64
|
-
next if target.nil? or target.empty?
|
65
|
-
key = [source, target] * "~"
|
66
|
-
if data[key].nil? or info.nil?
|
67
|
-
data[key] = info
|
68
|
-
else
|
69
|
-
old_info = data[key]
|
70
|
-
info = old_info.zip(info).collect{|p| p * ";;" }
|
71
|
-
data[key] = info
|
40
|
+
database.with_monitor(options[:monitor]) do
|
41
|
+
database.through do |source, values|
|
42
|
+
case database.type
|
43
|
+
when :single
|
44
|
+
values = [[values]]
|
45
|
+
when :list
|
46
|
+
values = values.collect{|v| [v] }
|
47
|
+
when :flat
|
48
|
+
values = [values]
|
72
49
|
end
|
73
|
-
if
|
74
|
-
|
75
|
-
|
50
|
+
next if values.empty?
|
51
|
+
next if source.nil? or source.empty?
|
52
|
+
next if values.empty?
|
53
|
+
|
54
|
+
targets, *rest = values
|
55
|
+
|
56
|
+
size = targets ? targets.length : 0
|
57
|
+
|
58
|
+
rest.each_with_index do |list,i|
|
59
|
+
list.replace [list.first] * size if list.length == 1
|
60
|
+
end if recycle and size > 1
|
61
|
+
|
62
|
+
rest = Misc.zip_fields rest
|
63
|
+
|
64
|
+
annotations = rest.length > 1 ?
|
65
|
+
targets.zip(rest) :
|
66
|
+
targets.zip(rest * targets.length)
|
67
|
+
|
68
|
+
annotations.each do |target, info|
|
69
|
+
next if target.nil? or target.empty?
|
70
|
+
key = [source, target] * "~"
|
71
|
+
if data[key].nil? or info.nil?
|
72
|
+
data[key] = info
|
73
|
+
else
|
74
|
+
old_info = data[key]
|
75
|
+
info = old_info.zip(info).collect{|p| p * ";;" }
|
76
|
+
data[key] = info
|
77
|
+
end
|
78
|
+
if undirected
|
79
|
+
reverse_key = [target,source] * "~"
|
80
|
+
data[reverse_key] = info unless data.include? reverse_key
|
81
|
+
end
|
76
82
|
end
|
77
83
|
end
|
78
84
|
end
|
@@ -83,9 +89,11 @@ module Association
|
|
83
89
|
end.tap do |data|
|
84
90
|
data.read if not Hash === data and data.respond_to? :read
|
85
91
|
Association::Index.setup data
|
92
|
+
data.entity_options = options[:entity_options] if options[:entity_options]
|
86
93
|
data
|
87
94
|
end
|
88
95
|
end
|
96
|
+
|
89
97
|
module Index
|
90
98
|
|
91
99
|
attr_accessor :source_field, :target_field, :undirected
|
@@ -156,6 +164,26 @@ module Association
|
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
167
|
+
def to_matrix(value_field = nil, &block)
|
168
|
+
value_field = fields.first if value_field.nil? and fields.length == 1
|
169
|
+
value_pos = identify_field value_field if value_field and String === value_field
|
170
|
+
key_field = source_field
|
171
|
+
|
172
|
+
tsv = if value_pos
|
173
|
+
AssociationItem.incidence self.keys, key_field do |key|
|
174
|
+
if block_given?
|
175
|
+
yield self[key][value_pos]
|
176
|
+
else
|
177
|
+
self[key][value_pos]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
elsif block_given?
|
181
|
+
AssociationItem.incidence self.keys, key_field, &block
|
182
|
+
else
|
183
|
+
AssociationItem.incidence self.keys, key_field
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
159
187
|
#{{{ Subset
|
160
188
|
|
161
189
|
def subset(source, target)
|
@@ -54,23 +54,27 @@ module AssociationItem
|
|
54
54
|
reverse ? knowledge_base.target(database) : knowledge_base.source(database)
|
55
55
|
end
|
56
56
|
|
57
|
+
property :undirected => :both do
|
58
|
+
knowledge_base.undirected(database)
|
59
|
+
end
|
60
|
+
|
57
61
|
property :target_entity => :array2single do
|
58
62
|
type = reverse ? knowledge_base.source(database) : knowledge_base.target(database)
|
59
63
|
knowledge_base.annotate self.target, type, database #if self.target.any?
|
60
64
|
end
|
61
65
|
|
62
|
-
property :undirected => :both do
|
63
|
-
knowledge_base.undirected(database)
|
64
|
-
end
|
65
|
-
|
66
66
|
property :source_entity => :array2single do
|
67
67
|
type = reverse ? knowledge_base.target(database) : knowledge_base.source(database)
|
68
|
-
knowledge_base.annotate self.source, type #if self.source.any?
|
68
|
+
knowledge_base.annotate self.source, type, database #if self.source.any?
|
69
69
|
end
|
70
70
|
|
71
|
+
property :index => :both do |database|
|
72
|
+
@index ||= knowledge_base.get_index(database)
|
73
|
+
end
|
71
74
|
property :value => :array2single do
|
72
|
-
|
73
|
-
value
|
75
|
+
index = index(database)
|
76
|
+
value = (reverse ? index.reverse : index).chunked_values_at self
|
77
|
+
value.collect{|v| NamedArray.setup(v, index.fields)}
|
74
78
|
end
|
75
79
|
|
76
80
|
property :info_fields => :both do
|
@@ -126,7 +130,7 @@ module AssociationItem
|
|
126
130
|
value = block.call p
|
127
131
|
matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
|
128
132
|
else
|
129
|
-
matches[s] ||= Hash.new{
|
133
|
+
matches[s] ||= Hash.new{false}
|
130
134
|
matches[s][t] ||= true
|
131
135
|
end
|
132
136
|
end
|
@@ -21,17 +21,20 @@ module Association
|
|
21
21
|
data = Persist.persist_tsv(file, "Association Database", options, persist_options) do |data|
|
22
22
|
tsv = Association.database(file, options.merge(:persist => persist))
|
23
23
|
tsv = tsv.to_double unless tsv.type == :double
|
24
|
+
|
24
25
|
tsv.annotate data
|
25
26
|
|
26
27
|
data.serializer = :double if data.respond_to? :serializer
|
27
|
-
tsv.
|
28
|
-
|
28
|
+
tsv.with_monitor(options[:monitor]) do
|
29
|
+
tsv.through do |k,v|
|
30
|
+
data[k] = v
|
31
|
+
end
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
34
|
data
|
33
35
|
end
|
34
|
-
|
36
|
+
data.entity_options = options[:entity_options] if options[:entity_options]
|
37
|
+
data
|
35
38
|
end
|
36
39
|
|
37
40
|
end
|
@@ -116,7 +116,7 @@ module Association
|
|
116
116
|
field_headers << header
|
117
117
|
end
|
118
118
|
|
119
|
-
field_pos = info_fields.collect{|f| raise "Field #{f} not found. Options: #{
|
119
|
+
field_pos = info_fields.collect{|f| raise "Field #{f} not found. Options: #{all_fields * ", "}" unless all_fields.include?(f); f == :key ? 0 : all_fields.index(f); }
|
120
120
|
|
121
121
|
source_format = specs[:source][2]
|
122
122
|
target_format = specs[:target][2]
|
data/lib/rbbt/entity.rb
CHANGED
@@ -2,15 +2,19 @@ require 'rbbt/annotations'
|
|
2
2
|
require 'rbbt/entity/identifiers'
|
3
3
|
|
4
4
|
module Entity
|
5
|
+
|
6
|
+
UNPERSISTED_PREFIX = "entity_unpersisted_property_"
|
5
7
|
|
6
8
|
class << self
|
7
9
|
attr_accessor :formats, :entity_property_cache
|
8
10
|
end
|
9
|
-
|
10
|
-
self.entity_property_cache = "var/entity_property"
|
11
11
|
self.formats = {}
|
12
|
-
|
13
|
-
|
12
|
+
dir = (defined?(Rbbt)? Rbbt.var.entity_property : 'var/entity_property')
|
13
|
+
self.entity_property_cache = dir
|
14
|
+
|
15
|
+
def self.entity_property_cache=(dir)
|
16
|
+
@entity_property_cache = dir
|
17
|
+
end
|
14
18
|
|
15
19
|
attr_accessor :all_formats
|
16
20
|
def self.extended(base)
|
@@ -22,19 +26,19 @@ module Entity
|
|
22
26
|
|
23
27
|
attr_accessor :template, :list_template, :action_template, :list_action_template, :keep_id
|
24
28
|
|
25
|
-
def _ary_property_cache
|
26
|
-
@_ary_property_cache ||= {}
|
27
|
-
end
|
28
|
-
|
29
29
|
def self.format=(formats)
|
30
30
|
formats = [formats] unless Array === formats
|
31
31
|
self.all_formats ||= []
|
32
32
|
self.all_formats = self.all_formats.concat(formats).uniq
|
33
33
|
formats.each do |format|
|
34
|
-
Entity.formats[format]
|
34
|
+
Entity.formats[format] ||= self
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def _ary_property_cache
|
39
|
+
@_ary_property_cache ||= {}
|
40
|
+
end
|
41
|
+
|
38
42
|
def base_entity
|
39
43
|
self.annotation_types.select{|m| Entity === m}.last
|
40
44
|
end
|
@@ -90,7 +94,7 @@ module Entity
|
|
90
94
|
define_method single_name, &block
|
91
95
|
define_method name do |*args|
|
92
96
|
if Array === self
|
93
|
-
self.collect{|e| e.send(
|
97
|
+
self.collect{|e| e.send(single_name, *args)}
|
94
98
|
else
|
95
99
|
self.send(single_name, *args)
|
96
100
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module Entity
|
2
|
-
|
3
2
|
def self.identifier_files(field)
|
4
3
|
entity_type = Entity.formats[field]
|
5
4
|
return [] unless entity_type and entity_type.include? Entity::Identified
|
@@ -12,6 +11,12 @@ module Entity
|
|
12
11
|
base.annotation :format
|
13
12
|
base.annotation :organism
|
14
13
|
|
14
|
+
|
15
|
+
|
16
|
+
class << base
|
17
|
+
attr_accessor :identifier_files, :formats, :default_format, :name_format, :description_format
|
18
|
+
end
|
19
|
+
|
15
20
|
base.module_eval do
|
16
21
|
def identity_type
|
17
22
|
self.annotation_types.select{|m| m.include? Entity::Identified }.last
|
@@ -50,6 +55,7 @@ module Entity
|
|
50
55
|
end
|
51
56
|
|
52
57
|
return self if target_format == format
|
58
|
+
|
53
59
|
if Array === self
|
54
60
|
self.annotate(identifier_index(target_format, self.format).values_at(*self))
|
55
61
|
else
|
@@ -73,8 +79,6 @@ module Entity
|
|
73
79
|
|
74
80
|
end
|
75
81
|
|
76
|
-
attr_accessor :identifier_files, :formats, :default_format, :name_format, :description_format
|
77
|
-
|
78
82
|
def add_identifiers(file, default = nil, name = nil, description = nil)
|
79
83
|
if TSV === file
|
80
84
|
all_fields = file.all_fields
|
@@ -88,6 +92,8 @@ module Entity
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
95
|
+
self.include Entity::Identified unless Entity::Identified === self
|
96
|
+
|
91
97
|
self.format = all_fields
|
92
98
|
@formats ||= []
|
93
99
|
@formats.concat all_fields
|
@@ -100,9 +106,6 @@ module Entity
|
|
100
106
|
@identifier_files ||= []
|
101
107
|
@identifier_files << file
|
102
108
|
@identifier_files.uniq!
|
103
|
-
|
104
|
-
|
105
|
-
self.include Entity::Identified unless Entity::Identified === self
|
106
109
|
end
|
107
110
|
|
108
111
|
end
|
@@ -19,17 +19,26 @@ class KnowledgeBase
|
|
19
19
|
|
20
20
|
|
21
21
|
def entity_options_for(type, database_name = nil)
|
22
|
-
|
22
|
+
entity_options = self.entity_options
|
23
|
+
IndiferentHash.setup entity_options if entity_options and not IndiferentHash === entity_options
|
24
|
+
options = entity_options[type.to_s] || entity_options[Entity.formats[type.to_s].to_s] || {}
|
23
25
|
options[:format] = @format[type] if @format.include? :type
|
24
26
|
options = {:organism => namespace}.merge(options)
|
25
|
-
if database_name
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
if database_name
|
28
|
+
database = get_database(database_name)
|
29
|
+
if database.entity_options and (database.entity_options[type] or database.entity_options[Entity.formats[type.to_s].to_s])
|
30
|
+
options = options.merge(database.entity_options[type] || database.entity_options[Entity.formats[type.to_s].to_s])
|
31
|
+
end
|
29
32
|
end
|
30
33
|
options
|
31
34
|
end
|
32
35
|
|
36
|
+
def annotate(entities, type, database = nil)
|
37
|
+
format = @format[type] || type
|
38
|
+
entity_options = entity_options_for(type, database)
|
39
|
+
Misc.prepare_entity(entities, format, entity_options)
|
40
|
+
end
|
41
|
+
|
33
42
|
def translate(entities, type)
|
34
43
|
if format = @format[type] and (entities.respond_to? :format and format != entities.format)
|
35
44
|
entities.to format
|
@@ -38,11 +47,6 @@ class KnowledgeBase
|
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
|
-
def annotate(entities, type, database = nil)
|
42
|
-
format = @format[type] || type
|
43
|
-
Misc.prepare_entity(entities, format, entity_options_for(type, database))
|
44
|
-
end
|
45
|
-
|
46
50
|
def source_type(name)
|
47
51
|
Entity.formats[source(name)]
|
48
52
|
end
|
@@ -36,9 +36,11 @@ class KnowledgeBase
|
|
36
36
|
|
37
37
|
def get_index(name, options = {})
|
38
38
|
name = name.to_s
|
39
|
-
|
40
|
-
@indices[key] ||=
|
39
|
+
@indices[[name, options]] ||=
|
41
40
|
begin
|
41
|
+
fp = Misc.fingerprint([name,options])
|
42
|
+
key = name.to_s + "_" + Misc.digest(fp)
|
43
|
+
|
42
44
|
Persist.memory("Index:" << [key, dir] * "@") do
|
43
45
|
options = options.dup
|
44
46
|
persist_dir = dir
|
@@ -48,6 +50,14 @@ class KnowledgeBase
|
|
48
50
|
options = Misc.add_defaults options, registered_options if registered_options and registered_options.any?
|
49
51
|
options = Misc.add_defaults options, :persist_file => persist_file, :persist_dir => persist_dir, :namespace => namespace, :format => format, :persist => true
|
50
52
|
|
53
|
+
if entity_options
|
54
|
+
options[:entity_options] ||= {}
|
55
|
+
entity_options.each do |type, info|
|
56
|
+
options[:entity_options][type] ||= {}
|
57
|
+
options[:entity_options][type] = Misc.add_defaults options[:entity_options][type], info
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
51
61
|
persist_options = Misc.pull_keys options, :persist
|
52
62
|
|
53
63
|
index = if persist_file.exists? and persist_options[:persist] and not persist_options[:update]
|
@@ -81,6 +91,14 @@ class KnowledgeBase
|
|
81
91
|
options = Misc.add_defaults options, registered_options if registered_options and registered_options.any?
|
82
92
|
options = Misc.add_defaults options, :persist_file => persist_file, :namespace => namespace, :format => format, :persist => true
|
83
93
|
|
94
|
+
if entity_options
|
95
|
+
options[:entity_options] ||= {}
|
96
|
+
entity_options.each do |type, info|
|
97
|
+
options[:entity_options][type] ||= {}
|
98
|
+
options[:entity_options][type] = Misc.add_defaults options[:entity_options][type], info
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
84
102
|
persist_options = Misc.pull_keys options, :persist
|
85
103
|
|
86
104
|
database = if persist_file.exists? and persist_options[:persist] and not persist_options[:update]
|
data/lib/rbbt/resource/path.rb
CHANGED
data/lib/rbbt/resource/rake.rb
CHANGED
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -84,7 +84,7 @@ module TSV
|
|
84
84
|
|
85
85
|
def with_monitor(value = true)
|
86
86
|
saved_monitor = @monitor
|
87
|
-
@monitor = value
|
87
|
+
@monitor = value.nil? ? false : value
|
88
88
|
res = yield
|
89
89
|
@monitor = saved_monitor
|
90
90
|
res
|
@@ -471,10 +471,8 @@ module TSV
|
|
471
471
|
end
|
472
472
|
|
473
473
|
def namespace=(value)
|
474
|
-
#self.send(:[]=, "__tsv_hash_namespace", value.nil? ? SERIALIZED_NIL : TSV::TSV_SERIALIZER.dump(value), true)
|
475
474
|
self.send(:[]=, "__tsv_hash_namespace", dump_entry_value(value), true)
|
476
475
|
@namespace = value
|
477
|
-
@entity_options = nil
|
478
476
|
end
|
479
477
|
|
480
478
|
def fields=(value)
|
data/lib/rbbt/tsv/change_id.rb
CHANGED
@@ -89,7 +89,7 @@ module TSV
|
|
89
89
|
def self.translation_index(files, target = nil, source = nil, options = {})
|
90
90
|
return nil if source == target
|
91
91
|
options = Misc.add_defaults options.dup, :persist => true
|
92
|
-
fields = source ? [source] : nil
|
92
|
+
fields = (source and not source.empty?) ? [source] : nil
|
93
93
|
files.each do |file|
|
94
94
|
if TSV === file
|
95
95
|
all_fields = file.all_fields
|
@@ -117,7 +117,7 @@ module TSV
|
|
117
117
|
|
118
118
|
common_field = (all_fields & other_all_fields).first
|
119
119
|
|
120
|
-
if common_field and (source.nil? or all_fields.include? source) and other_all_fields.include? target
|
120
|
+
if common_field and (source.nil? or source.empty? or all_fields.include? source) and other_all_fields.include? target
|
121
121
|
|
122
122
|
index = Persist.persist_tsv(nil, Misc.fingerprint(files), {:files => files, :source => source, :target => target}, :prefix => "Translation index", :persist => options[:persist]) do |data|
|
123
123
|
|
data/lib/rbbt/tsv/manipulate.rb
CHANGED
@@ -253,15 +253,16 @@ module TSV
|
|
253
253
|
case type
|
254
254
|
when :double
|
255
255
|
new_key_field_name, new_field_names = through new_key_field, new_fields, uniq, zipped do |key, value|
|
256
|
-
if
|
256
|
+
if data[key]
|
257
|
+
current = data[key].dup
|
257
258
|
value.each_with_index do |v, i|
|
258
|
-
if
|
259
|
-
|
259
|
+
if current[i]
|
260
|
+
current[i] += v if v
|
260
261
|
else
|
261
262
|
current[i] = v || []
|
262
263
|
end
|
263
264
|
end
|
264
|
-
data[key] = current
|
265
|
+
data[key] = current
|
265
266
|
else
|
266
267
|
data[key] = value.collect{|v| v.nil? ? nil : v.dup}
|
267
268
|
end
|
@@ -269,7 +270,7 @@ module TSV
|
|
269
270
|
when :flat
|
270
271
|
new_key_field_name, new_field_names = through new_key_field, new_fields, uniq, zipped do |key, value|
|
271
272
|
data[key] ||= []
|
272
|
-
data[key]
|
273
|
+
data[key] += value
|
273
274
|
end
|
274
275
|
end
|
275
276
|
end
|
data/lib/rbbt/tsv/parser.rb
CHANGED
@@ -31,7 +31,6 @@ class RbbtProcessQueue
|
|
31
31
|
rescue ClosedStream
|
32
32
|
rescue Aborted, Interrupt
|
33
33
|
Log.warn "Worker #{Process.pid} aborted"
|
34
|
-
Kernel.exit! 0
|
35
34
|
rescue Exception
|
36
35
|
Log.exception $!
|
37
36
|
@callback_queue.push($!) if @callback_queue
|
@@ -39,6 +38,7 @@ class RbbtProcessQueue
|
|
39
38
|
ensure
|
40
39
|
@callback_queue.close_write if @callback_queue
|
41
40
|
end
|
41
|
+
Kernel.exit! 0
|
42
42
|
end
|
43
43
|
|
44
44
|
def run_with_respawn(multiplier = nil)
|
data/lib/rbbt/util/misc/pipes.rb
CHANGED
@@ -409,7 +409,9 @@ class Step
|
|
409
409
|
if stream
|
410
410
|
begin
|
411
411
|
Misc.consume_stream stream
|
412
|
+
stream.join if stream.respond_to? :join
|
412
413
|
rescue Exception
|
414
|
+
stream.abort
|
413
415
|
self._abort
|
414
416
|
raise $!
|
415
417
|
end
|
@@ -427,7 +429,7 @@ class Step
|
|
427
429
|
|
428
430
|
grace
|
429
431
|
|
430
|
-
join_stream if status ==
|
432
|
+
join_stream if status.to_s == "streaming"
|
431
433
|
|
432
434
|
return self if not Open.exists? info_file
|
433
435
|
|
@@ -42,7 +42,7 @@ when options[:tokyocabinet_bd]
|
|
42
42
|
tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
|
43
43
|
puts tsv.summary
|
44
44
|
else
|
45
|
-
header = TSV.parse_header(Open.open(file), options)
|
45
|
+
header = TSV.parse_header(Open.open(file, :nocache => true), options)
|
46
46
|
|
47
47
|
puts "File: #{ file }"
|
48
48
|
puts "Type: #{header.type}"
|
@@ -78,5 +78,12 @@ TP53 NFKB1|GLI1 activation|activation true|true
|
|
78
78
|
assert tsv.match("TP53").length > 10
|
79
79
|
end
|
80
80
|
|
81
|
+
def test_index_flat_to_matrix
|
82
|
+
require 'rbbt/sources/tfacts'
|
83
|
+
file = TFacts.regulators
|
84
|
+
tsv = Association.index(file, :type => :flat, :source => "Transcription Factor Associated Gene Name=~Associated Gene Name", :merge => true)
|
85
|
+
assert(tsv.to_matrix(false))
|
86
|
+
end
|
87
|
+
|
81
88
|
|
82
89
|
end
|
@@ -55,7 +55,7 @@ TP53 NFKB1|GLI1 activation|activation true|true
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_index_persist_reverse
|
58
|
-
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:source => "TG", :target => "SG=~Associated Gene Name"), :persist => true).reverse
|
58
|
+
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge( :source => "TG", :target => "SG=~Associated Gene Name"), :persist => true).reverse
|
59
59
|
tsv.unnamed = false
|
60
60
|
assert_equal "inhibition", tsv["MDM2~TP53"]["Effect"]
|
61
61
|
assert_equal %w(MDM2~TP53), tsv.match("MDM2")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper')
|
2
|
+
require 'rbbt/util/tmpfile'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rbbt/knowledge_base'
|
5
|
+
require 'rbbt/knowledge_base/entity'
|
6
|
+
|
7
|
+
module Gene
|
8
|
+
extend Entity
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestKnowledgeEnity < Test::Unit::TestCase
|
12
|
+
|
13
|
+
EFFECT =StringIO.new <<-END
|
14
|
+
#: :sep=" "#:type=:double
|
15
|
+
#SG TG Effect
|
16
|
+
MDM2 TP53 inhibition
|
17
|
+
TP53 NFKB1|GLI1 activation|activation true|true
|
18
|
+
END
|
19
|
+
|
20
|
+
EFFECT_OPTIONS = {
|
21
|
+
:source => "SG=~Associated Gene Name",
|
22
|
+
:target => "TG=~Associated Gene Name=>Ensembl Gene ID",
|
23
|
+
:undirected => true,
|
24
|
+
:persist => true,
|
25
|
+
:namespace => "Hsa"
|
26
|
+
}
|
27
|
+
Gene.add_identifiers datafile_test('identifiers')
|
28
|
+
|
29
|
+
EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup
|
30
|
+
|
31
|
+
KNOWLEDGE_BASE = KnowledgeBase.new '/tmp/kb.foo2', "Hsa"
|
32
|
+
KNOWLEDGE_BASE.format = {"Gene" => "Associated Gene Name"}
|
33
|
+
|
34
|
+
KNOWLEDGE_BASE.register :effects, EFFECT_TSV, EFFECT_OPTIONS.dup
|
35
|
+
|
36
|
+
def test_entity_options
|
37
|
+
KNOWLEDGE_BASE.entity_options = {"Gene" => {:organism => "Mmu"}}
|
38
|
+
assert_equal "Mmu", KNOWLEDGE_BASE.children(:effects, "TP53").target_entity.organism
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -73,9 +73,10 @@ TP53 NFKB1|GLI1 activation|activation true|true
|
|
73
73
|
assert_equal count, count2
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
76
|
def test_pina2
|
77
|
+
KNOWLEDGE_BASE.entity_options["Gene"] = {:organism => "Mmu"}
|
78
78
|
index = KNOWLEDGE_BASE.get_index(:pina, :persist => true, :source_format => "Ensembl Gene ID", :target_format => "Ensembl Gene ID", :undirected => true)
|
79
|
+
assert_equal "Mmu", index.entity_options["Gene"][:organism]
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../test_helper')
|
2
|
+
require 'rbbt/util/tmpfile'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rbbt/knowledge_base'
|
5
|
+
require 'rbbt/knowledge_base/query'
|
6
|
+
|
7
|
+
module Gene
|
8
|
+
extend Entity
|
9
|
+
end
|
10
|
+
class TestKnowledgeBaseSyndicate < Test::Unit::TestCase
|
11
|
+
|
12
|
+
EFFECT =StringIO.new <<-END
|
13
|
+
#: :sep=" "#:type=:double
|
14
|
+
#SG TG Effect
|
15
|
+
MDM2 TP53 inhibition
|
16
|
+
TP53 NFKB1|GLI1 activation|activation true|true
|
17
|
+
END
|
18
|
+
|
19
|
+
EFFECT_OPTIONS = {
|
20
|
+
:source => "SG=~Associated Gene Name",
|
21
|
+
:target => "TG=~Associated Gene Name=>Ensembl Gene ID",
|
22
|
+
:persist => false,
|
23
|
+
:identifiers => datafile_test('identifiers'),
|
24
|
+
:undirected => true,
|
25
|
+
:namespace => "Hsa"
|
26
|
+
}
|
27
|
+
|
28
|
+
EFFECT_TSV = TSV.open EFFECT, EFFECT_OPTIONS.dup
|
29
|
+
|
30
|
+
KNOWLEDGE_BASE = KnowledgeBase.new '/tmp/kb.foo2', "Hsa"
|
31
|
+
KNOWLEDGE_BASE.format = {"Gene" => "Ensembl Gene ID"}
|
32
|
+
KNOWLEDGE_BASE.entity_options["Gene"] = {:organism => "Mmu", :test_option => "TEST"}
|
33
|
+
|
34
|
+
KNOWLEDGE_BASE.register :effects, EFFECT_TSV, EFFECT_OPTIONS.dup
|
35
|
+
|
36
|
+
def test_syndicate_entity_options
|
37
|
+
Gene.add_identifiers datafile_test('identifiers')
|
38
|
+
kb = KnowledgeBase.new "/tmp/kb.foo3", "Hsa"
|
39
|
+
kb.format = {"Gene" => "Associated Gene Name"}
|
40
|
+
kb.syndicate :orig, KNOWLEDGE_BASE
|
41
|
+
assert_equal "Mmu", KNOWLEDGE_BASE.entity_options_for("Gene", "effects")[:organism]
|
42
|
+
assert_equal "Mmu", kb.get_index("effects@orig").entity_options["Gene"][:organism]
|
43
|
+
assert_equal "Mmu", kb.get_database("effects@orig").entity_options["Gene"][:organism]
|
44
|
+
assert_equal "Mmu", kb.entity_options_for("Gene", "effects@orig")[:organism]
|
45
|
+
assert_equal "Mmu", kb.children("effects@orig", "TP53").source_entity.organism
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/test/rbbt/test_entity.rb
CHANGED
@@ -12,6 +12,7 @@ class TestA
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
Entity.entity_property_cache = Rbbt.tmp.test.entity_property.find
|
15
16
|
module ReversableString
|
16
17
|
extend Entity
|
17
18
|
|
@@ -21,7 +22,7 @@ module ReversableString
|
|
21
22
|
$count += 1
|
22
23
|
self.collect{|s| s.reverse}
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
property :reverse_text_single => :single do
|
26
27
|
$count += 1
|
27
28
|
self.reverse
|
@@ -31,7 +32,7 @@ module ReversableString
|
|
31
32
|
$count += 1
|
32
33
|
self.collect{|s| s.reverse}
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
property :reverse_text_single_p => :single do
|
36
37
|
$count += 1
|
37
38
|
self.reverse
|
@@ -51,11 +52,10 @@ module ReversableString
|
|
51
52
|
ReversableString.setup(c)
|
52
53
|
}
|
53
54
|
end
|
54
|
-
|
55
|
-
persist :reverse_text_ary_p
|
56
|
-
persist :
|
57
|
-
persist :
|
58
|
-
persist :reverse_text_single_p
|
55
|
+
|
56
|
+
persist :reverse_text_ary_p, :string
|
57
|
+
persist :reverse_text_single_p, :memory
|
58
|
+
#persist :_single_reverse_text_single_p, :string
|
59
59
|
|
60
60
|
persist :reverse_text_ary_p_array, :array, :dir => TmpFile.tmp_file
|
61
61
|
|
@@ -64,7 +64,7 @@ end
|
|
64
64
|
|
65
65
|
class TestEntity < Test::Unit::TestCase
|
66
66
|
|
67
|
-
def
|
67
|
+
def _test_property_ary
|
68
68
|
a = ["String1", "String2"]
|
69
69
|
ReversableString.setup(a)
|
70
70
|
|
@@ -84,7 +84,7 @@ class TestEntity < Test::Unit::TestCase
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
87
|
+
def _test_property_single
|
88
88
|
a = ["String1", "String2"]
|
89
89
|
ReversableString.setup a
|
90
90
|
|
@@ -96,7 +96,7 @@ class TestEntity < Test::Unit::TestCase
|
|
96
96
|
assert_equal 3, $count
|
97
97
|
end
|
98
98
|
|
99
|
-
def
|
99
|
+
def _test_property_ary_p
|
100
100
|
a = ["String1", "String2"]
|
101
101
|
ReversableString.setup a
|
102
102
|
|
@@ -114,15 +114,23 @@ class TestEntity < Test::Unit::TestCase
|
|
114
114
|
$count = 0
|
115
115
|
|
116
116
|
assert_equal "2gnirtS", a.reverse_text_single_p.last
|
117
|
+
|
117
118
|
assert_equal 2, $count
|
119
|
+
|
120
|
+
$count = 0
|
121
|
+
|
122
|
+
assert_equal "2gnirtS", a.reverse_text_single_p.last
|
123
|
+
assert_equal 0, $count
|
118
124
|
assert_equal "2gnirtS", a[1].reverse_text_single_p
|
119
|
-
assert_equal
|
125
|
+
assert_equal 0, $count
|
120
126
|
end
|
121
127
|
|
122
|
-
def
|
128
|
+
def _test_property_ary_p_array
|
123
129
|
a = ["String1", "String2"]
|
124
130
|
ReversableString.setup a
|
125
131
|
|
132
|
+
assert_equal "2gnirtS", a.reverse_text_ary_p_array.last
|
133
|
+
|
126
134
|
$count = 0
|
127
135
|
|
128
136
|
assert_equal "2gnirtS", a.reverse_text_ary_p_array.last
|
@@ -131,7 +139,7 @@ class TestEntity < Test::Unit::TestCase
|
|
131
139
|
assert_equal 1, $count
|
132
140
|
end
|
133
141
|
|
134
|
-
def
|
142
|
+
def _test_unpersist
|
135
143
|
a = ["String1", "String2"]
|
136
144
|
ReversableString.setup a
|
137
145
|
|
@@ -160,14 +168,14 @@ class TestEntity < Test::Unit::TestCase
|
|
160
168
|
|
161
169
|
end
|
162
170
|
|
163
|
-
def
|
171
|
+
def _test_persist_annotations
|
164
172
|
string = 'aaabbbccc'
|
165
173
|
ReversableString.setup(string)
|
166
174
|
assert_equal string.length, string.annotation_list.length
|
167
175
|
assert_equal string.length, string.annotation_list.length
|
168
176
|
end
|
169
177
|
|
170
|
-
def
|
178
|
+
def _test_clean_annotations
|
171
179
|
|
172
180
|
string = "test_string"
|
173
181
|
ReversableString.setup string
|
data/test/test_helper.rb
CHANGED
@@ -14,9 +14,10 @@ class Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
def setup
|
16
16
|
Random.new
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
|
18
|
+
Persist.cachedir = Rbbt.tmp.test.persistence.find :user if defined? Persist
|
19
|
+
|
20
|
+
Entity.entity_property_cache = Rbbt.tmp.test.entity_property.find(:user) if defined? Entity
|
20
21
|
end
|
21
22
|
|
22
23
|
def teardown
|
@@ -25,11 +26,16 @@ class Test::Unit::TestCase
|
|
25
26
|
# Persist::CONNECTIONS.values.each do |c| c.close end
|
26
27
|
# Persist::CONNECTIONS.clear
|
27
28
|
#end
|
29
|
+
|
30
|
+
#if defined? Entity
|
31
|
+
# FileUtils.rm_rf Entity.entity_property_cache.find(:user) if Entity.entity_property_cache =~ /tmp\/test/
|
32
|
+
#end
|
28
33
|
end
|
29
34
|
|
30
35
|
def self.datafile_test(file)
|
31
36
|
Path.setup(File.join(File.dirname(__FILE__), 'data', file.to_s))
|
32
37
|
end
|
38
|
+
|
33
39
|
def datafile_test(file)
|
34
40
|
Test::Unit::TestCase.datafile_test(file)
|
35
41
|
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.36
|
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-10-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -326,6 +326,7 @@ files:
|
|
326
326
|
- test/rbbt/knowledge_base/test_entity.rb
|
327
327
|
- test/rbbt/knowledge_base/test_query.rb
|
328
328
|
- test/rbbt/knowledge_base/test_registry.rb
|
329
|
+
- test/rbbt/knowledge_base/test_syndicate.rb
|
329
330
|
- test/rbbt/persist/test_tsv.rb
|
330
331
|
- test/rbbt/persist/tsv/test_cdb.rb
|
331
332
|
- test/rbbt/persist/tsv/test_kyotocabinet.rb
|
@@ -448,6 +449,7 @@ test_files:
|
|
448
449
|
- test/rbbt/knowledge_base/test_registry.rb
|
449
450
|
- test/rbbt/knowledge_base/test_entity.rb
|
450
451
|
- test/rbbt/knowledge_base/test_enrichment.rb
|
452
|
+
- test/rbbt/knowledge_base/test_syndicate.rb
|
451
453
|
- test/rbbt/knowledge_base/test_query.rb
|
452
454
|
- test/rbbt/test_resource.rb
|
453
455
|
- test/rbbt/test_entity.rb
|