rbbt-util 5.21.59 → 5.21.60

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: 6af6b7d19c8318dff73f410c5e4094aeaa9466d7
4
- data.tar.gz: cb78b1b85697ca27eb8716afe3b70513c4ffbe41
3
+ metadata.gz: 02bb66246a58680f8e703e49df480b977b2c1f6f
4
+ data.tar.gz: 428a2f61dbb7a216833864296f7212fbe1e1032b
5
5
  SHA512:
6
- metadata.gz: 46bf19741a3c8d36219cd75fef3a103cad844dd89d4534ea8af5ec3c01fbc1d3632d07c55a1a397d5737550ad5d85961804af7ef3df19f1dee0e7ea777f4175b
7
- data.tar.gz: 89ada9ba0db87dd8a2b10a2848e2d3f92c6bd2b0935177a1b50606604f7bee2a87667d6a02266842505965e79c4c3dac839a6b26bfd97eb9e1a6c21a0e02283d
6
+ metadata.gz: c22b4e1597fd4787667a4bc2f6a997177ea2cd93025e2b7a19720629850ddd60a1037bf7651bf570f9e2add3225c90df1375ef72fe4a2649fe4454f8ab393f83
7
+ data.tar.gz: edd5911b55194c38c5a2193d5937fc52911f4b18b3490bea729ad03c0f94890031083e98b9cc13a9d6beef855b354bf095f5dfe9db7852e8b06e0300d232713b
@@ -556,18 +556,36 @@ module TSV
556
556
  end
557
557
  end
558
558
 
559
- def dumper_stream(keys = nil, no_options = false)
560
- TSV::Dumper.stream self do |dumper|
559
+ def dumper_stream(keys = nil, no_options = false, unmerge = false)
560
+ unmerge = false unless type == :double
561
+
562
+ options = self.options
563
+ options[:type] = :list if unmerge
564
+
565
+ TSV::Dumper.stream options do |dumper|
561
566
  dumper.init unless no_options
562
567
  begin
563
568
  if keys
564
569
  keys.each do |key|
565
- dumper.add key, self[key]
570
+ if unmerge
571
+ Misc.zip_fields(self[key]).each do |values|
572
+ dumper.add key, values
573
+ end
574
+ else
575
+ dumper.add key, self[key]
576
+ end
566
577
  end
567
578
  else
568
579
  with_unnamed do
569
580
  each do |k,v|
570
- dumper.add k, v
581
+
582
+ if unmerge
583
+ Misc.zip_fields(v).each do |values|
584
+ dumper.add k, values
585
+ end
586
+ else
587
+ dumper.add k, v
588
+ end
571
589
  end
572
590
  end
573
591
  end
@@ -579,7 +597,7 @@ module TSV
579
597
  end
580
598
  end
581
599
 
582
- def to_s(keys = nil, no_options = false)
600
+ def to_s(keys = nil, no_options = false, unmerge = false)
583
601
  if FalseClass === keys or TrueClass === keys
584
602
  no_options = keys
585
603
  keys = nil
@@ -591,7 +609,7 @@ module TSV
591
609
  end
592
610
  end
593
611
 
594
- io = dumper_stream(keys, no_options)
612
+ io = dumper_stream(keys, no_options, unmerge)
595
613
 
596
614
  str = ''
597
615
  while block = io.read(Misc::BLOCK_SIZE)
@@ -71,7 +71,7 @@ module TSV
71
71
  cells.push v * sep2
72
72
  end
73
73
  else
74
- v = remove_link(v) if remove_links
74
+ v = _remove_link(v) if remove_links
75
75
  cells.push v
76
76
  end
77
77
  end
data/lib/rbbt/tsv/util.rb CHANGED
@@ -60,7 +60,7 @@ module TSV
60
60
 
61
61
  def self.abort_stream(file, exception = nil)
62
62
  return if file.nil?
63
- if Step === file
63
+ if defined? Step and Step === file
64
64
  if exception
65
65
  file.exception exception
66
66
  else
@@ -17,7 +17,7 @@ module Log
17
17
  end
18
18
  end
19
19
 
20
- attr_accessor :history, :mean_max
20
+ attr_accessor :history, :mean_max, :max_history
21
21
  def thr
22
22
  count = @ticks - @last_count
23
23
  if @last_time.nil?
@@ -34,7 +34,18 @@ module Log
34
34
  @history ||= [thr]
35
35
  else
36
36
  @history << thr
37
- @history.shift if @history.length > 20
37
+ max_history ||= case
38
+ when @ticks > 20
39
+ count = @ticks - @last_count
40
+ times = @max / count
41
+ num = times / 20
42
+ num = 2 if num < 2
43
+ count * num
44
+ else
45
+ 20
46
+ end
47
+ max_history = 100 if max_history > 100
48
+ @history.shift if @history.length > max_history
38
49
  end
39
50
 
40
51
  @mean_max ||= 0
@@ -97,4 +97,8 @@ module Misc
97
97
  sizes = sizes.collect{|v| (v.to_f/max * 100).to_i.to_f / 100}
98
98
  url = "https://chart.googleapis.com/chart?cht=v&chs=500x300&chd=t:#{sizes * ","}&chco=FF6342,ADDE63,63C6DE,FFFFFF&chdl=#{label}"
99
99
  end
100
+
101
+ def self.in_delta?(a, b, delta = 0.0001)
102
+ (a.to_f - b.to_f).abs < delta
103
+ end
100
104
  end
@@ -60,6 +60,10 @@ module Misc
60
60
  first.zip(*rest)
61
61
  end
62
62
 
63
+ def self.choose(array, select)
64
+ array.zip(select).select{|e,s| s }.collect{|e,s| e }
65
+ end
66
+
63
67
  def self.field_position(fields, field, quiet = false)
64
68
  return field if Integer === field or Range === field
65
69
  raise FieldNotFoundError, "Field information missing" if fields.nil? && ! quiet
@@ -419,12 +419,16 @@ module Open
419
419
  res = []
420
420
  while not f.eof?
421
421
  l = f.gets
422
- l = Misc.fixutf8(l)
422
+ l = Misc.fixutf8(l) unless options[:nofix]
423
423
  res << yield(l)
424
424
  end
425
425
  res
426
426
  else
427
- Misc.fixutf8(f.read)
427
+ if options[:nofix]
428
+ f.read
429
+ else
430
+ Misc.fixutf8(f.read)
431
+ end
428
432
  end
429
433
  end
430
434
  end
@@ -40,7 +40,9 @@ end
40
40
 
41
41
  field = options[:field]
42
42
 
43
- TSV.traverse(tsv, :fields => [field]) do |k,v|
43
+ fields = field.nil? ? nil : [field]
44
+
45
+ TSV.traverse(tsv, :fields => fields) do |k,v|
44
46
  if options[:lines]
45
47
  puts (Array === v ? v.flatten*"\n" : v.to_s )
46
48
  else
@@ -209,4 +209,16 @@ row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
209
209
  end
210
210
  end
211
211
 
212
+ def test_to_s_unmerge
213
+ content =<<-EOF
214
+ #Id ValueA ValueB OtherID
215
+ row1 a|A b|B Id1|Id2
216
+ row2 aa|aa|AA|AA b1|b2|B1|B2 Id1|Id1|Id2|Id2
217
+ EOF
218
+
219
+ TmpFile.with_file(content) do |filename|
220
+ tsv = TSV.open(filename, :sep => /\s+/)
221
+ assert_equal 6, CMD.cmd('grep -v "#" | cut -f 1', :in => tsv.to_s(nil, false, true)).read.split("\n").length
222
+ end
223
+ end
212
224
  end
@@ -314,4 +314,5 @@ row3 a C Id4
314
314
 
315
315
  end
316
316
  end
317
+
317
318
  end
@@ -70,5 +70,6 @@ class TestProgress < Test::Unit::TestCase
70
70
  end
71
71
 
72
72
  end
73
+
73
74
  end
74
75
 
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.59
4
+ version: 5.21.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -491,83 +491,83 @@ signing_key:
491
491
  specification_version: 4
492
492
  summary: Utilities for the Ruby Bioinformatics Toolkit (rbbt)
493
493
  test_files:
494
- - test/test_helper.rb
494
+ - test/rbbt/test_workflow.rb
495
495
  - test/rbbt/resource/test_path.rb
496
- - test/rbbt/association/test_item.rb
497
- - test/rbbt/association/test_database.rb
498
- - test/rbbt/association/test_open.rb
499
- - test/rbbt/association/test_index.rb
500
- - test/rbbt/association/test_util.rb
501
- - test/rbbt/util/test_concurrency.rb
502
- - test/rbbt/util/test_log.rb
503
- - test/rbbt/util/test_chain_methods.rb
504
- - test/rbbt/util/test_simpleopt.rb
505
- - test/rbbt/util/simpleopt/test_parse.rb
506
- - test/rbbt/util/simpleopt/test_get.rb
507
- - test/rbbt/util/simpleopt/test_setup.rb
508
496
  - test/rbbt/util/test_cmd.rb
509
- - test/rbbt/util/test_semaphore.rb
510
- - test/rbbt/util/concurrency/test_threads.rb
511
- - test/rbbt/util/concurrency/processes/test_socket.rb
512
- - test/rbbt/util/concurrency/test_processes.rb
513
- - test/rbbt/util/test_tmpfile.rb
514
- - test/rbbt/util/test_open.rb
515
- - test/rbbt/util/test_filecache.rb
516
- - test/rbbt/util/R/test_eval.rb
517
- - test/rbbt/util/R/test_model.rb
497
+ - test/rbbt/util/simpleopt/test_setup.rb
498
+ - test/rbbt/util/simpleopt/test_get.rb
499
+ - test/rbbt/util/simpleopt/test_parse.rb
500
+ - test/rbbt/util/test_chain_methods.rb
518
501
  - test/rbbt/util/test_simpleDSL.rb
519
- - test/rbbt/util/log/test_progress.rb
520
- - test/rbbt/util/test_colorize.rb
521
- - test/rbbt/util/test_R.rb
502
+ - test/rbbt/util/test_log.rb
503
+ - test/rbbt/util/test_open.rb
522
504
  - test/rbbt/util/misc/test_lock.rb
523
- - test/rbbt/util/misc/test_pipes.rb
505
+ - test/rbbt/util/misc/test_multipart_payload.rb
524
506
  - test/rbbt/util/misc/test_bgzf.rb
507
+ - test/rbbt/util/misc/test_pipes.rb
525
508
  - test/rbbt/util/misc/test_omics.rb
526
- - test/rbbt/util/misc/test_multipart_payload.rb
509
+ - test/rbbt/util/test_concurrency.rb
510
+ - test/rbbt/util/test_R.rb
511
+ - test/rbbt/util/log/test_progress.rb
512
+ - test/rbbt/util/test_colorize.rb
513
+ - test/rbbt/util/test_simpleopt.rb
527
514
  - test/rbbt/util/test_excel2tsv.rb
515
+ - test/rbbt/util/test_filecache.rb
516
+ - test/rbbt/util/concurrency/test_processes.rb
517
+ - test/rbbt/util/concurrency/test_threads.rb
518
+ - test/rbbt/util/concurrency/processes/test_socket.rb
519
+ - test/rbbt/util/test_semaphore.rb
528
520
  - test/rbbt/util/test_misc.rb
521
+ - test/rbbt/util/test_tmpfile.rb
522
+ - test/rbbt/util/R/test_model.rb
523
+ - test/rbbt/util/R/test_eval.rb
524
+ - test/rbbt/test_packed_index.rb
525
+ - test/rbbt/entity/test_identifiers.rb
526
+ - test/rbbt/test_association.rb
527
+ - test/rbbt/knowledge_base/test_traverse.rb
528
+ - test/rbbt/knowledge_base/test_registry.rb
529
+ - test/rbbt/knowledge_base/test_entity.rb
530
+ - test/rbbt/knowledge_base/test_enrichment.rb
531
+ - test/rbbt/knowledge_base/test_syndicate.rb
532
+ - test/rbbt/knowledge_base/test_query.rb
533
+ - test/rbbt/test_resource.rb
529
534
  - test/rbbt/test_entity.rb
535
+ - test/rbbt/test_knowledge_base.rb
536
+ - test/rbbt/annotations/test_util.rb
537
+ - test/rbbt/association/test_index.rb
538
+ - test/rbbt/association/test_item.rb
539
+ - test/rbbt/association/test_open.rb
540
+ - test/rbbt/association/test_util.rb
541
+ - test/rbbt/association/test_database.rb
542
+ - test/rbbt/test_tsv.rb
530
543
  - test/rbbt/workflow/step/test_dependencies.rb
531
- - test/rbbt/workflow/test_doc.rb
532
- - test/rbbt/workflow/test_step.rb
533
544
  - test/rbbt/workflow/test_task.rb
534
- - test/rbbt/test_association.rb
535
- - test/rbbt/test_knowledge_base.rb
536
- - test/rbbt/tsv/parallel/test_traverse.rb
537
- - test/rbbt/tsv/parallel/test_through.rb
545
+ - test/rbbt/workflow/test_step.rb
546
+ - test/rbbt/workflow/test_doc.rb
547
+ - test/rbbt/test_monitor.rb
548
+ - test/rbbt/test_persist.rb
549
+ - test/rbbt/test_annotations.rb
550
+ - test/rbbt/persist/test_tsv.rb
551
+ - test/rbbt/persist/tsv/test_lmdb.rb
552
+ - test/rbbt/persist/tsv/test_kyotocabinet.rb
553
+ - test/rbbt/persist/tsv/test_sharder.rb
554
+ - test/rbbt/persist/tsv/test_cdb.rb
555
+ - test/rbbt/persist/tsv/test_tokyocabinet.rb
556
+ - test/rbbt/persist/tsv/test_leveldb.rb
557
+ - test/rbbt/tsv/test_field_index.rb
538
558
  - test/rbbt/tsv/test_parallel.rb
539
- - test/rbbt/tsv/test_excel.rb
540
- - test/rbbt/tsv/test_accessor.rb
559
+ - test/rbbt/tsv/test_index.rb
560
+ - test/rbbt/tsv/test_matrix.rb
541
561
  - test/rbbt/tsv/test_change_id.rb
562
+ - test/rbbt/tsv/test_parser.rb
542
563
  - test/rbbt/tsv/test_stream.rb
564
+ - test/rbbt/tsv/test_util.rb
565
+ - test/rbbt/tsv/test_excel.rb
566
+ - test/rbbt/tsv/test_accessor.rb
543
567
  - test/rbbt/tsv/test_filter.rb
544
- - test/rbbt/tsv/test_matrix.rb
545
568
  - test/rbbt/tsv/test_attach.rb
546
569
  - test/rbbt/tsv/test_manipulate.rb
547
- - test/rbbt/tsv/test_field_index.rb
548
- - test/rbbt/tsv/test_index.rb
549
- - test/rbbt/tsv/test_util.rb
550
- - test/rbbt/tsv/test_parser.rb
551
- - test/rbbt/test_packed_index.rb
552
- - test/rbbt/test_persist.rb
570
+ - test/rbbt/tsv/parallel/test_through.rb
571
+ - test/rbbt/tsv/parallel/test_traverse.rb
553
572
  - test/rbbt/test_fix_width_table.rb
554
- - test/rbbt/knowledge_base/test_traverse.rb
555
- - test/rbbt/knowledge_base/test_entity.rb
556
- - test/rbbt/knowledge_base/test_query.rb
557
- - test/rbbt/knowledge_base/test_enrichment.rb
558
- - test/rbbt/knowledge_base/test_syndicate.rb
559
- - test/rbbt/knowledge_base/test_registry.rb
560
- - test/rbbt/entity/test_identifiers.rb
561
- - test/rbbt/test_monitor.rb
562
- - test/rbbt/test_workflow.rb
563
- - test/rbbt/test_annotations.rb
564
- - test/rbbt/annotations/test_util.rb
565
- - test/rbbt/test_resource.rb
566
- - test/rbbt/persist/tsv/test_tokyocabinet.rb
567
- - test/rbbt/persist/tsv/test_kyotocabinet.rb
568
- - test/rbbt/persist/tsv/test_lmdb.rb
569
- - test/rbbt/persist/tsv/test_leveldb.rb
570
- - test/rbbt/persist/tsv/test_cdb.rb
571
- - test/rbbt/persist/tsv/test_sharder.rb
572
- - test/rbbt/persist/test_tsv.rb
573
- - test/rbbt/test_tsv.rb
573
+ - test/test_helper.rb