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,225 +1,200 @@
1
- require 'rbbt/association/util'
2
- require 'rbbt/tsv/change_id'
3
-
4
- module Association
5
-
6
- def self.add_reciprocal(tsv)
7
- new = TSV.open(tsv.dumper_stream)
8
- tsv.with_unnamed do
9
- case tsv.type
10
- when :double
11
- tsv.through do |source, values|
12
- Misc.zip_fields(values).each do |info|
13
- target, *rest = info
14
- next if target == source
15
- rest.unshift source
16
- new.zip_new target, rest
17
- end
18
- end
19
- else
20
- end
21
- end
22
-
23
- tsv.annotate(new)
24
-
25
- new
26
- end
27
-
28
- def self.translate(tsv, source_final_format, target_final_format, options = {})
29
- source_field = tsv.key_field
30
- target_field = tsv.fields.first
31
- namespace = tsv.namespace
32
-
33
- data = Misc.process_options options, :data
34
-
35
- data ||= {}
36
- TmpFile.with_file do |tmpfile1|
37
- TmpFile.with_file do |tmpfile2|
38
- tmp_data1 = Persist.open_database(tmpfile1, true, :double, "HDB")
39
- tmp_data2 = Persist.open_database(tmpfile2, true, :double, "HDB")
40
-
41
- if source_final_format and source_field != source_final_format
42
- Log.debug("Changing source format from #{tsv.key_field} to #{source_final_format}")
43
-
44
- identifier_files = tsv.identifier_files.dup
45
- identifier_files = [Organism.identifiers("NAMESPACE")] if identifier_files.empty?
46
- identifier_files.concat Entity.identifier_files(source_final_format) if defined? Entity
47
- identifier_files.uniq!
48
- identifier_files.collect!{|f| f.annotate(f.gsub(/\bNAMESPACE\b/, namespace))} if namespace
49
- identifier_files.reject!{|f| f.match(/\bNAMESPACE\b/)}
50
-
51
- tsv = TSV.translate(tsv, source_field, source_final_format, options.merge(:identifier_files => identifier_files, :persist_data => tmp_data1))
52
- end
53
-
54
- # Translate target
55
- if target_final_format and target_field != target_final_format
56
- Log.debug("Changing target format from #{target_field} to #{target_final_format}")
57
- old_key_field = tsv.key_field
58
- tsv.key_field = "MASK"
59
-
60
- identifier_files = tsv.identifier_files.dup
61
- identifier_files.concat Entity.identifier_files(target_final_format) if defined? Entity
62
- identifier_files.uniq!
63
- identifier_files.collect!{|f| f.annotate(f.gsub(/\bNAMESPACE\b/, namespace))} if namespace
64
- identifier_files.reject!{|f| f.match(/\bNAMESPACE\b/)}
65
-
66
- tsv = TSV.translate(tsv, target_field, target_final_format, options.merge(:identifier_files => identifier_files, :persist_data => tmp_data2))
67
- tsv.key_field = old_key_field
68
- end
69
-
70
- tsv.through do |k,v|
71
- data[k] = v
72
- end
73
-
74
- tsv.annotate data
75
- end
76
- end
77
- end
78
-
79
- def self.reorder_tsv(tsv, options = {})
80
- fields, persist = Misc.process_options options, :fields, :persist
81
- all_fields = tsv.all_fields
82
-
83
- source_pos, field_pos, source_header, field_headers, source_format, target_format = headers(all_fields, fields, options)
84
-
85
- source_field = source_pos == :key ? :key : all_fields[source_pos]
86
- info_fields = field_pos.collect{|f| f == :key ? :key : all_fields[f]}
87
- options = options.merge({:key_field => source_field, :fields => info_fields})
88
-
89
- fields = field_headers if fields.nil?
90
-
91
- data = options[:data] || {}
92
- TmpFile.with_file do |tmpfile|
93
- tmp_data = Persist.open_database(tmpfile, true, :double, "HDB")
94
-
95
- tsv.with_monitor(options[:monitor]) do
96
- tsv = tsv.reorder source_field, tsv.all_fields.values_at(*field_pos), :persist => persist, :persist_data => tmp_data if true or source_field != tsv.key_field or (fields and tsv.fields != fields)
97
- end
98
-
99
- tsv.key_field = source_header
100
- tsv.fields = field_headers
101
-
102
- if source_format or target_format
103
- tsv = translate tsv, source_format, target_format, :persist => true, :data => data
104
- else
105
- tsv.through do |k,v|
106
- data[k] = v
107
- end
108
- tsv.annotate data
109
- end
110
- end
111
-
112
- tsv
113
- end
114
-
115
- def self.open_stream(stream, options = {})
116
- fields, persist, data = Misc.process_options options, :fields, :persist, :data
117
-
118
- parser = TSV::Parser.new stream, options.merge(:fields => nil, :key_field => nil)
119
- options = options.merge(parser.options)
120
- options = Misc.add_defaults options, :type => :double, :merge => true
121
-
122
- key_field, *_fields = all_fields = parser.all_fields
123
-
124
- source_pos, field_pos, source_header, field_headers, source_format, target_format = headers parser.all_fields, fields, options
125
-
126
- parser.key_field = source_pos
127
- parser.fields = field_pos
128
- parser.field_positions = field_pos
129
- parser.key_position = source_pos
130
-
131
- #case parser.type
132
- #when :single
133
- # class << parser
134
- # def get_values(parts)
135
- # [parts[@key_field], parts.values_at(*@fields).first]
136
- # end
137
- # end
138
- #when :list
139
- # class << parser
140
- # def get_values(parts)
141
- # [parts[@key_field], parts.values_at(*@fields)]
142
- # end
143
- # end
144
- #when :__double
145
- # class << parser
146
- # def get_values(parts)
147
- # [parts[@key_field].split(@sep2,-1), parts.values_at(*@fields).collect{|v| v.nil? ? [] : v.split(@sep2,-1) }]
148
- # end
149
- # end
150
- #when :flat
151
- # class << parser
152
- # def get_values(parts)
153
- # fields = (0..parts.length-1).to_a - [@key_field]
154
- # values = parts.values_at(*fields).compact.collect{|v| v.split(@sep2,-1) }.flatten
155
- # [parts[@key_field].split(@sep2,-1), values]
156
- # end
157
- # end
158
- #end
159
-
160
- open_options = options.merge(parser.options).merge(:parser => parser)
161
- open_options = Misc.add_defaults open_options, :monitor => {:desc => "Parsing #{ Misc.fingerprint stream }"}
162
-
163
- data ||= {}
164
- tsv = nil
165
- if data.respond_to?(:close) && data.respond_to?(:write)
166
- data.close
167
- data.write
168
- end
169
- TmpFile.with_file do |tmpfile|
170
- tmp_data = Persist.open_database(tmpfile, true, open_options[:type], "HDB")
171
-
172
- tsv = TSV.parse parser.stream, tmp_data, open_options
173
- tsv = tsv.to_double
174
- tsv.key_field = source_header
175
- tsv.fields = field_headers
176
-
177
- if source_format or target_format
178
- tsv = translate tsv, source_format, target_format, :persist => true, :data => data
179
- else
180
- tsv.through do |k,v|
181
- data[k] = v
182
- end
183
- tsv.annotate data
184
- end
185
-
186
- end
187
-
188
- tsv
189
- end
190
-
191
- def self.database(file, options = {})
192
- database = case file
193
- when (defined? Step and Step)
194
- file.clean if file.error? or file.aborted? or file.dirty?
195
- file.run(true) unless file.done? or file.started?
196
- file.join unless file.done?
197
- open_stream(TSV.get_stream(file), options.dup)
198
- when TSV
199
- file = file.to_double unless file.type == :double
200
- tsv = reorder_tsv(file, options.dup)
201
- if options[:data]
202
- data = options[:data]
203
- tsv.with_unnamed do
204
- tsv.with_monitor("Saving database #{Misc.fingerprint file}") do
205
- tsv.through do |k,v|
206
- data[k] = v
207
- end
208
- end
209
- end
210
- end
211
- tsv
212
- when IO
213
- open_stream(file, options.dup)
214
- else
215
- stream = TSV.get_stream(file)
216
- open_stream(stream, options.dup)
217
- end
218
-
219
- database.filename = file if Path === file && file.identifier_files.any?
220
- database.entity_options = options[:entity_options] if options[:entity_options]
221
-
222
- database
223
- end
224
-
225
- end
1
+ require_relative '../refactor'
2
+ Rbbt.require_instead 'scout/association'
3
+ #require 'rbbt/association/util'
4
+ #require 'rbbt/tsv/change_id'
5
+ #
6
+ #module Association
7
+ #
8
+ # def self.add_reciprocal(tsv)
9
+ # new = TSV.open(tsv.dumper_stream)
10
+ # tsv.with_unnamed do
11
+ # case tsv.type
12
+ # when :double
13
+ # tsv.through do |source, values|
14
+ # NamedArray.zip_fields(values).each do |info|
15
+ # target, *rest = info
16
+ # next if target == source
17
+ # rest.unshift source
18
+ # new.zip_new target, rest
19
+ # end
20
+ # end
21
+ # else
22
+ # end
23
+ # end
24
+ #
25
+ # tsv.annotate(new)
26
+ #
27
+ # new
28
+ # end
29
+ #
30
+ # def self.translate(tsv, source_final_format, target_final_format, options = {})
31
+ # source_field = tsv.key_field
32
+ # target_field = tsv.fields.first
33
+ # namespace = tsv.namespace
34
+ #
35
+ # data = IndiferentHash.process_options options, :data
36
+ #
37
+ # data ||= {}
38
+ # TmpFile.with_file do |tmpfile1|
39
+ # TmpFile.with_file do |tmpfile2|
40
+ # tmp_data1 = Persist.open_tokyocabinet(tmpfile1, true, :double, "HDB")
41
+ # tmp_data2 = Persist.open_tokyocabinet(tmpfile2, true, :double, "HDB")
42
+ #
43
+ # if source_final_format and source_field != source_final_format
44
+ # Log.debug("Changing source format from #{tsv.key_field} to #{source_final_format}")
45
+ #
46
+ # identifier_files = tsv.identifier_files.dup
47
+ # identifier_files = [Organism.identifiers("NAMESPACE")] if identifier_files.empty?
48
+ # identifier_files.concat Entity.identifier_files(source_final_format) if defined? Entity
49
+ # identifier_files.uniq!
50
+ # identifier_files.collect!{|f| f.annotate(f.gsub(/\bNAMESPACE\b/, namespace))} if namespace
51
+ # identifier_files.reject!{|f| f.match(/\bNAMESPACE\b/)}
52
+ #
53
+ # tsv = TSV.translate(tsv, source_field, source_final_format, identifiers: identifier_files)
54
+ # end
55
+ #
56
+ # # Translate target
57
+ # if target_final_format and target_field != target_final_format
58
+ # Log.debug("Changing target format from #{target_field} to #{target_final_format}")
59
+ # old_key_field = tsv.key_field
60
+ # tsv.key_field = "MASK"
61
+ #
62
+ # identifier_files = tsv.identifier_files.dup
63
+ # identifier_files.concat Entity.identifier_files(target_final_format) if defined? Entity
64
+ # identifier_files.uniq!
65
+ # identifier_files.collect!{|f| f.annotate(f.gsub(/\bNAMESPACE\b/, namespace))} if namespace
66
+ # identifier_files.reject!{|f| f.match(/\bNAMESPACE\b/)}
67
+ #
68
+ # tsv = TSV.translate(tsv, target_final_format, target_field, identifiers: identifier_files)
69
+ # tsv.key_field = old_key_field
70
+ # end
71
+ #
72
+ # tsv.through do |k,v|
73
+ # data[k] = v
74
+ # end
75
+ #
76
+ # tsv.annotate data
77
+ # end
78
+ # end
79
+ # end
80
+ #
81
+ # def self.reorder_tsv(tsv, options = {})
82
+ # fields, persist = IndiferentHash.process_options options, :fields, :persist
83
+ # all_fields = tsv.all_fields
84
+ #
85
+ # source_pos, field_pos, source_header, field_headers, source_format, target_format = headers(all_fields, fields, options)
86
+ #
87
+ # source_field = source_pos == :key ? :key : all_fields[source_pos]
88
+ # info_fields = field_pos.collect{|f| f == :key ? :key : all_fields[f]}
89
+ # options = options.merge({:key_field => source_field, :fields => info_fields})
90
+ #
91
+ # fields = field_headers if fields.nil?
92
+ #
93
+ # data = options[:data] || {}
94
+ # TmpFile.with_file do |tmpfile|
95
+ # tmp_data = Persist.open_tokyocabinet(tmpfile, true, :double, "HDB")
96
+ #
97
+ # tsv.with_monitor(options[:monitor]) do
98
+ # tsv = tsv.reorder source_field, tsv.all_fields.values_at(*field_pos), :persist => persist, :persist_data => tmp_data if true or source_field != tsv.key_field or (fields and tsv.fields != fields)
99
+ # end
100
+ #
101
+ # tsv.key_field = source_header
102
+ # tsv.fields = field_headers
103
+ #
104
+ # if source_format or target_format
105
+ # tsv = translate tsv, source_format, target_format, :persist => true, :data => data
106
+ # else
107
+ # tsv.through do |k,v|
108
+ # data[k] = v
109
+ # end
110
+ # tsv.annotate data
111
+ # end
112
+ # end
113
+ #
114
+ # tsv
115
+ # end
116
+ #
117
+ # def self.open_stream(stream, options = {})
118
+ # fields, persist, data = IndiferentHash.process_options options, :fields, :persist, :data
119
+ #
120
+ # parser = TSV::Parser.new stream, sep: options[:sep], type: options[:type]
121
+ # options = options.merge(parser.options)
122
+ # options = IndiferentHash.add_defaults options, :type => :double, :merge => true
123
+ #
124
+ # key_field, *_fields = all_fields = parser.all_fields
125
+ #
126
+ # source_pos, field_pos, source_header, field_headers, source_format, target_format = headers parser.all_fields, fields, options
127
+ #
128
+ # parser.key_field = source_pos
129
+ # parser.fields = field_pos
130
+ #
131
+ # open_options = options.merge(parser.options).merge(:parser => parser)
132
+ # open_options = IndiferentHash.add_defaults open_options, :monitor => {:desc => "Parsing #{ Log.fingerprint stream }"}
133
+ #
134
+ # data ||= {}
135
+ # tsv = nil
136
+ # if data.respond_to?(:close) && data.respond_to?(:write)
137
+ # data.close
138
+ # data.write
139
+ # end
140
+ # TmpFile.with_file do |tmpfile|
141
+ # tsv = Persist.open_tokyocabinet(tmpfile, true, open_options[:type], "HDB")
142
+ # TSV.setup(tsv, parser.options)
143
+ # parser.traverse do |k,v|
144
+ # tsv[k] = v
145
+ # end
146
+ #
147
+ # #tsv = TSV.parse parser.stream, tmp_data, open_options
148
+ # #tsv = tsv.to_double
149
+ # #tsv.key_field = source_header
150
+ # #tsv.fields = field_headers
151
+ #
152
+ # if source_format or target_format
153
+ # tsv = translate tsv, source_format, target_format, :persist => true, :data => data
154
+ # else
155
+ # tsv.through do |k,v|
156
+ # data[k] = v
157
+ # end
158
+ # tsv.annotate data
159
+ # end
160
+ #
161
+ # end
162
+ #
163
+ # tsv
164
+ # end
165
+ #
166
+ # def self.database(file, options = {})
167
+ # database = case file
168
+ # when (defined? Step and Step)
169
+ # file.clean if file.error? or file.aborted? or file.dirty?
170
+ # file.run(true) unless file.done? or file.started?
171
+ # file.join unless file.done?
172
+ # open_stream(TSV.get_stream(file), options.dup)
173
+ # when TSV
174
+ # file = file.to_double unless file.type == :double
175
+ # tsv = reorder_tsv(file, options.dup)
176
+ # if options[:data]
177
+ # data = options[:data]
178
+ # tsv.with_unnamed do
179
+ # tsv.with_monitor("Saving database #{Log.fingerprint file}") do
180
+ # tsv.through do |k,v|
181
+ # data[k] = v
182
+ # end
183
+ # end
184
+ # end
185
+ # end
186
+ # tsv
187
+ # when IO
188
+ # open_stream(file, options.dup)
189
+ # else
190
+ # stream = TSV.get_stream(file)
191
+ # open_stream(stream, options.dup)
192
+ # end
193
+ #
194
+ # database.filename = file if Path === file && file.identifier_files.any?
195
+ # database.entity_options = options[:entity_options] if options[:entity_options]
196
+ #
197
+ # database
198
+ # end
199
+ #
200
+ #end