rbbt-util 5.13.6 → 5.13.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cb8cbb3f115088d3b7a4fbe8fb9aa75cf4f4805
4
- data.tar.gz: f61c90e38a18f4227f434260c83b6cf2ea48542a
3
+ metadata.gz: a7fb14a033052fa9f9e469e40ab600e40dfa6f90
4
+ data.tar.gz: 38a1246aae816a12634ee5681954c11beac3c9af
5
5
  SHA512:
6
- metadata.gz: 25ac9c560885c7fb66acee8f693a6276f85f74fcaef12bfcc57c3ec59c3562bd3a1a8e25706dce34374c84f7186acaf9c2e901471e0c6002352182a5ecd7534b
7
- data.tar.gz: b83ebb5dcdd346679f8a3299fa72ef9dd414590bf5775bcf574639b30be77844dea1bda0a7d6e4b74865992567fae452ed6943fdaaa8be76b503d96d80b37ef9
6
+ metadata.gz: f55bd2c2fbdd1815df354e7b6bf56c6ef5ec2383acc5ead9fba128ba23048c979bf54a8a1c90392c6982c99e80beebf2a45f5c4f7fef8832aa4a3853292afacc
7
+ data.tar.gz: f515c4276f796c56826412ffffc23856b221d76be923dc8655234dc1e0cb92781028cc9b0d1e2c92b049724aaaa889b61e4eb79d7e27cca8451fd8749a521051
data/bin/rbbt_Rutil.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+
3
+ ENV["RBBT_LOG"] = "10"
4
+
2
5
  require 'rbbt-util'
3
6
  require 'rbbt/util/R'
4
7
 
@@ -114,7 +114,8 @@ module TSV
114
114
  cols2 = parts2.length
115
115
  end
116
116
 
117
- progress_monitor = Progress::Bar.new(size, 0, 100, "Merging fields") if monitor
117
+ #progress_monitor = Progress::Bar.new(size, 0, 100, "Merging fields") if monitor
118
+ progress_monitor = Log::ProgressBar.new(size, :desc => "Merging fields") if monitor
118
119
 
119
120
  entry_hash = options
120
121
  entry_hash.delete :sep if entry_hash[:sep] == "\t"
@@ -162,7 +162,8 @@ module TSV
162
162
  desc = @monitor[:desc] if @monitor.include? :desc
163
163
  step = @monitor[:step] if @monitor.include? :step
164
164
  end
165
- progress_monitor = Progress::Bar.new(size, 0, step, desc)
165
+ #progress_monitor = Progress::Bar.new(size, 0, step, desc)
166
+ progress_monitor = Log::ProgressBar.new(size, :desc => desc)
166
167
  else
167
168
  progress_monitor = nil
168
169
  end
@@ -496,7 +496,8 @@ module TSV
496
496
  desc = monitor[:desc] if monitor.include? :desc
497
497
  step = monitor[:step] if monitor.include? :step
498
498
  end
499
- progress_monitor = Progress::Bar.new(size, 0, step, desc)
499
+ #progress_monitor = Progress::Bar.new(size, 0, step, desc)
500
+ progress_monitor = Log::ProgressBar.new(size, :desc => desc)
500
501
  else
501
502
  progress_monitor = nil
502
503
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rbbt/util/cmd'
2
2
  require 'rbbt/tsv'
3
+ require 'rbbt/util/R/eval'
3
4
 
4
5
  module R
5
6
 
@@ -80,7 +81,7 @@ module TSV
80
81
  def R(script, open_options = {})
81
82
  TmpFile.with_file do |f|
82
83
  Open.write(f, self.to_s)
83
- Log.debug(R.run(
84
+ io = R.run(
84
85
  <<-EOF
85
86
  ## Loading tsv into data
86
87
  data = rbbt.tsv('#{f}');
@@ -90,12 +91,17 @@ data = rbbt.tsv('#{f}');
90
91
  ## Resaving data
91
92
  if (! is.null(data)){ rbbt.tsv.write('#{f}', data); }
92
93
  EOF
93
- ).read)
94
+ )
95
+
96
+ Log.debug(io.read)
97
+
94
98
  open_options = Misc.add_defaults open_options, :type => :list
95
99
  if open_options[:raw]
96
100
  Open.read(f)
97
101
  else
98
- TSV.open(f, open_options) unless open_options[:ignore_output]
102
+ tsv = TSV.open(f, open_options) unless open_options[:ignore_output]
103
+ tsv.key_field = open_options[:key] if open_options.include? :key
104
+ tsv
99
105
  end
100
106
  end
101
107
  end
@@ -0,0 +1,17 @@
1
+ module R
2
+ def self.instance
3
+ @@instance ||= begin
4
+ require 'rserve'
5
+ @@server_process = CMD.cmd('R CMD Rserve --vanilla', :pipe => true)
6
+ Rserve::Connection.new
7
+ end
8
+ end
9
+
10
+ def self.eval(cmd)
11
+ instance.eval(cmd).payload.first
12
+ end
13
+
14
+ def self.eval_a(cmd)
15
+ instance.eval(cmd).payload
16
+ end
17
+ end
data/lib/rbbt/util/cmd.rb CHANGED
@@ -219,15 +219,14 @@ module CMD
219
219
  Thread.exit
220
220
  end
221
221
 
222
+ ConcurrentStream.setup sout, :pids => [pid], :autojoin => true
222
223
  out = StringIO.new sout.read
223
224
  sout.close unless sout.closed?
224
- #SmartIO.tie out, pid, cmd, post, in_content, sin, serr
225
225
 
226
226
  Process.waitpid pid
227
227
 
228
228
  if not $?.success?
229
- exception = ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{$?.exitstatus}.\n#{err}"
230
- raise exception
229
+ raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{$?.exitstatus}.\n#{err}"
231
230
  else
232
231
  Log.log err, stderr if Integer === stderr and log
233
232
  end
@@ -2,7 +2,6 @@ require 'rbbt/util/concurrency/processes/worker'
2
2
  require 'rbbt/util/concurrency/processes/socket'
3
3
 
4
4
  class RbbtProcessQueue
5
- #{{{ RbbtProcessQueue
6
5
 
7
6
  attr_accessor :num_processes, :processes, :queue, :process_monitor, :cleanup, :join
8
7
  def initialize(num_processes, cleanup = nil, join = nil)
@@ -34,7 +34,7 @@ module Log
34
34
 
35
35
  @mean_max ||= 0
36
36
  if @history.length > 3
37
- mean = Misc.mean(@history)
37
+ mean = @mean = Misc.mean(@history)
38
38
  @mean_max = mean if mean > @mean_max
39
39
  end
40
40
 
@@ -60,7 +60,7 @@ module Log
60
60
 
61
61
  used = time - @start
62
62
  if @mean_max and @mean_max > 0
63
- eta = (@max - @ticks) / @mean_max
63
+ eta = (@max - @ticks) / @mean
64
64
  else
65
65
  eta = (@max - @ticks) / (@ticks/used)
66
66
  end
@@ -98,7 +98,9 @@ module Log
98
98
 
99
99
  def done(io = STDERR)
100
100
  done_msg = Log.color(:magenta, desc) << " " << Log.color(:green, "done")
101
- done_msg << " " << Log.color(:yellow, (@ticks).to_s) << " in " << Log.color(:blue, (Time.now - @start).to_i.to_s) << " sec."
101
+ ellapsed = (Time.now - @start).to_i
102
+ ellapsed = [ellapsed/3600, ellapsed/60 % 60, ellapsed % 60].map{|t| "%02i" % t }.join(':')
103
+ done_msg << " " << Log.color(:blue, (@ticks).to_s) << " in " << Log.color(:green, ellapsed)
102
104
  @last_count = 0
103
105
  @last_time = @start
104
106
  done_msg << " (" << thr_msg << ")"
@@ -221,11 +221,11 @@ module Misc
221
221
  rescue Aborted
222
222
  Log.warn "Aborted sensiblewrite -- #{ Log.reset << Log.color(:blue, path) }"
223
223
  content.abort if content.respond_to? :abort
224
- Open.rm_f path if File.exists? path
224
+ Open.rm path if File.exists? path
225
225
  rescue Exception
226
226
  Log.warn "Exception in sensiblewrite: #{$!.message} -- #{ Log.color :blue, path }"
227
227
  content.abort if content.respond_to? :abort
228
- Open.rm_f path if File.exists? path
228
+ Open.rm path if File.exists? path
229
229
  raise $!
230
230
  ensure
231
231
  FileUtils.rm_f tmp_path if File.exists? tmp_path
@@ -244,7 +244,7 @@ module Misc
244
244
  end
245
245
  end
246
246
 
247
- def self.sort_stream(stream, header_hash = "#")
247
+ def self.sort_stream(stream, header_hash = "#", cmd_args = nil)
248
248
  Misc.open_pipe do |sin|
249
249
  begin
250
250
  if defined? Step and Step === stream
@@ -271,7 +271,7 @@ module Misc
271
271
  end
272
272
  end
273
273
 
274
- sorted = CMD.cmd("sort", :in => line_stream, :pipe => true)
274
+ sorted = CMD.cmd("sort #{cmd_args || ""}", :in => line_stream, :pipe => true)
275
275
 
276
276
  while block = sorted.read(2048)
277
277
  sin.write block
@@ -27,12 +27,10 @@ class Step
27
27
 
28
28
  else
29
29
  Log.medium "Duplicating stream #{ Misc.fingerprint(stream) }"
30
- new = Misc.dup_stream(current)
31
- Log.medium str << Log.color(:green, " -> ") << "#{new.inspect}"
32
- new
30
+ Misc.dup_stream(current)
33
31
  end
34
32
  end
35
- when TSV::Dumper, TSV::Parser
33
+ when TSV::Dumper#, TSV::Parser
36
34
  stream = stream.stream
37
35
  return stream if stream.closed?
38
36
 
@@ -90,6 +88,7 @@ class Step
90
88
  end
91
89
 
92
90
  def exec(no_load=false)
91
+ dup_inputs
93
92
  dependencies.each{|dependency| dependency.exec(no_load) }
94
93
  @mutex.synchronize do
95
94
  @result = self._exec
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+
6
+ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+ Sort a TSV file, mantaining headers
10
+
11
+ $ rbbt tsv sort file.tsv
12
+
13
+ Display summary information. Works with Tokyocabinet HDB and BDB as well.
14
+
15
+ -hh--header_hash* Change the character used to mark the header line (defaults to #)
16
+ -h--help Help
17
+ EOF
18
+
19
+ SOPT.usage if options[:help]
20
+
21
+ file = ARGV.shift
22
+
23
+ file = STDIN if file == '-' or file.nil?
24
+
25
+ rest = ARGV.inject(""){|acc,e| acc << " '#{e}'" }
26
+
27
+ file_io = TSV.get_stream(file)
28
+ stream = Misc.sort_stream(file_io, options[:header_hash] || "#", rest)
29
+
30
+ begin
31
+ while line = stream.gets
32
+ puts line
33
+ end
34
+ rescue Exception
35
+ exit -1
36
+ end
@@ -67,9 +67,9 @@ workflow = Workflow.require_workflow workflow
67
67
  tasks = task ? [task] : workflow.libdir.examples.glob('*').collect{|file| File.basename file }
68
68
 
69
69
  task_result = {}
70
- TSV.traverse tasks, :threads => 5 do |task|
70
+ TSV.traverse tasks do |task|
71
71
  names = name ? [name] : workflow.libdir.examples[task].glob('*').collect{|file| File.basename file }
72
- TSV.traverse names, :threads => 5 do |name|
72
+ TSV.traverse names do |name|
73
73
  success = run_task workflow, task, name
74
74
  task_result[[task, name]] = success
75
75
  end
@@ -0,0 +1,16 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
2
+ require 'rbbt/util/R/eval'
3
+
4
+ class TestREval < Test::Unit::TestCase
5
+ def test_get
6
+ Misc.benchmark(100) do
7
+ a = R.eval <<-EOF
8
+ p = 12
9
+ a = p * 2
10
+ c(a)
11
+ EOF
12
+ assert_equal 12 * 2, a
13
+ end
14
+ end
15
+ end
16
+
@@ -5,7 +5,7 @@ require 'rbbt/util/misc'
5
5
 
6
6
  class TestMiscPipes < Test::Unit::TestCase
7
7
 
8
- def test_collapse_stream
8
+ def _test_collapse_stream
9
9
  text=<<-EOF
10
10
  row1 A B C
11
11
  row1 a b c
@@ -19,7 +19,7 @@ row2 aa bb cc
19
19
  assert_equal ["BB", "bb"], tsv["row2"][1]
20
20
  end
21
21
 
22
- def test_paste_stream
22
+ def _test_paste_stream
23
23
  text1=<<-EOF
24
24
  row1 A B C
25
25
  row2 AA BB CC
@@ -46,7 +46,7 @@ row3 ccc
46
46
  assert_equal ["AAA", "BBB", "CCC", "", "", "ccc"], tsv["row3"]
47
47
  end
48
48
 
49
- def test_sort_stream
49
+ def _test_sort_stream
50
50
  text =<<-EOF
51
51
  #: :sep=" "
52
52
  #Row LabelA LabelB LabelC
@@ -69,10 +69,19 @@ row3 AAA BBB CCC
69
69
  row1 A B C
70
70
  EOF
71
71
 
72
+ text = text * 10000
72
73
  TmpFile.with_file(text) do |tmp|
73
74
  io = Open.open(tmp)
74
75
  dup = Misc.dup_stream(io)
76
+ Misc.consume_stream io, true
75
77
  assert_equal text, dup.read
78
+ end
79
+
80
+
81
+ TmpFile.with_file(text) do |tmp|
82
+ io = Open.open(tmp)
83
+ dup = Misc.dup_stream(io)
84
+ Misc.consume_stream dup, true
76
85
  assert_equal text, io.read
77
86
  end
78
87
  end
@@ -18,5 +18,13 @@ data = data + 1
18
18
  tsv = TSV.setup({"a" => [1], "b" => [2]}, :type => :list, :key_field => "Letter", :fields => ["Number"])
19
19
  assert tsv.transpose("Field").include? "Number"
20
20
  end
21
+
22
+ def test_error
23
+ assert_raise ProcessFailed do
24
+ R.run <<-EOF
25
+ fadsfasdf
26
+ EOF
27
+ end
28
+ end
21
29
  end
22
30
 
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.13.6
4
+ version: 5.13.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -161,6 +161,7 @@ files:
161
161
  - lib/rbbt/tsv/stream.rb
162
162
  - lib/rbbt/tsv/util.rb
163
163
  - lib/rbbt/util/R.rb
164
+ - lib/rbbt/util/R/eval.rb
164
165
  - lib/rbbt/util/chain_methods.rb
165
166
  - lib/rbbt/util/cmd.rb
166
167
  - lib/rbbt/util/color.rb
@@ -250,6 +251,7 @@ files:
250
251
  - share/rbbt_commands/tsv/info
251
252
  - share/rbbt_commands/tsv/json
252
253
  - share/rbbt_commands/tsv/slice
254
+ - share/rbbt_commands/tsv/sort
253
255
  - share/rbbt_commands/tsv/subset
254
256
  - share/rbbt_commands/tsv/unzip
255
257
  - share/rbbt_commands/tsv/values
@@ -299,6 +301,7 @@ files:
299
301
  - test/rbbt/tsv/test_parser.rb
300
302
  - test/rbbt/tsv/test_stream.rb
301
303
  - test/rbbt/tsv/test_util.rb
304
+ - test/rbbt/util/R/test_eval.rb
302
305
  - test/rbbt/util/concurrency/processes/test_socket.rb
303
306
  - test/rbbt/util/concurrency/test_processes.rb
304
307
  - test/rbbt/util/concurrency/test_threads.rb
@@ -374,6 +377,7 @@ test_files:
374
377
  - test/rbbt/util/test_semaphore.rb
375
378
  - test/rbbt/util/test_misc.rb
376
379
  - test/rbbt/util/test_tmpfile.rb
380
+ - test/rbbt/util/R/test_eval.rb
377
381
  - test/rbbt/test_association.rb
378
382
  - test/rbbt/test_resource.rb
379
383
  - test/rbbt/test_entity.rb