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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/bin/rbbt +67 -90
- data/bin/rbbt_exec.rb +2 -2
- 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/filecache.rb +1 -1
- 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 +2 -2
- 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 +92 -105
- 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 +66 -0
- data/lib/rbbt/workflow/refactor.rb +150 -0
- data/lib/rbbt/workflow/remote_workflow/driver/rest.rb +1 -2
- 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 +96 -4
- data/python/rbbt/workflow/remote.py +104 -0
- data/python/rbbt/workflow.py +64 -0
- data/python/test.py +10 -0
- 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/retry +43 -0
- data/share/rbbt_commands/workflow/server +12 -2
- data/share/rbbt_commands/workflow/task +80 -73
- 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 +45 -6
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'rbbt/entity'
|
2
|
-
|
3
|
-
module Association
|
4
|
-
def self.identify_entity_format(format, fields)
|
5
|
-
entity_type = Entity.formats[format]
|
6
|
-
raise "Field #{ format } could not be resolved: #{fields}" if entity_type.nil?
|
7
|
-
main_field = fields.select{|f| Entity.formats[f] == entity_type}.first
|
8
|
-
raise "Field #{ format } not present, options: #{Misc.fingerprint fields}" if main_field.nil?
|
9
|
-
[main_field, nil, format]
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.parse_field_specification(spec)
|
13
|
-
return [spec,nil,nil] if Numeric === spec
|
14
|
-
spec = spec.split "=>" unless Array === spec
|
15
|
-
field_part, final_format = spec
|
16
|
-
|
17
|
-
field, format = field_part.split "=~", -1
|
18
|
-
|
19
|
-
field = nil if field.nil? or field.empty?
|
20
|
-
|
21
|
-
[field, format, final_format]
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.normalize_specs(spec, all_fields = nil)
|
25
|
-
return nil if spec.nil?
|
26
|
-
field, header, format = parse_field_specification spec
|
27
|
-
|
28
|
-
specs = if all_fields.nil? or all_fields.include? field
|
29
|
-
[field, header, format]
|
30
|
-
else
|
31
|
-
if all_fields.nil?
|
32
|
-
begin
|
33
|
-
identify_entity_format field, all_fields
|
34
|
-
rescue
|
35
|
-
[field, header, format]
|
36
|
-
end
|
37
|
-
else
|
38
|
-
[field, header, format]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
specs
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.extract_specs(all_fields=nil, options = {})
|
45
|
-
source, source_format, target, target_format, format = Misc.process_options options, :source, :source_format, :target, :target_format, :format
|
46
|
-
|
47
|
-
key_field, *fields = all_fields.nil? ? [nil] : all_fields
|
48
|
-
|
49
|
-
source_specs = normalize_specs source, all_fields
|
50
|
-
target_specs = normalize_specs target, all_fields
|
51
|
-
|
52
|
-
source_specs = [nil, nil, nil] if source_specs.nil?
|
53
|
-
target_specs = [nil, nil, nil] if target_specs.nil?
|
54
|
-
|
55
|
-
source_specs[2] = source_format if source_format
|
56
|
-
target_specs[2] = target_format if target_format
|
57
|
-
|
58
|
-
if source_specs.first and not all_fields.include? source_specs.first and defined? Entity and (_format = Entity.formats[source_specs.first.to_s])
|
59
|
-
_source = all_fields.select{|f| Entity.formats[f.to_s] == _format }.first
|
60
|
-
raise "Source not found #{source_specs}. Options: #{Misc.fingerprint all_fields}" if _source.nil?
|
61
|
-
source_specs[0] = _source
|
62
|
-
end
|
63
|
-
|
64
|
-
if target_specs.first and not all_fields.include? target_specs.first and defined? Entity and (_format = Entity.formats[target_specs.first.to_s])
|
65
|
-
_target = all_fields.select{|f| Entity.formats[f.to_s].to_s == _format.to_s }.first
|
66
|
-
raise "Target not found #{target_specs}. Options: #{Misc.fingerprint all_fields}" if _target.nil?
|
67
|
-
target_specs[0] = _target
|
68
|
-
end
|
69
|
-
|
70
|
-
if source_specs[0].nil? and target_specs[0].nil?
|
71
|
-
source_specs[0] = key_field
|
72
|
-
target_specs[0] = fields[0]
|
73
|
-
elsif source_specs[0].nil?
|
74
|
-
if target_specs[0] == :key or target_specs[0] == key_field
|
75
|
-
source_specs[0] = fields[0]
|
76
|
-
else
|
77
|
-
source_specs[0] = key_field
|
78
|
-
end
|
79
|
-
elsif target_specs[0].nil?
|
80
|
-
if source_specs[0] == fields.first
|
81
|
-
target_specs[0] = key_field
|
82
|
-
else
|
83
|
-
target_specs[0] = fields.first
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# If format is specified, then perhaps we need to change the
|
88
|
-
if target_specs[2].nil?
|
89
|
-
target_type = Entity.formats[target_specs[1] || target_specs[0]]
|
90
|
-
target_specs[2] = format[target_type.to_s] if format
|
91
|
-
target_specs[2] = nil if target_specs[2] == target_specs[0] or target_specs[2] == target_specs[1]
|
92
|
-
end
|
93
|
-
|
94
|
-
if source_specs[2].nil?
|
95
|
-
source_type = Entity.formats[source_specs[1] || source_specs[0]]
|
96
|
-
source_specs[2] = format[source_type.to_s] if format
|
97
|
-
source_specs[2] = nil if source_specs[2] == source_specs[0] or source_specs[2] == source_specs[1]
|
98
|
-
end
|
99
|
-
|
100
|
-
{:source => source_specs, :target => target_specs}
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.process_formats(field, default_format = {})
|
104
|
-
return nil if default_format.nil? or default_format.empty?
|
105
|
-
default_format.each do |type, format|
|
106
|
-
entity_type = Entity.formats[field] || format
|
107
|
-
return format if entity_type.to_s === type
|
108
|
-
end
|
109
|
-
return nil
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.headers(all_fields, info_fields = nil, options = {})
|
113
|
-
specs = extract_specs all_fields, options
|
114
|
-
|
115
|
-
source_field = specs[:source][0]
|
116
|
-
target_field = specs[:target][0]
|
117
|
-
|
118
|
-
#source_pos = all_fields.index source_field
|
119
|
-
#target_pos = all_fields.index target_field
|
120
|
-
|
121
|
-
source_pos = TSV.identify_field all_fields.first, all_fields[1..-1], source_field
|
122
|
-
target_pos = TSV.identify_field all_fields.first, all_fields[1..-1], target_field
|
123
|
-
|
124
|
-
source_pos = source_pos == :key ? 0 : source_pos + 1
|
125
|
-
target_pos = target_pos == :key ? 0 : target_pos + 1
|
126
|
-
|
127
|
-
source_header = specs[:source][1] || specs[:source][0]
|
128
|
-
target_header = specs[:target][1] || specs[:target][0]
|
129
|
-
|
130
|
-
info_fields = all_fields.dup if info_fields.nil?
|
131
|
-
info_fields.delete source_field
|
132
|
-
info_fields.delete target_field
|
133
|
-
info_fields.unshift target_field
|
134
|
-
|
135
|
-
field_headers = [target_header]
|
136
|
-
info_fields[1..-1].each do |field|
|
137
|
-
header = case field
|
138
|
-
when String
|
139
|
-
field
|
140
|
-
when Numeric
|
141
|
-
all_fields[field]
|
142
|
-
when :key
|
143
|
-
all_fields.first
|
144
|
-
end
|
145
|
-
|
146
|
-
field_headers << header
|
147
|
-
end
|
148
|
-
|
149
|
-
field_pos = info_fields.collect do |f|
|
150
|
-
p = TSV.identify_field all_fields.first, all_fields[1..-1], f
|
151
|
-
p == :key ? 0 : p + 1
|
152
|
-
end
|
153
|
-
|
154
|
-
field_pos.delete source_pos
|
155
|
-
|
156
|
-
source_format = specs[:source][2]
|
157
|
-
target_format = specs[:target][2]
|
158
|
-
|
159
|
-
|
160
|
-
if format = options[:format]
|
161
|
-
source_format = process_formats(specs[:source][1] || specs[:source][0], format) || source_format unless source_format
|
162
|
-
target_format = process_formats(specs[:target][1] || specs[:target][0], format) || target_format unless target_format
|
163
|
-
end
|
164
|
-
|
165
|
-
res = [source_pos, field_pos, source_header, field_headers, source_format, target_format]
|
166
|
-
Log.low "Headers -- #{res}"
|
167
|
-
res
|
168
|
-
end
|
169
|
-
end
|
data/lib/rbbt/association.rb
CHANGED
@@ -1,118 +1,119 @@
|
|
1
|
-
module Entity
|
2
|
-
def self.identifier_files(field)
|
3
|
-
entity_type = Entity.formats[field]
|
4
|
-
return [] unless entity_type and entity_type.include? Entity::Identified
|
5
|
-
entity_type.identifier_files
|
6
|
-
end
|
7
|
-
|
8
|
-
module Identified
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
base.annotation :format
|
12
|
-
base.annotation :organism
|
13
|
-
|
14
|
-
class << base
|
15
|
-
attr_accessor :identifier_files, :formats, :default_format, :name_format, :description_format
|
16
|
-
end
|
17
|
-
|
18
|
-
base.module_eval do
|
19
|
-
def identity_type
|
20
|
-
self.annotation_types.select{|m| m.include? Entity::Identified }.last
|
21
|
-
end
|
22
|
-
|
23
|
-
def identifier_files
|
24
|
-
files = identity_type.identifier_files.dup
|
25
|
-
files.collect!{|f| f.annotate f.gsub(/\bNAMESPACE\b/, organism) } if annotations.include? :organism and self.organism
|
26
|
-
if files.select{|f| f =~ /\bNAMESPACE\b/ }.any?
|
27
|
-
Log.warn "Rejecting some identifier files for lack of 'organism': " << files.select{|f| f =~ /\bNAMESPACE\b/ } * ", "
|
28
|
-
end
|
29
|
-
files.reject!{|f| f =~ /\bNAMESPACE\b/ }
|
30
|
-
files
|
31
|
-
end
|
32
|
-
|
33
|
-
def identifier_index(format = nil, source = nil)
|
34
|
-
Persist.memory("Entity index #{identity_type}: #{format} (from #{source || "All"})", :persist => true, :format => format, :source => source) do
|
35
|
-
source ||= self.respond_to?(:format)? self.format : nil
|
36
|
-
|
37
|
-
begin
|
38
|
-
index = TSV.translation_index(identifier_files, format, source, :persist => true)
|
39
|
-
raise "No index from #{ Misc.fingerprint source } to #{ Misc.fingerprint format }: #{Misc.fingerprint identifier_files}" if index.nil?
|
40
|
-
index.unnamed = true
|
41
|
-
index
|
42
|
-
rescue
|
43
|
-
raise $! if source.nil?
|
44
|
-
source = nil
|
45
|
-
retry
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
base.property :to => :both do |target_format|
|
52
|
-
|
53
|
-
target_format = case target_format
|
54
|
-
when :name
|
55
|
-
identity_type.name_format
|
56
|
-
when :default
|
57
|
-
identity_type.default_format
|
58
|
-
when :ensembl
|
59
|
-
identity_type.formats.select{|f| f =~ /Ensembl/}.first
|
60
|
-
else
|
61
|
-
target_format
|
62
|
-
end
|
63
|
-
|
64
|
-
return self if target_format == format
|
65
|
-
|
66
|
-
if Array === self
|
67
|
-
self.annotate(identifier_index(target_format, self.format).values_at(*self))
|
68
|
-
else
|
69
|
-
self.annotate(identifier_index(target_format, self.format)[self])
|
70
|
-
end.tap{|o| o.format = target_format unless o.nil? }
|
71
|
-
end
|
72
|
-
|
73
|
-
base.property :name => :both do
|
74
|
-
to(:name)
|
75
|
-
end
|
76
|
-
|
77
|
-
base.property :default => :both do
|
78
|
-
to(:default)
|
79
|
-
end
|
80
|
-
|
81
|
-
base.property :ensembl => :both do
|
82
|
-
to(:ensembl)
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def add_identifiers(file, default = nil, name = nil, description = nil)
|
90
|
-
if TSV === file
|
91
|
-
all_fields = file.all_fields
|
92
|
-
else
|
93
|
-
if file =~ /NAMESPACE/
|
94
|
-
all_fields = file.sub(/NAMESPACE/,'**').glob.collect do |f|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
@formats
|
107
|
-
@formats.
|
108
|
-
|
109
|
-
|
110
|
-
@
|
111
|
-
@
|
112
|
-
|
113
|
-
|
114
|
-
@identifier_files
|
115
|
-
@identifier_files
|
116
|
-
|
117
|
-
|
118
|
-
|
1
|
+
#module Entity
|
2
|
+
# def self.identifier_files(field)
|
3
|
+
# entity_type = Entity.formats[field]
|
4
|
+
# return [] unless entity_type and entity_type.include? Entity::Identified
|
5
|
+
# entity_type.identifier_files
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# module Identified
|
9
|
+
#
|
10
|
+
# def self.included(base)
|
11
|
+
# base.annotation :format
|
12
|
+
# base.annotation :organism
|
13
|
+
#
|
14
|
+
# class << base
|
15
|
+
# attr_accessor :identifier_files, :formats, :default_format, :name_format, :description_format
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# base.module_eval do
|
19
|
+
# def identity_type
|
20
|
+
# self.annotation_types.select{|m| m.include? Entity::Identified }.last
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def identifier_files
|
24
|
+
# files = identity_type.identifier_files.dup
|
25
|
+
# files.collect!{|f| f.annotate f.gsub(/\bNAMESPACE\b/, organism) } if annotations.include? :organism and self.organism
|
26
|
+
# if files.select{|f| f =~ /\bNAMESPACE\b/ }.any?
|
27
|
+
# Log.warn "Rejecting some identifier files for lack of 'organism': " << files.select{|f| f =~ /\bNAMESPACE\b/ } * ", "
|
28
|
+
# end
|
29
|
+
# files.reject!{|f| f =~ /\bNAMESPACE\b/ }
|
30
|
+
# files
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# def identifier_index(format = nil, source = nil)
|
34
|
+
# Persist.memory("Entity index #{identity_type}: #{format} (from #{source || "All"})", :persist => true, :format => format, :source => source) do
|
35
|
+
# source ||= self.respond_to?(:format)? self.format : nil
|
36
|
+
#
|
37
|
+
# begin
|
38
|
+
# index = TSV.translation_index(identifier_files, format, source, :persist => true)
|
39
|
+
# raise "No index from #{ Misc.fingerprint source } to #{ Misc.fingerprint format }: #{Misc.fingerprint identifier_files}" if index.nil?
|
40
|
+
# index.unnamed = true
|
41
|
+
# index
|
42
|
+
# rescue
|
43
|
+
# raise $! if source.nil?
|
44
|
+
# source = nil
|
45
|
+
# retry
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# base.property :to => :both do |target_format|
|
52
|
+
#
|
53
|
+
# target_format = case target_format
|
54
|
+
# when :name
|
55
|
+
# identity_type.name_format
|
56
|
+
# when :default
|
57
|
+
# identity_type.default_format
|
58
|
+
# when :ensembl
|
59
|
+
# identity_type.formats.select{|f| f =~ /Ensembl/}.first
|
60
|
+
# else
|
61
|
+
# target_format
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# return self if target_format == format
|
65
|
+
#
|
66
|
+
# if Array === self
|
67
|
+
# self.annotate(identifier_index(target_format, self.format).values_at(*self))
|
68
|
+
# else
|
69
|
+
# self.annotate(identifier_index(target_format, self.format)[self])
|
70
|
+
# end.tap{|o| o.format = target_format unless o.nil? }
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# base.property :name => :both do
|
74
|
+
# to(:name)
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# base.property :default => :both do
|
78
|
+
# to(:default)
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# base.property :ensembl => :both do
|
82
|
+
# to(:ensembl)
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# def add_identifiers(file, default = nil, name = nil, description = nil)
|
90
|
+
# if TSV === file
|
91
|
+
# all_fields = file.all_fields
|
92
|
+
# else
|
93
|
+
# if file =~ /NAMESPACE/
|
94
|
+
# all_fields = file.sub(/NAMESPACE/,'**').glob.collect do |f|
|
95
|
+
# header = TSV.parse_header(f)
|
96
|
+
# [header.key_field] + header.fields
|
97
|
+
# end.flatten.compact.uniq
|
98
|
+
# else
|
99
|
+
# all_fields = TSV.parse_header(file).all_fields
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# self.send(:include, Entity::Identified) unless Entity::Identified === self
|
104
|
+
#
|
105
|
+
# self.format = all_fields
|
106
|
+
# @formats ||= []
|
107
|
+
# @formats.concat all_fields
|
108
|
+
# @formats.uniq!
|
109
|
+
#
|
110
|
+
# @default_format = default if default
|
111
|
+
# @name_format = name if name
|
112
|
+
# @description_format = description if description
|
113
|
+
#
|
114
|
+
# @identifier_files ||= []
|
115
|
+
# @identifier_files << file
|
116
|
+
# @identifier_files.uniq!
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
#end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative '../annotations'
|
2
|
+
require_relative '../persist'
|
3
|
+
#module Entity
|
4
|
+
# def self.extended(base)
|
5
|
+
# base.extend Annotation
|
6
|
+
# base.extend Entity::Property
|
7
|
+
# base.instance_variable_set(:@properties, [])
|
8
|
+
# base.instance_variable_set(:@persisted_methods, {})
|
9
|
+
# base.include Entity::Object
|
10
|
+
# base.include AnnotatedArray
|
11
|
+
# end
|
12
|
+
#end
|