rbbt-util 5.21.77 → 5.21.78

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94b444c704c00b00fa41fc21ecda0eac99065d37
4
- data.tar.gz: d4c01b71ab11e74c7fb0c25822246688323c7e26
3
+ metadata.gz: 79f060e03080aa195d6e1c4372dd004653ed8801
4
+ data.tar.gz: 0af2cbb746b785018adbc4b37e377a74f84def35
5
5
  SHA512:
6
- metadata.gz: 9b41bd6356dcd57efdf98f0540af944b2e058b96a232ce5c724a2cba9767b5612464c5c3d9b5c5760b0b34f1bd2f7dd2ba800a642141ce8df7c13ae17984a2b7
7
- data.tar.gz: fc5b7a8b16b9b11ebf2d7906500016bc4416f0689fd64fadc31dd07e28f8bc1513a64c6dbfe80cca52d669bddb66ad01b5d51ba3d3b97174c35348286d79c502
6
+ metadata.gz: 5c791b7f553c8bc32512c7eab3bffc9d94bf072d878f5daf32dd0afc7a2e87b7cfcc290bab5430c99c715e7672856d1007bae8b6501aa71eb7f211b820a36b66
7
+ data.tar.gz: 4af9194d609ee3537a4add26274448316976a61f8f9064f7f0cadb9f37b8db0784cf3f3b4469ceb9a15324934e92e67e795b4ee07e0834801ba94c82fcb09500
data/lib/rbbt/persist.rb CHANGED
@@ -286,6 +286,9 @@ module Persist
286
286
  else
287
287
  Open.rm path if Open.exists? path
288
288
  end
289
+ rescue Aborted, Interrupt
290
+ Log.warn "Aborted loading persistence (#{ type }) #{ path }: #{$!.message}. Not erasing."
291
+ raise $!
289
292
  rescue Exception
290
293
  Log.warn "Exception loading persistence (#{ type }) #{ path }: #{$!.message}. Erase and retry."
291
294
  Open.rm path if Open.exists? path
@@ -694,7 +694,7 @@ Example:
694
694
  if new.include? k
695
695
  new[k] = Misc.zip_fields(Misc.zip_fields(new[k]) << rest)
696
696
  else
697
- new[k] = rest.collect{|v| [v]}
697
+ new[k] = rest.nil? ? nil : rest.collect{|v| [v]}
698
698
  end
699
699
  end
700
700
  end
@@ -166,13 +166,18 @@ module TSV
166
166
  traverser = Traverser.new key_field, fields, new_key_field, new_fields, type, uniq
167
167
 
168
168
  if @monitor
169
- desc = "Iterating TSV"
170
- step = 100
171
- if Hash === @monitor
172
- desc = @monitor[:desc] if @monitor.include? :desc
173
- step = @monitor[:step] if @monitor.include? :step
169
+ if Log::ProgressBar === @monitor
170
+ @monitor.max = size
171
+ progress_monitor = @monitor
172
+ else
173
+ desc = "Iterating TSV"
174
+ step = 100
175
+ if Hash === @monitor
176
+ desc = @monitor[:desc] if @monitor.include? :desc
177
+ step = @monitor[:step] if @monitor.include? :step
178
+ end
179
+ progress_monitor = Log::ProgressBar.new_bar(size, :desc => desc)
174
180
  end
175
- progress_monitor = Log::ProgressBar.new_bar(size, :desc => desc)
176
181
  else
177
182
  progress_monitor = nil
178
183
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -198,13 +198,14 @@ NULL
198
198
  end
199
199
  end
200
200
 
201
- def R_interactive(pre_script = nil)
201
+ def R_interactive(pre_script = nil, source = true)
202
202
  TmpFile.with_file do |f|
203
203
  Log.debug{"R Interactive:\n" << pre_script } if pre_script
204
204
  TmpFile.with_file(pre_script) do |script_file|
205
205
  Open.write(f, self.to_s)
206
206
  script = "data_file = '#{f}';\n"
207
207
  script << "script_file = '#{script_file}';\n" if pre_script
208
+ script << "source(script_file);\n" if source
208
209
  R.interactive(script)
209
210
  end
210
211
  end
@@ -13,12 +13,16 @@ module Colorize
13
13
  colors["green3"]
14
14
  when 'red'
15
15
  colors["red3"]
16
+ when 'yellow'
17
+ colors["gold1"]
18
+ when 'blue'
19
+ colors["RoyalBlue"]
16
20
  else
17
21
  colors[color.to_s] || color
18
22
  end
19
23
  end
20
24
 
21
- def self.continuous(array, start = :green, eend = :red, percent = false)
25
+ def self.continuous(array, start = "#EABD5D", eend = "#40324F", percent = false)
22
26
  start_color = Color.new from_name(start)
23
27
  end_color = Color.new from_name(eend)
24
28
 
@@ -70,7 +74,7 @@ module Colorize
70
74
 
71
75
  def self.tsv(tsv, options = {})
72
76
  values = tsv.values.flatten
73
- if Fixnum === values.first or (values.first.to_f != 0 and values[0] != "0")
77
+ if Fixnum === values.first or Float === values.first or (values.first.to_f != 0 and values[0] != "0" and values[0] != "0.0")
74
78
  value_colors = Misc.process_to_hash(values){continuous(values)}
75
79
  else
76
80
  value_colors = Misc.process_to_hash(values){distinct(values)}
@@ -100,7 +100,7 @@ class Step
100
100
  end
101
101
 
102
102
  def info(check_lock = true)
103
- return {} if info_file.nil? or not Open.exists? info_file
103
+ return {:status => :noinfo} if info_file.nil? or not Open.exists? info_file
104
104
  begin
105
105
  Misc.insist do
106
106
  begin
@@ -351,8 +351,10 @@ class Step
351
351
  end
352
352
 
353
353
  def dirty?
354
- return true if done? and not status == :done
355
- dirty_files = rec_dependencies.collect{|dependency| dependency.path unless dependency.error? and not dependency.recoverable_error? }.compact.uniq.reject{|path| not (Path === path) or path.exists?}
354
+ status = self.status
355
+ return true if done? and not status == :done and not status == :noinfo
356
+ return true if status == :done and not done?
357
+ dirty_files = rec_dependencies.collect{|dependency| dependency.path unless dependency.error? and not dependency.recoverable_error? }.compact.uniq.reject{|path| ! (Path === path) || path.exists?}
356
358
  if dirty_files.any?
357
359
  true
358
360
  else
@@ -61,6 +61,24 @@ class Step
61
61
  @inputs
62
62
  end
63
63
 
64
+ def recursive_inputs
65
+ if NamedArray === inputs
66
+ i = Hash[*inputs.fields.zip(inputs).flatten]
67
+ else
68
+ i = {}
69
+ end
70
+ dependencies.each do |dep|
71
+ di = dep.recursive_inputs
72
+ next unless NamedArray === di
73
+ di.fields.zip(di).each do |k,v|
74
+ i[k] = v unless i.include? k
75
+ end
76
+ end
77
+ v = i.values
78
+ NamedArray.setup v, i.keys
79
+ v
80
+ end
81
+
64
82
  def task_name
65
83
  @task.name
66
84
  end
@@ -83,7 +83,7 @@ class Step
83
83
  return if status == 'streaming' and job.running?
84
84
  end
85
85
 
86
- if (status == 'error' || job.aborted?) && job.recoverable_error?
86
+ if ((status == 'error' || job.aborted?) && job.recoverable_error?) || job.dirty?
87
87
  job.clean
88
88
  end
89
89
 
@@ -432,7 +432,7 @@ class Step
432
432
  end
433
433
 
434
434
  def abort
435
- return if done? and status == :done
435
+ return if done? and (status == :done or status == :noinfo)
436
436
  _abort
437
437
  log(:aborted, "Job aborted") unless aborted? or error?
438
438
  self
data/share/Rlib/util.R CHANGED
@@ -207,41 +207,6 @@ rbbt.acc <- function(data, new){
207
207
  }
208
208
  }
209
209
 
210
- rbbt.png_plot <- function(filename, width, height, p, ...){
211
- png(filename=filename, width=width, height=height, ...);
212
- eval(parse(text=p));
213
- }
214
-
215
- rbbt.heatmap <- function(filename, width, height, data, take_log=FALSE, ...){
216
- opar = par()
217
- png(filename=filename, width=width, height=height);
218
-
219
- #par(cex.lab=0.5, cex=0.5, ...)
220
-
221
- data = as.matrix(data)
222
- data[is.nan(data)] = NA
223
-
224
- #data = data[rowSums(!is.na(data))!=0, colSums(!is.na(data))!=0]
225
- data = data[rowSums(is.na(data))==0, ]
226
-
227
- if (take_log){
228
- for (study in colnames(data)){
229
- skip = sum(data[, study] <= 0) != 0
230
- if (!skip){
231
- data[, study] = log(data[, study])
232
- }
233
- }
234
- data = data[, colSums(is.na(data))==0]
235
- }
236
-
237
- data = stdize(data)
238
-
239
- heatmap.2(data, margins = c(20,5), scale='column')
240
-
241
- dev.off();
242
- par(opar)
243
- }
244
-
245
210
  rbbt.init <- function(data, new){
246
211
  if (is.null(data)){
247
212
  return(new);
@@ -303,73 +268,6 @@ rbbt.run <- function(filename){
303
268
 
304
269
  # UTILITIES
305
270
 
306
- # Addapted from http://www.phaget4.org/R/image_matrix.html
307
- rbbt.plot.matrix <- function(x, ...){
308
- min <- min(x, na.rm=T);
309
- max <- max(x, na.rm=T);
310
- yLabels <- rownames(x);
311
- xLabels <- colnames(x);
312
- title <-c();
313
- # check for additional function arguments
314
- if( length(list(...)) ){
315
- Lst <- list(...);
316
- if( !is.null(Lst$zlim) ){
317
- min <- Lst$zlim[1];
318
- max <- Lst$zlim[2];
319
- }
320
- if( !is.null(Lst$yLabels) ){
321
- yLabels <- c(Lst$yLabels);
322
- }
323
- if( !is.null(Lst$xLabels) ){
324
- xLabels <- c(Lst$xLabels);
325
- }
326
- if( !is.null(Lst$title) ){
327
- title <- Lst$title;
328
- }
329
- }
330
- # check for null values
331
- if( is.null(xLabels) ){
332
- xLabels <- c(1:ncol(x));
333
- }
334
- if( is.null(yLabels) ){
335
- yLabels <- c(1:nrow(x));
336
- }
337
-
338
- layout(matrix(data=c(1,2), nrow=1, ncol=2), widths=c(4,1), heights=c(1,1));
339
-
340
- # Red and green range from 0 to 1 while Blue ranges from 1 to 0
341
- ColorRamp <- rgb( seq(0,1,length=256), # Red
342
- seq(0,1,length=256), # Green
343
- seq(1,0,length=256)) # Blue
344
- ColorLevels <- seq(min, max, length=length(ColorRamp));
345
-
346
- # Reverse Y axis
347
- reverse <- nrow(x) : 1;
348
- yLabels <- yLabels[reverse];
349
- x <- x[reverse,];
350
-
351
- # Data Map
352
- par(mar = c(3,5,2.5,2));
353
- image(1:length(xLabels), 1:length(yLabels), t(x), col=ColorRamp, xlab="",
354
- ylab="", axes=FALSE, zlim=c(min,max));
355
- if( !is.null(title) ){
356
- title(main=title);
357
- }
358
- axis(BELOW<-1, at=1:length(xLabels), labels=xLabels, cex.axis=0.7);
359
- axis(LEFT <-2, at=1:length(yLabels), labels=yLabels, las= HORIZONTAL<-1,
360
- cex.axis=0.7);
361
-
362
- # Color Scale
363
- par(mar = c(3,2.5,2.5,2));
364
- image(1, ColorLevels,
365
- matrix(data=ColorLevels, ncol=length(ColorLevels),nrow=1),
366
- col=ColorRamp,
367
- xlab="",ylab="",
368
- xaxt="n");
369
-
370
- layout(1);
371
- }
372
-
373
271
  rbbt.log <- function(m){
374
272
  head = "R-Rbbt"
375
273
  cat(paste(head, "> ", m,"\n",sep=""), file = stderr())
@@ -556,3 +454,162 @@ rbbt.get.modes <- function(x,bw = NULL,spar = NULL) {
556
454
  df2
557
455
  }
558
456
 
457
+ #{{{ PLOTS
458
+
459
+ rbbt.png_plot <- function(filename, width, height, p, ...){
460
+ png(filename=filename, width=width, height=height, ...);
461
+ eval(parse(text=p));
462
+ }
463
+
464
+ rbbt.heatmap <- function(filename, width, height, data, take_log=FALSE, ...){
465
+ opar = par()
466
+ png(filename=filename, width=width, height=height);
467
+
468
+ #par(cex.lab=0.5, cex=0.5, ...)
469
+
470
+ data = as.matrix(data)
471
+ data[is.nan(data)] = NA
472
+
473
+ #data = data[rowSums(!is.na(data))!=0, colSums(!is.na(data))!=0]
474
+ data = data[rowSums(is.na(data))==0, ]
475
+
476
+ if (take_log){
477
+ for (study in colnames(data)){
478
+ skip = sum(data[, study] <= 0) != 0
479
+ if (!skip){
480
+ data[, study] = log(data[, study])
481
+ }
482
+ }
483
+ data = data[, colSums(is.na(data))==0]
484
+ }
485
+
486
+ data = stdize(data)
487
+
488
+ heatmap.2(data, margins = c(20,5), scale='column')
489
+
490
+ dev.off();
491
+ par(opar)
492
+ }
493
+
494
+ # Addapted from http://www.phaget4.org/R/image_matrix.html
495
+ rbbt.plot.matrix <- function(x, ...){
496
+ min <- min(x, na.rm=T);
497
+ max <- max(x, na.rm=T);
498
+ yLabels <- rownames(x);
499
+ xLabels <- colnames(x);
500
+ title <-c();
501
+ # check for additional function arguments
502
+ if( length(list(...)) ){
503
+ Lst <- list(...);
504
+ if( !is.null(Lst$zlim) ){
505
+ min <- Lst$zlim[1];
506
+ max <- Lst$zlim[2];
507
+ }
508
+ if( !is.null(Lst$yLabels) ){
509
+ yLabels <- c(Lst$yLabels);
510
+ }
511
+ if( !is.null(Lst$xLabels) ){
512
+ xLabels <- c(Lst$xLabels);
513
+ }
514
+ if( !is.null(Lst$title) ){
515
+ title <- Lst$title;
516
+ }
517
+ }
518
+ # check for null values
519
+ if( is.null(xLabels) ){
520
+ xLabels <- c(1:ncol(x));
521
+ }
522
+ if( is.null(yLabels) ){
523
+ yLabels <- c(1:nrow(x));
524
+ }
525
+
526
+ layout(matrix(data=c(1,2), nrow=1, ncol=2), widths=c(4,1), heights=c(1,1));
527
+
528
+ # Red and green range from 0 to 1 while Blue ranges from 1 to 0
529
+ ColorRamp <- rgb( seq(0,1,length=256), # Red
530
+ seq(0,1,length=256), # Green
531
+ seq(1,0,length=256)) # Blue
532
+ ColorLevels <- seq(min, max, length=length(ColorRamp));
533
+
534
+ # Reverse Y axis
535
+ reverse <- nrow(x) : 1;
536
+ yLabels <- yLabels[reverse];
537
+ x <- x[reverse,];
538
+
539
+ # Data Map
540
+ par(mar = c(3,5,2.5,2));
541
+ image(1:length(xLabels), 1:length(yLabels), t(x), col=ColorRamp, xlab="",
542
+ ylab="", axes=FALSE, zlim=c(min,max));
543
+ if( !is.null(title) ){
544
+ title(main=title);
545
+ }
546
+ axis(BELOW<-1, at=1:length(xLabels), labels=xLabels, cex.axis=0.7);
547
+ axis(LEFT <-2, at=1:length(yLabels), labels=yLabels, las= HORIZONTAL<-1,
548
+ cex.axis=0.7);
549
+
550
+ # Color Scale
551
+ par(mar = c(3,2.5,2.5,2));
552
+ image(1, ColorLevels,
553
+ matrix(data=ColorLevels, ncol=length(ColorLevels),nrow=1),
554
+ col=ColorRamp,
555
+ xlab="",ylab="",
556
+ xaxt="n");
557
+
558
+ layout(1);
559
+ }
560
+
561
+ # Adapted from: https://rstudio-pubs-static.s3.amazonaws.com/13301_6641d73cfac741a59c0a851feb99e98b.html
562
+ rbbt.plot.venn <- function(data, a, ...) {
563
+ library(VennDiagram)
564
+ group.matches <- function(data, fields) {
565
+ sub = data
566
+ for (i in 1:length(fields)) {
567
+ sub <- subset(sub, sub[,fields[i]] == T)
568
+ }
569
+ nrow(sub)
570
+ }
571
+
572
+ if (length(a) == 1) {
573
+ out <- draw.single.venn(group.matches(data, a), ...)
574
+ }
575
+ if (length(a) == 2) {
576
+ out <- draw.pairwise.venn(group.matches(data, a[1]), group.matches(data, a[2]), group.matches(data, a[1:2]), ...)
577
+ }
578
+ if (length(a) == 3) {
579
+ out <- draw.triple.venn(group.matches(data, a[1]), group.matches(data, a[2]), group.matches(data, a[3]), group.matches(data, a[1:2]),
580
+ group.matches(data, a[2:3]), group.matches(data, a[c(1, 3)]), group.matches(data, a), ...)
581
+ }
582
+ if (length(a) == 4) {
583
+ out <- draw.quad.venn(group.matches(data, a[1]), group.matches(data, a[2]), group.matches(data, a[3]), group.matches(data, a[4]),
584
+ group.matches(data, a[1:2]), group.matches(data, a[c(1, 3)]), group.matches(data, a[c(1, 4)]), group.matches(data, a[2:3]),
585
+ group.matches(data, a[c(2, 4)]), group.matches(data, a[3:4]), group.matches(data, a[1:3]), group.matches(data, a[c(1, 2,
586
+ 4)]), group.matches(data, a[c(1, 3, 4)]), group.matches(data, a[2:4]), group.matches(data, a), ...)
587
+ }
588
+ if (length(a) == 5) {
589
+ out <- draw.quintuple.venn(
590
+ group.matches(data, a[1]), group.matches(data, a[2]), group.matches(data, a[3]), group.matches(data, a[4]), group.matches(data, a[5]),
591
+ group.matches(data, a[c(1, 2)]), group.matches(data, a[c(1, 3)]), group.matches(data, a[c(1, 4)]), group.matches(data, a[c(1, 5)]),
592
+ group.matches(data, a[c(2, 3)]), group.matches(data, a[c(2, 4)]), group.matches(data, a[c(2, 5)]),
593
+ group.matches(data, a[c(3, 4)]), group.matches(data, a[c(3, 5)]),
594
+ group.matches(data, a[c(4, 5)]),
595
+ group.matches(data, a[c(1, 2, 3)]),group.matches(data, a[c(1, 2, 4)]),group.matches(data, a[c(1, 2, 5)]),
596
+ group.matches(data, a[c(1, 3, 4)]),group.matches(data, a[c(1, 3, 5)]),
597
+ group.matches(data, a[c(1, 4, 5)]),
598
+ group.matches(data, a[c(2, 3, 4)]),group.matches(data, a[c(2, 3, 5)]),
599
+ group.matches(data, a[c(2, 4, 5)]),
600
+ group.matches(data, a[c(3, 4, 5)]),
601
+ group.matches(data, a[c(1, 2, 3, 4)]),group.matches(data, a[c(1, 2, 3, 5)]),group.matches(data, a[c(1, 2, 4, 5)]),group.matches(data, a[c(1, 3, 4, 5)]),group.matches(data, a[c(2, 3, 4, 5)]),
602
+ group.matches(data, a),
603
+ ...)
604
+
605
+ }
606
+ if (!exists("out"))
607
+ out <- "Oops"
608
+ return(out)
609
+ }
610
+
611
+
612
+ rbbt.plot.text_scatter <- function(formula, data) {
613
+ plot(formula, data=data, cex = 0)
614
+ text(formula, data=data, cex = 0.6, labels=rownames(data))
615
+ }
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.21.77
4
+ version: 5.21.78
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake