rbbt-util 5.5.1 → 5.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWRkNDk5NDg4NWQ2YjNlMTcwZmM4OWFlZDM5OTViODRjZTQ5MTA4Ng==
4
+ NTE0ZTY1ZWVjMjZjMzBlMTQzNjNlMzlmYjY1NzBjNDFjZTc1NzExMA==
5
5
  data.tar.gz: !binary |-
6
- ZWNiNjM2MTQ0N2ZjMzM5NzBhZjc1YzA4MzRkOGYwM2RkNjBjM2M4Yg==
6
+ OWM2NGYwNDA0ODA4Y2FiNGQzMzE4ZjUwZDBiYTdiYmM2ZGVhYTc0ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjUwOGI4Mzk2NGJhOGQ4ZGUwOTlkYWJjYzViMjZlNDljNDI3MjIwNDBkYmY3
10
- MDJjMjExNGU4ODQ0NGRiZmQ5YzIyZDY0MmNiYmUzYTcyNWIyMTQwYTc1MGI2
11
- N2NmN2U4MThjOWIzYjdlYjQ4ZjJhMWQwYWZjZjMzN2NmNDQzMzM=
9
+ ODg1YTYxNGE5NWZkY2YyYmUzYmQ5ODlkZjQ0ZDgzZGZlNzA1YzZmNGU0NDZm
10
+ YzM2OGI3Y2RiOGMwNTI0ZDAyOWFiOTRjYmY5ODVmMjJkZjBlYTVkMWI2NTJj
11
+ ZGUyOGE4YWVmMjQyMzg2OGU2YzhjNjU3MDc5YTcwN2VjNDQwY2M=
12
12
  data.tar.gz: !binary |-
13
- NTc0MjNlZDRlMWM3OTI5MjcwOWI1NWIxZTkwNTg1ZmEzZGMzMTg0Yjg4NmFi
14
- Nzg1ZjJjZDk3MzI1N2Y3M2ZhNmEzMjIyMzVjY2ZjNWQxZDVjN2FmMDE1MTc4
15
- NWZhYWQzZGVkNTE4YzdkYTEyNzBlMmFlZTQyYzgwNzJlZGU0NzI=
13
+ NTk5NDg5OWZhYzU4ZDA3ODJlZjJmZDU2MTk5ZmJiNzJmNThhZWZhNmMxOWFj
14
+ YTY4MWI3Yjg5NmVmZWFkYTc5Mjk0OGI1YWQ3ZDc4NzJjNzIxZGE3ZTBkMjU2
15
+ ODM4ZGIwNDhhMThlNzRhNDQ2M2E1Y2QxNjg4YTkyZWZmYjU1NmI=
@@ -537,7 +537,15 @@ end
537
537
 
538
538
  def value_peek
539
539
  peek = {}
540
- keys[0..10].zip(values[0..10]).each do |k,v| peek[k] = v end
540
+ i = 0
541
+ begin
542
+ through do |k,v|
543
+ peek[k] = v
544
+ i += 1
545
+ raise "STOP" if i > 10
546
+ end
547
+ rescue
548
+ end
541
549
  peek
542
550
  end
543
551
 
data/lib/rbbt/tsv/util.rb CHANGED
@@ -126,6 +126,7 @@ module TSV
126
126
  end
127
127
  end
128
128
  self.annotate(new)
129
+ new.fields = new.fields[0..0] if new.fields
129
130
  new.type = :flat
130
131
  new
131
132
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -22,7 +22,7 @@ source('#{UTIL}');
22
22
  cmd << command
23
23
  end
24
24
 
25
- Log.debug "R Script:\n#{ cmd }"
25
+ Log.debug{"R Script:\n#{ cmd }"}
26
26
 
27
27
  if options.delete :monitor
28
28
  io = CMD.cmd('R --vanilla --slave --quiet', options.merge(:in => cmd, :pipe => true))
@@ -35,19 +35,16 @@ source('#{UTIL}');
35
35
  end
36
36
  end
37
37
 
38
- def self.interactive(init_file, options = {})
39
- CMD.cmd("env R_PROFILE='#{init_file}' xterm R")
40
- end
41
-
42
38
  def self.interactive(script, options = {})
43
39
  TmpFile.with_file do |init_file|
44
40
  Open.write(init_file) do |file|
45
41
  file.puts "# Loading basic rbbt environment"
42
+ file.puts "library(utils);\n"
46
43
  file.puts "source('#{R::UTIL}');\n"
47
44
  file.puts
48
45
  file.puts script
49
46
  end
50
- CMD.cmd("env R_PROFILE='#{init_file}' xterm R")
47
+ CMD.cmd("env R_PROFILE='#{init_file}' xterm \"$RHOME/bin/R\"")
51
48
  end
52
49
  end
53
50
 
@@ -98,10 +95,14 @@ if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
98
95
  end
99
96
  end
100
97
 
101
- def R_interactive(open_options = {})
98
+ def R_interactive(pre_script = nil)
102
99
  TmpFile.with_file do |f|
103
- Open.write(f, self.to_s)
104
- R.interactive("data_file = '#{f}';\n")
100
+ TmpFile.with_file(pre_script) do |script_file|
101
+ Open.write(f, self.to_s)
102
+ script = "data_file = '#{f}';\n"
103
+ script << "script_file = '#{script_file}';\n" if pre_script
104
+ R.interactive(script)
105
+ end
105
106
  end
106
107
  end
107
108
  end
data/lib/rbbt/util/cmd.rb CHANGED
@@ -29,10 +29,10 @@ module CMD
29
29
  rescue
30
30
  end
31
31
 
32
- Log.debug "Process #{ cmd } succeded" if $? and $?.success? and log
32
+ Log.debug{"Process #{ cmd } succeded" if $? and $?.success? and log}
33
33
 
34
34
  if $? and not $?.success?
35
- Log.debug "Raising exception" if log
35
+ Log.debug{"Raising exception" if log}
36
36
  exception = CMDError.new "Command [#{@pid}] #{@cmd} failed with error status #{$?.exitstatus}"
37
37
  original_close
38
38
  raise exception
@@ -52,7 +52,7 @@ module CMD
52
52
 
53
53
  def force_close
54
54
  if @pid
55
- Log.debug "Forcing close by killing '#{@pid}'" if log
55
+ Log.debug{"Forcing close by killing '#{@pid}'" if log}
56
56
  begin
57
57
  Process.kill("KILL", @pid)
58
58
  Process.waitpid(@pid)
@@ -158,8 +158,8 @@ module CMD
158
158
 
159
159
  exit(-1)
160
160
  rescue Exception
161
- Log.debug("CMDError: #{$!.message}") if log
162
- Log.debug("Backtrace: \n" + $!.backtrace * "\n") if log
161
+ Log.debug{ "CMDError: #{$!.message}" } if log
162
+ Log.debug{ "Backtrace: \n" + $!.backtrace * "\n" } if log
163
163
  raise CMDError, $!.message
164
164
  end
165
165
  }
@@ -173,7 +173,7 @@ module CMD
173
173
  serr = serr.first
174
174
 
175
175
 
176
- Log.debug "CMD: [#{pid}] #{cmd}" if log
176
+ Log.debug{"CMD: [#{pid}] #{cmd}" if log}
177
177
 
178
178
  if in_content.respond_to?(:read)
179
179
  Thread.new do
data/lib/rbbt/util/log.rb CHANGED
@@ -17,12 +17,15 @@ module Log
17
17
  @logfile = nil
18
18
  end
19
19
 
20
- SEVERITY_COLOR = ["0;37m", "0;32m", "0;33m", "0;31m","0;37m", "0;32m", "0;33m"].collect{|e| "\033[#{e}"}
20
+ WHITE, DARK, GREEN, YELLOW, RED = ["0;37m", "0m", "0;32m", "0;33m", "0;31m"].collect{|e| "\033[#{e}"}
21
+
22
+ SEVERITY_COLOR = [WHITE, GREEN, YELLOW, RED,WHITE, GREEN, YELLOW].collect{|e| "\033[#{e}"}
21
23
 
22
24
  def self.log(message = nil, severity = MEDIUM, &block)
23
25
  message ||= block
26
+ return if message.nil?
24
27
  severity_color = SEVERITY_COLOR[severity]
25
- font_color = {false => "\033[0;37m", true => "\033[0m"}[severity >= INFO]
28
+ font_color = {true => WHITE, false => DARK}[severity >= INFO]
26
29
 
27
30
  return if severity < self.severity
28
31
  message = message.call if Proc === message
@@ -46,7 +46,7 @@ module Misc
46
46
  when (ref.length == 1 and m.length == 1)
47
47
  m
48
48
  else
49
- Log.debug "Cannot understand: #{[ref, m]} (#{ muts })"
49
+ Log.debug{"Cannot understand: #{[ref, m]} (#{ muts })"}
50
50
  '-' * ref.length + m
51
51
  end
52
52
  end
@@ -223,11 +223,11 @@ module Misc
223
223
  end
224
224
  when TSV
225
225
  obj.with_unnamed do
226
- "TSV:{"<< fingerprint(obj.all_fields|| []).inspect << "," << fingerprint(obj.keys).inspect << "}"
226
+ "TSV:{"<< fingerprint(obj.all_fields|| []).inspect << ";" << fingerprint(obj.keys).inspect << "}"
227
227
  end
228
228
  when Hash
229
229
  if obj.length > 10
230
- "H:{"<< fingerprint(obj.keys) << "," << fingerprint(obj.values) << "}"
230
+ "H:{"<< fingerprint(obj.keys) << ";" << fingerprint(obj.values) << "}"
231
231
  else
232
232
  new = "{"
233
233
  obj.each do |k,v|
@@ -941,6 +941,7 @@ end
941
941
  return false
942
942
  end
943
943
 
944
+ # WARN: probably not thread safe...
944
945
  def self.in_dir(dir)
945
946
  old_pwd = FileUtils.pwd
946
947
  res = nil
@@ -948,8 +949,6 @@ end
948
949
  FileUtils.mkdir_p dir unless File.exists? dir
949
950
  FileUtils.cd dir
950
951
  res = yield
951
- rescue
952
- raise $!
953
952
  ensure
954
953
  FileUtils.cd old_pwd
955
954
  end
@@ -166,7 +166,7 @@ module SOPT
166
166
 
167
167
  if shortcuts.include? short
168
168
  i[:short] = short_for(i[:long])
169
- Log.debug("Short for #{ long } is taken. Changed to #{i[:short]}")
169
+ Log.debug{ "Short for #{ long } is taken. Changed to #{i[:short]}" }
170
170
  else
171
171
  shortcuts << i[:short] if short
172
172
  end
data/lib/rbbt/workflow.rb CHANGED
@@ -38,10 +38,10 @@ module Workflow
38
38
  begin
39
39
  $LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(filename)), 'lib'))
40
40
  require filename
41
- Log.info "Workflow loaded from: #{ filename }"
41
+ Log.debug{"Workflow loaded from: #{ filename }"}
42
42
  return true
43
43
  rescue Exception
44
- Log.warn "Error loading workflow: #{ filename }"
44
+ Log.warn{"Error loading workflow: #{ filename }"}
45
45
  raise $!
46
46
  end
47
47
  end
@@ -86,7 +86,7 @@ module Workflow
86
86
  # Already loaded
87
87
  begin
88
88
  Misc.string2const wf_name
89
- Log.debug "Workflow #{ wf_name } already loaded"
89
+ Log.debug{"Workflow #{ wf_name } already loaded"}
90
90
  return true
91
91
  rescue Exception
92
92
  end
@@ -97,13 +97,14 @@ module Workflow
97
97
  if Hash === remote_workflows and remote_workflows.include?(wf_name)
98
98
  url = remote_workflows[wf_name]
99
99
  require_remote_workflow(wf_name, url)
100
- Log.debug "Workflow #{ wf_name } loaded remotely: #{ url }"
100
+ Log.debug{"Workflow #{ wf_name } loaded remotely: #{ url }"}
101
101
  return
102
102
  end
103
103
  end
104
104
 
105
105
  # Load locally
106
106
 
107
+ Log.info{"Loading workflow #{wf_name}"}
107
108
  require_local_workflow(wf_name) || require_local_workflow(Misc.snake_case(wf_name)) || raise("Workflow not found or could not be loaded: #{ wf_name }")
108
109
  end
109
110
 
@@ -26,11 +26,13 @@ class Step
26
26
  def info
27
27
  return {} if not Open.exists? info_file
28
28
  begin
29
- Open.open(info_file) do |file|
30
- INFO_SERIALIAZER.load(file) || {}
29
+ Misc.insist(2, 0.5) do
30
+ Open.open(info_file) do |file|
31
+ INFO_SERIALIAZER.load(file) || {}
32
+ end
31
33
  end
32
34
  rescue Exception
33
- Log.debug "Error loading info file: " + info_file
35
+ Log.debug{"Error loading info file: " + info_file}
34
36
  raise $!
35
37
  end
36
38
  end
@@ -77,10 +77,10 @@ class Step
77
77
  self
78
78
  else
79
79
  begin
80
- Log.debug "Waiting for pid: #{@pid}"
80
+ Log.debug{"Waiting for pid: #{@pid}"}
81
81
  Process.waitpid @pid
82
82
  rescue Errno::ECHILD
83
- Log.debug "Process #{ @pid } already finished: #{ path }"
83
+ Log.debug{"Process #{ @pid } already finished: #{ path }"}
84
84
  end if Misc.pid_exists? @pid
85
85
  @pid = nil
86
86
  end
@@ -176,7 +176,7 @@ class Step
176
176
  begin
177
177
  run(true)
178
178
  rescue Step::Aborted
179
- Log.debug("Forked process aborted: #{@path}")
179
+ Log.debug{"Forked process aborted: #{@path}"}
180
180
  log :aborted, "Aborted"
181
181
  raise $!
182
182
  rescue Exception
@@ -12,8 +12,6 @@ app_dir = Rbbt.etc.app_dir.exists? ? Path.setup(Rbbt.etc.app_dir.read.strip) : R
12
12
 
13
13
  app_dir = app_dir[app]
14
14
 
15
- ddd app_dir
16
-
17
15
  server = options[:server] || 'thin'
18
16
  Misc.in_dir(app_dir) do
19
17
  require 'rack'
@@ -3,11 +3,11 @@ require 'rbbt/workflow'
3
3
  require 'rbbt/association'
4
4
  require 'rbbt/association/index'
5
5
 
6
- Workflow.require_workflow "Genomics"
7
- require 'rbbt/entity/gene'
8
6
  class TestAssociationIndex < Test::Unit::TestCase
9
7
 
10
8
  def setup
9
+ Workflow.require_workflow "Genomics"
10
+ require 'rbbt/entity/gene'
11
11
  end
12
12
 
13
13
  def teardown
@@ -6,8 +6,6 @@ require 'rbbt/entity'
6
6
  require 'rbbt/util/tmpfile'
7
7
  require 'test/unit'
8
8
 
9
- Workflow.require_workflow "Genomics"
10
- require 'rbbt/entity/gene'
11
9
 
12
10
  Workflow.require_workflow "TSVWorkflow"
13
11
 
@@ -35,18 +33,18 @@ class TestAssociations < Test::Unit::TestCase
35
33
  FileUtils.rm_rf DAssocs
36
34
  end
37
35
 
38
- def _test_simple_open
36
+ def test_simple_open
39
37
  database = Association.open(FAssocs, {}, :dir => DAssocs)
40
38
  assert_equal ["C", "K"], database["c"]["Entity2"]
41
39
  end
42
40
 
43
- def _test_source_open
41
+ def test_source_open
44
42
  database = Association.open(FAssocs, {:source => "Entity2", :zipped => true}, :dir => DAssocs)
45
43
  assert_equal ["c", "3", 'cc', "PTEN"], database["C"].flatten
46
44
  assert_equal ["c", "4", 'kk', "PTEN"], database["K"].flatten
47
45
  end
48
46
 
49
- def _test_target_open
47
+ def test_target_open
50
48
  database = Association.open(FAssocs, {:source => "Entity2", :target => "Entity3", :zipped => true}, :dir => DAssocs)
51
49
  assert_equal ["cc", "c", "3", "PTEN"], database["C"].flatten
52
50
  assert_equal ["kk", "c", "4", "PTEN"], database["K"].flatten
@@ -71,24 +69,24 @@ class TestAssociations < Test::Unit::TestCase
71
69
  end
72
70
 
73
71
 
74
- def _test_gene_open
72
+ def test_gene_open
75
73
  database = Association.open(FAssocs, {:source => "Gene=~Associated Gene Name", :target => "Entity3", :zipped => true}, :dir => DAssocs)
76
74
  assert_equal ["aa"], database["TP53"].first
77
75
  end
78
76
 
79
- def _test_gene_open_translate
77
+ def test_gene_open_translate
80
78
  tp53 = Gene.setup("TP53", "Associated Gene Name", "Hsa/jan2013")
81
79
  database = Association.open(FAssocs, {:source => "Gene=~Associated Gene Name", :source_format => "Ensembl Gene ID", :target => "Entity3", :zipped => true}, :dir => DAssocs)
82
80
  assert_equal ["aa"], database[tp53.ensembl].first
83
81
  end
84
82
 
85
- def _test_gene_target_open_translate
83
+ def test_gene_target_open_translate
86
84
  tp53 = Gene.setup("TP53", "Associated Gene Name", "Hsa/jan2013")
87
85
  database = Association.open(FAssocs, {:target => "Gene=~Associated Gene Name=>Ensembl Gene ID", :source => "Entity3", :zipped => true}, :dir => DAssocs)
88
86
  assert_equal [tp53.ensembl], database["aa"].first
89
87
  end
90
88
 
91
- def _test_ICGC
89
+ def test_ICGC
92
90
  assoc = Association.open(Open.open('ftp://data.dcc.icgc.org/current/Chronic_Lymphocytic_Leukemia-ISC_MICINN-ES/simple_somatic_mutation.CLLE-ES.tsv.gz'),
93
91
  { :source => "gene_affected=~Ensembl Gene ID=>Associated Gene Name", :target => "icgc_donor_id=~Sample",
94
92
  :fields => ['consequence_type'],
@@ -4,12 +4,13 @@ require 'test/unit'
4
4
  require 'rbbt/knowledge_base'
5
5
  require 'rbbt/sources/pina'
6
6
 
7
- require 'rbbt/workflow'
8
- Workflow.require_workflow "Genomics"
9
- require 'genomics_kb'
10
-
11
7
  class TestKnowledgeBase < Test::Unit::TestCase
12
8
  def setup
9
+ require 'rbbt/workflow'
10
+ Workflow.require_workflow "Genomics"
11
+ require 'genomics_kb'
12
+
13
+
13
14
  KnowledgeBase.knowledge_base_dir = Rbbt.tmp.knowledge_base_test.find
14
15
  @kb = Genomics.knowledge_base
15
16
  end
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.5.1
4
+ version: 5.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-21 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake