rbbt-util 5.44.1 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +2 -2
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +9 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +27 -17
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +11 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +40 -2
data/lib/rbbt/annotations.rb
CHANGED
@@ -1,320 +1,343 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if
|
95
|
-
annotation_values
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
object
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
else
|
151
|
-
self.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
when
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
#
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
object.instance_variable_set(:@
|
258
|
-
object.
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
annotation_values
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
object.
|
282
|
-
|
283
|
-
object
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
object.
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
object.
|
305
|
-
|
306
|
-
object
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
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
|