rbbt-util 5.44.1 → 6.0.4

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.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/bin/rbbt +67 -90
  4. data/bin/rbbt_exec.rb +2 -2
  5. data/etc/app.d/base.rb +2 -2
  6. data/etc/app.d/semaphores.rb +3 -3
  7. data/lib/rbbt/annotations/annotated_array.rb +207 -207
  8. data/lib/rbbt/annotations/refactor.rb +27 -0
  9. data/lib/rbbt/annotations/util.rb +282 -282
  10. data/lib/rbbt/annotations.rb +343 -320
  11. data/lib/rbbt/association/database.rb +200 -225
  12. data/lib/rbbt/association/index.rb +294 -291
  13. data/lib/rbbt/association/item.rb +227 -227
  14. data/lib/rbbt/association/open.rb +35 -34
  15. data/lib/rbbt/association/util.rb +0 -169
  16. data/lib/rbbt/association.rb +2 -4
  17. data/lib/rbbt/entity/identifiers.rb +119 -118
  18. data/lib/rbbt/entity/refactor.rb +12 -0
  19. data/lib/rbbt/entity.rb +319 -315
  20. data/lib/rbbt/hpc/batch.rb +72 -53
  21. data/lib/rbbt/hpc/lsf.rb +2 -2
  22. data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
  23. data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
  24. data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
  25. data/lib/rbbt/hpc/orchestrate.rb +19 -13
  26. data/lib/rbbt/hpc/slurm.rb +18 -18
  27. data/lib/rbbt/knowledge_base/entity.rb +13 -5
  28. data/lib/rbbt/knowledge_base/query.rb +2 -2
  29. data/lib/rbbt/knowledge_base/registry.rb +32 -31
  30. data/lib/rbbt/knowledge_base/traverse.rb +1 -1
  31. data/lib/rbbt/knowledge_base.rb +1 -1
  32. data/lib/rbbt/monitor.rb +36 -25
  33. data/lib/rbbt/persist/refactor.rb +166 -0
  34. data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
  35. data/lib/rbbt/persist/tsv.rb +187 -185
  36. data/lib/rbbt/persist.rb +556 -551
  37. data/lib/rbbt/refactor.rb +20 -0
  38. data/lib/rbbt/resource/path/refactor.rb +178 -0
  39. data/lib/rbbt/resource/path.rb +317 -497
  40. data/lib/rbbt/resource/util.rb +0 -48
  41. data/lib/rbbt/resource.rb +3 -390
  42. data/lib/rbbt/tsv/accessor.rb +2 -838
  43. data/lib/rbbt/tsv/attach.rb +303 -299
  44. data/lib/rbbt/tsv/change_id.rb +244 -245
  45. data/lib/rbbt/tsv/csv.rb +87 -85
  46. data/lib/rbbt/tsv/dumper.rb +2 -100
  47. data/lib/rbbt/tsv/excel.rb +26 -24
  48. data/lib/rbbt/tsv/field_index.rb +4 -1
  49. data/lib/rbbt/tsv/filter.rb +3 -2
  50. data/lib/rbbt/tsv/index.rb +2 -284
  51. data/lib/rbbt/tsv/manipulate.rb +750 -747
  52. data/lib/rbbt/tsv/marshal.rb +3 -3
  53. data/lib/rbbt/tsv/matrix.rb +2 -2
  54. data/lib/rbbt/tsv/parallel/through.rb +2 -1
  55. data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
  56. data/lib/rbbt/tsv/parser.rb +678 -678
  57. data/lib/rbbt/tsv/refactor.rb +195 -0
  58. data/lib/rbbt/tsv/stream.rb +253 -251
  59. data/lib/rbbt/tsv/util.rb +420 -420
  60. data/lib/rbbt/tsv.rb +210 -208
  61. data/lib/rbbt/util/R/eval.rb +4 -4
  62. data/lib/rbbt/util/R/plot.rb +62 -166
  63. data/lib/rbbt/util/R.rb +21 -18
  64. data/lib/rbbt/util/cmd.rb +2 -318
  65. data/lib/rbbt/util/color.rb +269 -269
  66. data/lib/rbbt/util/colorize.rb +89 -89
  67. data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
  68. data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
  69. data/lib/rbbt/util/concurrency/processes.rb +389 -386
  70. data/lib/rbbt/util/config.rb +169 -167
  71. data/lib/rbbt/util/filecache.rb +1 -1
  72. data/lib/rbbt/util/iruby.rb +20 -0
  73. data/lib/rbbt/util/log/progress/report.rb +241 -241
  74. data/lib/rbbt/util/log/progress/util.rb +99 -99
  75. data/lib/rbbt/util/log/progress.rb +102 -102
  76. data/lib/rbbt/util/log/refactor.rb +49 -0
  77. data/lib/rbbt/util/log.rb +486 -532
  78. data/lib/rbbt/util/migrate.rb +2 -2
  79. data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
  80. data/lib/rbbt/util/misc/development.rb +12 -11
  81. data/lib/rbbt/util/misc/exceptions.rb +117 -112
  82. data/lib/rbbt/util/misc/format.rb +2 -230
  83. data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
  84. data/lib/rbbt/util/misc/inspect.rb +2 -476
  85. data/lib/rbbt/util/misc/lock.rb +109 -106
  86. data/lib/rbbt/util/misc/omics.rb +9 -1
  87. data/lib/rbbt/util/misc/pipes.rb +765 -793
  88. data/lib/rbbt/util/misc/refactor.rb +20 -0
  89. data/lib/rbbt/util/misc/ssw.rb +27 -17
  90. data/lib/rbbt/util/misc/system.rb +92 -105
  91. data/lib/rbbt/util/misc.rb +39 -20
  92. data/lib/rbbt/util/named_array/refactor.rb +4 -0
  93. data/lib/rbbt/util/named_array.rb +3 -220
  94. data/lib/rbbt/util/open/refactor.rb +7 -0
  95. data/lib/rbbt/util/open.rb +3 -857
  96. data/lib/rbbt/util/procpath.rb +6 -6
  97. data/lib/rbbt/util/python/paths.rb +27 -0
  98. data/lib/rbbt/util/python/run.rb +115 -0
  99. data/lib/rbbt/util/python/script.rb +110 -0
  100. data/lib/rbbt/util/python/util.rb +3 -3
  101. data/lib/rbbt/util/python.rb +22 -81
  102. data/lib/rbbt/util/semaphore.rb +152 -148
  103. data/lib/rbbt/util/simpleopt.rb +9 -8
  104. data/lib/rbbt/util/ssh/refactor.rb +19 -0
  105. data/lib/rbbt/util/ssh.rb +122 -118
  106. data/lib/rbbt/util/tar.rb +117 -115
  107. data/lib/rbbt/util/tmpfile.rb +69 -67
  108. data/lib/rbbt/util/version.rb +2 -0
  109. data/lib/rbbt/workflow/refactor/entity.rb +11 -0
  110. data/lib/rbbt/workflow/refactor/export.rb +66 -0
  111. data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
  112. data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
  113. data/lib/rbbt/workflow/refactor/task_info.rb +66 -0
  114. data/lib/rbbt/workflow/refactor.rb +150 -0
  115. data/lib/rbbt/workflow/remote_workflow/driver/rest.rb +1 -2
  116. data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
  117. data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
  118. data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
  119. data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
  120. data/lib/rbbt/workflow/remote_workflow.rb +6 -1
  121. data/lib/rbbt/workflow/step/run.rb +766 -766
  122. data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
  123. data/lib/rbbt/workflow/step.rb +2 -362
  124. data/lib/rbbt/workflow/task.rb +118 -118
  125. data/lib/rbbt/workflow/usage.rb +289 -287
  126. data/lib/rbbt/workflow/util/archive.rb +6 -5
  127. data/lib/rbbt/workflow/util/data.rb +1 -1
  128. data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
  129. data/lib/rbbt/workflow/util/trace.rb +79 -44
  130. data/lib/rbbt/workflow.rb +4 -882
  131. data/lib/rbbt-util.rb +21 -13
  132. data/lib/rbbt.rb +16 -3
  133. data/python/rbbt/__init__.py +96 -4
  134. data/python/rbbt/workflow/remote.py +104 -0
  135. data/python/rbbt/workflow.py +64 -0
  136. data/python/test.py +10 -0
  137. data/share/Rlib/plot.R +37 -37
  138. data/share/Rlib/svg.R +22 -5
  139. data/share/install/software/lib/install_helpers +1 -1
  140. data/share/rbbt_commands/hpc/list +2 -3
  141. data/share/rbbt_commands/hpc/orchestrate +4 -4
  142. data/share/rbbt_commands/hpc/tail +2 -0
  143. data/share/rbbt_commands/hpc/task +10 -7
  144. data/share/rbbt_commands/lsf/list +2 -3
  145. data/share/rbbt_commands/lsf/orchestrate +4 -4
  146. data/share/rbbt_commands/lsf/tail +2 -0
  147. data/share/rbbt_commands/lsf/task +10 -7
  148. data/share/rbbt_commands/migrate +1 -1
  149. data/share/rbbt_commands/pbs/list +2 -3
  150. data/share/rbbt_commands/pbs/orchestrate +4 -4
  151. data/share/rbbt_commands/pbs/tail +2 -0
  152. data/share/rbbt_commands/pbs/task +10 -7
  153. data/share/rbbt_commands/resource/produce +8 -1
  154. data/share/rbbt_commands/slurm/list +2 -3
  155. data/share/rbbt_commands/slurm/orchestrate +4 -4
  156. data/share/rbbt_commands/slurm/tail +2 -0
  157. data/share/rbbt_commands/slurm/task +10 -7
  158. data/share/rbbt_commands/system/clean +5 -5
  159. data/share/rbbt_commands/system/status +5 -5
  160. data/share/rbbt_commands/tsv/get +2 -3
  161. data/share/rbbt_commands/tsv/info +10 -13
  162. data/share/rbbt_commands/tsv/keys +18 -14
  163. data/share/rbbt_commands/tsv/slice +2 -2
  164. data/share/rbbt_commands/tsv/transpose +6 -2
  165. data/share/rbbt_commands/workflow/info +20 -24
  166. data/share/rbbt_commands/workflow/list +1 -1
  167. data/share/rbbt_commands/workflow/prov +20 -13
  168. data/share/rbbt_commands/workflow/retry +43 -0
  169. data/share/rbbt_commands/workflow/server +12 -2
  170. data/share/rbbt_commands/workflow/task +80 -73
  171. data/share/rbbt_commands/workflow/write_info +26 -9
  172. data/share/software/opt/ssw/ssw.c +861 -0
  173. data/share/software/opt/ssw/ssw.h +130 -0
  174. data/share/workflow_config.ru +3 -3
  175. metadata +45 -6
@@ -1,227 +1,227 @@
1
- require 'rbbt/entity'
2
-
3
- module AssociationItem
4
- extend Object::Entity
5
-
6
- annotation :knowledge_base
7
- annotation :database
8
- annotation :reverse
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 => :both do
19
- if Array === self
20
- inverted = self.collect do |item|
21
- s,_sep,t= item.partition "~"
22
- new = [t,s] * _sep
23
- end
24
- self.annotate inverted
25
- inverted.reverse = ! reverse
26
- inverted
27
- else
28
- s,_sep,t= self.partition "~"
29
- inverted = self.annotate([t,s] * _sep)
30
- inverted.reverse = ! reverse
31
- inverted
32
- end
33
- end
34
-
35
- property :namespace => :both do
36
- knowledge_base.namespace
37
- end
38
-
39
- property :part => :array2single do
40
- self.clean_annotations.collect{|p| p.partition("~") }
41
- end
42
-
43
- property :target => :array2single do
44
- self.part.collect{|p| p[2]}
45
- end
46
-
47
- property :source => :array2single do
48
- self.clean_annotations.collect{|p| p[/[^~]+/] }
49
- end
50
-
51
- property :target_entity_type => :both do
52
- Entity.formats[target_type].to_s
53
- end
54
-
55
- property :source_entity_type => :both do
56
- Entity.formats[source_type].to_s
57
- end
58
-
59
- property :target_type => :both do
60
- if reverse
61
- knowledge_base.source(database)
62
- else
63
- knowledge_base.target(database)
64
- end
65
- end
66
-
67
- property :source_type => :both do
68
- if reverse
69
- knowledge_base.target(database)
70
- else
71
- knowledge_base.source(database)
72
- end
73
- end
74
-
75
- property :undirected => :both do
76
- knowledge_base.undirected(database)
77
- end
78
-
79
- property :target_entity => :array2single do
80
- type = target_type
81
- knowledge_base.annotate self.target, type, database #if self.target.any?
82
- end
83
-
84
- property :source_entity => :array2single do
85
- type = source_type
86
- knowledge_base.annotate self.source, type, database #if self.source.any?
87
- end
88
-
89
- property :index => :both do |database|
90
- @index ||= knowledge_base.get_index(database)
91
- end
92
- property :value => :array2single do
93
- index = index(database)
94
- value = self.reverse ? index.chunked_values_at(self.invert) : index.chunked_values_at(self)
95
- value.collect{|v| NamedArray.setup(v, index.fields)}
96
- end
97
-
98
- property :info_fields => :both do
99
- knowledge_base.index_fields(database)
100
- end
101
-
102
- property :info => :array2single do
103
- fields = self.info_fields
104
-
105
- return [{}] * self.length if fields.nil? or fields.empty?
106
-
107
- value = self.value
108
- value.collect{|v|
109
- raise "No info for pair; not registered in index" if v.nil?
110
- Hash[*fields.zip(v).flatten]
111
- }
112
- end
113
-
114
- property :tsv => :array do
115
- info_fields = self.info_fields
116
- fields = [self.source_type, self.target_type].concat info_fields
117
- type = [self.source_type, self.target_type] * "~"
118
- tsv = TSV.setup({}, :key_field => type, :fields => fields, :type => :list, :namespace => self.namespace)
119
- index = index(database)
120
- index.with_unnamed do
121
- index.chunked_values_at(self).each_with_index do |v,i|
122
- p = self[i]
123
- source, _sep, target = p.partition("~")
124
- if info_fields.empty?
125
- tsv[p] = [source, target]
126
- else
127
- tsv[p] = [source, target].concat v
128
- end
129
- end
130
- end
131
- tsv.entity_options = {:organism => namespace}
132
- knowledge_base.entity_options.each do |type,options|
133
- tsv.entity_options.merge! options
134
- end
135
- tsv
136
- end
137
-
138
- property :filter => :array do |*args,&block|
139
- block = args.pop if Proc === args.last
140
- keys = tsv.with_unnamed do tsv.select(*args, &block).keys end
141
- keys = self.annotate keys
142
- keys
143
- end
144
-
145
- def self.incidence(pairs, key_field = nil, &block)
146
- matrix = {}
147
- targets = []
148
- sources = []
149
- matches = {}
150
-
151
- pairs.inject([]){|acc,m| acc << m; acc << m.invert if m.respond_to?(:undirected) and m.undirected; acc }.each do |p|
152
- s, sep, t = p.partition "~"
153
-
154
- sources << s
155
- targets << t
156
- if block_given?
157
- matches[s] ||= Hash.new{nil}
158
- value = block.call p
159
- matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
160
- else
161
- matches[s] ||= Hash.new{false}
162
- matches[s][t] ||= true
163
- end
164
- end
165
-
166
- sources.uniq!
167
- targets = targets.uniq.sort
168
-
169
- matches.each do |s,hash|
170
- matrix[s] = hash.values_at(*targets)
171
- end
172
-
173
- defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
174
- end
175
-
176
- def self.adjacency(pairs, key_field = nil, &block)
177
- incidence = incidence(pairs, key_field, &block)
178
-
179
- targets = incidence.fields
180
- adjacency = TSV.setup({}, :key_field => incidence.key_field, :fields => ["Target"], :type => :double)
181
- TSV.traverse incidence, :into => adjacency, :unnamed => true do |k,values|
182
- target_values = targets.zip(values).reject{|t,v| v.nil? }.collect{|t,v| [t,v]}
183
- next if target_values.empty?
184
- [k, Misc.zip_fields(target_values)]
185
- end
186
- end
187
-
188
- def self._select_match(orig, elem)
189
- if Array === orig and Array === elem
190
- (orig & elem).any?
191
- elsif Array === orig
192
- orig.include? elem
193
- elsif Array === elem
194
- elem.include? orig
195
- else
196
- elem === orif
197
- end
198
- false
199
- end
200
-
201
- def self.select(list, method = nil, &block)
202
- if method and method.any?
203
- list.select do |item|
204
- method.collect do |key,value|
205
- case key
206
- when :target
207
- _select_match item.target, value
208
- when :source
209
- _select_match item.source, value
210
- else
211
- orig = item.info[key]
212
- orig = orig.split(";;") if String orig
213
- _select_match orig, value
214
- end
215
- end
216
- end
217
- else
218
- list.select(&block)
219
- end
220
- end
221
- end
222
-
223
- module TSV
224
- def self.incidence(tsv)
225
- AssociationItem.incidence Association.index(tsv, :persist => false).keys
226
- end
227
- end
1
+ #require_relative '../entity'
2
+ #
3
+ #module AssociationItem
4
+ # extend Entity
5
+ #
6
+ # annotation :knowledge_base
7
+ # annotation :database
8
+ # annotation :reverse
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 => :both do
19
+ # if Array === self
20
+ # inverted = self.collect do |item|
21
+ # s,_sep,t= item.partition "~"
22
+ # new = [t,s] * _sep
23
+ # end
24
+ # self.annotate inverted
25
+ # inverted.reverse = ! reverse
26
+ # inverted
27
+ # else
28
+ # s,_sep,t= self.partition "~"
29
+ # inverted = self.annotate([t,s] * _sep)
30
+ # inverted.reverse = ! reverse
31
+ # inverted
32
+ # end
33
+ # end
34
+ #
35
+ # property :namespace => :both do
36
+ # knowledge_base.namespace
37
+ # end
38
+ #
39
+ # property :part => :array2single do
40
+ # self.clean_annotations.collect{|p| p.partition("~") }
41
+ # end
42
+ #
43
+ # property :target => :array2single do
44
+ # self.part.collect{|p| p[2]}
45
+ # end
46
+ #
47
+ # property :source => :array2single do
48
+ # self.clean_annotations.collect{|p| p[/[^~]+/] }
49
+ # end
50
+ #
51
+ # property :target_entity_type => :both do
52
+ # Entity.formats[target_type].to_s
53
+ # end
54
+ #
55
+ # property :source_entity_type => :both do
56
+ # Entity.formats[source_type].to_s
57
+ # end
58
+ #
59
+ # property :target_type => :both do
60
+ # if reverse
61
+ # knowledge_base.source(database)
62
+ # else
63
+ # knowledge_base.target(database)
64
+ # end
65
+ # end
66
+ #
67
+ # property :source_type => :both do
68
+ # if reverse
69
+ # knowledge_base.target(database)
70
+ # else
71
+ # knowledge_base.source(database)
72
+ # end
73
+ # end
74
+ #
75
+ # property :undirected => :both do
76
+ # knowledge_base.undirected(database)
77
+ # end
78
+ #
79
+ # property :target_entity => :array2single do
80
+ # type = target_type
81
+ # knowledge_base.annotate self.target, type, database #if self.target.any?
82
+ # end
83
+ #
84
+ # property :source_entity => :array2single do
85
+ # type = source_type
86
+ # knowledge_base.annotate self.source, type, database #if self.source.any?
87
+ # end
88
+ #
89
+ # property :index => :both do |database|
90
+ # @index ||= knowledge_base.get_index(database)
91
+ # end
92
+ # property :value => :array2single do
93
+ # index = index(database)
94
+ # value = self.reverse ? index.chunked_values_at(self.invert) : index.chunked_values_at(self)
95
+ # value.collect{|v| NamedArray.setup(v, index.fields)}
96
+ # end
97
+ #
98
+ # property :info_fields => :both do
99
+ # knowledge_base.index_fields(database)
100
+ # end
101
+ #
102
+ # property :info => :array2single do
103
+ # fields = self.info_fields
104
+ #
105
+ # return [{}] * self.length if fields.nil? or fields.empty?
106
+ #
107
+ # value = self.value
108
+ # value.collect{|v|
109
+ # raise "No info for pair; not registered in index" if v.nil?
110
+ # Hash[*fields.zip(v).flatten]
111
+ # }
112
+ # end
113
+ #
114
+ # property :tsv => :array do
115
+ # info_fields = self.info_fields
116
+ # fields = [self.source_type, self.target_type].concat info_fields
117
+ # type = [self.source_type, self.target_type] * "~"
118
+ # tsv = TSV.setup({}, :key_field => type, :fields => fields, :type => :list, :namespace => self.namespace)
119
+ # index = index(database)
120
+ # index.with_unnamed do
121
+ # index.chunked_values_at(self).each_with_index do |v,i|
122
+ # p = self[i]
123
+ # source, _sep, target = p.partition("~")
124
+ # if info_fields.empty?
125
+ # tsv[p] = [source, target]
126
+ # else
127
+ # tsv[p] = [source, target].concat v
128
+ # end
129
+ # end
130
+ # end
131
+ # tsv.entity_options = {:namespace => namespace}
132
+ # knowledge_base.entity_options.each do |type,options|
133
+ # tsv.entity_options.merge! options
134
+ # end
135
+ # tsv
136
+ # end
137
+ #
138
+ # property :filter => :array do |*args,&block|
139
+ # block = args.pop if Proc === args.last
140
+ # keys = tsv.with_unnamed do tsv.select(*args, &block).keys end
141
+ # keys = self.annotate keys
142
+ # keys
143
+ # end
144
+ #
145
+ # def self.incidence(pairs, key_field = nil, &block)
146
+ # matrix = {}
147
+ # targets = []
148
+ # sources = []
149
+ # matches = {}
150
+ #
151
+ # pairs.inject([]){|acc,m| acc << m; acc << m.invert if m.respond_to?(:undirected) and m.undirected; acc }.each do |p|
152
+ # s, sep, t = p.partition "~"
153
+ #
154
+ # sources << s
155
+ # targets << t
156
+ # if block_given?
157
+ # matches[s] ||= Hash.new{nil}
158
+ # value = block.call p
159
+ # matches[s][t] = value unless value.nil? or (mv = matches[s][t] and value > mv)
160
+ # else
161
+ # matches[s] ||= Hash.new{false}
162
+ # matches[s][t] ||= true
163
+ # end
164
+ # end
165
+ #
166
+ # sources.uniq!
167
+ # targets = targets.uniq.sort
168
+ #
169
+ # matches.each do |s,hash|
170
+ # matrix[s] = hash.values_at(*targets)
171
+ # end
172
+ #
173
+ # defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
174
+ # end
175
+ #
176
+ # def self.adjacency(pairs, key_field = nil, &block)
177
+ # incidence = incidence(pairs, key_field, &block)
178
+ #
179
+ # targets = incidence.fields
180
+ # adjacency = TSV.setup({}, :key_field => incidence.key_field, :fields => ["Target"], :type => :double)
181
+ # TSV.traverse incidence, :into => adjacency, :unnamed => true do |k,values|
182
+ # target_values = targets.zip(values).reject{|t,v| v.nil? }.collect{|t,v| [t,v]}
183
+ # next if target_values.empty?
184
+ # [k, Misc.zip_fields(target_values)]
185
+ # end
186
+ # end
187
+ #
188
+ # def self._select_match(orig, elem)
189
+ # if Array === orig and Array === elem
190
+ # (orig & elem).any?
191
+ # elsif Array === orig
192
+ # orig.include? elem
193
+ # elsif Array === elem
194
+ # elem.include? orig
195
+ # else
196
+ # elem === orif
197
+ # end
198
+ # false
199
+ # end
200
+ #
201
+ # def self.select(list, method = nil, &block)
202
+ # if method and method.any?
203
+ # list.select do |item|
204
+ # method.collect do |key,value|
205
+ # case key
206
+ # when :target
207
+ # _select_match item.target, value
208
+ # when :source
209
+ # _select_match item.source, value
210
+ # else
211
+ # orig = item.info[key]
212
+ # orig = orig.split(";;") if String orig
213
+ # _select_match orig, value
214
+ # end
215
+ # end
216
+ # end
217
+ # else
218
+ # list.select(&block)
219
+ # end
220
+ # end
221
+ #end
222
+ #
223
+ #module TSV
224
+ # def self.incidence(tsv)
225
+ # AssociationItem.incidence Association.index(tsv, :persist => false).keys
226
+ # end
227
+ #end
@@ -1,35 +1,36 @@
1
- require 'rbbt/association/database'
1
+ #require 'rbbt/association/database'
2
2
 
3
- module Association
4
- def self.version_file(file, namespace)
5
- old_file, file = file, file.sub('NAMESPACE', namespace) if namespace and String === file
6
- old_file.annotate file if Path === old_file
7
- file
8
- end
9
-
10
- def self.open(file, options = nil, persist_options = nil)
11
- options = options.nil? ? {} : options.dup
12
- persist_options = persist_options.nil? ? Misc.pull_keys(options, :persist) : persist_options.dup
13
-
14
- options = Misc.add_defaults options, :zipped => true, :merge => true, :monitor => {:desc => "Opening database #{Misc.fingerprint file}"}
15
- options[:zipped] = false unless options[:merge]
16
- persist_options = Misc.add_defaults persist_options.dup, :persist => true, :dir => Rbbt.var.associations
17
- persist = persist_options[:persist]
18
-
19
- file = version_file(file, options[:namespace]) if options[:namespace] and String === file
20
-
21
- data = Persist.persist_tsv(file, nil, options, persist_options.merge(:prefix => "Association Database")) do |data|
22
- file = file.call if Proc === file
23
-
24
- options = options.dup
25
- data.serializer = :double if data.respond_to? :serializer
26
-
27
- tsv = Association.database(file, options.merge(:unnamed => true, :data => data, :type => :double))
28
-
29
- data
30
- end
31
- data.entity_options = options[:entity_options] if options[:entity_options]
32
- data
33
- end
34
-
35
- end
3
+ #module Association
4
+ # def self.version_file(file, namespace)
5
+ # old_file, file = file, file.sub('NAMESPACE', namespace) if namespace and String === file
6
+ # old_file.annotate file if Path === old_file
7
+ # file
8
+ # end
9
+ #
10
+ # def self.open(file, options = nil, persist_options = nil)
11
+ # options = options.nil? ? {} : options.dup
12
+ # persist_options = persist_options.nil? ? IndiferentHash.pull_keys(options, :persist) : persist_options.dup
13
+ #
14
+ # options = IndiferentHash.add_defaults options, :zipped => true, :merge => true, :monitor => {:desc => "Opening database #{Log.fingerprint file}"}
15
+ # options[:zipped] = false unless options[:merge]
16
+ # persist_options = IndiferentHash.add_defaults persist_options.dup, :persist => true, :dir => Rbbt.var.associations
17
+ # persist = persist_options[:persist]
18
+ #
19
+ # file = version_file(file, options[:namespace]) if options[:namespace] and String === file
20
+ #
21
+ # data = Persist.persist_tsv(file, nil, options, persist_options.merge(:prefix => "Association Database")) do |data|
22
+ # data = {} if data.nil?
23
+ # file = file.call if Proc === file
24
+ #
25
+ # options = options.dup
26
+ # data.serializer = :double if data.respond_to? :serializer
27
+ #
28
+ # tsv = Association.database(file, options.merge(:unnamed => true, :data => data, :type => :double))
29
+ #
30
+ # data
31
+ # end
32
+ # data.entity_options = options[:entity_options] if options[:entity_options]
33
+ # data
34
+ # end
35
+ #
36
+ #end