rbbt-util 5.17.23 → 5.17.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/persist.rb +3 -5
- data/lib/rbbt/tsv/util.rb +4 -0
- data/lib/rbbt/util/R.rb +2 -0
- data/lib/rbbt/util/R/model.rb +0 -1
- data/lib/rbbt/util/R/plot.rb +109 -0
- data/lib/rbbt/util/misc/lock.rb +13 -9
- data/lib/rbbt/util/misc/pipes.rb +4 -0
- data/lib/rbbt/util/open.rb +1 -1
- data/lib/rbbt/workflow/accessor.rb +21 -8
- data/share/Rlib/svg.R +59 -0
- data/share/rbbt_commands/app/template +0 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b5fa2c99f1f5a1055a498543a82cf6c2e411477
|
4
|
+
data.tar.gz: 8aa11e4383e4b2a5c7720c521d46192d2f0c282c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6894a3cf476efbf5b17447cf70376e37a2c648f8dfeba0acfe13e0272d8f487a7bda9114593497bf0c546d553923c96e74544a6e2d5359b47ec92e61aa0053
|
7
|
+
data.tar.gz: 257842a422857624986f833453280ee834a2d1547de0dd595ad191735bed123c746eb2a6a9f08098cb5a11ab9b59bc7dd308c839f8a54109c6d3f4bd295b2feb
|
data/lib/rbbt/persist.rb
CHANGED
@@ -295,11 +295,9 @@ module Persist
|
|
295
295
|
end
|
296
296
|
|
297
297
|
rescue Lockfile::StolenLockError
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
rescue Exception
|
302
|
-
end
|
298
|
+
Log.medium "Lockfile stolen: #{path} - #{lock_filename}"
|
299
|
+
Log.exception $!
|
300
|
+
sleep 1 + rand(2)
|
303
301
|
retry
|
304
302
|
rescue Exception
|
305
303
|
Log.medium "Error in persist: #{path}#{Open.exists?(path) ? Log.color(:red, " Erasing") : ""}"
|
data/lib/rbbt/tsv/util.rb
CHANGED
@@ -4,9 +4,11 @@ module TSV
|
|
4
4
|
def self.reorder_stream(stream, positions, sep = "\t")
|
5
5
|
Misc.open_pipe do |sin|
|
6
6
|
line = stream.gets
|
7
|
+
line.strip! unless line.nil?
|
7
8
|
while line =~ /^#\:/
|
8
9
|
sin.puts line
|
9
10
|
line = stream.gets
|
11
|
+
line.strip! unless line.nil?
|
10
12
|
end
|
11
13
|
while line =~ /^#/
|
12
14
|
if Hash === positions
|
@@ -19,6 +21,7 @@ module TSV
|
|
19
21
|
end
|
20
22
|
sin.puts "#" + line.sub!(/^#/,'').strip.split(sep).values_at(*positions).compact * sep
|
21
23
|
line = stream.gets
|
24
|
+
line.strip! unless line.nil?
|
22
25
|
end
|
23
26
|
while line
|
24
27
|
if Hash === positions
|
@@ -31,6 +34,7 @@ module TSV
|
|
31
34
|
end
|
32
35
|
sin.puts line.strip.split(sep).values_at(*positions) * sep
|
33
36
|
line = stream.gets
|
37
|
+
line.strip! unless line.nil?
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/rbbt/util/R.rb
CHANGED
data/lib/rbbt/util/R/model.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
module R
|
2
|
+
module SVG
|
3
|
+
def self.ggplotSVG(data, script = nil, width = nil, height = nil, options = {})
|
4
|
+
width ||= 3
|
5
|
+
height ||= 3
|
6
|
+
values = []
|
7
|
+
|
8
|
+
options = options.dup
|
9
|
+
|
10
|
+
sources = [:plot, Rbbt.share.Rlib["svg.R"].find(:lib), options[:source]].flatten.compact
|
11
|
+
options.delete :source
|
12
|
+
|
13
|
+
if data
|
14
|
+
data.each do |k,v|
|
15
|
+
v = Array === v ? v : [v]
|
16
|
+
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
17
|
+
values = v
|
18
|
+
break
|
19
|
+
end
|
20
|
+
values = [values] unless Array === values
|
21
|
+
field_classes = values.collect do |v|
|
22
|
+
case v
|
23
|
+
when FalseClass, TrueClass
|
24
|
+
"'logical'"
|
25
|
+
when Fixnum, Float
|
26
|
+
"'numeric'"
|
27
|
+
when String
|
28
|
+
if v.strip =~ /^[-+]?[\d\.]+$/
|
29
|
+
"'numeric'"
|
30
|
+
else
|
31
|
+
"'character'"
|
32
|
+
end
|
33
|
+
when Symbol
|
34
|
+
"'factor'"
|
35
|
+
else
|
36
|
+
":NA"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
40
|
+
|
41
|
+
TmpFile.with_file nil, true, :extension => 'svg' do |tmpfile|
|
42
|
+
data.R <<-EOF, sources, options
|
43
|
+
plot = { #{script} }
|
44
|
+
|
45
|
+
rbbt.SVG.save('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
|
46
|
+
data = NULL
|
47
|
+
EOF
|
48
|
+
Open.read(tmpfile).gsub(/(glyph\d+-\d+)/, '\1-' + File.basename(tmpfile))
|
49
|
+
end
|
50
|
+
else
|
51
|
+
|
52
|
+
TmpFile.with_file nil, true, :extension => 'svg' do |tmpfile|
|
53
|
+
R.run <<-EOF, sources, options
|
54
|
+
plot = { #{script} }
|
55
|
+
|
56
|
+
rbbt.SVG.save('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
|
57
|
+
data = NULL
|
58
|
+
EOF
|
59
|
+
Open.read(tmpfile).gsub(/(glyph\d+-\d+)/, '\1-' + File.basename(tmpfile))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module PNG
|
66
|
+
|
67
|
+
def self.ggplotPNG(filename, data, script = nil, width = nil, height = nil, options = {})
|
68
|
+
width ||= 3
|
69
|
+
height ||= 3
|
70
|
+
values = []
|
71
|
+
|
72
|
+
sources = [:plot, options[:source]].flatten.compact
|
73
|
+
|
74
|
+
data.each do |k,v|
|
75
|
+
v = Array === v ? v : [v]
|
76
|
+
next if v == "NA" or v.nil? or v.include? "NA" or v.include? nil
|
77
|
+
values = v
|
78
|
+
break
|
79
|
+
end
|
80
|
+
values = [values] unless Array === values
|
81
|
+
field_classes = values.collect do |v|
|
82
|
+
case v
|
83
|
+
when FalseClass, TrueClass
|
84
|
+
"'logical'"
|
85
|
+
when Fixnum, Float
|
86
|
+
"'numeric'"
|
87
|
+
when String
|
88
|
+
if v.strip =~ /^[-+]?[\d\.]+$/
|
89
|
+
"'numeric'"
|
90
|
+
else
|
91
|
+
"'character'"
|
92
|
+
end
|
93
|
+
when Symbol
|
94
|
+
"'factor'"
|
95
|
+
else
|
96
|
+
":NA"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
|
100
|
+
|
101
|
+
data.R <<-EOF, :plot, options
|
102
|
+
plot = { #{script} }
|
103
|
+
|
104
|
+
ggsave('#{filename}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
|
105
|
+
data = NULL
|
106
|
+
EOF
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/rbbt/util/misc/lock.rb
CHANGED
@@ -3,26 +3,25 @@ module Misc
|
|
3
3
|
if use
|
4
4
|
Log.medium "Activating lockfile ids"
|
5
5
|
Lockfile.dont_use_lock_id = false
|
6
|
-
Lockfile.refresh = 20
|
7
|
-
Lockfile.max_age = 60
|
8
|
-
Lockfile.suspend =
|
6
|
+
#Lockfile.refresh = 20
|
7
|
+
#Lockfile.max_age = 60
|
8
|
+
#Lockfile.suspend = 2
|
9
9
|
else
|
10
10
|
Log.medium "De-activating lockfile ids"
|
11
11
|
Lockfile.dont_use_lock_id = true
|
12
|
-
Lockfile.refresh = 5
|
13
|
-
Lockfile.max_age =
|
14
|
-
Lockfile.suspend = 5
|
12
|
+
#Lockfile.refresh = 5
|
13
|
+
#Lockfile.max_age = 60 * 10
|
14
|
+
#Lockfile.suspend = 5
|
15
15
|
end
|
16
16
|
|
17
|
-
Lockfile.refresh =
|
18
|
-
Lockfile.max_age =
|
17
|
+
Lockfile.refresh = 10
|
18
|
+
Lockfile.max_age = 60
|
19
19
|
Lockfile.suspend = 2
|
20
20
|
end
|
21
21
|
|
22
22
|
self.use_lock_id = ENV["RBBT_NO_LOCKFILE_ID"] != "true"
|
23
23
|
|
24
24
|
LOCK_MUTEX = Mutex.new
|
25
|
-
#def self.lock(file, unlock = true, options = {})
|
26
25
|
def self.lock(file, unlock = true, options = {})
|
27
26
|
unlock, options = true, unlock if Hash === unlock
|
28
27
|
return yield if file.nil?
|
@@ -35,7 +34,12 @@ module Misc
|
|
35
34
|
lockfile = options[:lock]
|
36
35
|
lockfile.lock unless lockfile.locked?
|
37
36
|
when FalseClass
|
37
|
+
lockfile = nil
|
38
38
|
unlock = false
|
39
|
+
when Path, String
|
40
|
+
lock_path = options[:lock]
|
41
|
+
lockfile = Lockfile.new(lock_path, options)
|
42
|
+
lockfile.lock
|
39
43
|
else
|
40
44
|
lock_path = File.expand_path(file + '.lock')
|
41
45
|
lockfile = Lockfile.new(lock_path, options)
|
data/lib/rbbt/util/misc/pipes.rb
CHANGED
@@ -224,6 +224,9 @@ module Misc
|
|
224
224
|
lock_options = lock_options[:lock] if Hash === lock_options[:lock]
|
225
225
|
tmp_path = Persist.persistence_path(path, {:dir => Misc.sensiblewrite_dir})
|
226
226
|
tmp_path_lock = Persist.persistence_path(path, {:dir => Misc.sensiblewrite_lock_dir})
|
227
|
+
|
228
|
+
tmp_path_lock = nil if FalseClass === options[:lock]
|
229
|
+
|
227
230
|
Misc.lock tmp_path_lock, lock_options do
|
228
231
|
|
229
232
|
if Open.exists? path and not force
|
@@ -264,6 +267,7 @@ module Misc
|
|
264
267
|
Open.rm path if File.exists? path
|
265
268
|
rescue Exception
|
266
269
|
Log.medium "Exception in sensiblewrite: #{$!.message} -- #{ Log.color :blue, path }"
|
270
|
+
Log.exception $!
|
267
271
|
content.abort if content.respond_to? :abort
|
268
272
|
Open.rm path if File.exists? path
|
269
273
|
raise $!
|
data/lib/rbbt/util/open.rb
CHANGED
@@ -275,7 +275,7 @@ module Open
|
|
275
275
|
end
|
276
276
|
|
277
277
|
def self.lock(file, options = {}, &block)
|
278
|
-
if (dir_sub_path = find_repo_dir(file))
|
278
|
+
if file and (dir_sub_path = find_repo_dir(file))
|
279
279
|
dir, sub_path = dir_sub_path
|
280
280
|
repo = get_repo_from_dir(dir)
|
281
281
|
Misc.lock_in_repo(repo, sub_path, &block)
|
@@ -14,7 +14,18 @@ class Step
|
|
14
14
|
jobs = [jobs] if Step === jobs
|
15
15
|
begin
|
16
16
|
threads = []
|
17
|
-
|
17
|
+
|
18
|
+
threads = jobs.collect do |j|
|
19
|
+
Thread.new do
|
20
|
+
begin
|
21
|
+
j.join
|
22
|
+
rescue Exception
|
23
|
+
Log.error "Exception waiting for job: #{Log.color :blue, j.path}"
|
24
|
+
raise $!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
18
29
|
threads.each{|t| t.join }
|
19
30
|
rescue Exception
|
20
31
|
threads.each{|t| t.exit }
|
@@ -65,10 +76,11 @@ class Step
|
|
65
76
|
end
|
66
77
|
|
67
78
|
def info_lock
|
68
|
-
@info_lock
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
@info_lock = begin
|
80
|
+
path = Persist.persistence_path(info_file + '.lock', {:dir => Step.lock_dir})
|
81
|
+
Lockfile.new path, :refresh => false, :dont_use_lock_id => true
|
82
|
+
end if @info_lock.nil?
|
83
|
+
@info_lock
|
72
84
|
end
|
73
85
|
|
74
86
|
def info(check_lock = true)
|
@@ -125,7 +137,7 @@ class Step
|
|
125
137
|
i = info(false)
|
126
138
|
i.merge! hash
|
127
139
|
@info_cache = i
|
128
|
-
Misc.sensiblewrite(info_file, INFO_SERIALIAZER.dump(i), :force => true)
|
140
|
+
Misc.sensiblewrite(info_file, INFO_SERIALIAZER.dump(i), :force => true, :lock => false)
|
129
141
|
@info_cache_time = Time.now
|
130
142
|
value
|
131
143
|
end
|
@@ -248,7 +260,9 @@ class Step
|
|
248
260
|
|
249
261
|
def log(status, message = nil, &block)
|
250
262
|
self.status = status
|
251
|
-
|
263
|
+
if message
|
264
|
+
self.message Log.uncolor(message)
|
265
|
+
end
|
252
266
|
Step.log(status, message, path, &block)
|
253
267
|
end
|
254
268
|
|
@@ -517,7 +531,6 @@ module Workflow
|
|
517
531
|
when Array
|
518
532
|
workflow, task, options = dependency
|
519
533
|
|
520
|
-
#options = dependency.last if Hash === dependency.last
|
521
534
|
_inputs = IndiferentHash.setup(inputs.dup)
|
522
535
|
options.each{|i,v|
|
523
536
|
case v
|
data/share/Rlib/svg.R
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
library(plyr)
|
2
|
+
library(proto)
|
3
|
+
library(ggplot2)
|
4
|
+
library(gridSVG)
|
5
|
+
library(grid)
|
6
|
+
library(XML)
|
7
|
+
library(ggthemes)
|
8
|
+
library(Cairo)
|
9
|
+
|
10
|
+
# Modified from http://aaronecay.com/blog/2014/02/tooltips-in-ggplot/
|
11
|
+
|
12
|
+
rbbt.SVG.extract <- function(plot, size=NULL, prefix=NULL, ...){
|
13
|
+
|
14
|
+
if (is.null(prefix)) prefix = rbbt.random_string();
|
15
|
+
if (is.null(size)){
|
16
|
+
print(plot, type='cairo');
|
17
|
+
mysvg <- grid.export(prefix=prefix, ...)
|
18
|
+
}else{
|
19
|
+
base.size = 10 * (7/size)
|
20
|
+
resolution = 72 * (size/7)
|
21
|
+
|
22
|
+
if (length(plot$theme) == 0) plot <- plot + theme_gdocs();
|
23
|
+
|
24
|
+
plot$theme$text$size = base.size
|
25
|
+
|
26
|
+
print(plot, type='cairo')
|
27
|
+
|
28
|
+
mysvg <- grid.export(res=resolution, prefix=prefix, ...)
|
29
|
+
}
|
30
|
+
|
31
|
+
xml <- saveXML(mysvg$svg)
|
32
|
+
xml
|
33
|
+
}
|
34
|
+
|
35
|
+
rbbt.SVG.save <- function(filename, plot, width=NULL, height=NULL){
|
36
|
+
if (is.null(width)){
|
37
|
+
if (is.null(height)){
|
38
|
+
size = NULL
|
39
|
+
}else{
|
40
|
+
size=height
|
41
|
+
}
|
42
|
+
}else{
|
43
|
+
if (is.null(height)){
|
44
|
+
size = width
|
45
|
+
}else{
|
46
|
+
size=max(width, height)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
xml = rbbt.SVG.extract(plot, size)
|
51
|
+
fileConn<-file(filename, 'w')
|
52
|
+
cat(xml, file=fileConn)
|
53
|
+
close(fileConn)
|
54
|
+
}
|
55
|
+
|
56
|
+
rbbt.SVG.save.fast <- function(filename, plot, width=3, height=3){
|
57
|
+
ggsave(file=filename, plot, width=width, height=height);
|
58
|
+
}
|
59
|
+
|
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.17.
|
4
|
+
version: 5.17.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/rbbt/util/R.rb
|
217
217
|
- lib/rbbt/util/R/eval.rb
|
218
218
|
- lib/rbbt/util/R/model.rb
|
219
|
+
- lib/rbbt/util/R/plot.rb
|
219
220
|
- lib/rbbt/util/chain_methods.rb
|
220
221
|
- lib/rbbt/util/cmd.rb
|
221
222
|
- lib/rbbt/util/color.rb
|
@@ -274,6 +275,7 @@ files:
|
|
274
275
|
- lib/rbbt/workflow/task.rb
|
275
276
|
- lib/rbbt/workflow/usage.rb
|
276
277
|
- share/Rlib/plot.R
|
278
|
+
- share/Rlib/svg.R
|
277
279
|
- share/Rlib/util.R
|
278
280
|
- share/config.ru
|
279
281
|
- share/install/software/lib/install_helpers
|