rbbt-util 5.21.115 → 5.21.116

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: 646ea32ae9ce7ff64c1d2ba88179b9883ca19522
4
- data.tar.gz: 7cfc05f02e007ce786ab4e2158fde5c324375ad3
3
+ metadata.gz: 77c923c4547ab8c088116d35a69d5963d69c9288
4
+ data.tar.gz: 1d770671abe5b42e35e7466239f3a20d68c54615
5
5
  SHA512:
6
- metadata.gz: bf93e300a29a6736da94cd6f715e9a17088dfb6d1a5ac4b51315191d00668930ca53bb3cd8fbd162d0591b7f3173da3a5500fff55ca267f1c08702b77193293d
7
- data.tar.gz: f143574d50f916ffa09e196335246e89fcdb99ef08ce82e22e17eb271bfefde22ab159f8b4a24befa1fe114911d162c4b39290878c33f5da7c89745773094c23
6
+ metadata.gz: 435ffaa1be1e204fd0e98c4c7e0f8d3df28dffb79ca1acd0102d32d6078ff2d64d8a27cff3158ec4fd7034b2168b70b44df1cd511be46b582feeb48e95ca08b4
7
+ data.tar.gz: '08612a841a790fcbd898133e21c47188c905cee765aa8db675464cef651f0c842986249a65192014953451f9fa16cae4c3108360b18f8830c2b7951913b34056'
@@ -692,10 +692,14 @@ Example:
692
692
  if merge
693
693
  self.through do |key,values|
694
694
  field_values = values[field_pos]
695
- values.delete_at(field_pos) if delete
695
+ if delete
696
+ values = values.dup
697
+ values.delete_at(field_pos)
698
+ end
696
699
  next if field_values.nil?
697
700
  zipped = Misc.zip_fields(values)
698
701
  field_values.zip(zipped).each do |field_value,rest|
702
+ rest = [nil] * values.length if rest.nil?
699
703
  k = [key,field_value]*sep
700
704
  if new.include? k
701
705
  new[k] = Misc.zip_fields(Misc.zip_fields(new[k]) << rest)
@@ -712,6 +716,7 @@ Example:
712
716
  next if field_values.nil?
713
717
  zipped = Misc.zip_fields(values)
714
718
  field_values.zip(zipped).each do |field_value,rest|
719
+ rest = [nil] * values.length if rest.nil?
715
720
  k = [key,field_value]*sep
716
721
  new[k] = rest
717
722
  end
@@ -730,7 +735,7 @@ Example:
730
735
  new
731
736
  end
732
737
 
733
- def zip(field = 0, merge = false, sep = ":")
738
+ def zip(merge = false, field = "New Field", sep = ":")
734
739
  new = {}
735
740
  self.annotate new
736
741
 
@@ -740,9 +745,12 @@ Example:
740
745
  if merge
741
746
  self.through do |key,values|
742
747
  new_key, new_value = key.split(sep)
743
- new_values = values + [[new_value]]
748
+ new_values = values + [[new_value] * values.first.length]
744
749
  if new.include? new_key
745
- new[new_key] = Misc.zip_fields(Misc.zip_fields(new[new_key]) << new_values)
750
+ current = new[new_key]
751
+ current.each_with_index do |v,i|
752
+ v.concat(new_values[i])
753
+ end
746
754
  else
747
755
  new[new_key] = new_values
748
756
  end
@@ -763,5 +771,13 @@ Example:
763
771
 
764
772
  new
765
773
  end
774
+
775
+ def remove_duplicates(pivot = 0)
776
+ new = self.annotate({})
777
+ self.through do |k,values|
778
+ new[k] = Misc.zip_fields(Misc.zip_fields(values).uniq)
779
+ end
780
+ new
781
+ end
766
782
  end
767
783
 
data/lib/rbbt/util/R.rb CHANGED
@@ -60,8 +60,13 @@ source('#{UTIL}');
60
60
  Open.write(init_file) do |f|
61
61
  f.puts "# Loading basic rbbt environment"
62
62
  f.puts "library(utils, quietly=TRUE);\n"
63
+ f.puts "interactive.script.file = '#{init_file}'"
64
+
63
65
  f.puts "source('#{R::UTIL}');\n"
64
- f.puts
66
+ f.puts "rbbt.require('readr')"
67
+ f.puts "interactive.script = read_file(interactive.script.file)"
68
+ f.puts "cat(interactive.script)"
69
+ f.puts ""
65
70
  f.puts script
66
71
  end
67
72
  CMD.cmd("env R_PROFILE='#{init_file}' xterm \"$R_HOME/bin/R\"")
data/lib/rbbt/util/cmd.rb CHANGED
@@ -6,6 +6,9 @@ module CMD
6
6
  def self.process_cmd_options(options = {})
7
7
  string = ""
8
8
  options.each do |option, value|
9
+ raise "Invalid option key: #{option.inspect}" if option.to_s !~ /^[a-z_0-9\-=]+$/i
10
+ raise "Invalid option value: #{value.inspect}" if value.to_s.include? "'"
11
+
9
12
  case
10
13
  when value.nil? || FalseClass === value
11
14
  next
@@ -13,9 +16,9 @@ module CMD
13
16
  string << "#{option} "
14
17
  else
15
18
  if option.to_s.chars.to_a.last == "="
16
- string << "#{option}#{value} "
19
+ string << "#{option}'#{value}' "
17
20
  else
18
- string << "#{option} #{value} "
21
+ string << "#{option} '#{value}' "
19
22
  end
20
23
  end
21
24
  end
@@ -75,10 +78,8 @@ module CMD
75
78
  STDOUT.reopen sout.last
76
79
  sout.last.close
77
80
 
78
-
79
81
  STDOUT.sync = STDERR.sync = true
80
82
 
81
-
82
83
  exec(ENV, cmd)
83
84
 
84
85
  exit(-1)
@@ -175,6 +175,7 @@ module Misc
175
175
  end
176
176
 
177
177
  def self.humanize_list(list)
178
+ return "" if list.empty?
178
179
  if list.length == 1
179
180
  list.first
180
181
  else
@@ -50,7 +50,7 @@ module Open
50
50
 
51
51
  def self.wget(url, options = {})
52
52
  Log.low "WGET:\n -URL: #{ url }\n -OPTIONS: #{options.inspect}"
53
- options = Misc.add_defaults options, "--user-agent=" => 'firefox', :pipe => true
53
+ options = Misc.add_defaults options, "--user-agent=" => 'rbbt', :pipe => true
54
54
 
55
55
  wait(options[:nice], options[:nice_key]) if options[:nice]
56
56
  options.delete(:nice)
@@ -123,7 +123,7 @@ class Step
123
123
  def updated?
124
124
  return true unless done?
125
125
 
126
- out_of_date.empty?
126
+ @updated ||= out_of_date.empty?
127
127
  end
128
128
 
129
129
  def kill_children
data/share/Rlib/svg.R CHANGED
@@ -20,11 +20,11 @@ rbbt.SVG.extract <- function(plot, size=NULL, prefix=NULL, ...){
20
20
  resolution = 72 * (size/7)
21
21
 
22
22
  if (length(plot$theme) == 0) plot <- plot + theme_gdocs();
23
+ if (length(plot$theme$text) == 0) plot <- plot + theme(text = element_text(size=base.size));
23
24
 
24
25
  plot$theme$text$size = base.size
25
26
 
26
27
  print(plot, type='cairo')
27
-
28
28
  mysvg <- grid.export(res=resolution, prefix=prefix, ...)
29
29
  }
30
30
 
data/share/Rlib/util.R CHANGED
@@ -615,7 +615,7 @@ rbbt.plot.matrix <- function(x, ...){
615
615
 
616
616
  # Adapted from: https://rstudio-pubs-static.s3.amazonaws.com/13301_6641d73cfac741a59c0a851feb99e98b.html
617
617
  rbbt.plot.venn <- function(data, a, ...) {
618
- rbbt.require(VennDiagram)
618
+ rbbt.require('VennDiagram')
619
619
  group.matches <- function(data, fields) {
620
620
  sub = data
621
621
  for (i in 1:length(fields)) {
@@ -221,4 +221,34 @@ row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
221
221
  assert_equal 6, CMD.cmd('grep -v "#" | cut -f 1', :in => tsv.to_s(nil, false, true)).read.split("\n").length
222
222
  end
223
223
  end
224
+
225
+ def test_remove_duplicates
226
+ content =<<-EOF
227
+ #Id ValueA ValueB OtherID
228
+ row1 a|A|a|a b|B|b| Id1|Id2|Id1|Id1
229
+ row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
230
+ EOF
231
+
232
+ TmpFile.with_file(content) do |filename|
233
+ tsv = TSV.open(filename, :sep => /\s+/)
234
+ assert_equal %w(a A a), tsv.remove_duplicates["row1"]["ValueA"]
235
+ assert tsv.remove_duplicates["row1"]["ValueB"].include?("")
236
+ end
237
+
238
+ end
239
+
240
+ def test_unzip_zip
241
+ content =<<-EOF
242
+ #Id ValueA ValueB OtherID
243
+ row1 a|A|a|a b|B|b| Id1|Id2|Id1|Id1
244
+ row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
245
+ EOF
246
+
247
+ TmpFile.with_file(content) do |filename|
248
+ tsv = TSV.open(filename, :sep => /\s+/)
249
+ assert_equal ["b", "b", ""], tsv.unzip("ValueA", true)["row1:a"]["ValueB"]
250
+ assert_equal ["b", "b", "", "B"].sort, tsv.unzip("ValueA", true).zip(true)["row1"]["ValueB"].sort
251
+ end
252
+
253
+ end
224
254
  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.21.115
4
+ version: 5.21.116
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-12-14 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake