rbbt-util 5.28.4 → 5.28.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eb8b404c84b1c6d07f3d13ffeaeb97a4b9fd59bf237241b98e184cbfdb98a43
4
- data.tar.gz: f2a0e7c55aa053a7d559143b1ae235558355fd1f4f61f2845864e47b621e37fc
3
+ metadata.gz: 2fa2f71df9aef8810599ab3660c847c084dea75ccb2485d294cfa1962e341162
4
+ data.tar.gz: 7eb004ddf8bcf30b00325dc5251d9ed73a307de433c18c0847eb4d70a4bea1e2
5
5
  SHA512:
6
- metadata.gz: fd8348766af38ef48c379966ae2766e59fcb14714d78a5130856cdfef2d5a87eeabb4ae519a2fa6a2fa862d6b71cfff711eefe293b3f0954af6b0f70bbf58bdd
7
- data.tar.gz: a8187db527df84d7db46e1cc049ed8e3a850188da16d0834408af102bf7f02977524786ab1267e6d047744d3e8cca3cc02c1382ede7b8766a61468867e2f8464
6
+ metadata.gz: 6ba23322f9ac768f1782c4e26605c50171b6d35d1d3c2acc0ef195e26ca39af851a232e1581ca2ec220899b7780f35f8d0d36e1f61f0b0e6500c883999c3760b
7
+ data.tar.gz: afa0952f228a951ea78506ad0776fd96dbfbd2b91bac73310ee6807e4a7d0a74c7ca8f582880c5abd28bbf709c8be3d9dff1797056be756962091b2e97031f30
@@ -451,12 +451,15 @@ EOF
451
451
  out = CMD.cmd("tail -f '#{fout}'", :pipe => true) if File.exists?(fout) and not tail == :STDERR
452
452
  err = CMD.cmd("tail -f '#{ferr}'", :pipe => true) if File.exists?(ferr)
453
453
 
454
- Misc.consume_stream(err, true, STDERR) if err
455
- Misc.consume_stream(out, true, STDOUT) if out
454
+ terr = Misc.consume_stream(err, true, STDERR) if err
455
+ tout = Misc.consume_stream(out, true, STDOUT) if out
456
456
 
457
457
  sleep 3 while CMD.cmd("squeue --job #{job}").read.include? job.to_s
458
+ rescue Aborted
458
459
  ensure
459
460
  begin
461
+ terr.exit if terr
462
+ tout.exit if tout
460
463
  err.close if err
461
464
  err.join if err
462
465
  rescue Exception
@@ -25,6 +25,7 @@ module Persist
25
25
  MEMORY = {} unless defined? MEMORY
26
26
  MAX_FILE_LENGTH = 150
27
27
 
28
+ # Return non-false if the first file is newer than the second file
28
29
  def self.newer?(path, file)
29
30
  return true if not Open.exists?(file)
30
31
  path = path.find if Path === path
@@ -550,9 +550,17 @@ module TSV
550
550
  "\t" << ([""] * fields.length) * "\t" << "\n"
551
551
  end
552
552
  when Array
553
- "\t" << values.collect{|v| Array === v ? v * "|" : v} * "\t" << "\n"
553
+ if fields.nil? or fields.empty?
554
+ "\n"
555
+ else
556
+ "\t" << values.collect{|v| Array === v ? v * "|" : v} * "\t" << "\n"
557
+ end
554
558
  else
555
- "\t" << values.to_s << "\n"
559
+ if fields.nil? or fields.empty?
560
+ "\n"
561
+ else
562
+ "\t" << values.to_s << "\n"
563
+ end
556
564
  end
557
565
  end
558
566
 
@@ -32,9 +32,17 @@ module TSV
32
32
  sep + ([""] * fields.length) * sep << "\n"
33
33
  end
34
34
  when Array
35
- sep + (values.collect{|v| Array === v ? v * "|" : v} * sep) << "\n"
35
+ if fields.nil? or fields.empty?
36
+ "\n"
37
+ else
38
+ sep + (values.collect{|v| Array === v ? v * "|" : v} * sep) << "\n"
39
+ end
36
40
  else
37
- sep + values.to_s << "\n"
41
+ if fields.nil? or fields.empty?
42
+ "\n"
43
+ else
44
+ sep + values.to_s << "\n"
45
+ end
38
46
  end
39
47
  end
40
48
 
@@ -377,6 +377,7 @@ module TSV
377
377
  obj.run(true) unless obj.done? || obj.started? || obj.result
378
378
 
379
379
  stream = obj.get_stream
380
+ options = {:type => :array}.merge(options) if obj.result_type == :array
380
381
 
381
382
  if stream
382
383
  traverse_obj(stream, options, &block)
@@ -623,6 +624,8 @@ module TSV
623
624
  def self.traverse(obj, options = {}, &block)
624
625
  into = options[:into]
625
626
 
627
+ into = options[:into] = Open.open(into, :mode => "w") if Misc.is_filename?(into)
628
+
626
629
  case into
627
630
  when :stream
628
631
  sout = Misc.open_pipe false, false do |sin|
@@ -184,7 +184,11 @@ module TSV
184
184
  str = ""
185
185
  str << preamble.strip << "\n" if preamble and not preamble.empty?
186
186
  if fields
187
- str << header_hash << (key_field || "ID").to_s << sep << (fields * sep) << "\n"
187
+ if fields.empty?
188
+ str << header_hash << (key_field || "ID").to_s << "\n"
189
+ else
190
+ str << header_hash << (key_field || "ID").to_s << sep << (fields * sep) << "\n"
191
+ end
188
192
  end
189
193
 
190
194
  str
@@ -15,7 +15,7 @@ module Rbbt::Config
15
15
  end
16
16
 
17
17
  def self.load_file(file)
18
- Log.debug "Loading file: #{ file }"
18
+ Log.debug "Loading config file: #{ file }"
19
19
  TSV.traverse file, :type => :array do |line|
20
20
  next if line =~ /^#/
21
21
  key, value, *tokens = line.strip.split(/\s/)
@@ -85,6 +85,7 @@ module Rbbt::Config
85
85
  priorities
86
86
  end
87
87
 
88
+ # For equal priorities the matching prioritizes tokens ealier in the list
88
89
  def self.get(key, *tokens)
89
90
  options = tokens.pop if Hash === tokens.last
90
91
  default = options.nil? ? nil : options[:default]
@@ -292,7 +292,7 @@ module Misc
292
292
  files = obj.glob("**/*")
293
293
  "directory: #{Misc.fingerprint(files)}"
294
294
  else
295
- "file: " << obj << "--" << mtime_str(obj)
295
+ "file: " << Open.realpath(obj) << "--" << mtime_str(obj)
296
296
  end
297
297
  else
298
298
  obj + " (file missing)"
@@ -113,7 +113,7 @@ end
113
113
  end
114
114
 
115
115
  def self.is_filename?(string)
116
- return true if defined? PATH and Path === string
116
+ return true if defined? Path and Path === string
117
117
  return true if string.respond_to? :exists
118
118
  return true if String === string and string.length < 265 and File.exist?(string)
119
119
  return false
@@ -397,7 +397,7 @@ module Open
397
397
  if dir_sub_path_source.nil? and dir_sub_path_target.nil?
398
398
  FileUtils.mkdir_p File.dirname(target) unless File.exist? File.dirname(target)
399
399
  tmp_target = File.join(File.dirname(target), '.tmp_mv.' + File.basename(target))
400
- FileUtils.cp source, tmp_target
400
+ FileUtils.cp_r source, tmp_target
401
401
  FileUtils.mv tmp_target, target
402
402
  return
403
403
  end
@@ -364,6 +364,7 @@ module Workflow
364
364
  raise ParameterException, "Inputs #{Misc.humanize_list(missing_inputs)} are required but were not provided or are nil"
365
365
  end
366
366
 
367
+ # jobname => true sets the value of the input to the name of the job
367
368
  if task.input_options
368
369
  jobname_input = task.input_options.select{|i,o| o[:jobname]}.collect{|i,o| i }.first
369
370
  else
@@ -26,105 +26,106 @@ module Workflow
26
26
  raise "No '#{name}' task in '#{self.to_s}' Workflow" if task.nil?
27
27
  id = File.join(self.to_s, name.to_s)
28
28
  @task_info ||= {}
29
- @task_info[id] ||= begin description = task.description
30
- result_description = task.result_description
31
- result_type = task.result_type
32
- inputs = rec_inputs(name).uniq
33
- input_types = rec_input_types(name)
34
- input_descriptions = rec_input_descriptions(name)
35
- input_use = rec_input_use(name)
36
- input_defaults = rec_input_defaults(name)
37
- input_options = rec_input_options(name)
38
- extension = task.extension
39
- export = case
40
- when (synchronous_exports.include?(name.to_sym) or synchronous_exports.include?(name.to_s))
41
- :synchronous
42
- when (asynchronous_exports.include?(name.to_sym) or asynchronous_exports.include?(name.to_s))
43
- :asynchronous
44
- when (exec_exports.include?(name.to_sym) or exec_exports.include?(name.to_s))
45
- :exec
46
- when (stream_exports.include?(name.to_sym) or stream_exports.include?(name.to_s))
47
- :stream
48
- else
49
- :none
50
- end
29
+ @task_info[id] ||= begin
30
+ description = task.description
31
+ result_description = task.result_description
32
+ result_type = task.result_type
33
+ inputs = rec_inputs(name).uniq
34
+ input_types = rec_input_types(name)
35
+ input_descriptions = rec_input_descriptions(name)
36
+ input_use = rec_input_use(name)
37
+ input_defaults = rec_input_defaults(name)
38
+ input_options = rec_input_options(name)
39
+ extension = task.extension
40
+ export = case
41
+ when (synchronous_exports.include?(name.to_sym) or synchronous_exports.include?(name.to_s))
42
+ :synchronous
43
+ when (asynchronous_exports.include?(name.to_sym) or asynchronous_exports.include?(name.to_s))
44
+ :asynchronous
45
+ when (exec_exports.include?(name.to_sym) or exec_exports.include?(name.to_s))
46
+ :exec
47
+ when (stream_exports.include?(name.to_sym) or stream_exports.include?(name.to_s))
48
+ :stream
49
+ else
50
+ :none
51
+ end
51
52
 
52
- dependencies = task_dependencies[name].select{|dep| String === dep or Symbol === dep}
53
- info = { :id => id,
54
- :description => description,
55
- :export => export,
56
- :inputs => inputs,
57
- :input_types => input_types,
58
- :input_descriptions => input_descriptions,
59
- :input_defaults => input_defaults,
60
- :input_options => input_options,
61
- :input_use => input_use,
62
- :result_type => result_type,
63
- :result_description => result_description,
64
- :dependencies => dependencies,
65
- :extension => extension
66
- }
67
- end
53
+ dependencies = task_dependencies[name].select{|dep| String === dep or Symbol === dep}
54
+ { :id => id,
55
+ :description => description,
56
+ :export => export,
57
+ :inputs => inputs,
58
+ :input_types => input_types,
59
+ :input_descriptions => input_descriptions,
60
+ :input_defaults => input_defaults,
61
+ :input_options => input_options,
62
+ :input_use => input_use,
63
+ :result_type => result_type,
64
+ :result_description => result_description,
65
+ :dependencies => dependencies,
66
+ :extension => extension
67
+ }
68
+ end
68
69
  end
69
70
 
70
71
  def rec_dependencies(taskname)
71
72
  @rec_dependencies ||= {}
72
73
  @rec_dependencies[taskname] ||= begin
73
- if task_dependencies.include? taskname
74
-
75
- deps = task_dependencies[taskname]
76
-
77
- #all_deps = deps.select{|dep| String === dep or Symbol === dep or Array === dep}
78
-
79
- all_deps = []
80
- deps.each do |dep|
81
- if DependencyBlock === dep
82
- all_deps << dep.dependency if dep.dependency
83
- else
84
- all_deps << dep unless Proc === dep
85
- end
86
-
87
- begin
88
- case dep
89
- when Array
90
- wf, t, o = dep
91
-
92
- wf.rec_dependencies(t.to_sym).each do |d|
93
- if Array === d
94
- new = d.dup
95
- else
96
- new = [dep.first, d]
97
- end
98
-
99
- if Hash === o and not o.empty?
100
- if Hash === new.last
101
- hash = new.last.dup
102
- o.each{|k,v| hash[k] ||= v}
103
- new[new.length-1] = hash
104
- else
105
- new.push o.dup
74
+ if task_dependencies.include? taskname
75
+
76
+ deps = task_dependencies[taskname]
77
+
78
+ #all_deps = deps.select{|dep| String === dep or Symbol === dep or Array === dep}
79
+
80
+ all_deps = []
81
+ deps.each do |dep|
82
+ if DependencyBlock === dep
83
+ all_deps << dep.dependency if dep.dependency
84
+ else
85
+ all_deps << dep unless Proc === dep
86
+ end
87
+
88
+ begin
89
+ case dep
90
+ when Array
91
+ wf, t, o = dep
92
+
93
+ wf.rec_dependencies(t.to_sym).each do |d|
94
+ if Array === d
95
+ new = d.dup
96
+ else
97
+ new = [dep.first, d]
98
+ end
99
+
100
+ if Hash === o and not o.empty?
101
+ if Hash === new.last
102
+ hash = new.last.dup
103
+ o.each{|k,v| hash[k] ||= v}
104
+ new[new.length-1] = hash
105
+ else
106
+ new.push o.dup
107
+ end
108
+ end
109
+
110
+ all_deps << new
111
+ end if wf && t
112
+
113
+ when String, Symbol
114
+ rec_deps = rec_dependencies(dep.to_sym)
115
+ all_deps.concat rec_deps
116
+ when DependencyBlock
117
+ dep = dep.dependency
118
+ raise TryAgain
119
+ end
120
+ rescue TryAgain
121
+ retry
122
+ end
106
123
  end
124
+ all_deps.uniq
125
+ else
126
+ []
107
127
  end
108
-
109
- all_deps << new
110
- end if wf && t
111
-
112
- when String, Symbol
113
- rec_deps = rec_dependencies(dep.to_sym)
114
- all_deps.concat rec_deps
115
- when DependencyBlock
116
- dep = dep.dependency
117
- raise TryAgain
118
- end
119
- rescue TryAgain
120
- retry
121
- end
122
- end
123
- all_deps.uniq
124
- else
125
- []
126
- end
127
- end
128
+ end
128
129
  end
129
130
 
130
131
  def task_from_dep(dep)
@@ -182,7 +183,7 @@ module Workflow
182
183
  acc
183
184
  }.tap{|h| IndiferentHash.setup(h)}
184
185
  end
185
-
186
+
186
187
  def rec_input_use(taskname)
187
188
  task = task_from_dep(taskname)
188
189
  deps = rec_dependencies(taskname)
@@ -474,7 +475,7 @@ module Workflow
474
475
  else
475
476
  workdir_find = workdir
476
477
  end
477
-
478
+
478
479
  workdir_find = File.expand_path(workdir_find)
479
480
  path = File.expand_path(path)
480
481
  dir = File.dirname(path)
@@ -81,9 +81,10 @@ module Workflow
81
81
  if forget
82
82
  remove = config :remove_dep_tasks, :remove_dep_tasks, :default => REMOVE_DEP_TASKS
83
83
  self.archive_deps
84
+ self.copy_files_dir
84
85
  self.dependencies = self.dependencies - [dep]
85
86
  Open.rm_rf self.files_dir if Open.exist? self.files_dir
86
- FileUtils.cp_r dep.files_dir, self.files_dir if Open.exist? dep.files_dir
87
+ FileUtils.cp_r dep.files_dir, self.files_dir if Open.exist?(dep.files_dir)
87
88
  Open.ln_h dep.path, self.tmp_path
88
89
  case remove.to_s
89
90
  when 'true'
@@ -92,8 +93,10 @@ module Workflow
92
93
  dep.recursive_clean
93
94
  end
94
95
  else
95
- Open.rm_rf self.files_dir
96
- Open.link dep.files_dir, self.files_dir
96
+ if Open.exists?(dep.files_dir)
97
+ Open.rm_rf self.files_dir
98
+ Open.link dep.files_dir, self.files_dir
99
+ end
97
100
  Open.link dep.path, self.path
98
101
  end
99
102
  nil
@@ -1,9 +1,9 @@
1
- module Workflow
1
+ module Cromwell
2
2
 
3
3
  Rbbt.claim Rbbt.software.opt.jar["cromwell.jar"], :url, "https://github.com/broadinstitute/cromwell/releases/download/48/cromwell-48.jar"
4
4
  Rbbt.claim Rbbt.software.opt.jar["wdltool.jar"], :url, "https://github.com/broadinstitute/wdltool/releases/download/0.14/wdltool-0.14.jar"
5
5
 
6
- def run_cromwell(file, work_dir, options = {})
6
+ def self.run_cromwell(file, work_dir, options = {})
7
7
  cromwell_inputs_file = Misc.process_options options, :cromwell_inputs_file
8
8
  jar = Rbbt.software.opt.jar["cromwell.jar"].produce.find
9
9
  if cromwell_inputs_file
@@ -12,7 +12,9 @@ module Workflow
12
12
  CMD.cmd_log("java -jar '#{jar}' run '#{file}' --workflow-root='#{work_dir}'", options.merge("add_option_dashes" => true))
13
13
  end
14
14
  end
15
+ end
15
16
 
17
+ module Workflow
16
18
  def load_cromwell(file)
17
19
  jar = Rbbt.software.opt.jar["wdltool.jar"].produce.find
18
20
  inputs = JSON.load(CMD.cmd("java -jar '#{jar}' inputs '#{file}'"))
@@ -85,7 +85,11 @@ class RemoteWorkflow
85
85
 
86
86
  RemoteWorkflow::REST.__prepare_inputs_for_restclient(params)
87
87
  name = RemoteWorkflow.capture_exception do
88
- RestClient.post(self.encode(url), params)
88
+ begin
89
+ RestClient.post(self.encode(url), params)
90
+ rescue RestClient::MovedPermanently, RestClient::Found, RestClient::TemporaryRedirect
91
+ raise RbbtException, "REST end-point moved to: #{$!.response.headers[:location]}"
92
+ end
89
93
  end
90
94
 
91
95
  Log.debug{ "RestClient jobname returned for #{ url } - #{Misc.fingerprint params}: #{name}" }
@@ -84,6 +84,7 @@ class Step
84
84
  end
85
85
 
86
86
  def load_dependencies_from_info
87
+ relocated = nil
87
88
  @dependencies = (self.info[:dependencies] || []).collect do |task,name,dep_path|
88
89
  if Open.exists?(dep_path) || Open.exists?(dep_path + '.info')
89
90
  Workflow._load_step dep_path
@@ -108,6 +109,14 @@ class Step
108
109
  @inputs || []
109
110
  end
110
111
 
112
+ def copy_files_dir
113
+ if File.symlink?(self.files_dir)
114
+ realpath = Open.realpath(self.files_dir)
115
+ Open.rm self.files_dir
116
+ Open.cp realpath, self.files_dir
117
+ end
118
+ end
119
+
111
120
  def archive_deps
112
121
  self.set_info :archived_info, archived_info
113
122
  self.set_info :archived_dependencies, info[:dependencies]
@@ -411,7 +420,7 @@ class Step
411
420
  return
412
421
  end
413
422
 
414
- if (Open.exists?(path) or Open.broken_link?(path)) or Open.exists?(pid_file) or Open.exists?(info_file) or Open.exists?(files_dir)
423
+ if (Open.exists?(path) or Open.broken_link?(path)) or Open.exists?(pid_file) or Open.exists?(info_file) or Open.exists?(files_dir) or Open.broken_link?(files_dir)
415
424
 
416
425
  @result = nil
417
426
  @pid = nil
@@ -419,8 +428,8 @@ class Step
419
428
  Misc.insist do
420
429
  Open.rm info_file if Open.exists?(info_file)
421
430
  Open.rm md5_file if Open.exists?(md5_file)
422
- Open.rm path if (Open.exists?(path) or Open.broken_link?(path))
423
- Open.rm_rf files_dir if Open.exists?(files_dir)
431
+ Open.rm path if (Open.exists?(path) || Open.broken_link?(path))
432
+ Open.rm_rf files_dir if Open.exists?(files_dir) || Open.broken_link?(files_dir)
424
433
  Open.rm pid_file if Open.exists?(pid_file)
425
434
  Open.rm tmp_path if Open.exists?(tmp_path)
426
435
  end
@@ -454,12 +463,15 @@ class Step
454
463
  return [] if dependencies.nil? or dependencies.empty?
455
464
 
456
465
  new_dependencies = []
466
+ archived_deps = self.info[:archived_info] ? self.info[:archived_info].keys : []
467
+
457
468
  dependencies.each{|step|
458
469
  #next if self.done? && Open.exists?(info_file) && info[:dependencies] && info[:dependencies].select{|task,name,path| path == step.path }.empty?
459
- next if seen.include? step
470
+ next if archived_deps.include? step.path
471
+ next if seen.include? step.path
460
472
  next if self.done? && need_run && ! updatable?
461
473
 
462
- r = step.rec_dependencies(need_run, new_dependencies)
474
+ r = step.rec_dependencies(need_run, new_dependencies.collect{|d| d.path})
463
475
  new_dependencies.concat r
464
476
  new_dependencies << step
465
477
  }