rbbt-util 5.34.13 → 5.34.14

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
  SHA256:
3
- metadata.gz: 9481e1e7a7e7341b95824a48c314d2316a7283e356ea916b424edb2f15886616
4
- data.tar.gz: 5012fb19a8cb88d1e9764a2b6ab049e203c38bc2daf758e112c8e256dca68565
3
+ metadata.gz: b2e50428f936aab209874c5f26e7504aa14da9a30bc7e2b13575432527a5b6a4
4
+ data.tar.gz: e522b76bb910b477e303e2cfc323c8708fa4d3bbecc0a7c46de473fe81f1ef6a
5
5
  SHA512:
6
- metadata.gz: e72b2d6f831128ace58d54e62fdad1f180acdd74d9c73304cc315760dd66c7705b733d024b62794c165a2ea00cdbf6b1d67569f1b40a8e19822424a1638ecd1f
7
- data.tar.gz: f8ffee23f77ac7024a06b50d7b48ba6db900080fa06e78d44e61dd4274b4843d6fd203644a5c9be0b730e1728a3b0550e32fc503401744737dcc2bed7401ce8d
6
+ metadata.gz: e73a4ceda5eca11497ea4f0fe91fda7275375aaf8aeb6f9f70a45a46d4c71022527d7cd32c0cb30700a6bc2724bd1e2d2e0bd808a553ee3c8d6e729baa1dc2c0
7
+ data.tar.gz: a050c5defff3e3d36fe5682c117802d54cfeb930e3e61ff96da29e326719bf97af6fe85b5c30812dd91c5c6a447201164c15a3e1714aa1226690a0c49782ba9a
data/lib/rbbt/resource.rb CHANGED
@@ -204,6 +204,10 @@ module Resource
204
204
  case type
205
205
  when :string
206
206
  Misc.sensiblewrite(final_path, content)
207
+ when :csv
208
+ require 'rbbt/tsv/csv'
209
+ tsv = TSV.csv Open.open(content)
210
+ Misc.sensiblewrite(final_path, tsv.to_s)
207
211
  when :url
208
212
  options = {}
209
213
  options[:noz] = true if Open.gzip?(final_path) || Open.bgzip?(final_path) || Open.zip?(final_path)
data/lib/rbbt/tsv/csv.rb CHANGED
@@ -25,7 +25,9 @@ module TSV
25
25
  when Path
26
26
  CSV.read obj.find.open, options
27
27
  when String
28
- if Misc.is_filename?(obj)
28
+ if Open.remote?(obj)
29
+ CSV.read Open.open(obj), options
30
+ elsif Misc.is_filename?(obj)
29
31
  CSV.read obj, options
30
32
  else
31
33
  CSV.new obj, **options
@@ -266,7 +266,7 @@ module TSV
266
266
 
267
267
  def self.xls(filename, options ={})
268
268
  if Open.remote? filename
269
- TmpFile.with_file do |tmp|
269
+ TmpFile.with_file nil, :extension => 'xls' do |tmp|
270
270
  Open.download(filename, tmp)
271
271
  TSV::XLS.read(tmp, options)
272
272
  end
@@ -278,7 +278,7 @@ module TSV
278
278
  def self.xlsx(filename, options ={})
279
279
  if Open.remote? filename
280
280
 
281
- TmpFile.with_file do |tmp|
281
+ TmpFile.with_file nil, :extension => 'xlsx' do |tmp|
282
282
  Open.download(filename, tmp)
283
283
  TSV::XLSX.read(tmp, options)
284
284
  end
@@ -193,6 +193,16 @@ def self.add_libdir(dir=nil)
193
193
  insist(3, &block)
194
194
  end
195
195
 
196
+ def self.chunk(array, num)
197
+ total = array.length
198
+ current = 0
199
+ while current < total
200
+ last = current + num - 1
201
+ yield array[current..last]
202
+ current = last + 1
203
+ end
204
+ end
205
+
196
206
  # Divides the array into +num+ chunks of the same size by placing one
197
207
  # element in each chunk iteratively.
198
208
  def self.divide(array, num)
@@ -71,6 +71,9 @@ module Misc
71
71
  end
72
72
 
73
73
  def self.timespan(str, default = "s")
74
+
75
+ return - timespan(str[1..-1], default) if str[0] == "-"
76
+
74
77
  if str.include?(":")
75
78
  seconds, minutes, hours = str.split(":").reverse
76
79
  return seconds.to_i + minutes.to_i * 60 + hours.to_i * 60 * 60
@@ -86,7 +89,7 @@ module Misc
86
89
  "h" => (60 * 60),
87
90
  "d" => (60 * 60 * 24),
88
91
  "w" => (60 * 60 * 24 * 7),
89
- "mo" => (60 * 60 * 24 * 30),
92
+ "mo" => (60 * 60 * 24 * 31),
90
93
  "y" => (60 * 60 * 24 * 365),
91
94
  }
92
95
 
@@ -640,7 +640,7 @@ module Open
640
640
  io
641
641
  end
642
642
 
643
- def self.download(url, file)
643
+ def self.download_old(url, file)
644
644
  Open.open(url, :mode => 'rb', :noz => true) do |sin|
645
645
  Open.open(file, :mode => 'wb') do |sout|
646
646
  Misc.consume_stream(sin, false, sout)
@@ -648,6 +648,10 @@ module Open
648
648
  end
649
649
  end
650
650
 
651
+ def self.download(url, path)
652
+ Open.wget(url, "--output-document" => path, :pipe => false)
653
+ end
654
+
651
655
  def self.can_open?(file)
652
656
  String === file and (Open.exist?(file) or remote?(file))
653
657
  end
@@ -841,7 +845,4 @@ module Open
841
845
  File.symlink?(path) && ! File.exist?(File.readlink(path))
842
846
  end
843
847
 
844
- def self.download(url, path)
845
- Open.wget(url, "--output-document" => path)
846
- end
847
848
  end
@@ -203,7 +203,7 @@ class Step
203
203
  files
204
204
  end
205
205
 
206
- def file(name)
206
+ def file(name=nil)
207
207
  Path.setup(File.join(files_dir, name.to_s), workflow, self)
208
208
  end
209
209
 
data/share/Rlib/plot.R CHANGED
@@ -39,3 +39,9 @@ geom_entity <- function (real.geom = NULL, mapping = NULL, data = NULL, stat = "
39
39
  }
40
40
 
41
41
  rbbt.ggplot2.rotate_x_labels <- function(){ theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) }
42
+
43
+ rbbt.ggplot2.theme <- function(plot){
44
+
45
+ plot + theme_classic() + scale_y_continuous(labels=scales::comma) + scale_x_continuous(labels=scales::comma) + rbbt.ggplot2.rotate_x_labels()
46
+
47
+ }
data/share/Rlib/util.R CHANGED
@@ -812,7 +812,7 @@ rbbt.plot.text_scatter <- function(formula, data) {
812
812
  rbbt.install.CRAN <- function(pkg){
813
813
  cat("Try CRAN install:", pkg, "\n")
814
814
  res = FALSE
815
- tryCatch({ install.packages(pkg); library(pkg); res = TRUE; }, error = function(e){ str(e); warning(paste("Could not install CRAN ", pkg)); res = FALSE })
815
+ tryCatch({ install.packages(pkg); library(pkg, character.only=T); res = TRUE; }, error = function(e){ str(e); warning(paste("Could not install CRAN ", pkg)); res = FALSE })
816
816
  return(res)
817
817
  }
818
818
 
@@ -610,6 +610,8 @@ EOF
610
610
  assert_equal 60*60*24, Misc.timespan('1d')
611
611
  assert_equal 60*60*24, Misc.timespan('1d')
612
612
  assert_equal 60*60*24, Misc.timespan('24:00:00')
613
+
614
+ assert_equal Misc.timespan('1min'), - Misc.timespan('-1min')
613
615
  end
614
616
 
615
617
  def test_remove_long_items
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.34.13
4
+ version: 5.34.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-19 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake