rbbt-util 5.5.47 → 5.5.48

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTU3YjVkYzhlZmQ4ZTIxNzJkM2VlNzRmZWU3ZTgzZjMyNDRkMTA2YQ==
4
+ N2M0YzQ0ZDZhNzU1NjA0ZmFkZWQ2NGYyN2E5YWRlY2VmZTc3MTc1NA==
5
5
  data.tar.gz: !binary |-
6
- NzM0ODA4YzdlNjVkMDA2NmQ4MzgzYjQ4MmM1YzY2Mjg2NDk1MzlkYg==
6
+ ZWY5ZGUwYTNmODQ2Y2IzN2UxYWUyOTdjMjBkY2ZlZjJlYzZhMTViMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjUwNjFjNzIyZTA3YWZlYjYwMDBkYzA0YmFjMTYwODhiNzI0MzJiODdmMGU2
10
- OTRhOWI3NjYzMTdjOTE0YTc2YWZhMThiNTI1N2YwNjk1YmIzN2FhYjg1YWQz
11
- NzU3ZDViOGNmNDgzZWU5Yzk4YzdhNjA5MDE3NzFkMGMxYjZkY2M=
9
+ NWQxMDI1NGI3YzQwZTRhNDIwZmNkNjIyNjkzMmQ4MDk3MzlmN2EyYjk1YzI1
10
+ OTdiYjk5NmQ2NTViN2IzOTI0Nzc1ZWEyOGFmNzdlZDkyYTE3OGM2MDQ0Njgz
11
+ MTAzMDljN2Y4OTNmMWJiNGM4MTAyMWM4ZGFkNGVkYWFhZjA3Nzc=
12
12
  data.tar.gz: !binary |-
13
- NTYwZmMzZTc4Y2QzMjcyMmFkZTJiMDYyMzRhYzNiNTUxZWZmYmQzOTNlODEw
14
- ZDMzYjA0OGZlMDljNzQ2ZWVhODcyNTc2NzMyOWE4Y2IxZmZmNTFlY2E1ODZl
15
- YTU2YjZlMmMzZmRhNzIyMzdjMmU5ZTY1YTlmZTg4NTQwMzc2ZWQ=
13
+ ZmY0OTBjNzUxNjRlZmY3NTNkZDY3ZmIwNDY0ZmFkOWVlZjgyZDNkZWIwMGFk
14
+ ODQxZTI3ZDdlZGIwNWY3OWY1NTcyZTI1M2NlYjY5Y2FkMDlhYWExNTgyMTZi
15
+ MTBjODc4ODRkZDNkNDJjNDAyNTE4MjJjODg1YTQzN2I2ZjA2MWE=
data/lib/rbbt/persist.rb CHANGED
@@ -129,16 +129,16 @@ module Persist
129
129
  when :nil
130
130
  nil
131
131
  when :boolean
132
- Open.write(path, content ? "true" : "false")
132
+ Misc.sensiblewrite(path, content ? "true" : "false")
133
133
  when :fwt
134
134
  content.file.seek 0
135
- Open.write(path, content.file.read)
135
+ Misc.sensiblewrite(path, content.file.read)
136
136
  when :tsv
137
- Open.write(path, content.to_s)
137
+ Misc.sensiblewrite(path, content.to_s)
138
138
  when :annotations
139
- Open.write(path, Annotated.tsv(content, :all).to_s)
139
+ Misc.sensiblewrite(path, Annotated.tsv(content, :all).to_s)
140
140
  when :string, :text
141
- Open.write(path, content)
141
+ Misc.sensiblewrite(path, content)
142
142
  when :binary
143
143
  content.force_encoding("ASCII-8BIT") if content.respond_to? :force_encoding
144
144
  f = File.open(path, 'wb')
@@ -147,18 +147,18 @@ module Persist
147
147
  content
148
148
  when :array
149
149
  if content.empty?
150
- Open.write(path, "")
150
+ Misc.sensiblewrite(path, "")
151
151
  else
152
- Open.write(path, content * "\n" + "\n")
152
+ Misc.sensiblewrite(path, content * "\n" + "\n")
153
153
  end
154
154
  when :marshal_tsv
155
- Open.write(path, Marshal.dump(content.dup))
155
+ Misc.sensiblewrite(path, Marshal.dump(content.dup))
156
156
  when :marshal
157
- Open.write(path, Marshal.dump(content))
157
+ Misc.sensiblewrite(path, Marshal.dump(content))
158
158
  when :yaml
159
- Open.write(path, YAML.dump(content))
159
+ Misc.sensiblewrite(path, YAML.dump(content))
160
160
  when :float, :integer, :tsv
161
- Open.write(path, content.to_s)
161
+ Misc.sensiblewrite(path, content.to_s)
162
162
  else
163
163
  raise "Unknown persistence: #{ type }"
164
164
  end
@@ -102,7 +102,6 @@ module Persist
102
102
  end
103
103
  end
104
104
 
105
-
106
105
  def write_and_close
107
106
  lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir})
108
107
  Misc.lock(lock_filename) do
@@ -190,7 +189,9 @@ module Persist
190
189
 
191
190
  FileUtils.rm path if File.exists? path
192
191
 
193
- data = open_tokyocabinet(path, true, persist_options[:serializer], persist_options[:engine] || TokyoCabinet::HDB)
192
+ tmp_path = path + '.persist'
193
+
194
+ data = open_tokyocabinet(tmp_path, true, persist_options[:serializer], persist_options[:engine] || TokyoCabinet::HDB)
194
195
  data.serializer = :type if TSV === data and data.serializer.nil?
195
196
 
196
197
  data.close
@@ -210,13 +211,14 @@ module Persist
210
211
  end
211
212
  rescue Exception
212
213
  Log.error "Captured error during persist_tsv. Erasing: #{path}"
213
- FileUtils.rm path if path and File.exists? path
214
+ FileUtils.rm tmp_path if tmp_path and File.exists? tmp_path
214
215
  raise $!
215
216
  ensure
216
- begin
217
- data.close if data.respond_to? :close
218
- rescue
219
- raise $!
217
+ data.close if data.respond_to? :close
218
+ if tmp_path
219
+ FileUtils.mv tmp_path, path if File.exists? tmp_path and not File.exists? path
220
+ tsv = TC_CONNECTIONS[path] = TC_CONNECTIONS.delete tmp_path
221
+ tsv.persistence_path = path
220
222
  end
221
223
  end
222
224
 
@@ -225,4 +227,78 @@ module Persist
225
227
 
226
228
  data
227
229
  end
230
+
231
+ def self.get_filename(source)
232
+ case
233
+ when Path === source
234
+ source
235
+ when (source.respond_to?(:filename) and source.filename)
236
+ source.filename
237
+ when source.respond_to?(:cmd)
238
+ "CMD-#{Misc.digest(source.cmd)}"
239
+ when TSV === source
240
+ "TSV[#{Misc.digest Misc.fingerprint(source)}]"
241
+ end || source.object_id.to_s
242
+ end
243
+
244
+ def self.persist_tsv(source, filename, options = {}, persist_options = {}, &block)
245
+ persist_options[:prefix] ||= "TSV"
246
+
247
+ if data = persist_options[:data]
248
+ yield data
249
+ return data
250
+ end
251
+
252
+ filename ||= get_filename(source)
253
+
254
+ path = persistence_path(filename, persist_options, options)
255
+
256
+ lock_filename = Persist.persistence_path(path, {:dir => TSV.lock_dir})
257
+
258
+ if not persist_options[:persist]
259
+ data = {}
260
+
261
+ yield(data)
262
+
263
+ return data
264
+ end
265
+
266
+ if is_persisted? path and not persist_options[:update]
267
+ Log.debug "TSV persistence up-to-date: #{ path }"
268
+ return open_tokyocabinet(path, false, nil, persist_options[:engine] || TokyoCabinet::HDB)
269
+ end
270
+
271
+ Misc.lock lock_filename do
272
+ begin
273
+ if is_persisted? path
274
+ Log.debug "TSV persistence up-to-date: #{ path }"
275
+ return open_tokyocabinet(path, false, nil, persist_options[:engine] || TokyoCabinet::HDB)
276
+ end
277
+
278
+ FileUtils.rm path if File.exists? path
279
+
280
+ Log.medium "TSV persistence creating: #{ path }"
281
+
282
+ tmp_path = path + '.persist'
283
+
284
+ data = open_tokyocabinet(tmp_path, true, persist_options[:serializer], persist_options[:engine] || TokyoCabinet::HDB)
285
+ data.serializer = :type if TSV === data and data.serializer.nil?
286
+
287
+ data.write_and_read do
288
+ yield data
289
+ end
290
+
291
+ FileUtils.mv tmp_path, path if File.exists? tmp_path and not File.exists? path
292
+ tsv = TC_CONNECTIONS[path] = TC_CONNECTIONS.delete tmp_path
293
+ tsv.persistence_path = path
294
+
295
+ data
296
+ rescue Exception
297
+ Log.error "Captured error during persist_tsv. Erasing: #{path}"
298
+ FileUtils.rm tmp_path if tmp_path and File.exists? tmp_path
299
+ FileUtils.rm path if path and File.exists? path
300
+ raise $!
301
+ end
302
+ end
303
+ end
228
304
  end
data/lib/rbbt/resource.rb CHANGED
@@ -63,7 +63,8 @@ module Resource
63
63
 
64
64
  case response
65
65
  when Net::HTTPSuccess then
66
- Open.write(final_path, response.body)
66
+ #Misc.sensiblewrite(final_path, response.body)
67
+ Misc.sensiblewrite(final_path){ Net::HTTP.get_response(URI(url)).body }
67
68
  when Net::HTTPRedirection then
68
69
  location = response['location']
69
70
  Log.debug("Feching directory from: #{location}. Into: #{final_path}")
@@ -1,7 +1,5 @@
1
1
  require 'yaml'
2
2
  module TSV
3
- #extend ChainMethods
4
- #self.chain_prefix = :tsv
5
3
 
6
4
  TSV_SERIALIZER = YAML
7
5
  SERIALIZED_NIL = TSV_SERIALIZER.dump nil
@@ -126,7 +126,7 @@ module TSV
126
126
  data_options = Misc.pull_keys options, :data
127
127
  identifiers = TSV.open(file, data_options)
128
128
  identifiers.with_monitor :desc => "Creating Index for #{ file }" do
129
- identifiers.index(options.merge :persist_data => data, :persist => persist_options[:persist])
129
+ index = identifiers.index(options.merge :persist_data => data, :persist => persist_options[:persist])
130
130
  end
131
131
  end
132
132
  end
@@ -273,192 +273,5 @@ module TSV
273
273
  tsv.range_index(start_field, end_field, options)
274
274
  end
275
275
  end
276
-
277
-
278
- # def self.field_matches(tsv, values)
279
- # values = [values] if not Array === values
280
- # Log.debug "Matcing #{values.length} values to #{tsv.filename}"
281
- #
282
- # if values.flatten.sort[0..9].compact.collect{|n| n.to_i} == (1..10).to_a
283
- # return {}
284
- # end
285
- #
286
- # key_field = tsv.key_field
287
- # fields = tsv.fields
288
- #
289
- # field_values = {}
290
- # fields.each{|field|
291
- # field_values[field] = []
292
- # }
293
- #
294
- # if tsv.type == :double
295
- # tsv.through do |key,entry_values|
296
- # fields.zip(entry_values).each do |field,entry_field_values|
297
- # field_values[field].concat entry_field_values unless entry_field_values.nil?
298
- # end
299
- # end
300
- # else
301
- # tsv.through do |key,entry_values|
302
- # fields.zip(entry_values).each do |field,entry_field_values|
303
- # field_values[field] << entry_field_values
304
- # end
305
- # end
306
- # end
307
- #
308
- # field_values.each do |field,field_value_list|
309
- # field_value_list.replace(values & field_value_list.flatten.uniq)
310
- # end
311
- #
312
- # field_values[key_field] = values & tsv.keys
313
- #
314
- # field_values
315
- # end
316
- #
317
- # def field_matches(values)
318
- # TSV.field_matches(self, values)
319
- # end
320
- #
321
- # def guess_field(values)
322
- # field_matches(values).sort_by{|field, matches| matches.uniq.length}.last
323
- # end
324
- #
325
- # def pos_index(pos_field = nil, options = {})
326
- # pos_field ||= "Position"
327
- #
328
- # options = Misc.add_defaults options,
329
- # :persistence => true, :persistence_file => nil, :persistence_update => false
330
- #
331
- # prefix = "Pos[#{pos_field}]"
332
- #
333
- # Persistence.persist(filename, prefix, :fwt, options.merge({
334
- # :pos_field => pos_field,
335
- # :filters => (self.respond_to?(:filters)? filters.collect{|f| [f.match, f.value]} : [])
336
- # })) do |file, options, filename|
337
- # pos_field = options[:pos_field]
338
- # value_size = 0
339
- # index_data = []
340
- #
341
- # through :key, pos_field do |key, values|
342
- # value_size = key.length if key.length > value_size
343
- #
344
- # pos = values.first
345
- # if Array === pos
346
- # pos.each do |p|
347
- # index_data << [key, p.to_i]
348
- # end
349
- # else
350
- # index_data << [key, pos.to_i]
351
- # end
352
- # end
353
- #
354
- # index = FixWidthTable.get(:memory, value_size, false)
355
- # index.add_point index_data
356
- # index.read
357
- # index
358
- # end
359
- # end
360
- #
361
- # def self.pos_index(file, pos_field = nil, options = {})
362
- # options = Misc.add_defaults options,
363
- # :persistence => true, :persistence_file => nil, :persistence_update => false, :persistence_source => file, :tsv_serializer => :list,
364
- # :data_persistence => false, :data_persistence_file => nil, :data_persistence_update => false, :data_persistence_source => file
365
- #
366
- # #options_data = {
367
- # # :cast => Misc.process_options(options, :data_cast),
368
- # # :persistence => Misc.process_options(options, :data_persistence),
369
- # # :monitor => Misc.process_options(options, :data_monitor),
370
- # # :persistence_file => Misc.process_options(options, :data_persistence_file),
371
- # # :persistence_update => Misc.process_options(options, :data_persistence_update),
372
- # # :in_situ_persistence => Misc.process_options(options,:data_in_situ_persistence),
373
- # # :persistence_source => Misc.process_options(options, :data_persistence_source),
374
- # # :importtsv => Misc.process_options(options, :data_importtsv),
375
- # #}
376
- #
377
- # options_data = Misc.pull_data_keys(options)
378
- #
379
- # prefix = "Pos[#{pos_field}]"
380
- #
381
- # new = Persistence.persist(file, prefix, :fwt, options.merge({:pos_field => pos_field})) do |file, options, filename|
382
- # tsv = TSV.new(file, :list, options_data)
383
- #
384
- # if options.include?(:filters) and Array === options[:filters] and not options[:filters].empty?
385
- # tsv.filter
386
- # options[:filters].each do |match, value, persistence|
387
- # tsv.add_filter(match, value, persistence)
388
- # end
389
- # end
390
- #
391
- # tsv.pos_index options[:pos_field], options.merge(:persistence => false, :persistence_file => nil)
392
- # end
393
- # end
394
- #
395
- # def range_index(start_field = nil, end_field = nil, options = {})
396
- # start_field ||= "Start"
397
- # end_field ||= "End"
398
- # options = Misc.add_defaults options,
399
- # :persistence => true, :persistence_file => nil, :persistence_update => false
400
- #
401
- # prefix = "Range[#{start_field}-#{end_field}]"
402
- #
403
- # Persistence.persist(filename, prefix, :fwt, options.merge({
404
- # :start_field => start_field, :end_field => end_field,
405
- # :filters => (self.respond_to?(:filters)? filters.collect{|f| [f.match, f.value]} : [])
406
- # })) do |file, options, filename|
407
- # start_field, end_field = options.values_at :start_field, :end_field
408
- #
409
- # value_size = 0
410
- # index_data = []
411
- #
412
- # through :key, [start_field, end_field] do |key, values|
413
- # value_size = key.length if key.length > value_size
414
- #
415
- # start_pos, end_pos = values
416
- #
417
- # if Array === start_pos
418
- # start_pos.zip(end_pos).each do |s,e|
419
- # index_data << [key, [s.to_i, e.to_i]]
420
- # end
421
- # else
422
- # index_data << [key, [start_pos.to_i, end_pos.to_i]]
423
- # end
424
- # end
425
- #
426
- # index = FixWidthTable.get(:memory, value_size, true)
427
- # index.add_range index_data
428
- # index.read
429
- # index
430
- # end
431
- # end
432
- #
433
- # def self.range_index(file, start_field = nil, end_field = nil, options = {})
434
- # options = Misc.add_defaults options,
435
- # :persistence => true, :persistence_file => nil, :persistence_update => false, :persistence_source => file, :tsv_serializer => :list,
436
- # :data_persistence => false, :data_persistence_file => nil, :data_persistence_update => false, :data_persistence_source => file
437
- #
438
- # options_data = {
439
- # :persistence => Misc.process_options(options, :data_persistence),
440
- # :persistence_file => Misc.process_options(options, :data_persistence_file),
441
- # :persistence_update => Misc.process_options(options, :data_persistence_update),
442
- # :persistence_source => Misc.process_options(options, :data_persistence_source),
443
- # }
444
- #
445
- # prefix = "Range[#{start_field}-#{end_field}]"
446
- #
447
- # options_data[:type] = :flat if options[:order] == false
448
- #
449
- # Persistence.persist(file, prefix, :fwt, options.merge({:start_field => start_field, :end_field => end_field})) do |file, options, filename|
450
- # tsv = TSV.new(file, :list, options_data)
451
- #
452
- # if options.include?(:filters) and Array === options[:filters] and not options[:filters].empty?
453
- # tsv.filter
454
- # options[:filters].each do |match, value, persistence|
455
- # tsv.add_filter(match, value, persistence)
456
- # end
457
- # end
458
- #
459
- # tsv.range_index options[:start_field], options[:end_field], options.merge(:persistence => false, :persistence_file => nil)
460
- # end
461
- # end
462
- #
463
276
  end
464
277
 
@@ -449,18 +449,31 @@ module TSV
449
449
 
450
450
  when (String === method and method =~ /name:(.*)/)
451
451
  name = $1
452
+ old_unnamed = self.unnamed
453
+ self.unnamed = false
452
454
  if name.strip =~ /^\/(.*)\/$/
453
455
  regexp = Regexp.new $1
454
456
  through :key, key do |key, values|
455
- values = [values] if type == :single
456
- new[key] = self[key] if invert ^ (values.flatten.select{|v| v.name =~ regexp}.any?)
457
+ case type
458
+ when :single
459
+ values = values.annotate([values])
460
+ when :double
461
+ values = values[0]
462
+ end
463
+ new[key] = self[key] if invert ^ (values.select{|v| v.name =~ regexp}.any?)
457
464
  end
458
465
  else
459
466
  through :key, key do |key, values|
460
- values = [values] if type == :single
461
- new[key] = self[key] if invert ^ (values.flatten.select{|v| v.name == name}.any?)
467
+ case type
468
+ when :single
469
+ values = values.annotate([values])
470
+ when :double
471
+ values = values[0]
472
+ end
473
+ new[key] = self[key] if invert ^ (values.select{|v| v.name == name}.any?)
462
474
  end
463
475
  end
476
+ self.unnamed = old_unnamed
464
477
 
465
478
  when String === method
466
479
  with_unnamed do
data/lib/rbbt/tsv/util.rb CHANGED
@@ -81,6 +81,29 @@ module TSV
81
81
  TSV.identify_field(key_field, fields, field)
82
82
  end
83
83
 
84
+ def to_list
85
+ new = {}
86
+ case type
87
+ when :double
88
+ through do |k,v|
89
+ new[k] = v.collect{|e| e.first}
90
+ end
91
+ when :flat
92
+ through do |k,v|
93
+ new[k] = [v.first]
94
+ end
95
+ when :single
96
+ through do |k,v|
97
+ new[k] = [v]
98
+ end
99
+ when :list
100
+ self
101
+ end
102
+ self.annotate(new)
103
+ new.type = :list
104
+ new
105
+ end
106
+
84
107
  def to_double
85
108
  new = {}
86
109
  case type
@@ -154,6 +177,4 @@ module TSV
154
177
  new
155
178
  end
156
179
 
157
-
158
-
159
180
  end
@@ -1,6 +1,7 @@
1
1
  require 'lockfile'
2
2
  require 'net/smtp'
3
3
  require 'digest/md5'
4
+ require 'narray'
4
5
  require 'cgi'
5
6
 
6
7
  class Hash
@@ -477,7 +478,6 @@ end
477
478
  }
478
479
 
479
480
  def self.fast_align(reference, sequence)
480
- require 'narray'
481
481
  init_gap = -1
482
482
  gap = -2
483
483
  diff = -2
@@ -488,7 +488,6 @@ end
488
488
 
489
489
  a = NArray.int(cols, rows)
490
490
 
491
-
492
491
  for spos in 0..cols-1 do a[spos, 0] = spos * init_gap end
493
492
  for rpos in 0..rows-1 do a[0, rpos] = rpos * init_gap end
494
493
 
@@ -905,7 +904,8 @@ end
905
904
 
906
905
  res = nil
907
906
 
908
- lockfile = Lockfile.new(File.expand_path(file + '.lock'))
907
+ lock_path = File.expand_path(file + '.lock')
908
+ lockfile = Lockfile.new(lock_path)
909
909
 
910
910
  begin
911
911
  if File.exists? lockfile and
@@ -917,15 +917,21 @@ end
917
917
  end
918
918
  rescue
919
919
  Log.warn("Error checking lockfile #{lockfile}: #{$!.message}. Removing. Content: #{begin Open.read(lockfile) rescue "Could not open file" end}")
920
- FileUtils.rm lockfile if File.exists? lockfile
920
+ FileUtils.rm lockfile if File.exists?(lockfile)
921
921
  end
922
922
 
923
- lockfile.lock do
924
- res = yield file, *args
923
+ begin
924
+ lockfile.lock do
925
+ res = yield file, *args
926
+ end
927
+ rescue Interrupt
928
+ Log.error "Process #{Process.pid} interrupted while in lock: #{ lock_path }"
929
+ raise $!
925
930
  end
926
931
 
927
932
  res
928
933
  end
934
+
929
935
 
930
936
  LOCK_REPO_SERIALIZER=Marshal
931
937
 
@@ -1011,32 +1017,32 @@ end
1011
1017
  end
1012
1018
  end
1013
1019
 
1014
- def self.sensiblewrite(path, content)
1020
+ def self.sensiblewrite(path, content = nil)
1021
+ return if File.exists? path
1015
1022
  Misc.lock path + '.sensible_write' do
1016
1023
  if not File.exists? path
1017
1024
  begin
1018
1025
  tmp_path = path + '.tmp'
1026
+ content = yield if block_given?
1019
1027
  case
1020
1028
  when String === content
1021
1029
  File.open(tmp_path, 'w') do |f| f.write content end
1022
1030
  when (IO === content or StringIO === content)
1023
- File.open(tmp_path, 'w') do |f| while l = content.gets; f.write l; end end
1024
- else
1025
- File.open(tmp_path, 'w') do |f| end
1031
+ File.open(tmp_path, 'w') do |f|
1032
+ while l = content.gets; f.write l; end
1033
+ end
1034
+ else
1035
+ File.open(tmp_path, 'w') do |f| end
1036
+ end
1037
+ FileUtils.mv tmp_path, path
1038
+ rescue Exception
1039
+ FileUtils.rm_f tmp_path if File.exists? tmp_path
1040
+ FileUtils.rm_f path if File.exists? path
1041
+ raise $!
1026
1042
  end
1027
- FileUtils.mv tmp_path, path
1028
- rescue Interrupt
1029
- FileUtils.rm_f tmp_path if File.exists? tmp_path
1030
- FileUtils.rm_f path if File.exists? path
1031
- raise "Interrupted (Ctrl-c)"
1032
- rescue Exception
1033
- FileUtils.rm_f tmp_path if File.exists? tmp_path
1034
- FileUtils.rm_f path if File.exists? path
1035
- raise $!
1036
1043
  end
1037
1044
  end
1038
1045
  end
1039
- end
1040
1046
 
1041
1047
  def self.add_defaults(options, defaults = {})
1042
1048
  case
@@ -3,11 +3,13 @@ require 'rbbt/workflow'
3
3
  require 'rbbt/association'
4
4
  require 'rbbt/association/index'
5
5
 
6
+ gem 'rbbt-sources'
7
+ Workflow.require_workflow "Genomics"
8
+ require 'rbbt/entity/gene'
9
+
6
10
  class TestAssociationIndex < Test::Unit::TestCase
7
11
 
8
12
  def setup
9
- Workflow.require_workflow "Genomics"
10
- require 'rbbt/entity/gene'
11
13
  end
12
14
 
13
15
  def teardown
@@ -1,13 +1,20 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'rbbt/util/tmpfile'
3
+ require 'test/unit'
4
+
2
5
  require 'rbbt/workflow'
6
+ require 'rbbt/entity'
7
+
3
8
  require 'rbbt/association'
4
9
  require 'rbbt/knowledge_base'
5
- require 'rbbt/entity'
6
- require 'rbbt/util/tmpfile'
7
- require 'test/unit'
8
10
 
11
+ gem 'rbbt-sources'
12
+ gem 'rbbt-phgx'
13
+
14
+ Log.severity=0
9
15
  Workflow.require_workflow "Genomics"
10
16
  require 'rbbt/entity/gene'
17
+ require 'rbbt/sources/pina'
11
18
 
12
19
  TEST_ASSOCIATIONS =<<-EOF
13
20
  #: :sep=" "#:namespace=Hsa/jan2013
@@ -51,7 +58,6 @@ class TestAssociations < Test::Unit::TestCase
51
58
  end
52
59
 
53
60
  def test_target_open
54
- require 'rbbt/sources/pina'
55
61
 
56
62
  database = Association.open(Pina.protein_protein,{
57
63
  :undirected => false,
@@ -2,20 +2,25 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'test/unit'
4
4
  require 'rbbt/knowledge_base'
5
+
6
+ gem 'rbbt-sources'
7
+ gem 'rbbt-phgx'
8
+ gem 'rest-client'
9
+
5
10
  require 'rbbt/sources/pina'
11
+ require 'rbbt/workflow'
12
+ Workflow.require_workflow "Genomics"
13
+ require 'genomics_kb'
6
14
 
7
15
  class TestKnowledgeBase < Test::Unit::TestCase
8
16
  def setup
9
- require 'rbbt/workflow'
10
- Workflow.require_workflow "Genomics"
11
- require 'genomics_kb'
12
-
13
-
14
17
  KnowledgeBase.knowledge_base_dir = Rbbt.tmp.knowledge_base_test.find
15
18
  @kb = Genomics.knowledge_base
16
19
  end
17
20
 
18
21
  def test_register
22
+ require 'rbbt/sources/pina'
23
+
19
24
  TmpFile.with_file do |dir|
20
25
  kb = KnowledgeBase.new dir
21
26
 
@@ -173,7 +173,6 @@ row1 1
173
173
  row2 4
174
174
  EOF
175
175
 
176
- require 'rbbt/sources/organism'
177
176
  TmpFile.with_file(content) do |filename|
178
177
  tsv = TSV.open(filename, :sep => /\s+/, :cast => :to_i, :type => :single, :fields => "Value")
179
178
  assert_equal 1, tsv["row1"]
@@ -192,7 +191,6 @@ row1 1 2
192
191
  row2 4
193
192
  EOF
194
193
 
195
- require 'rbbt/sources/organism'
196
194
  TmpFile.with_file(content) do |filename|
197
195
  tsv = TSV.open(filename, :sep => /\s+/, :type => :single, :key_field => "Value", :fields => ["Id"])
198
196
  assert_equal "row1", tsv["1"]
@@ -217,9 +217,9 @@ row2 E
217
217
  tsv1 = Rbbt.tmp.test.test1.data.tsv :double, :sep => /\s+/
218
218
  tsv2 = Rbbt.tmp.test.test2.data.tsv :double, :sep => /\s+/
219
219
 
220
- tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce.find.to_s
220
+ tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce.find #.to_s
221
221
 
222
- tsv1.attach tsv2, :fields => ["OtherID"], :persist_input => true
222
+ tsv1.attach tsv2, :fields => ["OtherID"] #, :persist_input => true
223
223
 
224
224
  assert_equal tsv1.fields, %w(ValueA ValueB OtherID)
225
225
  assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
@@ -1,4 +1,5 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
+ require 'rbbt/tsv'
2
3
  require 'rbbt/tsv/filter'
3
4
 
4
5
  class TestTSVFilters < Test::Unit::TestCase
@@ -129,9 +130,10 @@ row2 A B
129
130
  tsv.filter
130
131
  tsv.add_filter "field:ValueA", ["A"], Rbbt.tmp.test.Filter.fieldValueA.find(:user)
131
132
 
133
+ puts tsv
132
134
  elem = []
133
135
  tsv.through do |k,v| elem << k end
134
- assert_equal 2, elem.size
136
+ assert_equal 1, elem.size
135
137
  end
136
138
  end
137
139
 
@@ -112,13 +112,13 @@ row3 A a|B Id4
112
112
  def test_index_static
113
113
  content =<<-EOF
114
114
  #Id ValueA ValueB OtherID
115
- row1 a|aa|aaa b|A Id1
116
- row2 A a|B Id3
117
- row3 A a|B Id4
115
+ row1 a|aa|aaa b|B Id1
116
+ row2 A bb Id3
117
+ row3 AA bb Id4
118
118
  EOF
119
119
 
120
120
  TmpFile.with_file(content) do |filename|
121
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => false)
121
+ index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => true, :data_persist => true)
122
122
  assert_equal "Id1", index['a']
123
123
  assert_equal "Id3", index['A']
124
124
  assert_equal "OtherID", index.fields.first
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+ require 'rbbt-util'
2
3
  require 'rbbt/util/filecache'
3
4
  require 'test/unit'
4
5
 
@@ -41,7 +41,7 @@ class TestStep < Test::Unit::TestCase
41
41
  step2 = Step.new tmpfile + 'step2', task2, [], step1
42
42
 
43
43
  step1.clean
44
- step2.run
44
+ step2.clean.run
45
45
  assert_equal "TEST2", Open.read(tmpfile + 'step2')
46
46
  end
47
47
  end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rbbt'
3
+
4
4
  require 'test/unit'
5
- require 'rbbt/util/log'
6
- require 'rbbt/util/tmpfile'
7
- require 'rbbt/resource/path'
8
5
  require 'fileutils'
6
+ require 'rubygems'
7
+
8
+ require 'rbbt'
9
+ require 'rbbt/resource/path'
9
10
 
10
11
  class Test::Unit::TestCase
11
12
  include FileUtils
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.5.47
4
+ version: 5.5.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -232,7 +232,6 @@ files:
232
232
  - test/rbbt/workflow/test_step.rb
233
233
  - test/rbbt/workflow/test_task.rb
234
234
  - test/test_helper.rb
235
- - test/test_rbbt.rb
236
235
  homepage: http://github.com/mikisvaz/rbbt-util
237
236
  licenses:
238
237
  - MIT
@@ -291,5 +290,4 @@ test_files:
291
290
  - test/rbbt/util/test_chain_methods.rb
292
291
  - test/rbbt/util/test_R.rb
293
292
  - test/rbbt/util/test_simpleDSL.rb
294
- - test/test_rbbt.rb
295
293
  - test/test_helper.rb
data/test/test_rbbt.rb DELETED
@@ -1,10 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
- require 'rbbt'
3
- require 'rbbt/util/misc'
4
- require 'rbbt/util/open'
5
-
6
- class TestRbbt < Test::Unit::TestCase
7
- def test_true
8
- assert true
9
- end
10
- end