rbbt-util 5.37.16 → 5.38.1

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/lib/rbbt/annotations.rb +2 -0
  3. data/lib/rbbt/hpc/batch.rb +15 -6
  4. data/lib/rbbt/hpc/orchestrate.rb +1 -0
  5. data/lib/rbbt/persist.rb +2 -2
  6. data/lib/rbbt/resource/path.rb +1 -0
  7. data/lib/rbbt/resource/rake.rb +1 -1
  8. data/lib/rbbt/resource.rb +7 -2
  9. data/lib/rbbt/tsv/excel.rb +5 -1
  10. data/lib/rbbt/tsv/parser.rb +2 -2
  11. data/lib/rbbt/util/misc/development.rb +6 -1
  12. data/lib/rbbt/util/misc/exceptions.rb +10 -0
  13. data/lib/rbbt/util/misc/format.rb +3 -0
  14. data/lib/rbbt/util/misc/indiferent_hash.rb +9 -6
  15. data/lib/rbbt/util/misc/inspect.rb +22 -8
  16. data/lib/rbbt/util/misc/options.rb +1 -1
  17. data/lib/rbbt/util/misc/pipes.rb +3 -3
  18. data/lib/rbbt/util/open.rb +0 -1
  19. data/lib/rbbt/util/ssh.rb +107 -14
  20. data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +75 -15
  21. data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +16 -7
  22. data/lib/rbbt/workflow/remote_workflow/remote_step.rb +1 -0
  23. data/lib/rbbt/workflow/step/dependencies.rb +6 -5
  24. data/lib/rbbt/workflow/step/info.rb +1 -1
  25. data/lib/rbbt/workflow/step/run.rb +1 -1
  26. data/lib/rbbt/workflow/step/save_load_inputs.rb +9 -8
  27. data/lib/rbbt/workflow/step.rb +7 -2
  28. data/lib/rbbt/workflow/usage.rb +3 -3
  29. data/lib/rbbt/workflow.rb +1 -1
  30. data/share/rbbt_commands/hpc/list +293 -293
  31. data/share/rbbt_commands/lsf/list +293 -293
  32. data/share/rbbt_commands/resource/find +2 -1
  33. data/share/rbbt_commands/resource/glob +1 -1
  34. data/share/rbbt_commands/slurm/list +293 -293
  35. data/share/rbbt_commands/workflow/task +63 -21
  36. data/test/rbbt/test_resource.rb +7 -2
  37. data/test/rbbt/tsv/test_accessor.rb +21 -4
  38. data/test/rbbt/tsv/test_parser.rb +28 -0
  39. data/test/rbbt/util/misc/test_indiferent_hash.rb +14 -0
  40. data/test/rbbt/util/test_cmd.rb +7 -1
  41. data/test/rbbt/util/test_open.rb +3 -3
  42. data/test/rbbt/util/test_ssh.rb +10 -0
  43. metadata +7 -3
@@ -93,6 +93,8 @@ def fix_options(workflow, task, job_options)
93
93
  TrueClass === value or %w(true TRUE T yes).include? value
94
94
  when :float
95
95
  value.to_f
96
+ when :path
97
+ Path.setup(value)
96
98
  when :integer
97
99
  value.to_i
98
100
  when :text
@@ -419,13 +421,6 @@ begin
419
421
  exit 0
420
422
  end
421
423
 
422
- if tasks = options.delete(:produce)
423
- tasks = tasks.split(",")
424
- produce_cpus = (options[:produce_cpus] || 1)
425
- puts Step.produce_dependencies(job, tasks, prepare_cpus)
426
- exit 0
427
- end
428
-
429
424
  def match_dependencies(queries, dependencies)
430
425
  queries = queries.collect{|q| q.include?("#") ? q.split("#") : q }
431
426
 
@@ -443,30 +438,69 @@ begin
443
438
  matched
444
439
  end
445
440
 
441
+ def replace_relayed_jobs(jobs_to_relay, server, produce_dependencies_for_relay = false, run_type = :run)
442
+ jobs_to_relay.each do |job|
443
+ ComputeDependency.setup(job, :bootstrap)
444
+ next if job.done?
445
+ Log.low "Relaying #{Misc.fingerprint job} to #{server}"
446
+ jmeta = class << job; self; end
447
+
448
+ job.instance_variable_set(:@job, job)
449
+ job.instance_variable_set(:@host, server)
450
+ job.instance_variable_set(:@produce_dependencies, produce_dependencies_for_relay)
451
+
452
+ jmeta.define_method :run do |*args|
453
+ if done?
454
+ load
455
+ else
456
+ RemoteWorkflow::SSH.relay_job_list([@job], @host, :run_type => run_type, :migrate => true, :produce_dependencies => @produce_dependencies)
457
+ Step.migrate(@job, 'user', :source => @host)
458
+ load
459
+ end
460
+ end
461
+ #job.dependencies = []
462
+
463
+ #([job] + job.rec_dependencies).each do |j|
464
+ # next if job.done?
465
+ # jmeta = class << j; self; end
466
+
467
+ # j.instance_variable_set(:@job, job)
468
+ # j.instance_variable_set(:@host, server)
469
+ # j.instance_variable_set(:@produce_dependencies, produce_dependencies_for_relay)
470
+
471
+ # jmeta.define_method :run do |*args|
472
+ # if done?
473
+ # load
474
+ # else
475
+ # RemoteWorkflow::SSH.relay_job_list([@job], @host, :run_type => run_type, :migrate => true, :produce_dependencies => @produce_dependencies)
476
+ # Step.migrate(@job, 'user', :source => @host)
477
+ # load
478
+ # end
479
+ # end
480
+ #end
481
+ end
482
+ end
483
+
484
+
446
485
  if server = options.delete(:relay)
447
486
  require 'rbbt/workflow/remote_workflow'
448
487
  relay_dependencies = options.delete(:relay_dependencies).split(",")
449
488
  produce_dependencies_for_relay = options.delete(:produce_dependencies_for_relay)
450
- if relay_dependencies
451
- match_dependencies(relay_dependencies, job.rec_dependencies).each do |dep|
452
- RemoteWorkflow::SSH.relay_job(dep, server, :run_type => :run, :migrate => true, :produce_dependencies => produce_dependencies_for_relay)
453
- end
454
- else
455
- RemoteWorkflow::SSH.relay_job(job, server, :run_type => :run, :migrate => true, :produce_dependencies => produce_dependencies_for_relay)
456
- end
489
+
490
+ jobs_to_relay = relay_dependencies ? match_dependencies(relay_dependencies, job.rec_dependencies) : [job]
491
+ jobs_to_relay.reject!{|d| d.done? }
492
+
493
+ replace_relayed_jobs(jobs_to_relay, server, produce_dependencies_for_relay, :run)
457
494
  end
458
495
 
459
496
  if server = options.delete(:slurm_relay)
460
497
  require 'rbbt/workflow/remote_workflow'
461
498
  relay_dependencies = options.delete(:relay_dependencies).split(",")
462
499
  produce_dependencies_for_relay = options.delete(:produce_dependencies_for_relay)
463
- if relay_dependencies
464
- match_dependencies(relay_dependencies, job.rec_dependencies).each do |dep|
465
- RemoteWorkflow::SSH.relay_job(dep, server, :run_type => :orchestrate, :migrate => true, :produce_dependencies => produce_dependencies_for_relay)
466
- end
467
- else
468
- RemoteWorkflow::SSH.relay_job(job, server, :run_type => :orchestrate, :migrate => true, :produce_dependencies => produce_dependencies_for_relay)
469
- end
500
+ jobs_to_relay = relay_dependencies ? match_dependencies(relay_dependencies, job.rec_dependencies) : [job]
501
+ jobs_to_relay.reject!{|d| d.done? }
502
+
503
+ replace_relayed_jobs(jobs_to_relay, server, produce_dependencies_for_relay, :orchestrate)
470
504
  end
471
505
 
472
506
 
@@ -488,6 +522,14 @@ begin
488
522
  end
489
523
  end
490
524
 
525
+ if tasks = options.delete(:produce)
526
+ tasks = tasks.split(",")
527
+ produce_cpus = (options[:produce_cpus] || 1)
528
+ puts Step.produce_dependencies(job, tasks, produce_cpus)
529
+ exit 0
530
+ end
531
+
532
+
491
533
  if do_fork
492
534
  ENV["RBBT_NO_PROGRESS"] = "true"
493
535
  if detach
@@ -7,6 +7,8 @@ require 'test/unit'
7
7
  module TestResource
8
8
  extend Resource
9
9
 
10
+ self.subdir = 'tmp/tmp-share/resource/TestResource/'
11
+
10
12
  claim tmp.test.google, :url, "http://google.com"
11
13
  claim tmp.test.string, :string, "TEST"
12
14
  claim tmp.test.proc, :proc do
@@ -79,8 +81,8 @@ class TestTSV < Test::Unit::TestCase
79
81
  end
80
82
 
81
83
  def test_libdir
82
- assert File.exist?(TestResource[].share.Rlib["util.R"].find(:lib))
83
- assert File.exist?(TestResource[].share.Rlib["util.R"].find)
84
+ assert File.exist?(Rbbt.share.Rlib["util.R"].find(:lib))
85
+ assert File.exist?(Rbbt.share.Rlib["util.R"].find)
84
86
  end
85
87
 
86
88
  def __test_server
@@ -100,6 +102,9 @@ class TestTSV < Test::Unit::TestCase
100
102
  assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
101
103
  assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify(File.join(ENV["HOME"], '.rbbt/share/databases/DATABASE/FILE'))
102
104
  assert_equal 'share/databases/DATABASE/FILE', Rbbt.identify('/usr/local/share/rbbt/databases/DATABASE/FILE')
105
+
106
+ assert_equal 'etc/somefile', TestResource.identify(TestResource.etc.somefile.find(:user))
107
+ assert_equal 'etc/somefile', TestResource.identify(TestResource.etc.somefile.find(:local))
103
108
  end
104
109
 
105
110
  end
@@ -199,13 +199,30 @@ row3 A|AA|AAA|AAA B Id3 3
199
199
 
200
200
  def test_unzip
201
201
  content =<<-EOF
202
- #Id ValueA ValueB OtherID
203
- row1 a|A b|B Id1|Id2
204
- row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
202
+ #: :type=:list
203
+ #PMID:Sentence number:TF:TG Transcription Factor (Associated Gene Name) Target Gene (Associated Gene Name) Sign Negation PMID
204
+ 24265317:3:NR1H3:FASN NR1H3 FASN 24265317
205
+ 17522048:0:NR1H3:FASN NR1H3 FASN + 17522048
206
+ 19903962:0:NR1H3:FASN NR1H3 FASN 19903962
207
+ 19903962:7:NR1H3:FASN NR1H3 FASN 19903962
208
+ 22183856:4:NR1H3:FASN NR1H3 FASN 22183856
209
+ 22641099:4:NR1H3:FASN NR1H3 FASN + 22641099
210
+ 23499676:8:NR1H3:FASN NR1H3 FASN + 23499676
211
+ 11790787:5:NR1H3:FASN NR1H3 FASN 11790787
212
+ 11790787:7:NR1H3:FASN NR1H3 FASN + 11790787
213
+ 11790787:9:NR1H3:FASN NR1H3 FASN + 11790787
214
+ 11790787:11:NR1H3:FASN NR1H3 FASN 11790787
215
+ 17522048:1:NR1H3:FASN NR1H3 FASN + 17522048
216
+ 17522048:3:NR1H3:FASN NR1H3 FASN 17522048
217
+ 22160584:1:NR1H3:FASN NR1H3 FASN 22160584
218
+ 22160584:5:NR1H3:FASN NR1H3 FASN + 22160584
219
+ 22160584:8:NR1H3:FASN NR1H3 FASN + 22160584
205
220
  EOF
206
221
 
207
222
  TmpFile.with_file(content) do |filename|
208
- tsv = TSV.open(filename, :sep => /\s+/)
223
+ tsv = TSV.open(filename, :key_field => "Transcription Factor (Associated Gene Name)", :fields => ["Target Gene (Associated Gene Name)", "Sign", "PMID"], :merge => true, :type => :double)
224
+ unzip = tsv.unzip(0,true)
225
+ assert_equal unzip["NR1H3:FASN"][0].length, unzip["NR1H3:FASN"][1].length
209
226
  end
210
227
  end
211
228
 
@@ -69,5 +69,33 @@ A B C D E
69
69
  end
70
70
  end
71
71
 
72
+ def test_merge
73
+ content =<<-EOF
74
+ #: :type=:double
75
+ #PMID:Sentence number:TF:TG Transcription Factor (Associated Gene Name) Target Gene (Associated Gene Name) Sign Negation PMID
76
+ 24265317:3:NR1H3:FASN NR1H3 FASN 24265317
77
+ 17522048:0:NR1H3:FASN NR1H3 FASN + 17522048
78
+ 19903962:0:NR1H3:FASN NR1H3 FASN 19903962
79
+ 19903962:7:NR1H3:FASN NR1H3 FASN 19903962
80
+ 22183856:4:NR1H3:FASN NR1H3 FASN 22183856
81
+ 22641099:4:NR1H3:FASN NR1H3 FASN + 22641099
82
+ 23499676:8:NR1H3:FASN NR1H3 FASN + 23499676
83
+ 11790787:5:NR1H3:FASN NR1H3 FASN 11790787
84
+ 11790787:7:NR1H3:FASN NR1H3 FASN + 11790787
85
+ 11790787:9:NR1H3:FASN NR1H3 FASN + 11790787
86
+ 11790787:11:NR1H3:FASN NR1H3 FASN 11790787
87
+ 17522048:1:NR1H3:FASN NR1H3 FASN + 17522048
88
+ 17522048:3:NR1H3:FASN NR1H3 FASN 17522048
89
+ 22160584:1:NR1H3:FASN NR1H3 FASN 22160584
90
+ 22160584:5:NR1H3:FASN NR1H3 FASN + 22160584
91
+ 22160584:8:NR1H3:FASN NR1H3 FASN + 22160584
92
+ EOF
93
+
94
+ TmpFile.with_file(content) do |filename|
95
+ tsv = TSV.open(filename, :key_field => "Transcription Factor (Associated Gene Name)", :fields => ["Target Gene (Associated Gene Name)", "Sign", "PMID"], :merge => true, :type => :double)
96
+ assert_equal 16, tsv["NR1H3"]["Sign"].length
97
+ end
98
+ end
99
+
72
100
  end
73
101
 
@@ -0,0 +1,14 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestIndiferentHash < Test::Unit::TestCase
5
+ def test_recursive
6
+ a = {:a => {:b => 1 } }
7
+ IndiferentHash.setup(a)
8
+
9
+ assert IndiferentHash === a["a"]
10
+ assert_equal 1, a[:a]["b"]
11
+ assert_equal 1, a["a"][:b]
12
+ end
13
+ end
14
+
@@ -39,7 +39,7 @@ class TestCmd < Test::Unit::TestCase
39
39
  assert_nothing_raised ProcessFailed do CMD.cmd('ls -fake_option', :no_fail => true, :pipe => true) end
40
40
 
41
41
  assert_raise ProcessFailed do CMD.cmd('fake-command', :stderr => true, :pipe => true).join end
42
- assert_raise ProcessFailed do CMD.cmd('ls -fake_option', :stderr => true, :pipe => true).join end
42
+ assert_raise ConcurrentStreamProcessFailed do CMD.cmd('ls -fake_option', :stderr => true, :pipe => true).join end
43
43
  end
44
44
 
45
45
  def test_pipes
@@ -78,4 +78,10 @@ line33
78
78
  def test_bash
79
79
  puts CMD.bash("awk 'test'")
80
80
  end
81
+
82
+ def test_cmd_error
83
+ assert_raise ConcurrentStreamProcessFailed do
84
+ CMD.cmd_log("ruby -e 'puts 1; STDERR.puts 1; sleep 2; raise'")
85
+ end
86
+ end
81
87
  end
@@ -98,7 +98,7 @@ class TestOpen < Test::Unit::TestCase
98
98
  4
99
99
  EOF
100
100
  TmpFile.with_file(content) do |file|
101
- `bgzip #{file}`
101
+ `gzip #{file}`
102
102
  assert_equal(content, Open.read(file + '.gz'))
103
103
  puts content
104
104
  FileUtils.rm file + '.gz'
@@ -181,8 +181,8 @@ class TestOpen < Test::Unit::TestCase
181
181
  Misc.consume_stream(StringIO.new(text), false, file)
182
182
 
183
183
  assert_equal text, Open.read(file)
184
- assert !File.exist?(file)
185
- assert Open.exists? file
184
+ assert Open.exists?(file)
185
+ refute File.exist?(file)
186
186
  end
187
187
 
188
188
  end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestSSH < Test::Unit::TestCase
5
+ def test_marshal
6
+
7
+ assert TrueClass === SSHLine.rbbt('turbo', 'true')
8
+ end
9
+ end
10
+
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.37.16
4
+ version: 5.38.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-30 00:00:00.000000000 Z
11
+ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -530,6 +530,7 @@ files:
530
530
  - test/rbbt/util/misc/test_communication.rb
531
531
  - test/rbbt/util/misc/test_development.rb
532
532
  - test/rbbt/util/misc/test_format.rb
533
+ - test/rbbt/util/misc/test_indiferent_hash.rb
533
534
  - test/rbbt/util/misc/test_lock.rb
534
535
  - test/rbbt/util/misc/test_multipart_payload.rb
535
536
  - test/rbbt/util/misc/test_omics.rb
@@ -556,6 +557,7 @@ files:
556
557
  - test/rbbt/util/test_semaphore.rb
557
558
  - test/rbbt/util/test_simpleDSL.rb
558
559
  - test/rbbt/util/test_simpleopt.rb
560
+ - test/rbbt/util/test_ssh.rb
559
561
  - test/rbbt/util/test_tmpfile.rb
560
562
  - test/rbbt/workflow/step/test_dependencies.rb
561
563
  - test/rbbt/workflow/step/test_save_load_inputs.rb
@@ -587,7 +589,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
587
589
  - !ruby/object:Gem::Version
588
590
  version: '0'
589
591
  requirements: []
590
- rubygems_version: 3.4.8
592
+ rubygems_version: 3.4.13
591
593
  signing_key:
592
594
  specification_version: 4
593
595
  summary: Utilities for the Ruby Bioinformatics Toolkit (rbbt)
@@ -608,6 +610,7 @@ test_files:
608
610
  - test/rbbt/util/test_procpath.rb
609
611
  - test/rbbt/util/python/test_util.rb
610
612
  - test/rbbt/util/misc/test_development.rb
613
+ - test/rbbt/util/misc/test_indiferent_hash.rb
611
614
  - test/rbbt/util/misc/test_omics.rb
612
615
  - test/rbbt/util/misc/test_pipes.rb
613
616
  - test/rbbt/util/misc/test_serialize.rb
@@ -630,6 +633,7 @@ test_files:
630
633
  - test/rbbt/util/test_excel2tsv.rb
631
634
  - test/rbbt/util/test_misc.rb
632
635
  - test/rbbt/util/test_open.rb
636
+ - test/rbbt/util/test_ssh.rb
633
637
  - test/rbbt/util/test_simpleopt.rb
634
638
  - test/rbbt/util/simpleopt/test_parse.rb
635
639
  - test/rbbt/util/simpleopt/test_setup.rb