rbbt-util 5.26.6 → 5.26.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a856a792ffcb0f6e395e2452f75624050653ec72
4
- data.tar.gz: 193c1d2cf21224d5233151417f61d3e8b1cb52fa
2
+ SHA256:
3
+ metadata.gz: 73dc573b119d00638cd05d906db7e13ae1d4c1f402bc447192127bf42a2538de
4
+ data.tar.gz: f18941095a6cd114cffc2140bd5272b9a624bf83b2dd423da91efdb4381c82a6
5
5
  SHA512:
6
- metadata.gz: 5c58296853107056685a6a12045eed29b92027972997ccde07b1498dd569bb92093199fa0b74f4d56b894f2dddd647947f8b14275e2ee312ead5eee350511717
7
- data.tar.gz: e19d29cb5e5694dcd5f95f4944ea287cc390b10bcde624553824b4e4072aca245edd2857e1f99b6dec1091264200076f0e41fc5c8e1653e68f8a9273e550f315
6
+ metadata.gz: 0231c8e2b307671ad8abea117ad86d086fe21a9db202ca8486a16e97b352671f447f67a74fc7bbf0f8fc622f85e996fbacd20eb054e749f11a9a13b0650e0cfd
7
+ data.tar.gz: 4b347b870203aa41f520cd767a30df6a1ab84b4278d6454923f59f4d8ba30137a8577cf7a1f22aa4b4e5c6a30ec1a5f0884edb79a84706bf988eb76b81589f04
data/lib/rbbt/monitor.rb CHANGED
@@ -173,7 +173,7 @@ module Rbbt
173
173
  end
174
174
  else
175
175
  #cmd = "find -L '#{ taskdir }/' -not \\( -path \"#{taskdir}/*.files/*\" -prune \\) -not -name '*.pid' -not -name '*.notify' -not -name '\\.*' 2>/dev/null"
176
- cmd = "find -L '#{ taskdir }/' -not \\( -path \"#{taskdir}/.info/*\" -prune \\) -not \\( -path \"#{taskdir}/*.files/*\" -prune \\) -not -name '*.pid' -not -name '*.notify' -not -name '\\.*' \\( -not -type d -o -name '*.files' \\) 2>/dev/null"
176
+ cmd = "find -L '#{ taskdir }/' -not \\( -path \"#{taskdir}/.info/*\" -prune \\) -not \\( -path \"#{taskdir}/*.files/*\" -prune \\) -not -name '*.pid' -not -name '*.md5' -not -name '*.notify' -not -name '\\.*' \\( -not -type d -o -name '*.files' \\) 2>/dev/null"
177
177
 
178
178
  CMD.cmd(cmd, :pipe => true)
179
179
  end
@@ -395,7 +395,7 @@ module TSV
395
395
  new[key] = values if invert ^ ([key,values].flatten.select{|v| v =~ method}.any?)
396
396
  end
397
397
  end
398
- when String === method
398
+ when (String === method || Symbol === method)
399
399
  if block_given?
400
400
  case
401
401
  when block.arity == 1
@@ -75,7 +75,7 @@ module Log
75
75
  def thr_msg
76
76
  if @history.nil?
77
77
  @history ||= [[@ticks, Time.now] ]
78
- else
78
+ elsif @last_ticks != @ticks
79
79
  @history << [@ticks, Time.now]
80
80
  max_history ||= case
81
81
  when @ticks > 20
@@ -96,13 +96,16 @@ module Log
96
96
  @history.shift if @history.length > max_history
97
97
  end
98
98
 
99
+ @last_ticks = @ticks
100
+
99
101
  @mean_max ||= 0
100
- if @history.length > 3
102
+ if @history.length > 2
101
103
 
102
104
  sticks, stime = @history.first
103
105
  ssticks, sstime = @history[-3]
104
106
  lticks, ltime = @history.last
105
107
 
108
+
106
109
  mean = @mean = (lticks - sticks).to_f / (ltime - stime)
107
110
  short_mean = (lticks - ssticks).to_f / (ltime - sstime)
108
111
 
@@ -328,8 +328,8 @@ module Misc
328
328
  end
329
329
 
330
330
  def self.chr_cmp_strict(chr1, chr2)
331
- chr1 = chr1.sub(/^chr/)
332
- chr2 = chr2.sub(/^chr/)
331
+ chr1 = chr1.sub(/^chr/, '')
332
+ chr2 = chr2.sub(/^chr/, '')
333
333
  if (m1 = chr1.match(/(\d+)$/)) && (m2 = chr2.match(/(\d+)$/))
334
334
  m1[1].to_i <=> m2[1].to_i
335
335
  elsif chr1 =~ /\d+$/
@@ -17,13 +17,13 @@ module TmpFile
17
17
 
18
18
  # Creates a random file name, with the given suffix and a random number
19
19
  # up to +max+
20
- def self.random_name(s = "", max = 10000000)
20
+ def self.random_name(s = "tmp-", max = 10000000)
21
21
  n = rand(max)
22
22
  s + n.to_s
23
23
  end
24
24
 
25
25
  # Creates a random filename in the temporary directory
26
- def self.tmp_file(s = "", max=10000000, dir = TMPDIR)
26
+ def self.tmp_file(s = "tmp-", max=10000000, dir = TMPDIR)
27
27
  File.expand_path(File.join(dir, random_name(s,max)))
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ module TmpFile
31
31
  options, content, erase = content, nil, true if Hash === content
32
32
  options, erase = erase, true if Hash === erase
33
33
 
34
- prefix = options[:prefix] || ""
34
+ prefix = options[:prefix] || "tmp-"
35
35
  tmpdir = options[:tmpdir] || TMPDIR
36
36
  max = options[:max] || 10000000
37
37
  tmpfile = tmp_file prefix, max, tmpdir
@@ -53,7 +53,7 @@ module TmpFile
53
53
  end
54
54
 
55
55
  def self.with_dir(erase = true, options = {})
56
- prefix = options[:prefix] || ""
56
+ prefix = options[:prefix] || "tmpdir-"
57
57
  tmpdir = tmp_file prefix
58
58
 
59
59
  FileUtils.mkdir_p tmpdir
@@ -73,8 +73,9 @@ module Workflow
73
73
  if forget
74
74
  self.dependencies = self.dependencies - [dep]
75
75
  self.set_info :dependency, dependencies.collect{|dep| [dep.task_name, dep.name, dep.path]}
76
+ Open.rm_rf self.files_dir if Open.exist? self.files_dir
76
77
  FileUtils.cp_r dep.files_dir, self.files_dir if Open.exist? dep.files_dir
77
- Open.cp dep.path, self.tmp_path
78
+ Open.ln_h dep.path, self.tmp_path
78
79
  else
79
80
  Open.link dep.path, self.path
80
81
  end
@@ -42,7 +42,7 @@ module Workflow
42
42
  dir = Path.setup(dir.dup)
43
43
  input_names.each do |input|
44
44
  file = dir[input].find
45
- file = dir.glob(input.to_s + ".*").first if file.nil? or not file.exists?
45
+ file = dir.glob(input.to_s + ".*").reject{|f| f =~ /\.md5$/}.first if file.nil? or not file.exists?
46
46
  Log.debug "Trying #{ input }: #{file}"
47
47
  next unless file and file.exists?
48
48
 
@@ -1,6 +1,6 @@
1
1
  class Step
2
2
  class ResourceManager
3
- class NotEoughResources < Exception
3
+ class NotEnoughResources < Exception
4
4
  end
5
5
 
6
6
  attr_accessor :cpus, :memory
@@ -15,7 +15,7 @@ class Step
15
15
  RbbtSemaphore.synchronize(@semaphore) do
16
16
  if (@cpus && cpus && @cpus < cups) ||
17
17
  (@memory && memory && @memory < memory)
18
- raise NotEoughResources
18
+ raise NotEnoughResources
19
19
  end
20
20
  begin
21
21
  @cpus -= cpus
@@ -61,7 +61,7 @@ class Step
61
61
  jdeps.reject!{|dep| dep.done? }
62
62
  @job_deps[job.path] = []
63
63
  jdeps.each do |dep|
64
- next if dep.done?
64
+ #next if dep.done?
65
65
  @dep_jobs[dep.path] ||= []
66
66
  @job_deps[job.path] << dep.path
67
67
  @dep_jobs[dep.path] << job.path
@@ -69,128 +69,135 @@ class Step
69
69
  end
70
70
  end
71
71
 
72
-
73
- def self.ready
72
+ def ready
74
73
  @job_deps.select do |jobp,deps|
75
74
  (@missing & deps).empty?
76
75
  end.collect{|jobp,deps| jobp}
77
76
  end
78
77
 
79
- def self.next
78
+ def used
79
+ iii @dep_jobs
80
+ @dep_jobs.select do |dep,jobs|
81
+ iif [dep, @missing.to_a, jobs]
82
+ (@missing & jobs).empty?
83
+ end.keys
84
+ end
85
+
86
+ def next
80
87
  priorities = {}
81
88
  @jobs.each do |job|
82
- priorities = 1
89
+ priorities[job.path] = 1
83
90
  end
84
91
 
85
92
  @missing.each do |jobp|
86
93
  end
87
94
 
88
- @dep_jobsb
89
- end
90
- end
91
- end
92
-
93
- def self._priorities(jobs)
94
- job_level = {}
95
- jobs.each do |job|
96
- job_level[job.path] = 1.0
97
- end
98
-
99
- with_deps = jobs.dup
100
- dep_jobs = {}
101
- job_deps = {}
102
- while with_deps.any?
103
- job = with_deps.pop
104
- level = job_level[job.path]
105
- job_deps[job.path] = []
106
- jdeps = job.dependencies
107
- jdeps += job.inputs.flatten.select{|i| Step === i}
108
-
109
- jdeps.reject!{|dep| dep.done? }
110
- jdeps.each do |dep|
111
- next if dep.done?
112
- dep_jobs[dep.path] ||= []
113
- job_level[dep.path] = level / (10 * jdeps.length) if job_level[dep.path].nil? || job_level[dep.path] < level / (10 * jdeps.length)
114
- job_deps[job.path] << dep.path
115
- dep_jobs[dep.path] << job.path
116
- with_deps << dep unless job_deps.include? dep.path
95
+ ready.first
117
96
  end
118
97
  end
119
- [job_level, job_deps, dep_jobs]
120
98
  end
121
99
 
122
- def self.produce_jobs(jobs, cpus, step_cpus = {})
123
- require 'fc'
124
-
125
- step_cpus = IndiferentHash.setup(step_cpus || {})
126
-
127
- deps = []
128
-
129
- jobs = [jobs] unless Array === jobs
130
-
131
- job_level, job_deps, dep_jobs = self._priorities(jobs)
132
-
133
- jobps = {}
134
- (jobs + jobs.collect{|job| job.rec_dependencies}).flatten.uniq.each do |job|
135
- jobps[job.path] = job
136
- end
137
-
138
- prio_queue = FastContainers::PriorityQueue.new :max
139
-
140
- job_deps.each do |jobp,depps|
141
- next if depps.any?
142
- level = job_level[jobp]
143
-
144
- prio_queue.push(jobp, level)
145
- end
146
-
147
- queue = RbbtProcessQueue.new cpus
148
-
149
- missing = job_deps.keys
150
- queue.callback do |jobp|
151
- Log.info "Done: #{jobp}"
152
- missing -= [jobp]
153
-
154
- job_level, job_deps, dep_jobs = self._priorities(jobs)
155
-
156
- parentsp = dep_jobs[jobp]
157
-
158
- parentsp.each do |parentp|
159
- next unless job_deps[parentp].include? jobp
160
- job_deps[parentp] -= [jobp]
161
- if job_deps[parentp].empty?
162
- level = job_level[parentp]
163
- prio_queue.push(parentp, level )
164
- end
165
- end if parentsp
166
- prio_queue_new = FastContainers::PriorityQueue.new :max
167
- while prio_queue.any?
168
- elem = prio_queue.pop
169
- prio_queue_new.push(elem, job_level[elem])
170
- end
171
- prio_queue = prio_queue_new
172
- end
173
-
174
- queue.init do |jobp|
175
- Log.info "Processing: #{jobp}"
176
- job = jobps[jobp]
177
- job_cpus = step_cpus[job.task_name] || 1
178
- sleep 0.5
179
- #job.produce
180
- jobp
181
- end
182
-
183
- while missing.any?
184
- while prio_queue.empty? && missing.any?
185
- sleep 1
186
- end
187
- break if missing.empty?
188
- jobp = prio_queue.pop
189
- queue.process jobp
190
- end
191
-
192
- queue.join
193
- end
100
+ #def self._priorities(jobs)
101
+ # job_level = {}
102
+ # jobs.each do |job|
103
+ # job_level[job.path] = 1.0
104
+ # end
105
+
106
+ # with_deps = jobs.dup
107
+ # dep_jobs = {}
108
+ # job_deps = {}
109
+ # while with_deps.any?
110
+ # job = with_deps.pop
111
+ # level = job_level[job.path]
112
+ # job_deps[job.path] = []
113
+ # jdeps = job.dependencies
114
+ # jdeps += job.inputs.flatten.select{|i| Step === i}
115
+
116
+ # jdeps.reject!{|dep| dep.done? }
117
+ # jdeps.each do |dep|
118
+ # next if dep.done?
119
+ # dep_jobs[dep.path] ||= []
120
+ # job_level[dep.path] = level / (10 * jdeps.length) if job_level[dep.path].nil? || job_level[dep.path] < level / (10 * jdeps.length)
121
+ # job_deps[job.path] << dep.path
122
+ # dep_jobs[dep.path] << job.path
123
+ # with_deps << dep unless job_deps.include? dep.path
124
+ # end
125
+ # end
126
+ # [job_level, job_deps, dep_jobs]
127
+ #end
128
+
129
+ #def self.produce_jobs(jobs, cpus, step_cpus = {})
130
+ # require 'fc'
131
+
132
+ # step_cpus = IndiferentHash.setup(step_cpus || {})
133
+
134
+ # deps = []
135
+
136
+ # jobs = [jobs] unless Array === jobs
137
+
138
+ # job_level, job_deps, dep_jobs = self._priorities(jobs)
139
+
140
+ # jobps = {}
141
+ # (jobs + jobs.collect{|job| job.rec_dependencies}).flatten.uniq.each do |job|
142
+ # jobps[job.path] = job
143
+ # end
144
+
145
+ # prio_queue = FastContainers::PriorityQueue.new :max
146
+
147
+ # job_deps.each do |jobp,depps|
148
+ # next if depps.any?
149
+ # level = job_level[jobp]
150
+
151
+ # prio_queue.push(jobp, level)
152
+ # end
153
+
154
+ # queue = RbbtProcessQueue.new cpus
155
+
156
+ # missing = job_deps.keys
157
+ # queue.callback do |jobp|
158
+ # Log.info "Done: #{jobp}"
159
+ # missing -= [jobp]
160
+
161
+ # job_level, job_deps, dep_jobs = self._priorities(jobs)
162
+
163
+ # parentsp = dep_jobs[jobp]
164
+
165
+ # parentsp.each do |parentp|
166
+ # next unless job_deps[parentp].include? jobp
167
+ # job_deps[parentp] -= [jobp]
168
+ # if job_deps[parentp].empty?
169
+ # level = job_level[parentp]
170
+ # prio_queue.push(parentp, level )
171
+ # end
172
+ # end if parentsp
173
+ # prio_queue_new = FastContainers::PriorityQueue.new :max
174
+ # while prio_queue.any?
175
+ # elem = prio_queue.pop
176
+ # prio_queue_new.push(elem, job_level[elem])
177
+ # end
178
+ # prio_queue = prio_queue_new
179
+ # end
180
+ #
181
+ # queue.init do |jobp|
182
+ # Log.info "Processing: #{jobp}"
183
+ # job = jobps[jobp]
184
+ # job_cpus = step_cpus[job.task_name] || 1
185
+ # sleep 0.5
186
+ # #job.produce
187
+ # jobp
188
+ # end
189
+
190
+ # while missing.any?
191
+ # while prio_queue.empty? && missing.any?
192
+ # sleep 1
193
+ # end
194
+ # break if missing.empty?
195
+ # jobp = prio_queue.pop
196
+ # queue.process jobp
197
+ # end
198
+
199
+ # queue.join
200
+ #end
194
201
  end
195
202
 
196
203
 
@@ -219,9 +226,13 @@ if __FILE__ == $0
219
226
  Workflow.require_workflow "HTS"
220
227
 
221
228
  jobs = []
222
- jobs << Sample.job(:mutect2, "QUINTANA-15")
223
- jobs << Sample.job(:mutect2, "QUINTANA-25")
224
- jobs << Sample.job(:mutect2, "QUINTANA-28")
229
+ # jobs << Sample.job(:mutect2, "QUINTANA-15")
230
+ # jobs << Sample.job(:mutect2, "QUINTANA-25")
231
+ # jobs << Sample.job(:mutect2, "QUINTANA-22")
232
+ jobs << Sample.job(:mutect2, "small")
225
233
 
226
234
  sched = Step::Scheduler.new(jobs, 3)
235
+ iii sched.ready
236
+ iii sched.used
237
+ iii sched.next
227
238
  end
@@ -119,6 +119,11 @@ class Step
119
119
  Log.info str
120
120
  end
121
121
 
122
+ def input_dependencies
123
+ inputs.flatten.select{|i| Step === i}
124
+ end
125
+
126
+
122
127
  def execute_dependency(dependency, log = true)
123
128
  task_name = self.task_name
124
129
  canfail_paths = self.canfail_paths
@@ -247,7 +252,7 @@ class Step
247
252
  respawn = rest && rest.include?(:always_respawn)
248
253
  respawn = :always if respawn.nil?
249
254
 
250
- Misc.bootstrap(list, cpus, :bar => "Bootstrapping dependencies for #{path} [#{cpus}]", :respawn => respawn) do |dep|
255
+ Misc.bootstrap(list, cpus, :bar => "Bootstrapping dependencies for #{self.short_path} [#{cpus}]", :respawn => respawn) do |dep|
251
256
  begin
252
257
  Signal.trap(:INT) do
253
258
  dep.abort
@@ -338,7 +343,7 @@ class Step
338
343
 
339
344
  compute_deps = rec_dependencies.collect do |dep|
340
345
  next unless ComputeDependency === dep
341
- dep.rec_dependencies
346
+ dep.rec_dependencies + dep.inputs.flatten.select{|i| Step === i}
342
347
  end.compact.flatten.uniq
343
348
 
344
349
  canfail_paths = self.canfail_paths
@@ -353,24 +358,15 @@ class Step
353
358
  raise $! unless canfail_paths.include? step.path
354
359
  end
355
360
  next unless step.dependencies and step.dependencies.any?
356
- step.dependencies.each do |step_dep|
361
+ (step.dependencies + step.input_dependencies).each do |step_dep|
357
362
  next if step_dep.done? or step_dep.running? or (ComputeDependency === step_dep and (step_dep.compute == :nodup or step_dep.compute == :ignore))
358
363
  dep_step[step_dep.path] ||= []
359
364
  dep_step[step_dep.path] << step_dep
360
365
  end
361
- step.inputs.each do |inputs|
362
- inputs = [inputs] unless Array === inputs
363
- inputs.each do |step_dep|
364
- next unless Step === step_dep
365
- next if step_dep.done? or step_dep.running? or (ComputeDependency === step_dep and (step_dep.compute == :nodup or step_dep.compute == :ignore))
366
- dep_step[step_dep.path] ||= []
367
- dep_step[step_dep.path] << step_dep
368
- end
369
- end
370
366
  end
371
367
 
372
368
  produced = []
373
- dependencies.each do |dep|
369
+ (dependencies + input_dependencies).each do |dep|
374
370
  next unless ComputeDependency === dep
375
371
  if dep.compute == :produce
376
372
  dep.produce
@@ -382,16 +378,16 @@ class Step
382
378
 
383
379
  required_dep_paths = []
384
380
  dep_step.each do |path,list|
385
- required_dep_paths << path if list.length > 1
381
+ #required_dep_paths << path if list.length > 1
382
+ required_dep_paths << path if (list & dependencies).any?
386
383
  end
387
384
 
388
385
  required_dep_paths.concat dependencies.collect{|dep| dep.path}
389
- required_dep_paths.concat(rec_dependencies.collect do |dep|
390
- dep.inputs.flatten.select{|i| Step === i}.collect{|d| d.path}
391
- end.flatten)
386
+
387
+ required_dep_paths.concat input_dependencies.collect{|dep| dep.path}
392
388
 
393
389
  required_dep_paths.concat(dependencies.collect do |dep|
394
- [dep.path] + dep.inputs.flatten.select{|i| Step === i}.collect{|d| d.path}
390
+ [dep.path] + dep.input_dependencies
395
391
  end.flatten)
396
392
 
397
393
  log :dependencies, "Dependencies for step #{Log.color :yellow, task.name.to_s || ""}"
@@ -238,15 +238,6 @@ class Step
238
238
  :versions => Rbbt.versions
239
239
  })
240
240
 
241
-
242
- begin
243
- run_dependencies
244
- rescue Exception
245
- Open.rm pid_file if Open.exists?(pid_file)
246
- stop_dependencies
247
- raise $!
248
- end
249
-
250
241
  new_inputs = []
251
242
  @inputs.each_with_index do |input,i|
252
243
  name = @task.inputs[i]
@@ -305,6 +296,14 @@ class Step
305
296
  set_info :inputs, Misc.remove_long_items(Misc.zip2hash(task.inputs, info_inputs))
306
297
  end
307
298
 
299
+ begin
300
+ run_dependencies
301
+ rescue Exception
302
+ Open.rm pid_file if Open.exists?(pid_file)
303
+ stop_dependencies
304
+ raise $!
305
+ end
306
+
308
307
  set_info :started, (start_time = Time.now)
309
308
  log :started, "Starting step #{Log.color :yellow, task.name.to_s || ""}"
310
309
 
@@ -117,7 +117,7 @@ if options[:plot]
117
117
  nodes <- read.csv("#{node_info_file}", header=T, as.is=T)
118
118
  links <- read.csv("#{edge_file}", header=T, as.is=T)
119
119
 
120
- library(igraph)
120
+ rbbt.require('igraph')
121
121
 
122
122
  net <- graph.data.frame(links, nodes, directed=T)
123
123
  net <- simplify(net, remove.multiple = F, remove.loops = T)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.26.6
4
+ version: 5.26.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-29 00:00:00.000000000 Z
11
+ date: 2019-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -517,8 +517,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
517
517
  - !ruby/object:Gem::Version
518
518
  version: '0'
519
519
  requirements: []
520
- rubyforge_project:
521
- rubygems_version: 2.6.13
520
+ rubygems_version: 3.0.3
522
521
  signing_key:
523
522
  specification_version: 4
524
523
  summary: Utilities for the Ruby Bioinformatics Toolkit (rbbt)