rbbt-util 5.21.91 → 5.21.92

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: f563cccf569fa61510d611058e9bbc3f15f4ecca
4
- data.tar.gz: 8d11affe29abde8039c69e64c53206a40584bfd0
3
+ metadata.gz: '085baf05c5686c39e301773dce420dd46947b483'
4
+ data.tar.gz: 1e45580741e0644488f7c891f1d737d8ff421668
5
5
  SHA512:
6
- metadata.gz: db6be501c52eefb3e8f7a66a494772462fb26652d3ec17f20215da24958f91d17ae5e7fb648c8dd12770cd500eced281fcd4fdbb174e1f9f86705cfd71f01bfe
7
- data.tar.gz: ce353bf4de86ec04797f6cf6b839bb6ee7fb19e4ad67e21d481404d34ea253ab0f79e7d09fc436a3c476be27e9ca33618562f2faa8987acfacb3940f5d1f0c26
6
+ metadata.gz: b07ae9833c2832a79511ca6539d7de339e8008d83bc1d7056bb0d679355fce723b5233598c2ca372d0d55e99e7f0352c1c3f489f9c42dce0dc58ba89c3b99998
7
+ data.tar.gz: c41b15827ed605424506a7bf44ceebd27ad0c95012cc449cebb04d9e2660af6c96a6b9897f0ff8c9ccf91564bd196b4a5c0f66f43784dba12c1ae15e86d017eb
@@ -100,6 +100,8 @@ module Association
100
100
 
101
101
  end
102
102
  end
103
+
104
+ data
103
105
  end.tap do |data|
104
106
  data.read if not Hash === data and data.respond_to? :read
105
107
  Association::Index.setup data
@@ -110,6 +110,7 @@ module TSV
110
110
  rows << row.values_at(0..(row.size - 1)).collect{|c| String === c ? c.gsub("\n", ' ') : c }
111
111
  end
112
112
 
113
+ num_values = rows.first.length
113
114
  File.open(filename, 'w') do |f|
114
115
  if header
115
116
  header = rows.shift
@@ -118,6 +119,7 @@ module TSV
118
119
 
119
120
  rows.each do |row|
120
121
  values = row.collect{|c| c.respond_to?(:value) ? c.value : c }
122
+ values[num_values-1] ||= nil
121
123
  f.puts values * "\t"
122
124
  end
123
125
  end
@@ -151,8 +153,6 @@ module TSV
151
153
  sheet = Misc.process_options options, :sheet
152
154
  header = Misc.process_options options, :header
153
155
 
154
- iii options
155
- iii sheet
156
156
  header = true unless header == false
157
157
  TmpFile.with_file do |filename|
158
158
  workbook = RubyXL::Parser.parse file
@@ -165,13 +165,17 @@ module TSV
165
165
  rows << row.cells.collect{|c| c.nil? ? nil : c.value}.collect{|c| String === c ? c.gsub("\n", ' ') : c }
166
166
  end
167
167
 
168
+ num_values = rows.first.length
168
169
  File.open(filename, 'w') do |f|
169
170
  if header
170
171
  header = rows.shift
171
172
  f.puts "#" + header * "\t"
172
173
  end
173
174
 
174
- rows.each do |row| f.puts row * "\t" end
175
+ rows.each do |row|
176
+ row[num_values-1] ||= nil
177
+ f.puts row * "\t"
178
+ end
175
179
  end
176
180
 
177
181
  TSV.open(filename, options)
@@ -717,12 +717,12 @@ module TSV
717
717
 
718
718
  def transpose(key_field = "Unkown ID")
719
719
  case type
720
+ when :single, :flat
721
+ transpose_list self.to_list, key_field
720
722
  when :list
721
723
  transpose_list key_field
722
724
  when :double
723
725
  transpose_double key_field
724
- else
725
- raise "Transposing only works for TSVs of type :list or :double"
726
726
  end
727
727
  end
728
728
 
@@ -39,7 +39,7 @@ module TSV
39
39
 
40
40
  preamble << line if line
41
41
  while line and (TrueClass === @header_hash or (String === @header_hash and Misc.fixutf8(line) =~ /^#{@header_hash}/ ))
42
- @fields = line.split(@sep)
42
+ @fields = line.split(@sep, -1)
43
43
  @key_field = @fields.shift
44
44
  @key_field = @key_field[(0 + header_hash.length)..-1] if String === @header_hash
45
45
 
@@ -234,7 +234,12 @@ module TSV
234
234
  if data.include? key
235
235
  new = data[key]
236
236
  new.each_with_index do |old, i|
237
- old.concat values[i]
237
+ next if values[i].nil?
238
+ if old.nil?
239
+ new[i] = values[i]
240
+ else
241
+ old.concat values[i]
242
+ end
238
243
  end
239
244
  data[key] = new
240
245
  else
@@ -247,6 +252,10 @@ module TSV
247
252
  def add_to_data_merge_zipped(data, keys, values)
248
253
  num = keys.length
249
254
 
255
+ values = values.collect do |v|
256
+ (v.nil? || v.empty?) ? [""] : v
257
+ end
258
+
250
259
  if values.first.length > 1 and num == 1
251
260
  keys = keys * values.first.length
252
261
  num = keys.length
@@ -248,7 +248,7 @@ module TSV
248
248
 
249
249
  while line =~ /^#/
250
250
  if Hash === positions
251
- new = (0..line.split(sep).length-1).to_a
251
+ new = (0..line.split(sep,-1).length-1).to_a
252
252
  positions.each do |k,v|
253
253
  new[k] = v
254
254
  new[v] = k
@@ -262,14 +262,14 @@ module TSV
262
262
 
263
263
  while line
264
264
  if Hash === positions
265
- new = (0..line.split(sep).length-1).to_a
265
+ new = (0..line.split(sep, -1).length-1).to_a
266
266
  positions.each do |k,v|
267
267
  new[k] = v
268
268
  new[v] = k
269
269
  end
270
270
  positions = new
271
271
  end
272
- values = line.split(sep)
272
+ values = line.split(sep, -1)
273
273
  new_values = values.values_at(*positions)
274
274
  sin.puts new_values * sep
275
275
  line = stream.gets
data/lib/rbbt/util/R.rb CHANGED
@@ -156,6 +156,11 @@ module TSV
156
156
  script = require_sources + "\n\n" + script if require_sources
157
157
 
158
158
  r_options = Misc.pull_keys open_options, :R
159
+
160
+ r_options[:monitor] = open_options[:monitor] if open_options.include?(:monitor)
161
+ r_options[:method] = open_options[:method] if open_options.include?(:method)
162
+ r_options[:debug] = open_options[:debug] if open_options.include?(:debug)
163
+
159
164
  r_options[:debug] = true if r_options[:method] == :debug
160
165
  if r_options.delete :debug
161
166
  r_options[:monitor] = true
data/lib/rbbt/util/log.rb CHANGED
@@ -17,7 +17,7 @@ module Log
17
17
  LOG_MUTEX = Mutex.new
18
18
 
19
19
  SEVERITY_NAMES ||= begin
20
- names = %w(DEBUG LOW MEDIUM HIGH INFO WARN ERROR )
20
+ names = %w(DEBUG LOW MEDIUM HIGH INFO WARN ERROR NONE )
21
21
  names.each_with_index do |name,i|
22
22
  eval "#{ name } = #{ i }"
23
23
  end
@@ -31,6 +31,7 @@ module Log
31
31
  line = stack.shift
32
32
  end
33
33
  line ||= caller.first
34
+ line.gsub('`', "'")
34
35
  end
35
36
 
36
37
  def self._ignore_stderr
@@ -229,12 +230,12 @@ module Log
229
230
  def self.exception(e)
230
231
  stack = caller
231
232
  error([e.class.to_s, e.message].compact * ": " )
232
- error("BACKTRACE: " << Log.last_caller(caller) << "\n" + color_stack(e.backtrace)*"\n")
233
+ error("BACKTRACE: " << Log.last_caller(stack) << "\n" + color_stack(e.backtrace)*"\n")
233
234
  end
234
235
 
235
236
  def self.deprecated(m)
236
237
  stack = caller
237
- warn("DEPRECATED: " << Log.last_caller(caller))
238
+ warn("DEPRECATED: " << Log.last_caller(stack))
238
239
  warn("* " << (m || "").to_s)
239
240
  end
240
241
 
@@ -248,7 +249,7 @@ module Log
248
249
  end
249
250
 
250
251
  def self.tsv(tsv)
251
- STDERR.puts Log.color :magenta, "TSV log: " << Log.last_caller(caller)
252
+ STDERR.puts Log.color :magenta, "TSV log: " << Log.last_caller(caller).gsub('`',"'")
252
253
  STDERR.puts Log.color(:blue, "=> "<< Misc.fingerprint(tsv), true)
253
254
  STDERR.puts Log.color(:cyan, "=> " << tsv.summary)
254
255
  end
@@ -181,4 +181,44 @@ module Misc
181
181
  end
182
182
  end
183
183
 
184
+ def self.parse_sql_values(txt)
185
+ io = StringIO.new txt.strip
186
+
187
+ values = []
188
+ fields = []
189
+ current = nil
190
+ quoted = false
191
+ while c = io.getc
192
+ if quoted
193
+ if c == "'"
194
+ quoted = false
195
+ else
196
+ current << c
197
+ end
198
+ else
199
+ case c
200
+ when "("
201
+ current = ""
202
+ when ")"
203
+ fields << current
204
+ values << fields
205
+ fields = []
206
+ current = nil
207
+ when ','
208
+ if not current.nil?
209
+ fields << current
210
+ current = ""
211
+ end
212
+ when "'"
213
+ quoted = true
214
+ when ";"
215
+ break
216
+ else
217
+ current << c
218
+ end
219
+ end
220
+ end
221
+ values
222
+ end
223
+
184
224
  end
@@ -66,6 +66,8 @@ module Misc
66
66
  (obj.respond_to?(:filename) and obj.filename ) ? "<IO:" + (obj.filename || obj.inspect + rand(100000)) + ">" : obj.inspect
67
67
  when File
68
68
  "<File:" + obj.path + ">"
69
+ when NamedArray
70
+ "[<NamedArray: fields=#{fingerprint obj.fields} -- values=#{fingerprint obj[0..-1]}]"
69
71
  when Array
70
72
  if (length = obj.length) > 10
71
73
  "[#{length}--" << (obj.values_at(0,1, length / 2, -2, -1).collect{|e| fingerprint(e)} * ",") << "]"
@@ -289,4 +291,16 @@ module Misc
289
291
  def self.obj2md5(obj)
290
292
  obj2digest(obj)
291
293
  end
294
+
295
+ def self.get_filename(obj)
296
+ if obj.respond_to? :filename
297
+ obj.filename
298
+ elsif obj.respond_to? :path
299
+ obj.path
300
+ elsif (Path === obj || (String === obj && Misc.is_filename?(obj)))
301
+ obj
302
+ else
303
+ nil
304
+ end
305
+ end
292
306
  end
@@ -308,7 +308,7 @@ module Misc
308
308
 
309
309
  def self.intersect_streams_read(io, sep=":")
310
310
  line = io.gets.chomp
311
- parts = line.split(sep)
311
+ parts = line.split(sep, -1)
312
312
  chr, start, eend, *rest = parts
313
313
  start = start.to_i
314
314
  if eend =~ /^\d+$/
@@ -661,4 +661,30 @@ module Misc
661
661
  end
662
662
 
663
663
 
664
+ def self.swap_quoted_character(stream, charout="\n", charin=" ", quote='"')
665
+ io = Misc.open_pipe do |sin|
666
+ begin
667
+ quoted = false
668
+ prev = nil
669
+ while c = stream.getc
670
+ if c == quote and not prev == "\\"
671
+ quoted = ! quoted
672
+ end
673
+ c = charin if c == charout and quoted
674
+ sin << c
675
+ prev = c
676
+ end
677
+ rescue
678
+ stream.abort if stream.respond_to? :abort
679
+ raise $!
680
+ ensure
681
+ stream.join if stream.respond_to? :join
682
+ end
683
+ end
684
+ end
685
+
686
+ def self.remove_quoted_new_line(stream, quote = '"')
687
+ swap_quoted_character(stream, "\n", " ", quote)
688
+ end
689
+
664
690
  end
@@ -9,7 +9,7 @@ module Open
9
9
  class OpenURLError < StandardError; end
10
10
  class OpenGzipError < StandardError; end
11
11
 
12
- REMOTE_CACHEDIR = "/tmp/open_cache"
12
+ REMOTE_CACHEDIR = File.join(ENV["HOME"], "/tmp/open_cache")
13
13
  FileUtils.mkdir REMOTE_CACHEDIR unless File.exist? REMOTE_CACHEDIR
14
14
 
15
15
  class << self
@@ -126,11 +126,11 @@ module Open
126
126
  # Grep
127
127
 
128
128
  def self.grep(stream, grep, invert = false)
129
- grep_cmd = 'egrep'
129
+ grep_cmd = ENV["GREP_CMD"] || "/bin/grep"
130
130
  case
131
131
  when Array === grep
132
132
  TmpFile.with_file(grep * "\n", false) do |f|
133
- CMD.cmd("#{grep_cmd} #{invert ? '-v' : ''}", "-w" => true, "-f" => f, :in => stream, :pipe => true, :post => proc{FileUtils.rm f})
133
+ CMD.cmd("#{grep_cmd} #{invert ? '-v' : ''} -", "-w" => true, "-F" => true, "-f" => f, :in => stream, :pipe => true, :post => proc{FileUtils.rm f})
134
134
  end
135
135
  else
136
136
  CMD.cmd("#{grep_cmd} #{invert ? '-v ' : ''} '#{grep}' -", :in => stream, :pipe => true, :post => proc{begin stream.force_close; rescue Exception; end if stream.respond_to?(:force_close)})
@@ -319,7 +319,7 @@ module Open
319
319
  end
320
320
 
321
321
  def self.zip?(file)
322
- !! (file =~ /\.zip/)
322
+ !! (file =~ /\.zip$/)
323
323
  end
324
324
 
325
325
 
data/lib/rbbt/workflow.rb CHANGED
@@ -386,6 +386,7 @@ module Workflow
386
386
  task = task_for path
387
387
  return remote_tasks[task].load_id(id) if remote_tasks and remote_tasks.include? task
388
388
  step = Step.new path, tasks[task.to_sym]
389
+ step.load_inputs_from_info
389
390
  set_step_dependencies(step)
390
391
  step
391
392
  end
@@ -696,7 +696,7 @@ module Workflow
696
696
  when :compute
697
697
  compute = v
698
698
  when Symbol
699
- rec_dependency = all_d.select{|d| d.task_name.to_sym == v }.first
699
+ rec_dependency = all_d.flatten.select{|d| d.task_name.to_sym == v }.first
700
700
 
701
701
  if rec_dependency.nil?
702
702
  if inputs.include? v
@@ -734,6 +734,8 @@ module Workflow
734
734
  path_deps = {}
735
735
  dependencies.each do |dependency|
736
736
  _inputs = IndiferentHash.setup(inputs.dup)
737
+ jobname = _inputs[:jobname] if _inputs.include? :jobname
738
+
737
739
  real_dep = case dependency
738
740
  when Array
739
741
  workflow, dep_task, options = dependency
@@ -743,6 +745,7 @@ module Workflow
743
745
  all_d = (real_dependencies + real_dependencies.collect{|d| d.rec_dependencies} ).flatten.compact.uniq
744
746
 
745
747
  _inputs = assign_dep_inputs(_inputs, options, all_d, workflow.task_info(dep_task))
748
+ jobname = _inputs[:jobname] if _inputs.include? :jobname
746
749
 
747
750
  job = workflow.job(dep_task, jobname, _inputs)
748
751
  ComputeDependency.setup(job, compute) if compute
@@ -45,25 +45,44 @@ class Step
45
45
  end
46
46
  @mutex = Mutex.new
47
47
  @info_mutex = Mutex.new
48
- @inputs = inputs || []
48
+ @inputs = inputs
49
49
  NamedArray.setup @inputs, task.inputs.collect{|s| s.to_s} if task and task.respond_to? :inputs and task.inputs
50
50
  end
51
51
 
52
- def inputs
53
- if @inputs.nil? and task and task.respond_to? :inputs
54
- @inputs = info[:inputs].values_at *task.inputs.collect{|name| name.to_s}
55
- end
52
+ def workflow
53
+ info[:workflow]
54
+ end
56
55
 
57
- if task.inputs and not NamedArray === @inputs
58
- NamedArray.setup @inputs, task.inputs
56
+ def load_inputs_from_info
57
+ if info[:inputs]
58
+ info_inputs = info[:inputs]
59
+ if task && task.respond_to?(:inputs) && task.inputs
60
+ IndiferentHash.setup info_inputs
61
+ @inputs = NamedArray.setup info_inputs.values_at(*task.inputs.collect{|name| name.to_s}), task.inputs
62
+ else
63
+ @inputs = NamedArray.setup info_inputs.values, info_inputs.keys
64
+ end
65
+ else
66
+ nil
59
67
  end
68
+ end
69
+
70
+ def inputs
71
+ return @inputs if NamedArray === @inputs
72
+
73
+ load_inputs_from_info if @inputs.nil?
60
74
 
61
- @inputs
75
+ NamedArray.setup(@inputs, task.inputs) if task && task.inputs && ! NamedArray === @inputs
76
+
77
+ @inputs || []
62
78
  end
63
79
 
64
80
  def recursive_inputs
65
81
  if NamedArray === inputs
66
- i = Hash[*inputs.fields.zip(inputs).flatten]
82
+ i = {}
83
+ inputs.zip(inputs.fields).each do |v,f|
84
+ i[f] = v
85
+ end
67
86
  else
68
87
  i = {}
69
88
  end
@@ -113,11 +132,27 @@ class Step
113
132
  self
114
133
  end
115
134
 
135
+ def result_type
136
+ @result_type ||= if @task.nil?
137
+ info[:result_type]
138
+ else
139
+ @task.result_type
140
+ end
141
+ end
142
+
143
+ def result_description
144
+ @result_description ||= if @task.nil?
145
+ info[:result_description]
146
+ else
147
+ @task.result_description
148
+ end
149
+ end
150
+
116
151
  def prepare_result(value, description = nil, entity_info = nil)
117
152
  res = case
118
153
  when IO === value
119
154
  begin
120
- res = case @task.result_type
155
+ res = case result_type
121
156
  when :array
122
157
  array = []
123
158
  while line = value.gets
@@ -206,13 +241,13 @@ class Step
206
241
  res = @result
207
242
  else
208
243
  join if not done?
209
- @path.exists? ? Persist.load_file(@path, @task.result_type) : exec
244
+ @path.exists? ? Persist.load_file(@path, result_type) : exec
210
245
  end
211
246
 
212
- if @task.result_description
247
+ if result_description
213
248
  entity_info = info.dup
214
249
  entity_info.merge! info[:inputs] if info[:inputs]
215
- res = prepare_result res, @task.result_description, entity_info
250
+ res = prepare_result res, result_description, entity_info
216
251
  end
217
252
 
218
253
  res
@@ -164,7 +164,7 @@ class Step
164
164
  raise $!
165
165
  rescue Exception
166
166
  Log.error "Exception in dep. #{ Log.color :red, dependency.task_name.to_s } -- #{$!.message}"
167
- Log.exception $!
167
+ #Log.exception $!
168
168
  raise $!
169
169
  end
170
170
  end
@@ -2,7 +2,7 @@ require 'rbbt/workflow/step/dependencies'
2
2
 
3
3
  class Step
4
4
 
5
- attr_reader :stream, :dupped, :saved_stream, :inputs
5
+ attr_reader :stream, :dupped, :saved_stream
6
6
 
7
7
  def get_stream
8
8
  @mutex.synchronize do
@@ -21,7 +21,7 @@ class Step
21
21
  def resolve_input_steps
22
22
  step = false
23
23
  pos = 0
24
- new_inputs = @inputs.collect do |i|
24
+ new_inputs = inputs.collect do |i|
25
25
  begin
26
26
  if Step === i
27
27
  step = true
@@ -115,6 +115,10 @@ class Step
115
115
  :issued => (issue_time = Time.now),
116
116
  :name => name,
117
117
  :clean_name => clean_name,
118
+ :workflow => @task.workflow.to_s,
119
+ :task_name => @task.name,
120
+ :result_type => @task.result_type,
121
+ :result_description => @task.result_description
118
122
  })
119
123
 
120
124
  set_info :dependencies, dependencies.collect{|dep| [dep.task_name, dep.name, dep.path]}
@@ -124,11 +128,19 @@ class Step
124
128
  rescue Exception
125
129
  FileUtils.rm pid_file if File.exist?(pid_file)
126
130
  stop_dependencies
127
- Log.exception $!
128
131
  raise $!
129
132
  end
130
133
 
131
- set_info :inputs, Misc.remove_long_items(Misc.zip2hash(task.inputs, @inputs)) unless task.inputs.nil?
134
+ if not task.inputs.nil?
135
+ info_inputs = @inputs.collect do |i|
136
+ if Path === i
137
+ i.to_s
138
+ else
139
+ i
140
+ end
141
+ end
142
+ set_info :inputs, Misc.remove_long_items(Misc.zip2hash(task.inputs, info_inputs))
143
+ end
132
144
 
133
145
  set_info :started, (start_time = Time.now)
134
146
  log :started, "Starting step #{Log.color :yellow, task.name.to_s || ""}"
@@ -2,7 +2,7 @@ require 'rbbt/util/misc'
2
2
  require 'rbbt/persist'
3
3
 
4
4
  module Task
5
- attr_accessor :inputs, :input_types, :result_type, :input_defaults, :input_descriptions, :input_options, :required_inputs, :description, :name, :result_description, :extension
5
+ attr_accessor :inputs, :input_types, :result_type, :input_defaults, :input_descriptions, :input_options, :required_inputs, :description, :name, :result_description, :extension, :workflow
6
6
 
7
7
  def self.setup(options = {}, &block)
8
8
  block.extend Task
@@ -92,6 +92,8 @@ module Task
92
92
  raise "Dependency task not found: #{dep}" if task.nil?
93
93
  next if seen.include? [wf, task.name]
94
94
 
95
+ task.workflow = wf if wf
96
+
95
97
  seen << [wf, task.name]
96
98
  new_inputs = task.inputs - maps
97
99
  next unless new_inputs.any?
@@ -33,7 +33,11 @@ module Task
33
33
  task_inputs = dep_inputs deps, workflow
34
34
  task_inputs.each do |task,new_inputs|
35
35
  task.inputs.zip(task.input_types.values_at(*task.inputs)).select{|i,t| t.to_sym == :select and task.input_options[i][:select_options] }.each{|i,t| selects << [i, task.input_options[i][:select_options]] }
36
- puts " #{Log.color :yellow, task.name.to_s}:"
36
+ if task.workflow and task.workflow != workflow
37
+ puts " #{Log.color :yellow, ["[#{task.workflow.to_s}]", task.name.to_s] *" "}:"
38
+ else
39
+ puts " #{Log.color :yellow, task.name.to_s}:"
40
+ end
37
41
  puts
38
42
  puts SOPT.input_doc(new_inputs, task.input_types, task.input_descriptions, task.input_defaults, true)
39
43
  puts
data/share/Rlib/util.R CHANGED
@@ -472,12 +472,12 @@ rbbt.get.modes <- function(x,bw = NULL,spar = NULL) {
472
472
 
473
473
  #{{{ PLOTS
474
474
 
475
- rbbt.png_plot <- function(filename, width, height, p, ...){
475
+ rbbt.png_plot <- function(filename, p, width=500, height=500, ...){
476
476
  png(filename=filename, width=width, height=height, ...);
477
477
  eval(parse(text=p));
478
478
  }
479
479
 
480
- rbbt.heatmap <- function(filename, width, height, data, take_log=FALSE, ...){
480
+ rbbt.heatmap <- function(filename, data, width=500, height=500, take_log=FALSE, ...){
481
481
  opar = par()
482
482
  png(filename=filename, width=width, height=height);
483
483
 
@@ -630,7 +630,35 @@ rbbt.plot.text_scatter <- function(formula, data) {
630
630
  text(formula, data=data, cex = 0.6, labels=rownames(data))
631
631
  }
632
632
 
633
- install.bioc <-function(pkg){
634
- source("http://bioconductor.org/biocLite.R")
635
- biocLite(pkg)
633
+ rbbt.install.CRAN <- function(pkg){
634
+ res = FALSE
635
+ tryCatch({ install.packages(pkg); res = TRUE }, error = function(e){ warning(paste("Could not install CRAN ", pkg)); res = FALSE })
636
+ return(res)
636
637
  }
638
+ rbbt.install.bioc <-function(pkg){
639
+ res = FALSE
640
+ tryCatch({ source("http://bioconductor.org/biocLite.R"); biocLite(pkg); res = TRUE }, error = function(e){ warning(paste("Could not install Bioconductor ", pkg)); res = FALSE })
641
+ return(res)
642
+ }
643
+
644
+ rbbt.install.github <- function(pkg, ...){
645
+ res = FALSE
646
+ tryCatch({ library(devtools); install_github(pkg, ...); res = TRUE }, error = function(e){ warning(paste("Could not install GITHUB ", pkg)); res = FALSE })
647
+ return(res)
648
+ }
649
+
650
+ rbbt.require <- function(pkg, ...){
651
+ list.of.packages <- c(pkg)
652
+ new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
653
+ for (pkg in new.packages){
654
+ if (!rbbt.install.github(pkg, ...)){
655
+ if (!rbbt.install.CRAN(pkg, ...)){
656
+ if (!rbbt.install.bioc(pkg, ...)){
657
+ stop("Error!", pkg)
658
+ }
659
+ }
660
+ }
661
+ }
662
+ library(list.of.packages, character.only=T)
663
+ }
664
+
@@ -13,7 +13,7 @@ require 'rbbt/rest/knowledge_base'
13
13
  require 'rbbt/rest/helpers'
14
14
  require 'rbbt/rest/web_tool'
15
15
 
16
- options = SOPT.get "-e--environment*:-p--port*:-s--server*:-b--bind*:-e--environment*:-R--RServe_session*:--finder:--views*:-w--workflows*"
16
+ options = SOPT.get "-e--environment*:-p--port*:-s--server*:-b--bind*:-e--environment*:-R--RServe_session*:--finder:--views*:-W--workflows*"
17
17
 
18
18
  template = ARGV.first
19
19
 
@@ -18,6 +18,7 @@ HIGH
18
18
  INFO
19
19
  WARN
20
20
  ERROR
21
+ NONE
21
22
 
22
23
  -h--help Print this help
23
24
 
@@ -3,10 +3,29 @@
3
3
  require 'rbbt-util'
4
4
  require 'rbbt/util/simpleopt'
5
5
 
6
- options = SOPT.get("-tch--tokyocabinet:-tcb--tokyocabinet_bd")
6
+ options = SOPT.setup <<EOF
7
7
 
8
- file = ARGV.shift
9
- value = ARGV.shift
8
+ Query a TSV value
9
+
10
+ $ rbbt tsv get [options] <filename.tsv|-> <key>
11
+
12
+ Use - to read from STDIN
13
+
14
+ -tch--tokyocabinet File is a tokyocabinet hash database
15
+ -tcb--tokyocabinet_bd File is a tokyocabinet B database
16
+ -f--fields* Fields to extract
17
+ -k--key_field* Use this field as key
18
+ -h--help Print this help
19
+ -l--lines Separate in lines
20
+ EOF
21
+
22
+ rbbt_usage and exit 0 if options[:help]
23
+
24
+ file, key = ARGV
25
+
26
+ raise ParameterException, "Please specify file and key" if key.nil?
27
+
28
+ file = STDIN if file == '-'
10
29
 
11
30
  case
12
31
  when options[:tokyocabinet]
@@ -14,13 +33,31 @@ when options[:tokyocabinet]
14
33
  when options[:tokyocabinet_bd]
15
34
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
16
35
  else
17
- tsv = TSV.open(file, :grep => value )
36
+ if String === file
37
+ file = file.dup
38
+ Path.setup(File.expand_path(file))
39
+ end
40
+ tsv = file
18
41
  end
19
42
 
20
- res = tsv[value]
43
+ fields = options[:fields]
44
+ key_field = options[:key_field]
45
+ fields = fields.split(/[,|]/, -1) unless fields.nil?
21
46
 
22
- if res.nil?
23
- raise "RECORD NOT FOUND"
24
- else
25
- puts tsv[value].report
47
+ parser = TSV::Parser.new tsv, :key_field => key_field, :fields => fields
48
+ fields ||= parser.fields
26
49
 
50
+ TSV.traverse(parser) do |k,v|
51
+ next unless k.include? key
52
+ if fields.length == 1
53
+ if options[:lines]
54
+ puts (Array === v ? v.flatten*"\n" : v.to_s )
55
+ else
56
+ puts (Array === v ? v.flatten*"\t" : v.to_s )
57
+ end
58
+ else
59
+ fields.zip(v).each do |field,v|
60
+ puts "#{Log.color :magenta, field+":"} #{v}"
61
+ end
62
+ end
63
+ end
@@ -63,7 +63,7 @@ else
63
63
  end
64
64
  puts "Rows: #{Log.color :blue, rows}"
65
65
  parts = []
66
- header.first_line.split(header.sep).each_with_index{|p,i| parts << (Log.color(:cyan, "(#{i}) ") << p.strip) }
66
+ header.first_line.split(header.sep, -1).each_with_index{|p,i| parts << (Log.color(:cyan, "(#{i}) ") << p.strip) }
67
67
  puts parts * "\t"
68
68
  puts
69
69
  end
@@ -14,6 +14,7 @@ Use - to read from STDIN
14
14
  -tch--tokyocabinet File is a tokyocabinet hash database
15
15
  -tcb--tokyocabinet_bd File is a tokyocabinet B database
16
16
  -f--field* Limit to a particular field
17
+ -k--keys Print also keys
17
18
  -h--help Print this help
18
19
  -l--lines Separate in lines
19
20
 
@@ -45,6 +46,8 @@ fields = field.nil? ? nil : [field]
45
46
  TSV.traverse(tsv, :fields => fields) do |k,v|
46
47
  if options[:lines]
47
48
  puts (Array === v ? v.flatten*"\n" : v.to_s )
49
+ elsif options[:keys]
50
+ puts(k << "\t" << (Array === v ? v.flatten*"\t" : v.to_s ))
48
51
  else
49
52
  puts (Array === v ? v.flatten*"\t" : v.to_s )
50
53
  end
@@ -132,6 +132,7 @@ if recursive
132
132
 
133
133
  while deps.any? do
134
134
  dep = deps.shift
135
+ inputs = {} if inputs.nil?
135
136
  inputs = inputs.merge(dep.info[:inputs] || {})
136
137
  deps.concat (dep.info[:dependencies] || []).collect{|v| get_step v.last }
137
138
  end
@@ -139,14 +140,16 @@ if recursive
139
140
  inputs.each do |input,value|
140
141
  case value
141
142
  when nil
142
- puts " " << Misc.format_definition_list_item(input, 'nil', 80, 20, :blue)
143
+ puts Misc.format_definition_list_item(" " << input.to_s, 'nil', 80, 20, :blue)
143
144
  when Array
144
- puts " " << Misc.format_definition_list_item(input, (value.length > 6 ? value[0..5]*"\n" << "\n" << "..." : value * "\n" ), 80, 20, :blue)
145
+ puts Misc.format_definition_list_item(" " << input.to_s, (value.length > 6 ? (value[0..5])*"\n\n" << "\n\n" << "..." : value * "\n\n" ), 80, 20, :blue).gsub("\n\n","\n")
145
146
  when TrueClass, FalseClass
146
- puts " " << Misc.format_definition_list_item(input, value.to_s, 80, 20, :blue)
147
+ puts Misc.format_definition_list_item(" " << input.to_s, value.to_s, 80, 20, :blue)
147
148
  else
148
- text = value.to_s.split("\n")[0..5].compact * "\n\n"
149
- puts " " << Misc.format_definition_list_item(input, text, 80, 20, :blue)
149
+ lines = value.to_s.split("\n").collect{|l| l.length >= 60 ? l[0..45] + " ..." : l }
150
+ text = lines[0..5].compact * "\n\n"
151
+ text << "\n\n...\n\n" if lines.length > 6
152
+ puts Misc.format_definition_list_item(" " << input.to_s, text, 80, 20, :blue).gsub("\n\n","\n")
150
153
  end
151
154
  end
152
155
  end
@@ -184,6 +184,7 @@ the job dependencies recursively.
184
184
  -pn--printname Print the name of the job and exit without starting it
185
185
  -pf--printpath Print the path of the job result
186
186
  -cl--clean Clean the last step of the job so that it gets recomputed
187
+ -ct--clean_task* Clean a particular dependency task
187
188
  -rcl--recursive_clean Clean the last step and its dependencies to recompute the job completely
188
189
  --fork Run job asyncronously and monitor progress. It monitors detached processes as well
189
190
  --detach Run job asyncronously and detach process
@@ -210,6 +211,7 @@ do_fork = !!options.delete(:fork)
210
211
  detach = !!options.delete(:detach)
211
212
  do_exec = !!options.delete(:exec)
212
213
  clean = !!options.delete(:clean)
214
+ clean_task = options.delete(:clean_task)
213
215
  recursive_clean = !!options.delete(:recursive_clean)
214
216
  out = options.include?(:output) ? File.open(options[:output], 'wb') : STDOUT
215
217
 
@@ -298,6 +300,12 @@ if clean
298
300
  sleep 1
299
301
  end
300
302
 
303
+ if clean_task
304
+ job.rec_dependencies.each do |dep|
305
+ dep.clean if dep.task_name.to_s == clean_task.to_s
306
+ end
307
+ end
308
+
301
309
  if recursive_clean
302
310
  job.recursive_clean
303
311
  end
@@ -557,4 +557,11 @@ eum fugiat quo voluptas nulla pariatur?"
557
557
  assert Misc.break_lines(text, 10).split("\n").length == 1 + text.length / 10
558
558
  assert Misc.break_lines(text, 10).split("\n").select{|l| l.length > 10 }.empty?
559
559
  end
560
+
561
+ def test_parse_sql_values
562
+ str=<<'EOF'
563
+ (xxx,yyy,zzz),(aaa,'bb(,)b',ccc)
564
+ EOF
565
+ assert Misc.parse_sql_values(str)[1][1] == "bb(,)b"
566
+ end
560
567
  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.91
4
+ version: 5.21.92
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-07-06 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -508,83 +508,83 @@ signing_key:
508
508
  specification_version: 4
509
509
  summary: Utilities for the Ruby Bioinformatics Toolkit (rbbt)
510
510
  test_files:
511
- - test/rbbt/test_workflow.rb
511
+ - test/test_helper.rb
512
512
  - test/rbbt/resource/test_path.rb
513
- - test/rbbt/util/test_cmd.rb
514
- - test/rbbt/util/simpleopt/test_setup.rb
515
- - test/rbbt/util/simpleopt/test_get.rb
516
- - test/rbbt/util/simpleopt/test_parse.rb
517
- - test/rbbt/util/test_chain_methods.rb
518
- - test/rbbt/util/test_simpleDSL.rb
513
+ - test/rbbt/association/test_item.rb
514
+ - test/rbbt/association/test_database.rb
515
+ - test/rbbt/association/test_open.rb
516
+ - test/rbbt/association/test_index.rb
517
+ - test/rbbt/association/test_util.rb
518
+ - test/rbbt/util/test_concurrency.rb
519
519
  - test/rbbt/util/test_log.rb
520
+ - test/rbbt/util/test_chain_methods.rb
521
+ - test/rbbt/util/test_simpleopt.rb
522
+ - test/rbbt/util/simpleopt/test_parse.rb
523
+ - test/rbbt/util/simpleopt/test_get.rb
524
+ - test/rbbt/util/simpleopt/test_setup.rb
525
+ - test/rbbt/util/test_cmd.rb
526
+ - test/rbbt/util/test_semaphore.rb
527
+ - test/rbbt/util/concurrency/test_threads.rb
528
+ - test/rbbt/util/concurrency/processes/test_socket.rb
529
+ - test/rbbt/util/concurrency/test_processes.rb
530
+ - test/rbbt/util/test_tmpfile.rb
520
531
  - test/rbbt/util/test_open.rb
532
+ - test/rbbt/util/test_filecache.rb
533
+ - test/rbbt/util/R/test_eval.rb
534
+ - test/rbbt/util/R/test_model.rb
535
+ - test/rbbt/util/test_simpleDSL.rb
536
+ - test/rbbt/util/log/test_progress.rb
537
+ - test/rbbt/util/test_colorize.rb
538
+ - test/rbbt/util/test_R.rb
521
539
  - test/rbbt/util/misc/test_lock.rb
522
- - test/rbbt/util/misc/test_multipart_payload.rb
523
- - test/rbbt/util/misc/test_bgzf.rb
524
540
  - test/rbbt/util/misc/test_pipes.rb
541
+ - test/rbbt/util/misc/test_bgzf.rb
525
542
  - test/rbbt/util/misc/test_omics.rb
526
- - test/rbbt/util/test_concurrency.rb
527
- - test/rbbt/util/test_R.rb
528
- - test/rbbt/util/log/test_progress.rb
529
- - test/rbbt/util/test_colorize.rb
530
- - test/rbbt/util/test_simpleopt.rb
543
+ - test/rbbt/util/misc/test_multipart_payload.rb
531
544
  - test/rbbt/util/test_excel2tsv.rb
532
- - test/rbbt/util/test_filecache.rb
533
- - test/rbbt/util/concurrency/test_processes.rb
534
- - test/rbbt/util/concurrency/test_threads.rb
535
- - test/rbbt/util/concurrency/processes/test_socket.rb
536
- - test/rbbt/util/test_semaphore.rb
537
545
  - test/rbbt/util/test_misc.rb
538
- - test/rbbt/util/test_tmpfile.rb
539
- - test/rbbt/util/R/test_model.rb
540
- - test/rbbt/util/R/test_eval.rb
541
- - test/rbbt/test_packed_index.rb
542
- - test/rbbt/entity/test_identifiers.rb
543
- - test/rbbt/test_association.rb
544
- - test/rbbt/knowledge_base/test_traverse.rb
545
- - test/rbbt/knowledge_base/test_registry.rb
546
- - test/rbbt/knowledge_base/test_entity.rb
547
- - test/rbbt/knowledge_base/test_enrichment.rb
548
- - test/rbbt/knowledge_base/test_syndicate.rb
549
- - test/rbbt/knowledge_base/test_query.rb
550
- - test/rbbt/test_resource.rb
551
546
  - test/rbbt/test_entity.rb
552
- - test/rbbt/test_knowledge_base.rb
553
- - test/rbbt/annotations/test_util.rb
554
- - test/rbbt/association/test_index.rb
555
- - test/rbbt/association/test_item.rb
556
- - test/rbbt/association/test_open.rb
557
- - test/rbbt/association/test_util.rb
558
- - test/rbbt/association/test_database.rb
559
- - test/rbbt/test_tsv.rb
560
547
  - test/rbbt/workflow/step/test_dependencies.rb
561
- - test/rbbt/workflow/test_task.rb
562
- - test/rbbt/workflow/test_step.rb
563
548
  - test/rbbt/workflow/test_doc.rb
564
- - test/rbbt/test_monitor.rb
565
- - test/rbbt/test_persist.rb
566
- - test/rbbt/test_annotations.rb
567
- - test/rbbt/persist/test_tsv.rb
568
- - test/rbbt/persist/tsv/test_lmdb.rb
569
- - test/rbbt/persist/tsv/test_kyotocabinet.rb
570
- - test/rbbt/persist/tsv/test_sharder.rb
571
- - test/rbbt/persist/tsv/test_cdb.rb
572
- - test/rbbt/persist/tsv/test_tokyocabinet.rb
573
- - test/rbbt/persist/tsv/test_leveldb.rb
574
- - test/rbbt/tsv/test_field_index.rb
549
+ - test/rbbt/workflow/test_step.rb
550
+ - test/rbbt/workflow/test_task.rb
551
+ - test/rbbt/test_association.rb
552
+ - test/rbbt/test_knowledge_base.rb
553
+ - test/rbbt/tsv/parallel/test_traverse.rb
554
+ - test/rbbt/tsv/parallel/test_through.rb
575
555
  - test/rbbt/tsv/test_parallel.rb
576
- - test/rbbt/tsv/test_index.rb
577
- - test/rbbt/tsv/test_matrix.rb
578
- - test/rbbt/tsv/test_change_id.rb
579
- - test/rbbt/tsv/test_parser.rb
580
- - test/rbbt/tsv/test_stream.rb
581
- - test/rbbt/tsv/test_util.rb
582
556
  - test/rbbt/tsv/test_excel.rb
583
557
  - test/rbbt/tsv/test_accessor.rb
558
+ - test/rbbt/tsv/test_change_id.rb
559
+ - test/rbbt/tsv/test_stream.rb
584
560
  - test/rbbt/tsv/test_filter.rb
561
+ - test/rbbt/tsv/test_matrix.rb
585
562
  - test/rbbt/tsv/test_attach.rb
586
563
  - test/rbbt/tsv/test_manipulate.rb
587
- - test/rbbt/tsv/parallel/test_through.rb
588
- - test/rbbt/tsv/parallel/test_traverse.rb
564
+ - test/rbbt/tsv/test_field_index.rb
565
+ - test/rbbt/tsv/test_index.rb
566
+ - test/rbbt/tsv/test_util.rb
567
+ - test/rbbt/tsv/test_parser.rb
568
+ - test/rbbt/test_packed_index.rb
569
+ - test/rbbt/test_persist.rb
589
570
  - test/rbbt/test_fix_width_table.rb
590
- - test/test_helper.rb
571
+ - test/rbbt/knowledge_base/test_traverse.rb
572
+ - test/rbbt/knowledge_base/test_entity.rb
573
+ - test/rbbt/knowledge_base/test_query.rb
574
+ - test/rbbt/knowledge_base/test_enrichment.rb
575
+ - test/rbbt/knowledge_base/test_syndicate.rb
576
+ - test/rbbt/knowledge_base/test_registry.rb
577
+ - test/rbbt/entity/test_identifiers.rb
578
+ - test/rbbt/test_monitor.rb
579
+ - test/rbbt/test_workflow.rb
580
+ - test/rbbt/test_annotations.rb
581
+ - test/rbbt/annotations/test_util.rb
582
+ - test/rbbt/test_resource.rb
583
+ - test/rbbt/persist/tsv/test_tokyocabinet.rb
584
+ - test/rbbt/persist/tsv/test_kyotocabinet.rb
585
+ - test/rbbt/persist/tsv/test_lmdb.rb
586
+ - test/rbbt/persist/tsv/test_leveldb.rb
587
+ - test/rbbt/persist/tsv/test_cdb.rb
588
+ - test/rbbt/persist/tsv/test_sharder.rb
589
+ - test/rbbt/persist/test_tsv.rb
590
+ - test/rbbt/test_tsv.rb