rbbt-util 5.32.10 → 5.32.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rbbt +1 -0
  3. data/lib/rbbt/annotations/util.rb +1 -0
  4. data/lib/rbbt/entity.rb +6 -1
  5. data/lib/rbbt/hpc/batch.rb +26 -9
  6. data/lib/rbbt/hpc/orchestrate.rb +1 -0
  7. data/lib/rbbt/hpc/slurm.rb +29 -12
  8. data/lib/rbbt/resource.rb +51 -49
  9. data/lib/rbbt/tsv.rb +5 -0
  10. data/lib/rbbt/tsv/csv.rb +2 -2
  11. data/lib/rbbt/tsv/manipulate.rb +2 -0
  12. data/lib/rbbt/tsv/parallel/traverse.rb +8 -11
  13. data/lib/rbbt/util/R.rb +2 -2
  14. data/lib/rbbt/util/cmd.rb +39 -18
  15. data/lib/rbbt/util/log/progress/report.rb +20 -17
  16. data/lib/rbbt/util/log/progress/util.rb +2 -1
  17. data/lib/rbbt/util/misc/omics.rb +2 -2
  18. data/lib/rbbt/util/misc/system.rb +2 -2
  19. data/lib/rbbt/util/python.rb +63 -3
  20. data/lib/rbbt/util/simpleDSL.rb +4 -4
  21. data/lib/rbbt/workflow.rb +32 -4
  22. data/lib/rbbt/workflow/definition.rb +1 -1
  23. data/lib/rbbt/workflow/step.rb +37 -6
  24. data/lib/rbbt/workflow/step/accessor.rb +2 -2
  25. data/lib/rbbt/workflow/util/data.rb +35 -0
  26. data/lib/rbbt/workflow/util/provenance.rb +26 -7
  27. data/lib/rbbt/workflow/util/trace.rb +2 -1
  28. data/python/rbbt.py +7 -0
  29. data/share/install/software/lib/install_helpers +1 -1
  30. data/share/rbbt_commands/hpc/list +11 -7
  31. data/share/rbbt_commands/hpc/orchestrate +7 -1
  32. data/share/rbbt_commands/hpc/task +5 -0
  33. data/share/rbbt_commands/lsf/list +11 -7
  34. data/share/rbbt_commands/lsf/orchestrate +7 -1
  35. data/share/rbbt_commands/lsf/task +5 -0
  36. data/share/rbbt_commands/slurm/list +11 -7
  37. data/share/rbbt_commands/slurm/orchestrate +7 -1
  38. data/share/rbbt_commands/slurm/task +5 -0
  39. data/share/rbbt_commands/workflow/forget_deps +5 -4
  40. data/test/rbbt/util/test_python.rb +3 -2
  41. data/test/rbbt/util/test_simpleDSL.rb +3 -3
  42. data/test/rbbt/workflow/util/test_data.rb +48 -0
  43. metadata +86 -83
data/lib/rbbt/util/R.rb CHANGED
@@ -41,7 +41,7 @@ source('#{UTIL}');
41
41
 
42
42
  if monitor
43
43
  #io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true))
44
- io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true, :xvfb => true))
44
+ io = CMD.cmd('R --no-save --quiet', options.merge(:in => cmd, :pipe => true, :log => true, :xvfb => options[:xvfb]))
45
45
  while line = io.gets
46
46
  case monitor
47
47
  when Proc
@@ -52,7 +52,7 @@ source('#{UTIL}');
52
52
  end
53
53
  nil
54
54
  else
55
- CMD.cmd('R --no-save --slave --quiet', options.merge(:in => cmd, :xvfb => true))
55
+ CMD.cmd('R --no-save --slave --quiet', options.merge(:in => cmd, :xvfb => options[:xvfb]))
56
56
  end
57
57
  end
58
58
 
data/lib/rbbt/util/cmd.rb CHANGED
@@ -192,25 +192,47 @@ module CMD
192
192
 
193
193
  ConcurrentStream.setup sout, :pids => pids, :autojoin => no_wait, :no_fail => no_fail
194
194
 
195
- err_thread = Thread.new do
196
- while line = serr.gets
197
- bar.process(line) if bar
198
- sout.log = line
199
- Log.log "STDERR [#{pid}]: " + line, stderr
200
- end if Integer === stderr and log
201
- serr.close
195
+ if (Integer === stderr and log) || bar
196
+ err_thread = Thread.new do
197
+ while line = serr.gets
198
+ bar.process(line) if bar
199
+ sout.log = line
200
+ Log.log "STDERR [#{pid}]: " + line, stderr if log
201
+ end
202
+ serr.close
203
+ end
204
+ else
205
+ err_thread = Misc.consume_stream(serr, true)
202
206
  end
203
207
 
204
208
  sout.threads = [in_thread, err_thread, wait_thr].compact
205
209
 
206
210
  sout
207
211
  else
208
- err = ""
209
- err_thread = Thread.new do
210
- while not serr.eof?
211
- err << serr.gets if Integer === stderr
212
+
213
+ if bar
214
+ err = ""
215
+ err_thread = Thread.new do
216
+ while not serr.eof?
217
+ line = serr.gets
218
+ bar.process(line)
219
+ err << line if Integer === stderr and log
220
+ end
221
+ serr.close
212
222
  end
213
- serr.close
223
+ elsif log and Integer === stderr
224
+ err = ""
225
+ err_thread = Thread.new do
226
+ while not serr.eof?
227
+ err << serr.gets
228
+ end
229
+ serr.close
230
+ end
231
+ else
232
+ Misc.consume_stream(serr, true)
233
+ #serr.close
234
+ err_thread = nil
235
+ err = ""
214
236
  end
215
237
 
216
238
  ConcurrentStream.setup sout, :pids => pids, :threads => [in_thread, err_thread].compact, :autojoin => no_wait, :no_fail => no_fail
@@ -220,7 +242,11 @@ module CMD
220
242
 
221
243
  status = wait_thr.value
222
244
  if not status.success? and not no_fail
223
- raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}.\n#{err}"
245
+ if !err.empty?
246
+ raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}.\n#{err}"
247
+ else
248
+ raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{status.exitstatus}"
249
+ end
224
250
  else
225
251
  Log.log err, stderr if Integer === stderr and log
226
252
  end
@@ -263,11 +289,6 @@ module CMD
263
289
  if c == "\n"
264
290
  bar.process(line) if bar
265
291
  starting = true
266
- #if pid
267
- # Log.logn "STDOUT [#{pid}]: ", level
268
- #else
269
- # Log.logn "STDOUT: ", level
270
- #end
271
292
  line = "" if bar
272
293
  end
273
294
  end
@@ -12,32 +12,35 @@ module Log
12
12
  attr_accessor :history, :mean_max, :max_history
13
13
  def thr_msg
14
14
  if @history.nil?
15
- @history ||= [[@ticks, Time.now] ]
15
+ @history ||= [[0, @start], [@ticks, Time.now] ]
16
16
  elsif @last_ticks != @ticks
17
17
  @history << [@ticks, Time.now]
18
- max_history ||= case
19
- when @ticks > 20
20
- count = @ticks - @last_count
21
- count = 1 if count == 0
22
- if @max
23
- times = @max / count
24
- num = times / 20
25
- num = 2 if num < 2
26
- else
27
- num = 10
18
+ max_history ||= begin
19
+ max_history = case
20
+ when @ticks > 20
21
+ count = @ticks - @last_count
22
+ count = 1 if count == 0
23
+ if @max
24
+ times = @max / count
25
+ num = times / 20
26
+ num = 2 if num < 2
27
+ else
28
+ num = 10
29
+ end
30
+ count * num
31
+ else
32
+ 20
33
+ end
34
+ max_history = 30 if max_history > 30
35
+ max_history
28
36
  end
29
- count * num
30
- else
31
- 20
32
- end
33
- max_history = 30 if max_history > 30
34
37
  @history.shift if @history.length > max_history
35
38
  end
36
39
 
37
40
  @last_ticks = @ticks
38
41
 
39
42
  @mean_max ||= 0
40
- if @history.length > 2
43
+ if @history.length > 3
41
44
 
42
45
  sticks, stime = @history.first
43
46
  ssticks, sstime = @history[-3]
@@ -80,10 +80,11 @@ module Log
80
80
 
81
81
  def self.with_bar(max, options = {})
82
82
  bar = new_bar(max, options)
83
+ res = nil
83
84
  begin
84
85
  error = false
85
- yield bar
86
86
  keep = false
87
+ yield bar
87
88
  rescue KeepBar
88
89
  keep = true
89
90
  rescue
@@ -511,9 +511,9 @@ module Misc
511
511
 
512
512
  case chr_prefix.to_s.downcase
513
513
  when "remove"
514
- sort_order = sort_order.collect{|chr| "chr" + chr } unless sort_order.first.include?('chr')
515
- when "true", "add"
516
514
  sort_order = sort_order.collect{|chr| chr.sub('chr', '') } if sort_order.first.include?('chr')
515
+ when "true", "add"
516
+ sort_order = sort_order.collect{|chr| "chr" + chr } unless sort_order.first.include?('chr')
517
517
  end
518
518
 
519
519
  sort_genomic_locations_by_contig(mutations, sort_order)
@@ -112,10 +112,10 @@ end
112
112
  res
113
113
  end
114
114
 
115
- def self.is_filename?(string)
115
+ def self.is_filename?(string, need_to_exists = true)
116
116
  return true if defined? Path and Path === string
117
117
  return true if string.respond_to? :exists
118
- return true if String === string and string.length < 265 and File.exist?(string)
118
+ return true if String === string and string.length < 265 and (File.exist?(string) || ! need_to_exists)
119
119
  return false
120
120
  end
121
121
 
@@ -3,10 +3,56 @@ require 'pycall/import'
3
3
 
4
4
  module RbbtPython
5
5
  extend PyCall::Import
6
+
7
+ def self.exec(script)
8
+ PyCall.exec(script)
9
+ end
10
+
11
+ def self.iterate(iterator, options = {})
12
+ bar = options[:bar]
13
+
14
+ case bar
15
+ when TrueClass
16
+ bar = Log::ProgressBar.new nil, :desc => "RbbtPython iterate"
17
+ when String
18
+ bar = Log::ProgressBar.new nil, :desc => bar
19
+ end
20
+
21
+ while true
22
+ begin
23
+ yield iterator.__next__
24
+ bar.tick if bar
25
+ rescue PyCall::PyError
26
+ if $!.type.to_s == "<class 'StopIteration'>"
27
+ break
28
+ else
29
+ raise $!
30
+ end
31
+ rescue
32
+ bar.error if bar
33
+ raise $!
34
+ end
35
+ end
36
+
37
+ Log::ProgressBar.remove_bar bar if bar
38
+ nil
39
+ end
40
+
41
+ def self.collect(iterator, options = {}, &block)
42
+ acc = []
43
+ self.iterate(iterator, options) do |elem|
44
+ res = block.call elem
45
+ acc << res
46
+ end
47
+ acc
48
+ end
49
+
6
50
  def self.run(mod = nil, imports = nil, &block)
7
51
  if mod
8
- if imports
52
+ if Array === imports
9
53
  pyfrom mod, :import => imports
54
+ elsif Hash === imports
55
+ pyimport mod, imports
10
56
  else
11
57
  pyimport mod
12
58
  end
@@ -17,8 +63,10 @@ module RbbtPython
17
63
 
18
64
  def self.run_log(mod = nil, imports = nil, severity = 0, severity_err = nil, &block)
19
65
  if mod
20
- if imports
66
+ if Array === imports
21
67
  pyfrom mod, :import => imports
68
+ elsif Hash === imports
69
+ pyimport mod, imports
22
70
  else
23
71
  pyimport mod
24
72
  end
@@ -31,8 +79,10 @@ module RbbtPython
31
79
 
32
80
  def self.run_log_stderr(mod = nil, imports = nil, severity = 0, &block)
33
81
  if mod
34
- if imports
82
+ if Array === imports
35
83
  pyfrom mod, :import => imports
84
+ elsif Hash === imports
85
+ pyimport mod, imports
36
86
  else
37
87
  pyimport mod
38
88
  end
@@ -49,4 +99,14 @@ module RbbtPython
49
99
  end
50
100
  end
51
101
 
102
+ def self.add_paths(paths)
103
+ self.run 'sys' do
104
+ paths.each do |path|
105
+ sys.path.append path
106
+ end
107
+ end
108
+ end
109
+
110
+ RbbtPython.add_paths Rbbt.python.find_all
111
+ RbbtPython.pyimport "rbbt"
52
112
  end
@@ -38,13 +38,13 @@ module SimpleDSL
38
38
  hook_method(method)
39
39
 
40
40
  # Execute
41
+ @config ||= {}
41
42
  if actions.is_a? Proc
42
43
  begin
43
- require 'parse_tree_extensions'
44
- require 'parse_tree'
45
- require 'ruby2ruby'
46
- @config[@@method_name] = actions.to_ruby.collect[1..-2].join
44
+ require 'method_source'
45
+ @config[@@method_name] = actions.source.split("\n")[1..-2] * "\n"
47
46
  rescue Exception
47
+ Log.exception $!
48
48
  @config[@@method_name] = NoRuby2Ruby.new "The gem ruby2ruby is not installed. It will not work on ruby 1.9."
49
49
  end
50
50
 
data/lib/rbbt/workflow.rb CHANGED
@@ -347,6 +347,11 @@ module Workflow
347
347
 
348
348
  inputs = IndiferentHash.setup(inputs)
349
349
 
350
+ not_overriden = inputs.delete :not_overriden
351
+ if not_overriden
352
+ inputs[:not_overriden] = :not_overriden_dep
353
+ end
354
+
350
355
  Workflow.resolve_locals(inputs)
351
356
 
352
357
  task_info = task_info(taskname)
@@ -400,20 +405,43 @@ module Workflow
400
405
  jobname = DEFAULT_NAME if jobname.nil? or jobname.empty?
401
406
 
402
407
  dependencies = real_dependencies(task, jobname, defaults.merge(inputs), task_dependencies[taskname] || [])
403
- overriden = has_overriden_inputs || dependencies.select{|dep| dep.overriden }.any?
408
+
409
+ overriden_deps = dependencies.select{|d| d.overriden }
410
+ true_overriden_deps = overriden_deps.select{|d| TrueClass === d.overriden }
411
+
412
+ overriden = has_overriden_inputs || overriden_deps.any?
413
+
414
+ extension = task.extension
415
+
416
+ if extension == :dep_task
417
+ extension = nil
418
+ if dependencies.any?
419
+ dep_basename = File.basename(dependencies.last.path)
420
+ extension = dep_path.split(".").last if dep_basename.include?('.')
421
+ end
422
+ end
404
423
 
405
424
  if real_inputs.empty? && Workflow::TAG != :inputs && ! overriden
406
- step_path = step_path taskname, jobname, [], [], task.extension
425
+ step_path = step_path taskname, jobname, [], [], extension
407
426
  input_values = task.take_input_values(inputs)
408
427
  else
409
428
  input_values = task.take_input_values(inputs)
410
- step_path = step_path taskname, jobname, input_values, dependencies, task.extension
429
+ step_path = step_path taskname, jobname, input_values, dependencies, extension
411
430
  end
412
431
 
413
432
  job = get_job_step step_path, task, input_values, dependencies
414
433
  job.workflow = self
415
434
  job.clean_name = jobname
416
- job.overriden = overriden
435
+
436
+ case not_overriden
437
+ when TrueClass
438
+ job.overriden = has_overriden_inputs || true_overriden_deps.any?
439
+ when :not_overriden_dep
440
+ job.overriden = true if has_overriden_inputs || true_overriden_deps.any?
441
+ else
442
+ job.overriden = true if has_overriden_inputs || overriden_deps.any?
443
+ end
444
+
417
445
  job.real_inputs = real_inputs.keys
418
446
  job
419
447
  end
@@ -73,7 +73,7 @@ module Workflow
73
73
  REMOVE_DEP_TASKS = ENV["RBBT_REMOVE_DEP_TASKS"] == "true"
74
74
  def dep_task(name, workflow, oname, *rest, &block)
75
75
  dep(workflow, oname, *rest, &block)
76
- extension workflow.tasks[oname].extension if workflow.tasks.include?(oname) unless @extension
76
+ extension :dep_task unless @extension
77
77
  returns workflow.tasks[oname].result_description if workflow.tasks.include?(oname) unless @result_description
78
78
  task name do
79
79
  raise RbbtException, "dependency not found in dep_task" if dependencies.empty?
@@ -34,13 +34,40 @@ class Step
34
34
  end
35
35
  end
36
36
 
37
+
38
+ def overriden?
39
+ return true if @overriden
40
+ return true if dependencies.select{|dep| dep.overriden? }.any?
41
+ info[:archived_info].each do |f,i|
42
+ return true if i[:overriden] || i["overriden"]
43
+ end if info[:archived_info]
44
+ return false
45
+ end
46
+
37
47
  def overriden
38
- if @overriden.nil?
39
- return [] if dependencies.nil?
40
- dependencies.select{|dep| dep.overriden }.any?
41
- else
42
- @overriden
48
+ @overriden
49
+ #if @overriden.nil?
50
+ # return false if dependencies.nil?
51
+ # dependencies.select{|dep| dep.overriden? }.any?
52
+ #else
53
+ # @overriden
54
+ #end
55
+ end
56
+
57
+ def overriden_deps
58
+ ord = []
59
+ deps = dependencies.dup
60
+ while dep = deps.shift
61
+ case dep.overriden
62
+ when FalseClass
63
+ next
64
+ when Symbol
65
+ ord << dep
66
+ else
67
+ deps += dep.dependencies
68
+ end
43
69
  end
70
+ ord
44
71
  end
45
72
 
46
73
  def initialize(path, task = nil, inputs = nil, dependencies = nil, bindings = nil, clean_name = nil)
@@ -134,7 +161,11 @@ class Step
134
161
 
135
162
  archived_info = {}
136
163
  dependencies.each do |dep|
137
- archived_info[dep.path] = dep.info
164
+ if Symbol === dep.overriden && ! Open.exists?(dep.info_file)
165
+ archived_info[dep.path] = dep.overriden
166
+ else
167
+ archived_info[dep.path] = dep.info
168
+ end
138
169
  archived_info.merge!(dep.archived_info)
139
170
  end if dependencies
140
171
 
@@ -248,7 +248,7 @@ class Step
248
248
  def init_info(force = false)
249
249
  return nil if @exec || info_file.nil? || (Open.exists?(info_file) && ! force)
250
250
  Open.lock(info_file, :lock => info_lock) do
251
- i = {:status => :waiting, :pid => Process.pid, :path => path, :real_inputs => real_inputs}
251
+ i = {:status => :waiting, :pid => Process.pid, :path => path, :real_inputs => real_inputs, :overriden => overriden}
252
252
  i[:dependencies] = dependencies.collect{|dep| [dep.task_name, dep.name, dep.path]} if dependencies
253
253
  Misc.sensiblewrite(info_file, Step.serialize_info(i), :force => true, :lock => false)
254
254
  @info_cache = IndiferentHash.setup(i)
@@ -551,7 +551,7 @@ class Step
551
551
 
552
552
  def aborted?
553
553
  status = self.status
554
- status == :aborted || ((status != :dependencies && status != :cleaned && status != :noinfo && status != :setup && status != :noinfo) && nopid?)
554
+ status == :aborted || ((status != :ending && status != :dependencies && status != :cleaned && status != :noinfo && status != :setup && status != :noinfo) && nopid?)
555
555
  end
556
556
 
557
557
  # {{{ INFO