rbbt-util 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +2 -2
  3. data/bin/rbbt +45 -0
  4. data/bin/rbbt_dangling_locks.rb +9 -0
  5. data/bin/rbbt_monitor.rb +12 -10
  6. data/bin/run_workflow.rb +80 -18
  7. data/lib/rbbt.rb +1 -1
  8. data/lib/rbbt/annotations.rb +1 -19
  9. data/lib/rbbt/annotations/annotated_array.rb +23 -0
  10. data/lib/rbbt/fix_width_table.rb +2 -2
  11. data/lib/rbbt/persist.rb +13 -5
  12. data/lib/rbbt/persist/tsv.rb +2 -0
  13. data/lib/rbbt/resource.rb +4 -4
  14. data/lib/rbbt/resource/path.rb +35 -10
  15. data/lib/rbbt/resource/util.rb +54 -47
  16. data/lib/rbbt/tsv.rb +17 -15
  17. data/lib/rbbt/tsv/accessor.rb +35 -37
  18. data/lib/rbbt/tsv/excel.rb +3 -1
  19. data/lib/rbbt/tsv/manipulate.rb +27 -4
  20. data/lib/rbbt/tsv/parser.rb +13 -7
  21. data/lib/rbbt/util/R.rb +11 -1
  22. data/lib/rbbt/util/misc.rb +182 -26
  23. data/lib/rbbt/util/named_array.rb +14 -7
  24. data/lib/rbbt/util/open.rb +2 -1
  25. data/lib/rbbt/util/tmpfile.rb +16 -1
  26. data/lib/rbbt/workflow.rb +63 -101
  27. data/lib/rbbt/workflow/accessor.rb +19 -9
  28. data/lib/rbbt/workflow/annotate.rb +33 -64
  29. data/lib/rbbt/workflow/definition.rb +71 -0
  30. data/lib/rbbt/workflow/soap.rb +15 -5
  31. data/lib/rbbt/workflow/step.rb +57 -8
  32. data/lib/rbbt/workflow/usage.rb +72 -0
  33. data/share/lib/R/util.R +12 -0
  34. data/share/rbbt_commands/conf/web_user/add +26 -0
  35. data/share/rbbt_commands/conf/web_user/list +9 -0
  36. data/share/rbbt_commands/conf/web_user/remove +18 -0
  37. data/share/rbbt_commands/workflow/remote/add +11 -0
  38. data/share/rbbt_commands/workflow/remote/list +9 -0
  39. data/share/rbbt_commands/workflow/remote/remove +9 -0
  40. data/share/rbbt_commands/workflow/task +181 -0
  41. data/test/rbbt/test_resource.rb +2 -1
  42. data/test/rbbt/test_workflow.rb +13 -0
  43. data/test/rbbt/tsv/test_manipulate.rb +18 -0
  44. data/test/rbbt/util/test_misc.rb +19 -39
  45. data/test/rbbt/util/test_tmpfile.rb +8 -0
  46. data/test/rbbt/workflow/test_soap.rb +2 -0
  47. metadata +31 -2
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2011 Miguel Vázquez García
1
+ Copyright (c) 2010-2013 Miguel Vázquez García
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -45,7 +45,6 @@
45
45
 
46
46
  gem install specific_install hoe
47
47
  gem specific_install -l https://github.com/bensomers/png.git
48
- gem specific_install -l https://github.com/felipec/soap4r.git
49
48
  gem specific_install -l https://github.com/mikisvaz/tokyocabinet_19_fix.git
50
49
 
51
50
  3.pre2 - A couple of gems are better installed beforehand, since they require some configuration
@@ -82,7 +81,8 @@
82
81
  git clone git@github.com:mikisvaz/rbbt-phgx.git
83
82
  git clone git@github.com:mikisvaz/rbbt-entities.git
84
83
  git clone git@github.com:mikisvaz/rbbt-dm.git
85
- git clone git@github.com:mikisvaz/rbbt-views.git
84
+ git clone git@github.com:mikisvaz/rbbt-rest.git
85
+ git clone git@github.com:mikisvaz/rbbt-studies.git
86
86
  alias druby="env RBBT_LOG=0 ruby $(for d in $HOME/git/rbbt-*;do echo -n "-I$d/lib ";done)"
87
87
  alias drake="env RBBT_LOG=0 rake $(for d in $HOME/git/rbbt-*;do echo -n "-I$d/lib ";done)"
88
88
 
data/bin/rbbt ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt'
4
+
5
+ $rbbt_command_dir = Rbbt.share.rbbt_commands
6
+
7
+ def commands(prev)
8
+ rbbt_command_dir = $rbbt_command_dir
9
+
10
+ prev.each do |previous_command|
11
+ rbbt_command_dir = rbbt_command_dir[previous_command]
12
+ end
13
+
14
+ command_file_dirs = rbbt_command_dir.find_all
15
+ command_files = command_file_dirs.collect{|d| d.glob('*') }.flatten
16
+ command_files.collect{|p| File.basename(p) }.uniq.reject{|p| p =~ /\.desc$/}.sort
17
+ end
18
+
19
+ dir = $rbbt_command_dir
20
+ prev = []
21
+
22
+ while ARGV.any?
23
+ command = ARGV.shift
24
+ case
25
+ when File.directory?(dir[command].find)
26
+ prev << command
27
+ dir = dir[command]
28
+ when dir[command].exists?
29
+ load dir[command].find
30
+ exit 0
31
+ else
32
+ raise "Command not understood"
33
+ end
34
+ end
35
+
36
+ puts "Command:"
37
+ puts
38
+ puts " #{File.basename($0)} #{prev * " "}"
39
+ puts
40
+ puts "Subcommands:"
41
+ puts
42
+ commands(prev).each do |command|
43
+ puts " " << command
44
+ end
45
+
@@ -0,0 +1,9 @@
1
+ require 'rbbt/util/open'
2
+ require 'rbbt/util/misc'
3
+
4
+ lockfiles= `find . -name *.lock`.split "\n"
5
+ lockfiles.each do |file|
6
+ Open.read(file) =~ /^pid: (\d+)/
7
+ pid = $1
8
+ puts [file + " (#{ pid })", Misc.pid_exists?(pid) ? "Running" : "Missing"] * ": "
9
+ end
data/bin/rbbt_monitor.rb CHANGED
@@ -4,20 +4,19 @@ require 'rbbt-util'
4
4
  require 'fileutils'
5
5
  require 'rbbt/util/simpleopt'
6
6
  require 'rbbt/workflow/step'
7
+ require 'rbbt/util/misc'
7
8
 
8
- options = SOPT.get("-l--list:-z--zombies:-e--errors:-c--clean:-n--name:-a--all:-w--wipe:-f--file*")
9
+ options = SOPT.get("-l--list:-z--zombies:-e--errors:-c--clean:-n--name:-a--all:-w--wipe:-f--file*:-q--quick")
10
+
11
+
12
+ YAML::ENGINE.yamler = 'syck' if defined? YAML::ENGINE and YAML::ENGINE.respond_to? :yamler
9
13
 
10
14
  def info_files
11
15
  Dir.glob('**/*.info')
12
16
  end
13
17
 
14
18
  def running?(info)
15
- begin
16
- Process.kill 0, info[:pid]
17
- true
18
- rescue
19
- false
20
- end
19
+ Misc.pid_exists? info[:pid]
21
20
  end
22
21
 
23
22
  def print_job(file, info, severity_color = nil)
@@ -27,7 +26,8 @@ def print_job(file, info, severity_color = nil)
27
26
  else
28
27
  info ||= {:status => :missing_info_file}
29
28
  str = [clean_file, info[:status].to_s] * " [ STATUS = " + " ]"
30
- str += " (#{running?(info)? :running : :zombie} #{info[:pid]})" if info.include? :pid
29
+ str += " (#{running?(info)? :running : :dead} #{info[:pid]})" if info.include? :pid
30
+ str += " (children: #{info[:children_pids].collect{|pid| [pid, Misc.pid_exists?(pid) ? "R" : "D"] * ":"} * ", "})" if info.include? :children_pids
31
31
 
32
32
  str = "#{severity_color}" << str << "\033[0m" if severity_color
33
33
  puts str
@@ -40,11 +40,12 @@ def list_jobs(options)
40
40
 
41
41
  info_files.each do |file|
42
42
  clean_file = file.sub('.info','')
43
- next if File.exists? clean_file
44
43
  begin
44
+ next if File.exists? clean_file and $quick
45
45
  info = YAML.load(Open.read(file))
46
+ next if File.exists? clean_file and not running? info
46
47
  rescue Exception
47
- Log.debug "Error parsing info file: #{ file }"
48
+ puts "Error parsing info file: #{ file }"
48
49
  info = nil
49
50
  end
50
51
 
@@ -100,6 +101,7 @@ end
100
101
 
101
102
 
102
103
  $name = options.delete :name
104
+ $quick = options.delete :quick
103
105
  case
104
106
  when (options[:clean] and not options[:list])
105
107
  if options[:file]
data/bin/run_workflow.rb CHANGED
@@ -25,7 +25,7 @@ end
25
25
  def fix_options(workflow, task, job_options)
26
26
  option_types = workflow.rec_input_types(task.name)
27
27
 
28
- workflow.resolve_locals(job_options)
28
+ #workflow.resolve_locals(job_options)
29
29
 
30
30
  job_options_cleaned = {}
31
31
 
@@ -80,35 +80,97 @@ def fix_options(workflow, task, job_options)
80
80
  job_options_cleaned
81
81
  end
82
82
 
83
- options = SOPT.get "-t--task*:-l--log*:-h--help:-n--name*:-cl--clean:-rcl-recursive_clean:-pn--printname:-srv--server:-p--port*"
83
+ options = SOPT.get "-t--task*:--profile:-l--log*:-h--help:-n--name*:-cl--clean:-rcl-recursive_clean:-pn--printname:-srv--server:-p--port*"
84
84
 
85
85
  workflow = ARGV.first
86
86
 
87
87
  if options[:server]
88
88
 
89
- require 'rbbt/util/log'
90
- require 'rbbt/workflow'
91
- require 'rbbt/workflow/rest'
92
- require 'sinatra'
93
- require 'compass'
89
+ #require 'rbbt/util/log'
90
+ #require 'rbbt/workflow'
91
+ #require 'rbbt/workflow/rest'
92
+ #require 'sinatra'
93
+ #require 'compass'
94
94
 
95
- Workflow.require_workflow workflow
96
- WorkflowREST.add_workflows *Workflow.workflows
95
+ #if workflow
96
+ # Workflow.require_workflow workflow
97
+ # WorkflowREST.add_workflows *Workflow.workflows
98
+ #end
99
+
100
+ #WorkflowREST.setup
101
+
102
+ #Sinatra::Application.port = options[:port] || 4567
103
+ #Sinatra::Application.run = true
104
+
105
+ #if workflow and File.exists? workflow
106
+ # Sinatra::Application.views = File.join(File.dirname(workflow), 'www/views')
107
+ #end
108
+
109
+ #sinatra_file = './lib/sinatra.rb'
110
+ #if File.exists? sinatra_file
111
+ # require sinatra_file
112
+ #end
113
+ require 'zurb-foundation'
114
+ require 'modular-scale'
115
+
116
+ require 'rbbt/rest/main'
117
+ require 'rbbt/rest/entity'
118
+ require 'rbbt/rest/workflow'
119
+ require 'rbbt/rest/file_server'
120
+ require 'rbbt/rest/helpers'
97
121
 
98
- WorkflowREST.setup
122
+ YAML::ENGINE.yamler = 'syck' if defined? YAML::ENGINE and YAML::ENGINE.respond_to? :yamler
99
123
 
100
- Sinatra::Application.port = options[:port] || 4567
101
- Sinatra::Application.run = true
124
+ Workflow.require_workflow workflow
125
+
126
+ class WorkflowRest < Sinatra::Base
127
+ get '/' do
128
+ redirect to(File.join('/', Workflow.workflows.last.to_s))
129
+ end
130
+ end
102
131
 
103
- if File.exists? workflow
104
- Sinatra::Application.views = File.join(File.dirname(workflow), 'www/views')
132
+ if options[:profile]
133
+ WorkflowRest.before File.join('/', Workflow.workflows.last.to_s, '*') do
134
+ @profile = true
135
+ end
105
136
  end
106
137
 
107
- sinatra_file = './lib/sinatra.rb'
108
- if File.exists? sinatra_file
109
- require sinatra_file
138
+ class WorkflowRest < Sinatra::Base
139
+
140
+ #{{{ MODULES AND HELPERS
141
+ register Sinatra::RbbtRESTMain
142
+ register Sinatra::RbbtRESTWorkflow
143
+ register Sinatra::RbbtRESTEntity
144
+ helpers Sinatra::RbbtMiscHelpers
145
+
146
+ #{{{ DIRECTORIES
147
+ local_var = Rbbt.var.find(:lib)
148
+ set :cache_dir , local_var.sinatra.cache.find
149
+ set :file_dir , local_var.sinatra.files.find
150
+ set :favourites_dir , local_var.sinatra.favourites.find
151
+ set :favourite_lists_dir , local_var.sinatra.favourite_lists
152
+
153
+ #{{{ SESSIONS
154
+ use Rack::Session::Cookie, :key => 'rack.session',
155
+ :path => '/',
156
+ :expire_after => 2592000,
157
+ :secret => "Workflow #{Workflow.workflows.inspect} secret!!"
158
+
159
+ #{{{ FOUNDATION RESOURCES
160
+ add_sass_load_path "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
161
+ add_sass_load_path "#{Gem.loaded_specs['zurb-foundation'].full_gem_path}/scss/"
162
+ add_sass_load_path "#{Gem.loaded_specs['modular-scale'].full_gem_path}/stylesheets/"
163
+ RbbtRESTHelpers.javascript_resources << Path.setup("#{Gem.loaded_specs['zurb-foundation'].full_gem_path}/js/foundation")
164
+ RbbtRESTHelpers.javascript_resources << Path.setup("#{Gem.loaded_specs['zurb-foundation'].full_gem_path}/js/vendor")
165
+
166
+ $title = "Workflow Scout"
167
+ use Rack::Deflater
110
168
  end
111
169
 
170
+ WorkflowRest.add_workflow Workflow.workflows.last, true
171
+
172
+ WorkflowRest.port = options[:port] || 4567
173
+ WorkflowRest.run!
112
174
  else
113
175
 
114
176
  # Set log, fork, clean, recursive_clean and help
@@ -147,7 +209,7 @@ else
147
209
  namespace, task = options.delete(:task).split('.')
148
210
  namespace = Misc.string2const(namespace)
149
211
  else
150
- task_name = options.delete(:task)
212
+ task_name = options.delete(:task).to_sym
151
213
  task = workflow.tasks[task_name]
152
214
  raise "Task not found: #{ task_name }" if task.nil?
153
215
  end
data/lib/rbbt.rb CHANGED
@@ -12,5 +12,5 @@ module Rbbt
12
12
  FileCache.cachedir = var.cache.filecache.find :user
13
13
  TmpFile.tmpdir = tmp.find :user
14
14
  Open.cachedir = var.cache["open-remote"].find :user
15
- Persist.cachedir = var.cache.persistence.find :user
15
+ Persist.cachedir = var.cache.persistence.find :user
16
16
  end
@@ -209,7 +209,7 @@ module Annotation
209
209
 
210
210
  hash.each do |key, value|
211
211
  begin
212
- next unless @annotations.include? (key = key.to_sym)
212
+ next unless @annotations.include?(key = key.to_sym)
213
213
  rescue
214
214
  next
215
215
  end
@@ -280,21 +280,3 @@ module Annotation
280
280
  mod.instance_variable_set(:@masked_annotations, self.masked_annotations.dup)
281
281
  end
282
282
  end
283
-
284
-
285
- if __FILE__ == $0
286
-
287
- module Gene
288
- extend Annotation
289
- annotation :format, :organism
290
- end
291
-
292
- a = %w(1 2 3 4 5 6 6)
293
- Gene.setup a, "Ensembl Gene ID", "Hsa"
294
-
295
- puts a.reject{|a| a.to_i < 6}.collect{|e| e.format}
296
-
297
- puts
298
-
299
- puts a.reject{|a| a.to_i < 6}.uniq.collect{|e| e.format}
300
- end
@@ -1,4 +1,6 @@
1
1
  module AnnotatedArray
2
+ attr_accessor :list_id
3
+
2
4
  def double_array
3
5
  AnnotatedArray === self.send(:[], 0, true)
4
6
  end
@@ -153,6 +155,27 @@ module AnnotatedArray
153
155
  res
154
156
  end
155
157
 
158
+ def select_by(method, *args, &block)
159
+ return [] if self.empty? and not self.respond_to? :annotate
160
+
161
+ values = self.send(method, *args)
162
+ values = values.clean_annotations if values.respond_to? :clean_annotations
163
+
164
+ new = []
165
+ if block_given?
166
+ self.clean_annotations.each_with_index do |e,i|
167
+ new << e if yield(values[i])
168
+ end
169
+ else
170
+ self.clean_annotations.each_with_index do |e,i|
171
+ new << e if values[i]
172
+ end
173
+ end
174
+ self.annotate(new)
175
+ new.extend AnnotatedArray
176
+
177
+ new
178
+ end
156
179
 
157
180
  %w(compact uniq flatten reverse sort_by).each do |method|
158
181
 
@@ -116,14 +116,14 @@ class FixWidthTable
116
116
  #{{{ Adding data
117
117
 
118
118
  def add_point(data)
119
- data.sort_by{|value, pos| pos}.each do |value, pos|
119
+ data.sort_by{|value, pos| pos }.each do |value, pos|
120
120
  add pos, value
121
121
  end
122
122
  end
123
123
 
124
124
  def add_range(data)
125
125
  latest = []
126
- data.sort_by{|value, pos| pos[0]}.each do |value, pos|
126
+ data.sort_by{|value, pos| pos[0] }.each do |value, pos|
127
127
  while latest.any? and latest[0] < pos[0]
128
128
  latest.shift
129
129
  end
data/lib/rbbt/persist.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rbbt'
1
2
  require 'rbbt/util/misc'
2
3
  require 'rbbt/util/open'
3
4
 
@@ -5,10 +6,10 @@ require 'rbbt/persist/tsv'
5
6
  require 'set'
6
7
 
7
8
  module Persist
8
- CACHEDIR="/tmp/tsv_persistent_cache"
9
+ CACHEDIR = "/tmp/tsv_persistent_cache" unless defined? CACHEDIR
9
10
  FileUtils.mkdir CACHEDIR unless File.exist? CACHEDIR
10
11
 
11
- MEMORY = {}
12
+ MEMORY = {} unless defined? MEMORY
12
13
 
13
14
  def self.cachedir=(cachedir)
14
15
  CACHEDIR.replace cachedir
@@ -72,7 +73,7 @@ module Persist
72
73
  File.join(persistence_dir, filename)
73
74
  end
74
75
 
75
- TRUE_STRINGS = Set.new ["true", "True", "TRUE", "t", "T", "1", "yes", "Yes", "YES", "y", "Y", "ON", "on"]
76
+ TRUE_STRINGS = Set.new ["true", "True", "TRUE", "t", "T", "1", "yes", "Yes", "YES", "y", "Y", "ON", "on"] unless defined? TRUE_STRINGS
76
77
  def self.load_file(path, type)
77
78
  case (type || "nil").to_sym
78
79
  when :nil
@@ -231,6 +232,7 @@ module Persist
231
232
  repo[subkey + entities.id << ":" << "SINGLE"] = tsv_values
232
233
  when (not Array === entities or (AnnotatedArray === entities and AnnotatedArray === entities.first))
233
234
  entities.each_with_index do |e,i|
235
+ next if e.nil?
234
236
  tsv_values = e.tsv_values("literal", "annotation_types", "JSON")
235
237
  repo[subkey + e.id << ":ANNOTATED_DOUBLE_ARRAY:" << i.to_s] = tsv_values
236
238
  end
@@ -276,12 +278,18 @@ end
276
278
  module LocalPersist
277
279
 
278
280
  attr_accessor :local_persist_dir
281
+
282
+ def local_persist_dir
283
+ @local_persist_dir ||= Rbbt.var.cache.persistence.find(:lib) if defined? Rbbt
284
+ @local_persist_dir
285
+ end
286
+
279
287
  def local_persist(name, type = nil, options= {}, &block)
280
- Persist.persist(name, type, options.merge({:dir => @local_persist_dir}), &block)
288
+ Persist.persist(name, type, options.merge({:dir => local_persist_dir}), &block)
281
289
  end
282
290
 
283
291
  def local_persist_tsv(source, name, opt = {}, options= {}, &block)
284
- Persist.persist_tsv(source, name, opt, options.merge({:dir => @local_persist_dir}), &block)
292
+ Persist.persist_tsv(source, name, opt, options.merge({:dir => local_persist_dir}), &block)
285
293
  end
286
294
 
287
295
  end
@@ -138,6 +138,8 @@ module Persist
138
138
  when persist_options[:persist]
139
139
 
140
140
  filename ||= case
141
+ when Path === source
142
+ source
141
143
  when source.respond_to?(:filename)
142
144
  source.filename
143
145
  when source.respond_to?(:cmd)
data/lib/rbbt/resource.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'rbbt/util/open'
1
+ require 'rbbt/util/open'
2
2
  require 'rbbt/util/log'
3
3
  require 'rbbt/util/chain_methods'
4
4
  require 'rbbt/resource/path'
5
- require 'rbbt/resource/rake'
6
-
5
+ #require 'rbbt/resource/rake'
6
+
7
7
  module Resource
8
8
  extend ChainMethods
9
9
  self.chain_prefix = :resource
@@ -53,7 +53,7 @@ module Resource
53
53
  if type == :install
54
54
  Log.debug "Preparing software: #{path}"
55
55
  path.produce
56
- software_dir = path.resource.root.software.find :user
56
+ software_dir = path.resource.root.software
57
57
  set_software_env(software_dir)
58
58
  end
59
59
  end