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/tsv/change_id.rb
CHANGED
@@ -1,245 +1,244 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
identifiers =
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
new[k] = v
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if
|
31
|
-
|
32
|
-
|
33
|
-
tsv = tsv.attach identifiers, :fields => [format], :persist_input => true
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
tsv = tsv.
|
40
|
-
|
41
|
-
tsv = tsv.
|
42
|
-
|
43
|
-
tsv
|
44
|
-
|
45
|
-
tsv
|
46
|
-
|
47
|
-
tsv
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
identifiers =
|
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
|
-
_values
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
Log.
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
new =
|
178
|
-
new
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
identifier_files
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
new_options = tsv.
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
dumper
|
205
|
-
dumper
|
206
|
-
|
207
|
-
new_key
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
dumper
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
values
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
values
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
new
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
new
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
1
|
+
require_relative '../refactor'
|
2
|
+
Rbbt.require_instead 'scout/tsv'
|
3
|
+
#require 'rbbt/tsv'
|
4
|
+
#require 'rbbt/persist'
|
5
|
+
#
|
6
|
+
#
|
7
|
+
#module TSV
|
8
|
+
# def self.change_key(tsv, format, options = {}, &block)
|
9
|
+
# options = Misc.add_defaults options, :persist => false, :identifiers => tsv.identifiers
|
10
|
+
#
|
11
|
+
# identifiers, persist_input = Misc.process_options options, :identifiers, :persist_input
|
12
|
+
#
|
13
|
+
# identifiers = Organism.identifiers(tsv.namespace) if identifiers.nil? and tsv.namespace
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# if ! tsv.fields.include?(format)
|
17
|
+
# new = {}
|
18
|
+
# tsv.each do |k,v|
|
19
|
+
# if v === String or v === Array
|
20
|
+
# new[k] = v.dup
|
21
|
+
# else
|
22
|
+
# new[k] = v
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# orig_fields = tsv.fields
|
26
|
+
# tsv = tsv.annotate new
|
27
|
+
# new.fields = new.fields.collect{|f| "TMP-" << f }
|
28
|
+
#
|
29
|
+
# orig_type = tsv.type
|
30
|
+
# tsv = tsv.to_double if orig_type != :double
|
31
|
+
#
|
32
|
+
# if Array === identifiers
|
33
|
+
# tsv = tsv.attach identifiers.first, :fields => [format], :persist_input => true, :identifiers => identifiers.last
|
34
|
+
# else
|
35
|
+
# tsv = tsv.attach identifiers, :fields => [format], :persist_input => true
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# tsv = tsv.reorder(format, tsv.fields[0..-2])
|
40
|
+
#
|
41
|
+
# tsv = tsv.to_flat if orig_type == :flat
|
42
|
+
#
|
43
|
+
# tsv = tsv.to_list(&block) if orig_type == :list
|
44
|
+
#
|
45
|
+
# tsv.fields = orig_fields
|
46
|
+
#
|
47
|
+
# tsv
|
48
|
+
# else
|
49
|
+
# tsv.reorder(format)
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# def change_key(format, options = {}, &block)
|
54
|
+
# options = Misc.add_defaults options, :identifiers => self.identifiers
|
55
|
+
# TSV.change_key(self, format, options, &block)
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# def self.swap_id(tsv, field, format, options = {}, &block)
|
59
|
+
# options = Misc.add_defaults options, :persist => false, :identifiers => tsv.identifiers, :compact => true
|
60
|
+
#
|
61
|
+
# identifiers, persist_input, compact = Misc.process_options options, :identifiers, :persist, :compact
|
62
|
+
# identifiers = tsv.identifier_files.first if identifiers.nil?
|
63
|
+
# identifiers = Organism.identifiers(tsv.namespace) if defined?(Organism) && identifiers.nil? && tsv.namespace && Organism.identifiers(tsv.namespace).exists?
|
64
|
+
# identifiers.namespace ||= tsv.namespace
|
65
|
+
#
|
66
|
+
# fields = (identifiers and identifiers.all_fields.include?(field))? [field] : nil
|
67
|
+
# #index = identifiers.index :target => format, :fields => fields, :persist => persist_input, :order => true
|
68
|
+
#
|
69
|
+
# grep = Organism.blacklist_genes(tsv.namespace).list if defined?(Organism) && identifiers.namespace && Organism.blacklist_genes(tsv.namespace).exists?
|
70
|
+
# if fields.nil?
|
71
|
+
# index = identifiers.index(:data_tsv_grep => grep, :data_invert_grep => true, :target => format, :persist => true, :order => true, :unnamed => true, :data_persist => true)
|
72
|
+
# else
|
73
|
+
# index = identifiers.index(:data_tsv_grep => grep, :data_invert_grep => true, :target => format, :fields => fields, :order => true, :unnamed => true, :persist => true, :data_persist => true)
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# orig_type = tsv.type
|
77
|
+
# tsv = tsv.to_double if orig_type != :double
|
78
|
+
#
|
79
|
+
# pos = tsv.fields.index field
|
80
|
+
# tsv.with_unnamed do
|
81
|
+
# if tsv.type == :list or tsv.type == :single
|
82
|
+
# tsv.through do |k,v|
|
83
|
+
# v[pos] = index[v[pos]]
|
84
|
+
# tsv[k] = v
|
85
|
+
# end
|
86
|
+
# else
|
87
|
+
# tsv.through do |k,v|
|
88
|
+
# _values = index.values_at(*v[pos])
|
89
|
+
# _values.compact! if compact
|
90
|
+
# v[pos] = _values
|
91
|
+
# tsv[k] = v
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# tsv.fields = tsv.fields.collect{|f| f == field ? format : f}
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# tsv = tsv.to_flat if orig_type == :flat
|
99
|
+
#
|
100
|
+
# tsv = tsv.to_list(&block) if orig_type == :list
|
101
|
+
#
|
102
|
+
# tsv
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# def swap_id(*args)
|
106
|
+
# TSV.swap_id(self, *args)
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# def self.translation_index(files, target = nil, source = nil, options = {})
|
110
|
+
# return nil if source == target
|
111
|
+
# options = Misc.add_defaults options.dup, :persist => true
|
112
|
+
#
|
113
|
+
# target = Entity.formats.find(target) if Entity.formats.find(target)
|
114
|
+
# source = Entity.formats.find(source) if Entity.formats.find(source)
|
115
|
+
# fields = (source and not source.empty?) ? [source] : nil
|
116
|
+
#
|
117
|
+
# files.each do |file|
|
118
|
+
# if TSV === file
|
119
|
+
# all_fields = file.all_fields
|
120
|
+
# target = file.fields.first if target.nil?
|
121
|
+
# if (source.nil? or all_fields.include? source) and all_fields.include? target
|
122
|
+
# return file.index(options.merge(:target => target, :fields => fields, :order => true))
|
123
|
+
# end
|
124
|
+
# else
|
125
|
+
# next unless file.exists?
|
126
|
+
# begin
|
127
|
+
# all_fields = TSV.parse_header(file).all_fields
|
128
|
+
# target = all_fields[1] if target.nil?
|
129
|
+
# if (source.nil? or all_fields.include? source) and all_fields.include? target
|
130
|
+
# index = TSV.index(file, options.merge(:target => target, :fields => fields, :order => true))
|
131
|
+
# return index
|
132
|
+
# end
|
133
|
+
# rescue Exception
|
134
|
+
# Log.exception $!
|
135
|
+
# Log.error "Exception reading identifier file: #{file.find}"
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# files.each do |file|
|
141
|
+
# all_fields = TSV === file ? file.all_fields : TSV.parse_header(file).all_fields
|
142
|
+
#
|
143
|
+
# files.each do |other_file|
|
144
|
+
# next if file == other_file
|
145
|
+
#
|
146
|
+
# other_all_fields = TSV === other_file ? other_file.all_fields : TSV.parse_header(other_file).all_fields
|
147
|
+
#
|
148
|
+
# common_field = (all_fields & other_all_fields).first
|
149
|
+
#
|
150
|
+
# if common_field and (source.nil? or source.empty? or all_fields.include? source) and other_all_fields.include? target
|
151
|
+
#
|
152
|
+
# index = Persist.persist_tsv(nil, Misc.fingerprint(files), {:files => files, :source => source, :target => target}, :prefix => "Translation index", :persist => options[:persist]) do |data|
|
153
|
+
#
|
154
|
+
# index = TSV === file ?
|
155
|
+
# file.index(options.merge(:target => common_field, :fields => fields)) :
|
156
|
+
# TSV.index(file, options.merge(:target => common_field, :fields => fields))
|
157
|
+
#
|
158
|
+
# other_index = TSV === other_file ?
|
159
|
+
# other_file.index(options.merge(:target => target, :fields => [common_field])) :
|
160
|
+
# TSV.index(other_file, options.merge(:target => target, :fields => [common_field]))
|
161
|
+
#
|
162
|
+
# data.serializer = :clean
|
163
|
+
#
|
164
|
+
# # ToDo: remove the need to to the `to_list` transformation
|
165
|
+
# data.merge! index.to_list.attach(other_index.to_list).slice([target]).to_single
|
166
|
+
# end
|
167
|
+
# return index
|
168
|
+
# end
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
# return nil
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# def self.translate(tsv, field, format, options = {})
|
175
|
+
# persist_options = Misc.pull_keys options, :persist
|
176
|
+
# new = TSV.open translate_stream(tsv, field, format, options), :persist => persist_options[:persist], :persist_data => persist_options[:data], :persist_file => persist_options[:file]
|
177
|
+
# new.identifiers = tsv.identifiers
|
178
|
+
# new
|
179
|
+
# end
|
180
|
+
#
|
181
|
+
# def self.translate_stream(tsv, field, format, options = {}, &block)
|
182
|
+
# options = Misc.add_defaults options, :persist => false, :identifier_files => tsv.identifier_files, :compact => true
|
183
|
+
#
|
184
|
+
# identifier_files, identifiers, persist_input, compact = Misc.process_options options, :identifier_files, :identifiers, :persist, :compact
|
185
|
+
# identifier_files = [tsv, identifiers].compact if identifier_files.nil? or identifier_files.empty?
|
186
|
+
#
|
187
|
+
# identifier_files.uniq!
|
188
|
+
#
|
189
|
+
# index = translation_index identifier_files, format, field, options.dup
|
190
|
+
# raise "No index: #{Misc.fingerprint([identifier_files, field, format])}" if index.nil?
|
191
|
+
#
|
192
|
+
# orig_type = tsv.type
|
193
|
+
# tsv = tsv.to_double if orig_type != :double
|
194
|
+
#
|
195
|
+
# pos = tsv.identify_field field
|
196
|
+
#
|
197
|
+
# new_options = tsv.options
|
198
|
+
# new_options[:identifiers] = tsv.identifiers.find if tsv.identifiers
|
199
|
+
#
|
200
|
+
# case pos
|
201
|
+
# when :key
|
202
|
+
# new_options[:key_field] = format if tsv.key_field == field
|
203
|
+
# dumper = TSV::Dumper.new new_options
|
204
|
+
# dumper.init
|
205
|
+
# TSV.traverse tsv, :into => dumper do |key,values|
|
206
|
+
# new_key = index[key]
|
207
|
+
# [new_key, values]
|
208
|
+
# end
|
209
|
+
# else
|
210
|
+
# new_options[:fields] = tsv.fields.collect{|f| f == field ? format : f }
|
211
|
+
# dumper = TSV::Dumper.new new_options
|
212
|
+
# dumper.init
|
213
|
+
#
|
214
|
+
# case tsv.type
|
215
|
+
# when :double
|
216
|
+
# TSV.traverse tsv, :into => dumper do |key,values|
|
217
|
+
# original = values[pos]
|
218
|
+
# new = index.values_at *original
|
219
|
+
# values[pos] = new
|
220
|
+
# [key, values]
|
221
|
+
# end
|
222
|
+
# when :list
|
223
|
+
# TSV.traverse tsv, :into => dumper do |key,values|
|
224
|
+
# original = values[pos]
|
225
|
+
# new = index[original]
|
226
|
+
# values[pos] = new
|
227
|
+
# [key, values]
|
228
|
+
# end
|
229
|
+
# when :flat
|
230
|
+
# TSV.traverse tsv, :into => dumper do |key,values|
|
231
|
+
# new = index.values_at *values
|
232
|
+
# [key, new]
|
233
|
+
# end
|
234
|
+
# when :single
|
235
|
+
# TSV.traverse tsv, :into => dumper do |key,original|
|
236
|
+
# new = index[original]
|
237
|
+
# [key, new]
|
238
|
+
# end
|
239
|
+
# end
|
240
|
+
# end
|
241
|
+
#
|
242
|
+
# dumper.stream
|
243
|
+
# end
|
244
|
+
#end
|