rbbt-util 5.14.14 → 5.14.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12a27683f6ea8562a740927dac6dca9e22854834
4
- data.tar.gz: 6d69aab1d30fa8d56fc8b579a241779e3d84054c
3
+ metadata.gz: b4562833949296544e288b767589677cdea4cd54
4
+ data.tar.gz: 50c2d8f06c365b3334ab046671031b4dadff448f
5
5
  SHA512:
6
- metadata.gz: 7e33da494e19497c5f1aaaca0a6bd35f32edf91d66dbbc2f6b7cfc9932e381bb4ca08ad703b85d5fde85d5c4cba483a48d2ea287ab5e83c5f4d4a82d4f174833
7
- data.tar.gz: 8fafdc22a685ce746ceb13cf10c6162c27afbcc51478c241a2d10402d904655b1c2e348e636758ac29cdcb48a3bf7ce9f3c6f4b50fecb45d895780308b8ff172
6
+ metadata.gz: 247c31f35e49849089188684402ae360d88800e4d90cdbe897c36a7d666f00360c10e308a2a5626411f7d917595930efa4213c2af20050e7b8ab235fc4b5f349
7
+ data.tar.gz: 31d136e11cc112d958568a7607fc673876822f8c350ffd326c9b66b58ca55dc6e48659ee1f80ff660527188eb30ba63d0ddfa703c3cef285c865ae8fbf5ff824
data/etc/app.d/base.rb CHANGED
@@ -19,11 +19,11 @@ helpers Sinatra::RbbtMiscHelpers
19
19
  use Rack::Session::Cookie, :key => 'rack.session',
20
20
  :path => '/',
21
21
  :expire_after => 2592000,
22
- :secret => 'StudyExplorer secret!!'
22
+ :secret => "#{self.to_s} secret!!"
23
23
 
24
24
 
25
25
  #{{{ DIRECTORIES
26
- local_var = Rbbt.var.find(:current)
26
+ local_var = Rbbt.var#.find(:current)
27
27
  set :cache_dir , local_var.sinatra.cache.find
28
28
  set :persist_dir , local_var.sinatra.cache.persistence.find
29
29
  set :persist_options , {:persist => true, :persist_dir => :persist_dir}
@@ -5,9 +5,9 @@ Rbbt.etc.requires.read.split("\n").each do |file|
5
5
  end if Rbbt.etc.requires.exists?
6
6
 
7
7
 
8
- Entity.entity_list_cache = Rbbt.var.find.sinatra.entity_lists
9
- Entity.entity_map_cache = Rbbt.var.find.sinatra.entity_maps
10
- Entity.entity_property_cache = Rbbt.var.find.sinatra.entity_properties
8
+ Entity.entity_list_cache = Rbbt.var.sinatra.find.entity_lists
9
+ Entity.entity_map_cache = Rbbt.var.sinatra.find.entity_maps
10
+ Entity.entity_property_cache = Rbbt.var.sinatra.find.entity_properties
11
11
 
12
12
  Rbbt.etc.entities.read.split("\n").each do |name|
13
13
  next if name.empty?
@@ -18,7 +18,7 @@ Rbbt.etc.entities.read.split("\n").each do |name|
18
18
  end
19
19
  end if Rbbt.etc.entities.exists?
20
20
 
21
- $annotation_repo = Rbbt.var.find.sinatra.annotation_repo.find
21
+ $annotation_repo = Rbbt.var.sinatra.annotation_repo.find
22
22
  (Rbbt.etc.persist_properties.yaml || {}).each do |name,list|
23
23
  next if name.empty?
24
24
  mod = Kernel.const_get name
@@ -77,13 +77,18 @@ module Association
77
77
  return [] if source.nil? or target.nil?
78
78
 
79
79
  if source == :all or source == "all"
80
- matches = keys
81
- else
82
- matches = source.uniq.inject([]){|acc,e|
83
- acc.concat(match(e))
84
- }
80
+ if target == :all or target == "all"
81
+ return keys
82
+ else
83
+ matches = reverse.subset(target, source)
84
+ return matches.collect{|m| r = m.partition "~"; r.reverse*"" }
85
+ end
85
86
  end
86
87
 
88
+ matches = source.uniq.inject([]){|acc,e|
89
+ acc.concat(match(e))
90
+ }
91
+
87
92
  return matches if target == :all or target == "all"
88
93
 
89
94
  target_matches = {}
@@ -23,6 +23,14 @@ module AssociationItem
23
23
  self.clean_annotations.collect{|p| p[/[^~]+/] }
24
24
  end
25
25
 
26
+ property :target_entity_type => :both do
27
+ Entity.formats[target_type].to_s
28
+ end
29
+
30
+ property :source_entity_type => :both do
31
+ Entity.formats[source_type].to_s
32
+ end
33
+
26
34
  property :target_type => :both do
27
35
  type = reverse ? knowledge_base.source(database) : knowledge_base.target(database)
28
36
  end
@@ -69,6 +77,10 @@ module AssociationItem
69
77
  self.each do |match|
70
78
  tsv[match] = [match.source, match.target].concat match.info.values_at(*info_fields)
71
79
  end
80
+ tsv.entity_options = {:organism => namespace}
81
+ knowledge_base.entity_options.each do |type,options|
82
+ tsv.entity_options.merge! options
83
+ end
72
84
  tsv
73
85
  end
74
86
 
@@ -194,7 +194,8 @@ class KnowledgeBase
194
194
  end
195
195
 
196
196
  def annotate(entities, type, database = nil)
197
- Misc.prepare_entity(entities, type, entity_options_for(type, database))
197
+ format = @format[type] || type
198
+ Misc.prepare_entity(entities, format, entity_options_for(type, database))
198
199
  end
199
200
 
200
201
  #{{{ Identify
@@ -304,7 +305,8 @@ class KnowledgeBase
304
305
  repo = get_index name
305
306
 
306
307
  begin
307
- setup(name, repo.subset_entities(entities))
308
+ s = repo.subset_entities(entities)
309
+ setup(name, s)
308
310
  rescue Exception
309
311
  target = entities[:target]
310
312
  source = entities[:source]
data/lib/rbbt/persist.rb CHANGED
@@ -18,7 +18,7 @@ module Persist
18
18
  attr_accessor :lock_dir
19
19
 
20
20
  def lock_dir
21
- @lock_dir ||= Rbbt.tmp.persist_locks.find
21
+ @lock_dir ||= Rbbt.tmp.persist_locks
22
22
  end
23
23
  end
24
24
 
data/lib/rbbt/resource.rb CHANGED
@@ -174,3 +174,4 @@ source "$INSTALL_HELPER_FILE"
174
174
  path
175
175
  end
176
176
  end
177
+
@@ -39,9 +39,13 @@ module Path
39
39
  end
40
40
 
41
41
  def glob(pattern = '*')
42
- return [] unless self.exists?
43
- exp = File.join(self.find, pattern)
44
- Dir.glob(exp).collect{|f| Path.setup(f, self.resource, self.pkgdir)}
42
+ if self.include? "*"
43
+ Dir.glob(self).collect{|f| Path.setup(f, self.resource, self.pkgdir)}
44
+ else
45
+ return [] unless self.exists?
46
+ exp = File.join(self.find, pattern)
47
+ Dir.glob(exp).collect{|f| Path.setup(f, self.resource, self.pkgdir)}
48
+ end
45
49
  end
46
50
 
47
51
  def [](name, orig = false)
@@ -67,14 +71,16 @@ module Path
67
71
  end
68
72
  end
69
73
 
70
- SEARCH_PATHS = {
74
+ SEARCH_PATHS = IndiferentHash.setup({
71
75
  :current => File.join("{PWD}", "{TOPLEVEL}", "{SUBPATH}"),
72
76
  :user => File.join(ENV['HOME'], ".{PKGDIR}", "{TOPLEVEL}", "{SUBPATH}"),
73
77
  :global => File.join('/', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
74
78
  :local => File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}"),
75
79
  :lib => File.join('{LIBDIR}', "{TOPLEVEL}", "{SUBPATH}"),
76
80
  :default => :user
77
- }
81
+ })
82
+
83
+ STANDARD_SEARCH = %w(current user local global lib cache bulk)
78
84
 
79
85
  search_path_file = File.join(ENV['HOME'], '.rbbt/etc/search_paths')
80
86
  if File.exists?(search_path_file)
@@ -95,7 +101,13 @@ module Path
95
101
 
96
102
  path = nil
97
103
  if where.nil?
98
- %w(current user local global lib).each do |w|
104
+ STANDARD_SEARCH.each do |w|
105
+ w = w.to_sym
106
+ next unless paths.include? w
107
+ path = find(w, caller_lib, paths)
108
+ return path if File.exists? path
109
+ end
110
+ (SEARCH_PATHS.keys - STANDARD_SEARCH).each do |w|
99
111
  w = w.to_sym
100
112
  next unless paths.include? w
101
113
  path = find(w, caller_lib, paths)
@@ -31,6 +31,7 @@ end
31
31
  module Resource
32
32
  def set_software_env(software_dir)
33
33
  software_dir.find_all.each do |software_dir|
34
+ next unless software_dir.exists?
34
35
  bin_dir = File.join(software_dir, 'bin')
35
36
  opt_dir = File.join(software_dir, 'opt')
36
37
 
@@ -259,4 +259,30 @@ module Misc
259
259
  Log.info "Delta: #{delta.inspect}"
260
260
  res
261
261
  end
262
+
263
+ def self.time_tick
264
+ if $_last_time_tick.nil?
265
+ $_last_time_tick = Time.now
266
+ puts "Tick started: #{Time.now}"
267
+ else
268
+ ellapsed = Time.now - $_last_time_tick
269
+ puts "Tick ellapsed: #{ellapsed.to_i} s. #{(ellapsed * 1000).to_i - ellapsed.to_i * 1000} ms"
270
+ $_last_time_tick = Time.now
271
+ end
272
+ end
273
+
274
+ def self.bootstrap(elems, num = :current, file = nil, &block)
275
+ cpus = case num
276
+ when :current
277
+ 4
278
+ when Integer
279
+ if num < 100
280
+ num
281
+ else
282
+ 32000 / num
283
+ end
284
+ end
285
+ file = caller.first + rand(1000000).to_s if file.nil?
286
+ RbbtSemaphore.fork_each_on_semaphore elems, cpus, file, &block
287
+ end
262
288
  end
@@ -14,6 +14,11 @@ module IndiferentHash
14
14
  new
15
15
  end
16
16
 
17
+ def []=(key,value)
18
+ delete(key)
19
+ super(key,value)
20
+ end
21
+
17
22
  def [](key)
18
23
  res = super(key)
19
24
  return res unless res.nil?
@@ -10,6 +10,11 @@ module NamedArray
10
10
  attr_accessor :entity_options
11
11
  attr_accessor :entity_templates
12
12
 
13
+ def shift
14
+ fields.shift
15
+ super
16
+ end
17
+
13
18
  def entity_templates
14
19
  @entity_templates ||= {}
15
20
  end
@@ -79,34 +79,20 @@ void post_semaphore(char* name){
79
79
 
80
80
  def self.fork_each_on_semaphore(elems, size, file = nil)
81
81
  with_semaphore(size, file) do |file|
82
- begin
83
82
 
84
- pids = elems.collect do |elem|
85
- Process.fork do
86
- begin
87
- RbbtSemaphore.synchronize(file) do
88
- yield elem
89
- end
90
- rescue Interrupt
91
- Log.warn "Process #{Process.pid} was aborted"
92
- end
83
+ TSV.traverse elems, :cpus => size*2, :bar => "Fork each on semaphore: #{ file }" do |elem|
84
+ elems.annotate elem if elems.respond_to? :annotate
85
+ begin
86
+ RbbtSemaphore.synchronize(file) do
87
+ yield elem
93
88
  end
89
+ rescue Interrupt
90
+ Log.warn "Process #{Process.pid} was aborted"
94
91
  end
95
-
96
- while pids.any?
97
- pid = Process.wait -1
98
- pids.delete pid
99
- end
100
- #pids.each do |pid| Process.waitpid pid end
101
-
102
- rescue Exception
103
- Log.warn "Killing children: #{pids.sort * ", " }"
104
- pids.each do |pid| begin Process.kill("INT", pid); rescue; end; end
105
- pids.each do |pid| begin RbbtSemaphore.post_semaphore(file); rescue; end; end
106
- Log.warn "Ensuring children are dead: #{pids.sort * ", " }"
107
- pids.each do |pid| begin Process.waitpid pid; rescue; end; end
108
92
  end
93
+
109
94
  end
95
+ true
110
96
  end
111
97
 
112
98
  def self.thread_each_on_semaphore(elems, size)
@@ -23,6 +23,7 @@ Misc.in_dir(app_dir) do
23
23
  if server == 'unicorn'
24
24
  `unicorn -c #{ Rbbt.share['unicorn.rb'].find } '#{config_ru_file}' -p #{options[:port] || "2887"}`
25
25
  else
26
- Rack::Server.start(options.merge(:config => config_ru_file))
26
+ options[:config] = config_ru_file
27
+ Rack::Server.start(options)
27
28
  end
28
29
  end
@@ -30,7 +30,9 @@ file = STDIN if file == '-'
30
30
 
31
31
  raise ParameterException, "Please specify the tsv file as argument" if file.nil?
32
32
 
33
- options[:fields] = options[:fields].split(/,\|/) if options[:fields]
33
+ iii options
34
+ options[:fields] = options[:fields].split(/[,\|]/) if options[:fields]
35
+ iii options
34
36
  options[:header_hash] = options["header_hash"]
35
37
  options[:sep] = options["sep"]
36
38
 
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.14.14
4
+ version: 5.14.15
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-08-02 00:00:00.000000000 Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake