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,320 +1,343 @@
1
- require 'rbbt/tsv'
2
- require 'rbbt/util/misc'
3
- require 'rbbt/annotations/annotated_array'
4
- require 'rbbt/annotations/util'
5
-
6
- #{{{ ANNOTATED
7
-
8
- module Annotated
9
- attr_accessor :container, :container_index
10
-
11
- def annotation_values
12
- @annotation_values ||= {}
13
- end
14
-
15
- def detach_annotations
16
- @annotation_values = @annotation_values.dup
17
- @annotation_values.instance_variable_set(:@annotation_md5, nil)
18
- @shared_annotations = false
19
- end
20
-
21
- def reset
22
- @info = nil
23
- @id = nil
24
- @self_md5 = nil
25
- annotation_values.instance_variable_set(:@annotation_md5, nil)
26
- end
27
-
28
- def annotation_types
29
-
30
- @annotation_types ||= class << self; self; end.
31
- included_modules.
32
- select{|m|
33
- Annotation === m
34
- }
35
- end
36
-
37
- def annotations
38
- if @annotations.nil?
39
- @annotations = []
40
-
41
- annotation_types.each do |annotation_type|
42
- @annotations.concat annotation_type.annotations
43
- end
44
-
45
- @annotations
46
- else
47
- @annotations
48
- end
49
- end
50
-
51
- def masked_annotations
52
- if @masked_annotations.nil?
53
- @masked_annotations = []
54
-
55
- annotation_types.each do |annotation_type|
56
- @masked_annotations.concat annotation_type.masked_annotations
57
- end
58
-
59
- @masked_annotations
60
- else
61
- @masked_annotations
62
- end
63
- end
64
-
65
- def unmasked_annotations
66
- @unmasked_annotations ||= annotations - masked_annotations
67
- end
68
-
69
- def info(masked = false)
70
-
71
- if @info.nil?
72
- annotation_values = self.annotation_values
73
- annotation_values = annotation_values.dup unless annotation_values.nil?
74
- info = annotation_values
75
- info[:annotation_types] = annotation_types
76
- info[:annotated_array] = true if AnnotatedArray === self
77
- @info = info
78
- end
79
-
80
- if masked
81
- if @masked_info.nil?
82
- @masked_info = @info.dup
83
- masked_annotations.each do |annotation|
84
- @masked_info.delete annotation
85
- end
86
- end
87
- @masked_info
88
- else
89
- @info
90
- end
91
- end
92
-
93
- def annotation_md5
94
- if annotation_values.instance_variable_get(:@annotation_md5).nil?
95
- annotation_values.instance_variable_set(:@annotation_md5, Misc.hash2md5(annotation_values))
96
- end
97
- annotation_values.instance_variable_get(:@annotation_md5)
98
- end
99
-
100
- def self_md5
101
- @self_md5 ||= Misc.digest(annotation_md5 + self.to_s)
102
- end
103
-
104
- # ToDo This does not make much sense, why not change :id directly
105
- def id
106
- @id ||= self.respond_to?(:annotation_id) ?
107
- annotation_id : self_md5
108
- end
109
-
110
- def annotate(object)
111
-
112
- return object unless Array === object or String === object
113
-
114
- annotation_types.each do |annotation|
115
- object.extend annotation unless annotation === object
116
- end
117
-
118
- object.instance_variable_set(:@annotation_types, nil)
119
-
120
- if object.instance_variables.include?(:@annotation_values)
121
- hash = {}
122
- object.instance_variable_get(:@annotation_values).each{|k,v| hash[k] = v}
123
- self.annotation_values.each{|k,v| hash[k] = v unless v.nil?}
124
-
125
- object.instance_variable_set(:@annotation_values, hash)
126
- object.instance_variable_set(:@shared_annotations, false)
127
- else
128
- object.instance_variable_set(:@annotation_values, self.annotation_values)
129
- object.instance_variable_set(:@shared_annotations, true)
130
- @shared_annotations = true
131
- end
132
-
133
- object.extend AnnotatedArray if AnnotatedArray === self and Array === object
134
-
135
- object
136
- end
137
-
138
- def clean_annotations(recursive = false)
139
- case
140
- when self.nil?
141
- nil
142
- when Array === self
143
- if recursive
144
- [].concat self.collect{|e| e.respond_to?(:clean_annotations)? e.clean_annotations : e}
145
- else
146
- [].concat self
147
- end
148
- when String === self
149
- "" << self
150
- else
151
- self.dup
152
- end
153
- end
154
-
155
- def self.purge(object)
156
- case object
157
- when Path
158
- object
159
- when String
160
- object.respond_to?(:clean_annotations) ?
161
- object.clean_annotations :
162
- object
163
- when Array
164
- object.respond_to?(:clean_annotations) ?
165
- object.clean_annotations(true) :
166
- object.inject([]){|acc,e| acc << Annotated.purge(e); acc}
167
- when TSV
168
- object.unnamed = true
169
- object
170
- when Hash
171
- new = {}
172
- object.each do |key, value|
173
- Annotated.purge key
174
- new[key] = Annotated.purge value
175
- end
176
- new
177
- else
178
- object
179
- end
180
- end
181
-
182
- def make_list
183
- new = [self]
184
- self.annotate(new)
185
- new.extend AnnotatedArray
186
- new
187
- end
188
- end
189
-
190
-
191
- #{{{ ANNOTATION
192
-
193
- module Annotation
194
- attr_accessor :annotations, :masked_annotations
195
-
196
- def annotations
197
- @annotations ||= []
198
- end
199
-
200
- def masked_annotations
201
- @masked_annotations ||= []
202
- end
203
-
204
- def unmasked_annotations
205
- annotations - masked_annotations
206
- end
207
-
208
- def annotation(*list)
209
-
210
- list.each do |annot|
211
- next if annotations.include? annot.to_sym
212
- annotations << annot.to_sym
213
-
214
- # Getter
215
- self.send(:define_method, annot.to_s) do
216
- annotation_values[annot]
217
- end
218
-
219
- # Setter
220
- self.send(:define_method, "#{ annot}=") do |value|
221
- if @shared_annotations
222
- detach_annotations # avoid side effects
223
- end
224
-
225
- reset
226
-
227
- annotation_values[annot] = value
228
- end
229
- end
230
- end
231
-
232
- def setup_hash(object, values)
233
- object.instance_variable_set(:@annotation_values, values)
234
- object.instance_variable_set(:@shared_annotations, true)
235
- object.reset
236
- object
237
- end
238
-
239
- def clean_and_setup_hash(object, hash)
240
- object.instance_variable_set(:@annotation_values, nil) if object.instance_variable_get(:@annotation_values).nil?
241
- annotation_values = object.instance_variable_get(:@annotation_values)
242
- annotation_values = annotation_values.nil? ? {} : annotation_values.dup
243
- annotation_values.instance_variable_set(:@annotation_md5, nil)
244
-
245
- hash.each do |key, value|
246
- begin
247
- next unless @annotations.include?(key = key.to_sym)
248
- rescue
249
- next
250
- end
251
-
252
- value = value.split("|") if String === value and value.include? "|"
253
-
254
- annotation_values[key] = value
255
- end
256
-
257
- object.instance_variable_set(:@annotation_values, annotation_values)
258
- object.instance_variable_set(:@shared_annotations, false)
259
-
260
- object.reset
261
-
262
- object
263
- end
264
-
265
- def setup_positional(object, *values)
266
- annotation_values = object.instance_variable_get(:@annotation_values)
267
- annotation_values = annotation_values.nil? ? {} : annotation_values.dup
268
- annotation_values.instance_variable_set(:@annotation_md5, nil)
269
-
270
- annotations.each_with_index do |name,i|
271
- value = values[i]
272
-
273
- value = value.split("|") if String === value and value.include? "|"
274
-
275
- annotation_values[name] = value
276
- end
277
-
278
-
279
- object.instance_variable_set(:@annotation_values, annotation_values)
280
-
281
- object.reset
282
-
283
- object
284
- end
285
-
286
- def setup(object, *values)
287
- return object if object.nil?
288
-
289
- object.extend self
290
- object.extend AnnotatedArray if Array === object
291
- object.instance_variable_set(:@annotation_types, nil)
292
-
293
- if Hash === (hash = values.last)
294
- setup_positional(object, *values[0..-2]) if values.length > 1
295
- clean_and_setup_hash(object, hash)
296
- else
297
- setup_positional(object, *values)
298
- end
299
-
300
- object
301
- end
302
-
303
- def fast_setup(object, hash, shared = false)
304
- object.extend self
305
- object.extend AnnotatedArray if Array === object
306
- object.instance_variable_set(:@annotation_values, hash)
307
- object.instance_variable_set(:@shared_annotations, true) if shared
308
- end
309
-
310
- def self.extended(object)
311
- object.module_eval do
312
- include Annotated
313
- end
314
- end
315
-
316
- def included(mod)
317
- mod.instance_variable_set(:@annotations, self.annotations.dup)
318
- mod.instance_variable_set(:@masked_annotations, self.masked_annotations.dup)
319
- end
320
- end
1
+ require_relative 'refactor'
2
+ Rbbt.require_instead 'scout/annotation'
3
+ Rbbt.require_instead 'scout/tsv'
4
+ require_relative 'annotations/refactor'
5
+ #module Annotation
6
+ # def self.extended(base)
7
+ # meta = class << base; self; end
8
+ #
9
+ # base.extend MetaExtension
10
+ #
11
+ # meta.define_method(:annotations) do
12
+ # meta.class_variable_get(:@@extension_attrs)
13
+ # end
14
+ #
15
+ # meta.define_method(:annotation) do |*args|
16
+ # base.extension_attr(*args)
17
+ # end
18
+ #
19
+ # base.define_method(:annotation_types) do
20
+ # self.extension_types
21
+ # end
22
+ # end
23
+ #end
24
+ ##require 'rbbt/tsv'
25
+ ##require 'rbbt/util/misc'
26
+ #require 'rbbt/annotations/annotated_array'
27
+ #require 'rbbt/annotations/util'
28
+ #
29
+ ##{{{ ANNOTATED
30
+ #
31
+ #module Annotated
32
+ # attr_accessor :container, :container_index
33
+ #
34
+ # def annotation_values
35
+ # @annotation_values ||= {}
36
+ # end
37
+ #
38
+ # def detach_annotations
39
+ # @annotation_values = @annotation_values.dup
40
+ # @annotation_values.instance_variable_set(:@annotation_md5, nil)
41
+ # @shared_annotations = false
42
+ # end
43
+ #
44
+ # def reset
45
+ # @info = nil
46
+ # @id = nil
47
+ # @self_md5 = nil
48
+ # annotation_values.instance_variable_set(:@annotation_md5, nil)
49
+ # end
50
+ #
51
+ # def annotation_types
52
+ #
53
+ # @annotation_types ||= class << self; self; end.
54
+ # included_modules.
55
+ # select{|m|
56
+ # Annotation === m
57
+ # }
58
+ # end
59
+ #
60
+ # def annotations
61
+ # if @annotations.nil?
62
+ # @annotations = []
63
+ #
64
+ # annotation_types.each do |annotation_type|
65
+ # @annotations.concat annotation_type.annotations
66
+ # end
67
+ #
68
+ # @annotations
69
+ # else
70
+ # @annotations
71
+ # end
72
+ # end
73
+ #
74
+ # def masked_annotations
75
+ # if @masked_annotations.nil?
76
+ # @masked_annotations = []
77
+ #
78
+ # annotation_types.each do |annotation_type|
79
+ # @masked_annotations.concat annotation_type.masked_annotations
80
+ # end
81
+ #
82
+ # @masked_annotations
83
+ # else
84
+ # @masked_annotations
85
+ # end
86
+ # end
87
+ #
88
+ # def unmasked_annotations
89
+ # @unmasked_annotations ||= annotations - masked_annotations
90
+ # end
91
+ #
92
+ # def info(masked = false)
93
+ #
94
+ # if @info.nil?
95
+ # annotation_values = self.annotation_values
96
+ # annotation_values = annotation_values.dup unless annotation_values.nil?
97
+ # info = annotation_values
98
+ # info[:annotation_types] = annotation_types
99
+ # info[:annotated_array] = true if AnnotatedArray === self
100
+ # @info = info
101
+ # end
102
+ #
103
+ # if masked
104
+ # if @masked_info.nil?
105
+ # @masked_info = @info.dup
106
+ # masked_annotations.each do |annotation|
107
+ # @masked_info.delete annotation
108
+ # end
109
+ # end
110
+ # @masked_info
111
+ # else
112
+ # @info
113
+ # end
114
+ # end
115
+ #
116
+ # def annotation_md5
117
+ # if annotation_values.instance_variable_get(:@annotation_md5).nil?
118
+ # annotation_values.instance_variable_set(:@annotation_md5, Misc.digest(annotation_values))
119
+ # end
120
+ # annotation_values.instance_variable_get(:@annotation_md5)
121
+ # end
122
+ #
123
+ # def self_md5
124
+ # @self_md5 ||= Misc.digest(annotation_md5 + self.to_s)
125
+ # end
126
+ #
127
+ # # ToDo This does not make much sense, why not change :id directly
128
+ # def id
129
+ # @id ||= self.respond_to?(:annotation_id) ?
130
+ # annotation_id : self_md5
131
+ # end
132
+ #
133
+ # def annotate(object)
134
+ #
135
+ # return object unless Array === object or String === object
136
+ #
137
+ # annotation_types.each do |annotation|
138
+ # object.extend annotation unless annotation === object
139
+ # end
140
+ #
141
+ # object.instance_variable_set(:@annotation_types, nil)
142
+ #
143
+ # if object.instance_variables.include?(:@annotation_values)
144
+ # hash = {}
145
+ # object.instance_variable_get(:@annotation_values).each{|k,v| hash[k] = v}
146
+ # self.annotation_values.each{|k,v| hash[k] = v unless v.nil?}
147
+ #
148
+ # object.instance_variable_set(:@annotation_values, hash)
149
+ # object.instance_variable_set(:@shared_annotations, false)
150
+ # else
151
+ # object.instance_variable_set(:@annotation_values, self.annotation_values)
152
+ # object.instance_variable_set(:@shared_annotations, true)
153
+ # @shared_annotations = true
154
+ # end
155
+ #
156
+ # object.extend AnnotatedArray if AnnotatedArray === self and Array === object
157
+ #
158
+ # object
159
+ # end
160
+ #
161
+ # def clean_annotations(recursive = false)
162
+ # case
163
+ # when self.nil?
164
+ # nil
165
+ # when Array === self
166
+ # if recursive
167
+ # [].concat self.collect{|e| e.respond_to?(:clean_annotations)? e.clean_annotations : e}
168
+ # else
169
+ # [].concat self
170
+ # end
171
+ # when String === self
172
+ # "" << self
173
+ # else
174
+ # self.dup
175
+ # end
176
+ # end
177
+ #
178
+ # def self.purge(object)
179
+ # case object
180
+ # when Path
181
+ # object
182
+ # when String
183
+ # object.respond_to?(:clean_annotations) ?
184
+ # object.clean_annotations :
185
+ # object
186
+ # when Array
187
+ # object.respond_to?(:clean_annotations) ?
188
+ # object.clean_annotations(true) :
189
+ # object.inject([]){|acc,e| acc << Annotated.purge(e); acc}
190
+ # when TSV
191
+ # object.unnamed = true
192
+ # object
193
+ # when Hash
194
+ # new = {}
195
+ # object.each do |key, value|
196
+ # Annotated.purge key
197
+ # new[key] = Annotated.purge value
198
+ # end
199
+ # new
200
+ # else
201
+ # object
202
+ # end
203
+ # end
204
+ #
205
+ # def make_list
206
+ # new = [self]
207
+ # self.annotate(new)
208
+ # new.extend AnnotatedArray
209
+ # new
210
+ # end
211
+ #end
212
+ #
213
+ #
214
+ ##{{{ ANNOTATION
215
+ #
216
+ #module Annotation
217
+ # attr_accessor :annotations, :masked_annotations
218
+ #
219
+ # def annotations
220
+ # @annotations ||= []
221
+ # end
222
+ #
223
+ # def masked_annotations
224
+ # @masked_annotations ||= []
225
+ # end
226
+ #
227
+ # def unmasked_annotations
228
+ # annotations - masked_annotations
229
+ # end
230
+ #
231
+ # def annotation(*list)
232
+ #
233
+ # list.each do |annot|
234
+ # next if annotations.include? annot.to_sym
235
+ # annotations << annot.to_sym
236
+ #
237
+ # # Getter
238
+ # self.send(:define_method, annot.to_s) do
239
+ # annotation_values[annot]
240
+ # end
241
+ #
242
+ # # Setter
243
+ # self.send(:define_method, "#{ annot}=") do |value|
244
+ # if @shared_annotations
245
+ # detach_annotations # avoid side effects
246
+ # end
247
+ #
248
+ # reset
249
+ #
250
+ # annotation_values[annot] = value
251
+ # end
252
+ # end
253
+ # end
254
+ #
255
+ # def setup_hash(object, values)
256
+ # object.instance_variable_set(:@annotation_values, values)
257
+ # object.instance_variable_set(:@shared_annotations, true)
258
+ # object.reset
259
+ # object
260
+ # end
261
+ #
262
+ # def clean_and_setup_hash(object, hash)
263
+ # object.instance_variable_set(:@annotation_values, nil) if object.instance_variable_get(:@annotation_values).nil?
264
+ # annotation_values = object.instance_variable_get(:@annotation_values)
265
+ # annotation_values = annotation_values.nil? ? {} : annotation_values.dup
266
+ # annotation_values.instance_variable_set(:@annotation_md5, nil)
267
+ #
268
+ # hash.each do |key, value|
269
+ # begin
270
+ # next unless @annotations.include?(key = key.to_sym)
271
+ # rescue
272
+ # next
273
+ # end
274
+ #
275
+ # value = value.split("|") if String === value and value.include? "|"
276
+ #
277
+ # annotation_values[key] = value
278
+ # end
279
+ #
280
+ # object.instance_variable_set(:@annotation_values, annotation_values)
281
+ # object.instance_variable_set(:@shared_annotations, false)
282
+ #
283
+ # object.reset
284
+ #
285
+ # object
286
+ # end
287
+ #
288
+ # def setup_positional(object, *values)
289
+ # annotation_values = object.instance_variable_get(:@annotation_values)
290
+ # annotation_values = annotation_values.nil? ? {} : annotation_values.dup
291
+ # annotation_values.instance_variable_set(:@annotation_md5, nil)
292
+ #
293
+ # annotations.each_with_index do |name,i|
294
+ # value = values[i]
295
+ #
296
+ # value = value.split("|") if String === value and value.include? "|"
297
+ #
298
+ # annotation_values[name] = value
299
+ # end
300
+ #
301
+ #
302
+ # object.instance_variable_set(:@annotation_values, annotation_values)
303
+ #
304
+ # object.reset
305
+ #
306
+ # object
307
+ # end
308
+ #
309
+ # def setup(object, *values)
310
+ # return object if object.nil?
311
+ #
312
+ # object.extend self
313
+ # object.extend AnnotatedArray if Array === object
314
+ # object.instance_variable_set(:@annotation_types, nil)
315
+ #
316
+ # if Hash === (hash = values.last)
317
+ # setup_positional(object, *values[0..-2]) if values.length > 1
318
+ # clean_and_setup_hash(object, hash)
319
+ # else
320
+ # setup_positional(object, *values)
321
+ # end
322
+ #
323
+ # object
324
+ # end
325
+ #
326
+ # def fast_setup(object, hash, shared = false)
327
+ # object.extend self
328
+ # object.extend AnnotatedArray if Array === object
329
+ # object.instance_variable_set(:@annotation_values, hash)
330
+ # object.instance_variable_set(:@shared_annotations, true) if shared
331
+ # end
332
+ #
333
+ # def self.extended(object)
334
+ # object.module_eval do
335
+ # include Annotated
336
+ # end
337
+ # end
338
+ #
339
+ # def included(mod)
340
+ # mod.instance_variable_set(:@annotations, self.annotations.dup)
341
+ # mod.instance_variable_set(:@masked_annotations, self.masked_annotations.dup)
342
+ # end
343
+ #end