rbbt-util 5.15.1 → 5.15.2

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: a156a4d881f09ce0cbd2a74e878f682a294d2355
4
- data.tar.gz: 5b85742823494158cbd422ae05eb49f1f9662cc1
3
+ metadata.gz: 018bba9e3d9b7f80d23369d9534036edee4ead06
4
+ data.tar.gz: 04bf22adf2e811413c22885bc8178be8cd497902
5
5
  SHA512:
6
- metadata.gz: 5209b9ac5483a28bd744902435b3c194cad41814a7825b48302de178bbc84ed327069c266004db203befc403e3fb0ecebda6b4e96ea4dc3f5b580f64a8d8fb9e
7
- data.tar.gz: e5ca07ed990db5ea1e4b4f5de902ea3c00e2d99960eb843b98306ea15550aa6e8e0e67893ba770bc0bcedc8b1b5e6f1e21829ea5e85595c935d18633edb633ee
6
+ metadata.gz: a164aec636a2c50eabc7801dd500d8ab38585da8b14abb59e4e9af7830a3754348aabe498c006910f03ad7a970e6118048b51b687fcfb8ac8cf85415641c447a
7
+ data.tar.gz: a6e0d2485331aa9ff75237e4d1b03a6b7fefa1a1cceb32b9dac44512f7c11c99e4d1078115df4b5340dcec6e035c3bdc4fb5f5a5e6075e501f8ee9d0ac681596
@@ -1,4 +1,4 @@
1
1
  #require 'zen-grids'
2
2
  require 'compass'
3
3
  require 'compass-susy'
4
- require 'font-awesome-sass'
4
+ require 'toolkit'
@@ -1,16 +1,18 @@
1
1
 
2
2
  EntityRESTHelpers.entity_resources.unshift Rbbt.www.views.find if Rbbt.www.views.exists?
3
3
  RbbtRESTHelpers.template_resources.unshift Rbbt.www.views.find if Rbbt.www.views.exists?
4
-
5
- #load Rbbt.etc['app.d']['foundation.rb'].find if Rbbt.etc['app.d']['foundation.rb'].exists?
4
+
6
5
  load Rbbt.etc['app.d']['grid_system.rb'].find if Rbbt.etc['app.d']['grid_system.rb'].exists?
7
6
 
8
7
  require 'sass-css-importer'
9
8
 
9
+ Sinatra::RbbtRESTMain.add_resource_path(Path.setup(ENV["RBBT_VIEWS_DIR"])) if ENV["RBBT_VIEWS_DIR"] and not ENV["RBBT_VIEWS_DIR"].empty?
10
+
10
11
  Compass::Frameworks::ALL.each do |importer|
11
12
  next unless importer.respond_to? :path
12
13
  path = importer.stylesheets_directory
13
14
  RbbtRESTHelpers.add_sass_load_path path
14
15
  end
16
+
15
17
  RbbtRESTHelpers.add_sass_load_path './www/views/compass'
16
18
 
@@ -25,8 +25,12 @@ module Annotated
25
25
  entity_id = info.delete(:entity_id) || info.delete("entity_id")
26
26
 
27
27
  annotation_types.each do |mod|
28
- mod = Misc.string2const(mod) if String === mod
29
- object.extend mod unless mod === object
28
+ begin
29
+ mod = Misc.string2const(mod) if String === mod
30
+ object.extend mod unless mod === object
31
+ rescue Exception
32
+ Log.warn "Exception loading annotation into object: #{$!.message}"
33
+ end
30
34
  end
31
35
 
32
36
  object.instance_variable_set(:@annotation_values, info)
@@ -68,6 +68,7 @@ module Association
68
68
  annotations.each do |target, info|
69
69
  next if target.nil? or target.empty?
70
70
  key = [source, target] * "~"
71
+
71
72
  if data[key].nil? or info.nil?
72
73
  data[key] = info
73
74
  else
@@ -75,12 +76,22 @@ module Association
75
76
  info = old_info.zip(info).collect{|p| p * ";;" }
76
77
  data[key] = info
77
78
  end
78
- if undirected
79
- reverse_key = [target,source] * "~"
80
- data[reverse_key] = info unless data.include? reverse_key
81
- end
82
79
  end
83
80
  end
81
+
82
+ if undirected
83
+ new_data = {}
84
+
85
+ data.through do |key,values|
86
+ reverse_key = key.split("~").reverse * "~"
87
+ new_data[reverse_key] = values
88
+ end
89
+
90
+ new_data.each do |key,values|
91
+ data[key] = values
92
+ end
93
+ end
94
+
84
95
  end
85
96
  end
86
97
  end.tap do |data|
@@ -219,7 +230,7 @@ module Association
219
230
 
220
231
  matches.each{|code|
221
232
  s,sep,t = code.partition "~"
222
- next if undirected and t > s
233
+ next if undirected and t > s and source.include? t
223
234
  target_matches[t] ||= []
224
235
  target_matches[t] << code
225
236
  }
@@ -124,11 +124,11 @@ module Association
124
124
  all_fields.first
125
125
  end
126
126
 
127
-
128
127
  field_headers << header
129
128
  end
130
129
 
131
130
  field_pos = info_fields.collect{|f| raise "Field #{f} not found. Options: #{all_fields * ", "}" unless all_fields.include?(f); f == :key ? 0 : all_fields.index(f); }
131
+ field_pos.delete source_pos
132
132
 
133
133
  source_format = specs[:source][2]
134
134
  target_format = specs[:target][2]
data/lib/rbbt/entity.rb CHANGED
@@ -8,7 +8,59 @@ module Entity
8
8
  class << self
9
9
  attr_accessor :formats, :entity_property_cache
10
10
  end
11
- self.formats = {}
11
+ FORMATS = begin
12
+ hash = {}
13
+ class << hash
14
+ alias orig_include? include?
15
+
16
+ attr_accessor :find_cache
17
+
18
+ def find(value)
19
+ self.find_cache ||= {}
20
+ if self.find_cache.include? value
21
+ self.find_cache[value]
22
+ else
23
+ self.find_cache[value] = begin
24
+ if orig_include? value
25
+ self.find_cache[value] = value
26
+ else
27
+ found = nil
28
+ each do |k,v|
29
+ if value =~ /\b#{Regexp.quote k}$/
30
+ found = k
31
+ break
32
+ end
33
+ end
34
+ found
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def [](value)
41
+ res = super
42
+ return res if res
43
+ key = find(value)
44
+ key ? super(key) : nil
45
+ end
46
+
47
+ def []=(key,value)
48
+ self.find_cache = nil
49
+ super
50
+ end
51
+
52
+ def include?(value)
53
+ find(value) != nil
54
+ end
55
+ end
56
+
57
+ hash
58
+ end
59
+
60
+ def self.formats
61
+ FORMATS
62
+ end
63
+
12
64
  dir = (defined?(Rbbt)? Rbbt.var.entity_property : 'var/entity_property')
13
65
  self.entity_property_cache = dir
14
66
 
@@ -25,12 +25,15 @@ module Entity
25
25
  def identifier_files
26
26
  files = identity_type.identifier_files.dup
27
27
  files.collect!{|f| f.annotate f.gsub(/\bNAMESPACE\b/, organism) } if annotations.include? :organism and self.organism
28
+ if files.select{|f| f =~ /\bNAMESPACE\b/ }.any?
29
+ Log.warn "Rejecting some identifier files for lack of 'organism': " << files.select{|f| f =~ /\bNAMESPACE\b/ } * ", "
30
+ end
28
31
  files.reject!{|f| f =~ /\bNAMESPACE\b/ }
29
32
  files
30
33
  end
31
34
 
32
35
  def identifier_index(format = nil, source = nil)
33
- Persist.memory("Entity index #{identity_type}: #{format} (from #{source || "All"})", :format => format, :source => source) do
36
+ Persist.memory("Entity index #{identity_type}: #{format} (from #{source || "All"})", :format => format, :source => source, :update => true) do
34
37
  source ||= self.respond_to?(:format)? self.format : nil
35
38
 
36
39
  index = TSV.translation_index(identifier_files, format, source, :persist => true)
data/lib/rbbt/tsv.rb CHANGED
@@ -60,6 +60,7 @@ module TSV
60
60
  unnamed = Misc.process_options options, :unnamed
61
61
  entity_options = Misc.process_options options, :entity_options
62
62
 
63
+
63
64
  Log.debug "TSV open: #{ filename } - #{Misc.fingerprint options }.#{unnamed ? " [unnamed]" : "[not unnamed]"}"
64
65
 
65
66
  data = nil
@@ -72,10 +73,12 @@ module TSV
72
73
  data.serializer = serializer
73
74
  end
74
75
 
76
+ tsv_grep = Misc.process_options options, :tsv_grep
77
+ tsv_grep ||= Misc.process_options options, :grep
75
78
  open_options = Misc.pull_keys options, :open
76
79
 
77
80
  stream = get_stream source, options.merge(open_options)
78
- parse stream, data, options
81
+ parse stream, data, options.merge(:tsv_grep => tsv_grep)
79
82
 
80
83
  data.filename = filename.to_s unless filename.nil?
81
84
 
@@ -646,35 +646,7 @@ Example:
646
646
  new
647
647
  end
648
648
 
649
- def unzip(field = 0, merge = false)
650
- new = {}
651
- field_pos = self.identify_field field
652
-
653
- self.through do |key,values|
654
- field_values = values.delete_at field_pos
655
- zipped = values.zip_fields
656
- field_values.zip(zipped).each do |value, *rest|
657
- k = [key,value]*":"
658
- if merge and new.include? k
659
- new[k] = Misc.zip_fields(rest)
660
- else
661
- new[k] = Misc.zip_fields(rest)
662
- end
663
- end
664
- end
665
-
666
- self.annotate new
667
- new.type = :list
668
-
669
- new.key_field = [self.key_field, self.fields[field_pos]] * ":"
670
- new_fields = self.fields.dup
671
- new_fields.delete_at field_pos
672
- new.fields = new_fields
673
-
674
- new
675
- end
676
-
677
- def unzip(field = 0, merge = false)
649
+ def unzip(field = 0, merge = false, sep = ":")
678
650
  new = {}
679
651
  self.annotate new
680
652
 
@@ -686,7 +658,7 @@ Example:
686
658
  next if field_values.nil?
687
659
  zipped = Misc.zip_fields(values)
688
660
  field_values.zip(zipped).each do |field_value,rest|
689
- k = [key,field_value]*":"
661
+ k = [key,field_value]*sep
690
662
  if new.include? k
691
663
  new[k] = Misc.zip_fields(Misc.zip_fields(new[k]) << rest)
692
664
  else
@@ -701,7 +673,7 @@ Example:
701
673
  next if field_values.nil?
702
674
  zipped = Misc.zip_fields(values)
703
675
  field_values.zip(zipped).each do |field_value,rest|
704
- k = [key,field_value]*":"
676
+ k = [key,field_value]*sep
705
677
  new[k] = rest
706
678
  end
707
679
  end
@@ -89,7 +89,11 @@ module TSV
89
89
  def self.translation_index(files, target = nil, source = nil, options = {})
90
90
  return nil if source == target
91
91
  options = Misc.add_defaults options.dup, :persist => true
92
+
93
+ target = Entity.formats.find(target) if Entity.formats.find(target)
94
+ source = Entity.formats.find(source) if Entity.formats.find(source)
92
95
  fields = (source and not source.empty?) ? [source] : nil
96
+
93
97
  files.each do |file|
94
98
  if TSV === file
95
99
  all_fields = file.all_fields
@@ -126,6 +130,7 @@ module TSV
126
130
 
127
131
  index = Persist.persist_tsv(nil, Misc.fingerprint(files), {:files => files, :source => source, :target => target}, :prefix => "Translation index", :persist => options[:persist]) do |data|
128
132
 
133
+ iii options.merge(:target => common_field, :fields => fields)
129
134
  index = TSV === file ?
130
135
  file.index(options.merge(:target => common_field, :fields => fields)) :
131
136
  TSV.index(file, options.merge(:target => common_field, :fields => fields))
@@ -85,6 +85,21 @@ module TSV
85
85
  end
86
86
  end
87
87
 
88
+ cells = cells.collect do |v|
89
+ case v
90
+ when Float
91
+ v.to_s.sub(/e(-?\d+)$/,'E\1')
92
+ when String
93
+ if v =~ /^-?[\d\.]+e(-?\d+)$/
94
+ v.sub(/e(-?\d+)$/,'E\1')
95
+ else
96
+ v
97
+ end
98
+ else
99
+ v
100
+ end
101
+ end
102
+
88
103
  sheet1.row(i).concat cells
89
104
  i += 1
90
105
  end
@@ -16,7 +16,7 @@ module TSV
16
16
  persist_options = Misc.pull_keys options, :persist
17
17
  persist_options[:prefix] ||= "Index[#{options[:target] || :key}]"
18
18
 
19
- Log.debug "Index: #{ filename } - #{options.inspect}"
19
+ Log.debug "Index: #{ filename } - #{Misc.fingerprint options}"
20
20
  Persist.persist_tsv self, filename, options, persist_options do |new|
21
21
  with_unnamed do
22
22
  target, fields, index_type, order = Misc.process_options options, :target, :fields, :type, :order
@@ -116,7 +116,7 @@ module TSV
116
116
  end
117
117
  end
118
118
 
119
- TSV.setup(new, :type => index_type, :filename => filename, :fields => [new_key_field], :key_field => new_fields * ", ")
119
+ TSV.setup(new, :type => index_type, :filename => filename, :fields => [new_key_field], :key_field => new_fields * ", ", :namespace => namespace)
120
120
  end
121
121
  end
122
122
  end
@@ -125,12 +125,12 @@ module TSV
125
125
  persist_options = Misc.pull_keys options, :persist
126
126
  persist_options[:prefix] ||= "StaticIndex[#{options[:target] || :key}]"
127
127
 
128
- Log.debug "Static Index: #{ file } - #{options.inspect}"
128
+ Log.debug "Static Index: #{ file } - #{Misc.fingerprint options}"
129
129
  Persist.persist_tsv nil, file, options, persist_options do |data|
130
130
  data_options = Misc.pull_keys options, :data
131
131
  identifiers = TSV.open(file, data_options)
132
132
  identifiers.with_monitor :desc => "Creating Index for #{ file }" do
133
- index = identifiers.index(options.merge :persist_data => data, :persist => persist_options[:persist])
133
+ identifiers.index(options.merge :persist_data => data, :persist => persist_options[:persist])
134
134
  end
135
135
  end
136
136
  end
@@ -383,6 +383,7 @@ module TSV
383
383
  def initialize(stream = nil, options = {})
384
384
  @header_hash = Misc.process_options(options, :header_hash) || "#"
385
385
  @sep = Misc.process_options(options, :sep) || "\t"
386
+ @tsv_grep = Misc.process_options(options, :tsv_grep)
386
387
  stream = TSV.get_stream stream
387
388
  @stream = stream
388
389
 
@@ -414,6 +415,8 @@ module TSV
414
415
  fix_fields(options)
415
416
 
416
417
  @type = @type.strip.to_sym if String === @type
418
+ #@type ||= :double if merge == true
419
+
417
420
  case @type
418
421
  when :double
419
422
  self.instance_eval do alias get_values get_values_double end
@@ -502,18 +505,24 @@ module TSV
502
505
  raise "No block given in TSV::Parser#traverse" unless block_given?
503
506
 
504
507
  stream = @stream
505
- # get parser
506
508
 
507
- # grep
508
- #if grep and false
509
- # stream.rewind if stream.eof?
510
- # stream = Open.grep(stream, grep, invert_grep)
511
- # self.first_line = stream.gets
512
- #end
513
509
 
514
510
  # first line
515
511
  line = self.rescue_first_line
516
512
 
513
+ if @tsv_grep
514
+
515
+ stream = Open.grep(stream, @tsv_grep, invert_grep)
516
+ stream.no_fail = true
517
+ begin
518
+ match = Open.grep(StringIO.new(line), @tsv_grep, invert_grep).read
519
+ line = stream.gets if match.empty?
520
+ rescue Exception
521
+ Log.exception $!
522
+ line = stream.gets
523
+ end
524
+ end
525
+
517
526
  progress_monitor, monitor = monitor, nil if Log::ProgressBar === monitor
518
527
  # setup monitor
519
528
  if monitor and (stream.respond_to?(:size) or (stream.respond_to?(:stat) and stream.stat.respond_to? :size)) and stream.respond_to?(:pos)
data/lib/rbbt/tsv/util.rb CHANGED
@@ -152,7 +152,7 @@ module TSV
152
152
  pos = fields.index field
153
153
  return pos if pos
154
154
  return identify_field(key_field, fields, field.to_i) if field =~ /^\d+$/
155
- raise "Field #{ field } was not found. Options: #{fields * ", "}" if pos.nil?
155
+ raise "Field #{ field } was not found. Options: (#{key_field || "NO_KEY_FIELD"}), #{(fields || ["NO_FIELDS"]) * ", "}" if pos.nil?
156
156
  else
157
157
  raise "Field #{ field } was not found. Options: (#{key_field || "NO_KEY_FIELD"}), #{(fields || ["NO_FIELDS"]) * ", "}"
158
158
  end
data/lib/rbbt/util/R.rb CHANGED
@@ -4,8 +4,9 @@ require 'rbbt/util/R/eval'
4
4
 
5
5
  module R
6
6
 
7
- LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'../../../share/Rlib')
7
+ LIB_DIR = Path.setup(File.join(File.expand_path(File.dirname(__FILE__)),'../../../share/Rlib'))
8
8
  UTIL = File.join(LIB_DIR, 'util.R')
9
+ PLOT = File.join(LIB_DIR, 'plot.R')
9
10
 
10
11
  def self.run(command, options = {})
11
12
  cmd =<<-EOF
@@ -127,10 +128,11 @@ module TSV
127
128
  open_options, source = source, nil if Hash === source
128
129
 
129
130
  source ||= Misc.process_options open_options, :source
130
- source = [source] if String === source
131
+ source = [source] unless Array === source
131
132
 
132
133
  require_sources = source.collect{|source|
133
- "source('#{source}');"
134
+ source = R::LIB_DIR["plot.R"] if source == :plot
135
+ "source('#{source}')"
134
136
  } * ";\n" if Array === source and source.any?
135
137
 
136
138
  script = require_sources + "\n\n" + script if require_sources
@@ -18,11 +18,14 @@ module R
18
18
  class Model
19
19
  R_METHOD = :eval
20
20
 
21
- attr_accessor :name, :formula
21
+ attr_accessor :name, :formula, :model_file
22
22
  def initialize(name, formula, data = nil, options = {})
23
23
  @name = name
24
24
  @formula = formula
25
25
  @options = options || {}
26
+ @model_file = options[:model_file] if options[:model_file]
27
+ @model_file ||= Misc.sanitize_filename(File.join(options[:model_dir], name)) if options[:model_dir]
28
+
26
29
  if data and not model_file.exists?
27
30
  method = Misc.process_options options, :fit
28
31
  fit(data, method || "lm", options)
@@ -15,12 +15,13 @@ module Colorize
15
15
  start_color = Color.new from_name(start)
16
16
  end_color = Color.new from_name(eend)
17
17
 
18
- array = array.collect{|v| v.to_f}
18
+ array = array.collect{|v| n = v.to_f; n = n > 100 ? 100 : n; n < 0.001 ? 0.001 : n}
19
19
  max = array.max
20
20
  min = array.min
21
21
  range = max - min
22
22
  array.collect do |v|
23
- start_color.blend end_color, (v - min) / range
23
+ ratio = (v-min) / range
24
+ start_color.blend end_color, ratio
24
25
  end
25
26
  end
26
27
 
@@ -89,7 +89,9 @@ class RbbtProcessQueue
89
89
 
90
90
  def push(obj)
91
91
  RbbtSemaphore.synchronize(@write_sem) do
92
+ multiple = MultipleResult === obj
92
93
  obj = Annotated.purge(obj)
94
+ obj.extend MultipleResult if multiple
93
95
  self.dump(obj, @swrite)
94
96
  end
95
97
  end
@@ -7,11 +7,11 @@ module Misc
7
7
 
8
8
  dup_array = options.delete :dup_array
9
9
 
10
- if Entity === field or (Entity.respond_to?(:formats) and Entity.formats.include? field)
10
+ if Entity === field or (Entity.respond_to?(:formats) and (_format = Entity.formats.find(field)))
11
11
  params = options.dup
12
12
 
13
13
  params[:format] ||= params.delete "format"
14
- params.merge!(:format => field) unless params.include?(:format) and not ((f = params[:format]).nil? or (String === f and f.empty?))
14
+ params.merge!(:format => _format) unless _format.nil? or (params.include?(:format) and not ((f = params[:format]).nil? or (String === f and f.empty?)))
15
15
 
16
16
  mod = Entity === field ? field : Entity.formats[field]
17
17
  entity = mod.setup(
data/share/Rlib/plot.R ADDED
@@ -0,0 +1,40 @@
1
+ library(ggplot2)
2
+
3
+ geom_entity <- function (real.geom = NULL, mapping = NULL, data = NULL, stat = "identity",
4
+ position = "identity", ...) {
5
+ rg <- real.geom(mapping = mapping, data = data, stat = stat,
6
+ position = position, ...)
7
+
8
+ rg$geom <- proto(rg$geom, {
9
+ draw <- function(., data, ...) {
10
+ grobs <- list()
11
+
12
+ for (i in 1:nrow(data)) {
13
+ grob <- .super$draw(., data[i,], ...)
14
+ if (is.null(data$entity.type))
15
+ grobs[[i]] <- garnishGrob(grob, `data-entity`=data[i,]$entity)
16
+ else
17
+ grobs[[i]] <- garnishGrob(grob, `data-entity`=data[i,]$entity, `data-entity-type`=data[i,]$entity.type)
18
+ }
19
+
20
+ ggplot2:::ggname("geom_entity", gTree(children = do.call("gList", grobs)))
21
+ }
22
+
23
+ draw_groups <- function(., data, ...) {
24
+ grobs <- list()
25
+
26
+ for (i in 1:nrow(data)) {
27
+ grob <- .super$draw_groups(., data[i,], ...)
28
+ if (is.null(data$entity.type))
29
+ grobs[[i]] <- garnishGrob(grob, `data-entity`=data[i,]$entity)
30
+ else
31
+ grobs[[i]] <- garnishGrob(grob, `data-entity`=data[i,]$entity, `data-entity-type`=data[i,]$entity.type)
32
+ }
33
+
34
+ ggplot2:::ggname("geom_entity", gTree(children = do.call("gList", grobs)))
35
+ }
36
+ })
37
+
38
+ rg
39
+ }
40
+
@@ -3,7 +3,7 @@
3
3
  require 'rbbt-util'
4
4
  require 'rbbt/util/simpleopt'
5
5
 
6
- options = SOPT.get "-e--environment*:-p--port*:-s--server*:-f--finder:-R--Rserve_session*:-ho--host*"
6
+ options = SOPT.get "-e--environment*:-p--port*:-s--server*:-f--finder:-R--Rserve_session*:-ho--host*:--views*"
7
7
  options[:Port] ||= options[:port]
8
8
  options[:Host] ||= "0.0.0.0"
9
9
  options[:Bind] ||= "0.0.0.0"
@@ -21,6 +21,7 @@ Misc.in_dir(app_dir) do
21
21
  require 'rack'
22
22
  ENV["RBBT_FINDER"] = "true" if options.include?(:finder)
23
23
  ENV["RACK_ENV"] = options[:environment] if options.include?(:environment)
24
+ ENV["RBBT_VIEWS_DIR"] = options[:views] if options.include?(:views)
24
25
 
25
26
  config_ru_file = File.exists?('./config.ru') ? './config.ru' : Rbbt.share['config.ru'].find
26
27
 
@@ -8,7 +8,7 @@ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_c
8
8
  options = SOPT.setup <<EOF
9
9
  Zip fields in a TSV file
10
10
 
11
- $ rbbt tsv info [options] file.tsv
11
+ $ rbbt tsv unzip [options] file.tsv
12
12
 
13
13
  Display summary information. Works with Tokyocabinet HDB and BDB as well.
14
14
 
@@ -36,7 +36,7 @@ def run_task(workflow, task, name)
36
36
  end
37
37
  end
38
38
  sleep 0.5
39
- path = Open.read(res).strip if File.exists? res
39
+ path = Open.read(res).strip.split("\n").last if File.exists? res
40
40
  end
41
41
  path = "NO RESULT" if path.nil? or path.empty?
42
42
 
@@ -13,7 +13,7 @@ require 'rbbt/rest/file_server'
13
13
  require 'rbbt/rest/knowledge_base'
14
14
  require 'rbbt/rest/helpers'
15
15
 
16
- options = SOPT.get "-e--environment*:-p--port*:-s--server*:-b--bind*:-e--environment*:-R--RServe_session*:--finder"
16
+ options = SOPT.get "-e--environment*:-p--port*:-s--server*:-b--bind*:-e--environment*:-R--RServe_session*:--finder:--views*"
17
17
 
18
18
  workflow = ARGV.first
19
19
 
@@ -31,6 +31,8 @@ load Rbbt.etc['app.d/init.rb'].find
31
31
  app = class WorkflowRest < Sinatra::Base; self end
32
32
 
33
33
  app.register Sinatra::RbbtRESTWorkflow
34
+ app.register Sinatra::RbbtRESTKnowledgeBase
35
+
34
36
  app.get '/' do
35
37
  redirect to(File.join('/', wf.to_s))
36
38
  end
@@ -43,7 +45,12 @@ app.class_eval do
43
45
  eval Rbbt.etc['app.d/finder.rb'].read
44
46
  end
45
47
 
46
- WorkflowRest.add_workflow wf, true
48
+ WorkflowRest.add_workflow wf, :all
49
+
50
+ if options[:views] and not options[:views].empty?
51
+ Sinatra::RbbtRESTMain.add_resource_path(Path.setup(options[:views]), true)
52
+ end
53
+
47
54
 
48
55
  WorkflowRest.port = options[:port] || 4567
49
56
  WorkflowRest.bind = options[:bind] || "0.0.0.0"
@@ -58,4 +58,7 @@ TP53 NFKB1|GLI1 activation|activation true|true
58
58
  assert_equal [["Bilateria"], ["Euteleostomi"], ["Duplicate"]], tsv["ENSG00000000003"]
59
59
  end
60
60
 
61
+ def test_gene_ages
62
+ assert Association.database('/home/mvazquezg/git/workflows/genomics/share/gene_ages', :source => "FamilyAge", :merge => true, :target => "Ensembl Gene ID", :persist => false).values.first.length > 1
63
+ end
61
64
  end
@@ -308,6 +308,22 @@ b 2
308
308
  end
309
309
  end
310
310
 
311
+ def test_tsv_grep
312
+ content =<<-EOF
313
+ #: :sep=/\\s+/#:type=:single
314
+ #Id Value
315
+ a 1
316
+ b 2
317
+ b 3
318
+ EOF
319
+
320
+ TmpFile.with_file(content) do |filename|
321
+ tsv = TSV.open(filename, :key_field => "Value", :tsv_grep => "2")
322
+ assert(tsv.include?("2"))
323
+ assert(! tsv.include?("3"))
324
+ end
325
+ end
326
+
311
327
  def test_grep_invert
312
328
  content =<<-EOF
313
329
  #: :sep=/\\s+/#:type=:single
@@ -317,8 +333,9 @@ b 2
317
333
  EOF
318
334
 
319
335
  TmpFile.with_file(content) do |filename|
320
- tsv = TSV.open(filename, :key_field => "Value", :grep => "#\\|2", :invert_grep => true)
336
+ tsv = TSV.open(filename, :key_field => "Value", :tsv_grep => "2", :invert_grep => true)
321
337
  assert(! tsv.include?("2"))
338
+ assert(tsv.include?("1"))
322
339
  end
323
340
  end
324
341
 
@@ -326,6 +343,7 @@ b 2
326
343
  content =<<-EOF
327
344
  #: :sep=/\\s+/#:type=:single#:namespace=Test
328
345
  #Id Value
346
+ a 7
329
347
  a 1
330
348
  b 2
331
349
  EOF
@@ -334,6 +352,7 @@ b 2
334
352
  tsv = TSV.open(filename, :key_field => "Value", :grep => "#\\|2")
335
353
  assert(! tsv.include?("1"))
336
354
  assert(tsv.include?("2"))
355
+ assert(! tsv.include?("7"))
337
356
  end
338
357
  end
339
358
 
@@ -533,4 +552,8 @@ row2 A AA AAA
533
552
  tsv = datafile_test('identifiers').tsv :persist => true, :shard_function => shard_function
534
553
  assert_equal 10000, tsv.keys.length + 2
535
554
  end
555
+
556
+ def test_merge_key_field
557
+ assert TSV.open('/home/mvazquezg/git/workflows/genomics/share/gene_ages', :key_field => "FamilyAge", :merge => true, :persist => false, :zipped => true, :type => :double).values.first.length > 1
558
+ end
536
559
  end
@@ -394,10 +394,14 @@ class TestTSVParallelThrough < Test::Unit::TestCase
394
394
  def test_store_multiple
395
395
  size = 1000
396
396
  array = (1..size).to_a.collect{|n| n.to_s}
397
- stream = TSV.traverse array, :bar => {:max => size, :desc => "Array"}, :cpus => 5, :into => :stream do |e|
398
- sleep 0.01
399
- [e,e+".alt"].extend MultipleResult
397
+
398
+ stream = TSV.traverse array, :bar => {:max => size, :desc => "Multiple into stream"}, :cpus => 2, :into => :stream do |e|
399
+ sleep 0.001
400
+ res = [e,e+".alt"]
401
+ res.extend MultipleResult
402
+ res
400
403
  end
404
+
401
405
  assert_equal size*2, stream.read.split("\n").length
402
406
  end
403
407
  end
@@ -13,12 +13,14 @@ rowa a|aa b|BB C|CC
13
13
 
14
14
  TmpFile.with_file(content) do |filename|
15
15
  tsv = TSV.open(File.open(filename), :sep => /\s+/, :type => :double)
16
+ Log.tsv tsv
17
+ Log.tsv tsv.reorder("ValueA", nil, :zipped => true)
16
18
  assert_equal ["A", "AA", "a", "aa"].sort, tsv.reorder("ValueA", nil, :zipped => true).keys.sort
17
19
  end
18
20
  end
19
21
 
20
22
 
21
- def test_through
23
+ def _test_through
22
24
  content =<<-EOF
23
25
  #Id ValueA ValueB OtherID
24
26
  row1 a|aa|aaa b Id1|Id2
@@ -37,7 +39,7 @@ row3 a C Id4
37
39
  end
38
40
  end
39
41
 
40
- def test_reorder_simple
42
+ def _test_reorder_simple
41
43
  content =<<-EOF
42
44
  #Id ValueA ValueB OtherID
43
45
  row1 a|aa|aaa b Id1|Id2
@@ -59,7 +61,7 @@ row3 a C Id4
59
61
  end
60
62
  end
61
63
 
62
- def test_reorder_remove_field
64
+ def _test_reorder_remove_field
63
65
  content =<<-EOF
64
66
  #Id ValueA ValueB OtherID
65
67
  row1 a|aa|aaa b Id1|Id2
@@ -81,7 +83,7 @@ row3 a C Id4
81
83
  end
82
84
  end
83
85
 
84
- def test_slice
86
+ def _test_slice
85
87
  content =<<-EOF
86
88
  #ID ValueA ValueB Comment
87
89
  row1 a b c
@@ -94,7 +96,7 @@ row2 A B C
94
96
  end
95
97
  end
96
98
 
97
- def test_select
99
+ def _test_select
98
100
  content =<<-EOF
99
101
  #Id ValueA ValueB OtherID
100
102
  row1 a|aa|aaa b Id1|Id2
@@ -132,7 +134,7 @@ row3 a C Id4
132
134
  end
133
135
  end
134
136
 
135
- def test_select_invert
137
+ def _test_select_invert
136
138
  content =<<-EOF
137
139
  #Id ValueA ValueB OtherID
138
140
  row1 a|aa|aaa b Id1|Id2
@@ -163,7 +165,7 @@ row3 a C Id4
163
165
  end
164
166
  end
165
167
 
166
- def test_process
168
+ def _test_process
167
169
  content =<<-EOF
168
170
  #Id ValueA ValueB OtherID
169
171
  row1 a|aa|aaa b Id1|Id2
@@ -182,7 +184,7 @@ row3 a C Id4
182
184
  end
183
185
  end
184
186
 
185
- def test_add_field
187
+ def _test_add_field
186
188
  content =<<-EOF
187
189
  #Id LetterValue:ValueA LetterValue:ValueB OtherID
188
190
  row1 a|aa|aaa b Id1|Id2
@@ -200,7 +202,7 @@ row3 a C Id4
200
202
  end
201
203
  end
202
204
 
203
- def test_add_field_double_with_list_result
205
+ def _test_add_field_double_with_list_result
204
206
  content =<<-EOF
205
207
  #Id LetterValue:ValueA LetterValue:ValueB OtherID
206
208
  row1 a|aa|aaa b Id1|Id2
@@ -219,7 +221,7 @@ row3 a C Id4
219
221
  end
220
222
  end
221
223
 
222
- def test_through_headless
224
+ def _test_through_headless
223
225
  content =<<-EOF
224
226
  row1 a|aa|aaa b Id1|Id2
225
227
  row2 A B Id3
@@ -229,17 +231,17 @@ row3 a C Id4
229
231
  TmpFile.with_file(content) do |filename|
230
232
  tsv = TSV.open(filename, :sep => /\s+/)
231
233
 
232
- test = false
234
+ _test = false
233
235
  tsv.through do
234
- test = true
236
+ _test = true
235
237
  end
236
- assert test
238
+ assert _test
237
239
 
238
240
  end
239
241
 
240
242
  end
241
243
 
242
- def test_reorder_flat
244
+ def _test_reorder_flat
243
245
  content =<<-EOF
244
246
  #Id ValueA
245
247
  row1 a aa aaa
@@ -255,7 +257,7 @@ row3 a
255
257
  end
256
258
  end
257
259
 
258
- def test_transpose
260
+ def _test_transpose
259
261
  content =<<-EOF
260
262
  #: :type=:list
261
263
  #Row vA vB vID
@@ -273,7 +275,7 @@ row3 a C Id4
273
275
 
274
276
  end
275
277
 
276
- def test_through_flat
278
+ def _test_through_flat
277
279
  content =<<-EOF
278
280
  #: :type=:flat
279
281
  #Row vA
@@ -440,7 +440,7 @@ eum fugiat quo voluptas nulla pariatur?"
440
440
  assert_equal "COSMIC", Misc.camel_case("COSMIC")
441
441
  end
442
442
 
443
- def test_texar
443
+ def _test_texar
444
444
  ppp Misc.html_tag('textarea', "hola\nadios\nagain")
445
445
  end
446
446
 
@@ -454,4 +454,8 @@ eum fugiat quo voluptas nulla pariatur?"
454
454
  puts `ls -l /proc/#{ Process.pid }/fd`
455
455
  end
456
456
 
457
+ def test_snake_case
458
+ ppp Misc.snake_case("KinaseSARfari")
459
+ end
460
+
457
461
  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.15.1
4
+ version: 5.15.2
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-11-21 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -268,6 +268,7 @@ files:
268
268
  - lib/rbbt/workflow/step/run.rb
269
269
  - lib/rbbt/workflow/task.rb
270
270
  - lib/rbbt/workflow/usage.rb
271
+ - share/Rlib/plot.R
271
272
  - share/Rlib/util.R
272
273
  - share/config.ru
273
274
  - share/install/software/lib/install_helpers