rbbt-util 5.6.10 → 5.6.11

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: b271b167bce0dcfd0cdd1c72e569633f410f02a0
4
- data.tar.gz: a0ded4de2b73712c66255e3ecaf2ee18198d4178
3
+ metadata.gz: 1c30ab5dc60391c384494c4607cc74c765d507b5
4
+ data.tar.gz: 8a599300be751940d1feb9b11a14fc83be187722
5
5
  SHA512:
6
- metadata.gz: 09962fd13e045bcf3f97b1655d41e1262e9216c454c7af0c3b207ec61f640ffac382e84dbaa995c45b25efd85bf32a56b2b3068ff75146b6125e54ac668c89ac
7
- data.tar.gz: 174808a701eba99667b447e8bfee0cc5bd0fbd4f29047b53de0358d8dd9ec75130340c63ed1861f6e9a63c018cbe4b48ca38ac74a50e19139501f8f72396b797
6
+ metadata.gz: 05b7d25435ee522bb08c7b0d8ad5355d56d1b1d91816c191bf1a4d831ae2fb829af9b0201ae84f7544fd51f37abb72395f4cd1d88bdc432ac0688c6e6fd27de7
7
+ data.tar.gz: 185cfbaa226f9512d56a42c76a9fbcc2c8b24de266c7ed4a91e7d1f6055608c4a5b7e6f087ac3090a673015af29c5d93e4b19d292a04fdf00c48ab5f8b4de4cc
@@ -31,7 +31,8 @@ module TSV
31
31
 
32
32
  done = false
33
33
  Open.write(output) do |os|
34
- os.puts TSV.header_lines(key_field, fields, options)
34
+ options.delete :sep if options[:sep] == "\t"
35
+ os.puts TSV.header_lines(key_field, fields, options)
35
36
 
36
37
  while line
37
38
  key, *parts = line.sub("\n",'').split(sep, -1)
data/lib/rbbt/tsv.rb CHANGED
@@ -171,33 +171,38 @@ module TSV
171
171
  end
172
172
 
173
173
  line_num = 1
174
- while not line.nil?
175
- begin
176
- progress_monitor.tick(stream.pos) if progress_monitor
177
-
178
- raise Parser::SKIP_LINE if line.empty?
179
-
180
- line = Misc.fixutf8(line)
181
- line = parser.process line
182
- parts = parser.chop_line line
183
- key, values = parser.get_values parts
184
- values = parser.cast_values values if parser.cast?
185
- parser.add_to_data data, key, values
186
- line = stream.gets
187
- line_num += 1
188
- raise Parser::END_PARSING if head and line_num > head.to_i
189
- rescue Parser::SKIP_LINE
174
+ begin
175
+ while not line.nil?
190
176
  begin
177
+ progress_monitor.tick(stream.pos) if progress_monitor
178
+
179
+ raise Parser::SKIP_LINE if line.empty?
180
+
181
+ line = Misc.fixutf8(line)
182
+ line = parser.process line
183
+ parts = parser.chop_line line
184
+ key, values = parser.get_values parts
185
+ values = parser.cast_values values if parser.cast?
186
+ parser.add_to_data data, key, values
191
187
  line = stream.gets
192
- next
188
+ line_num += 1
189
+ raise Parser::END_PARSING if head and line_num > head.to_i
190
+ rescue Parser::SKIP_LINE
191
+ begin
192
+ line = stream.gets
193
+ next
194
+ rescue IOError
195
+ break
196
+ end
197
+ rescue Parser::END_PARSING
198
+ break
193
199
  rescue IOError
200
+ Log.exception $!
194
201
  break
195
202
  end
196
- rescue Parser::END_PARSING
197
- break
198
- rescue IOError
199
- break
200
203
  end
204
+ ensure
205
+ stream.close unless stream.closed?
201
206
  end
202
207
 
203
208
  parser.setup data
@@ -278,7 +278,8 @@ module Misc
278
278
  obj.each do |k,v|
279
279
  new << k.to_s << '=>' << fingerprint(v) << ' '
280
280
  end
281
- new << "}"
281
+ new[-1] = "}"
282
+ new
282
283
  end
283
284
  else
284
285
  obj.to_s
@@ -64,6 +64,7 @@ void post_semaphore(char* name){
64
64
  def self.fork_each_on_semaphore(elems, size, file = nil)
65
65
  with_semaphore(size, file) do |file|
66
66
  begin
67
+
67
68
  pids = elems.collect do |elem|
68
69
  Process.fork do
69
70
  begin
@@ -78,7 +79,13 @@ void post_semaphore(char* name){
78
79
  end
79
80
  end
80
81
  end
81
- pids.each do |pid| Process.waitpid pid end
82
+
83
+ while pids.any?
84
+ pid = Process.wait -1
85
+ pids.delete pid
86
+ end
87
+ #pids.each do |pid| Process.waitpid pid end
88
+
82
89
  rescue Exception
83
90
  Log.error "Killing children: #{pids.sort * ", " }"
84
91
  pids.each do |pid| begin Process.kill("INT", pid); rescue; end; end
@@ -3,9 +3,8 @@ 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'
6
+ #Workflow.require_workflow "Genomics"
7
+ #require 'rbbt/entity/gene'
9
8
 
10
9
  class TestAssociationIndex < Test::Unit::TestCase
11
10
 
@@ -16,7 +15,7 @@ class TestAssociationIndex < Test::Unit::TestCase
16
15
  end
17
16
 
18
17
 
19
- def test_subset
18
+ def __test_subset
20
19
  require 'rbbt/sources/pina'
21
20
  require 'rbbt/sources/kegg'
22
21
  tp53 = Gene.setup("TP53", "Associated Gene Name", "Hsa/jan2013").ensembl
@@ -11,11 +11,8 @@ class TestPersistTSV < Test::Unit::TestCase
11
11
 
12
12
  def tsv_path
13
13
  Random.new
14
- #require 'rbbt/sources/organism'
15
- #Organism.identifiers("Hsa")
16
14
  require 'rbbt/workflow'
17
- Workflow.require_workflow "Genomics"
18
- require 'rbbt/entity/gene'
15
+ Workflow.require_workflow "Genomes1000"
19
16
  require 'rbbt/sources/genomes1000'
20
17
  CMD.cmd("grep -v '^\\.\t' | head -n #{MAX}", :in => Genomes1000.mutations.open, :pipe => true)
21
18
  end
@@ -26,7 +23,6 @@ class TestPersistTSV < Test::Unit::TestCase
26
23
  db= nil
27
24
  Misc.benchmark(1, "Build database with #{MAX - 2} entries") do
28
25
  db = TSV.open(file, :fields => [1], :persist => true, :persist_engine => engine, :persist_dir => tmp_file, :type => :single, :unnamed => true)
29
- fff db
30
26
  end
31
27
  test = db.keys.sort{rand}[1..100000]
32
28
  Misc.benchmark(5, "Access #{test.length} random entries") do
@@ -40,32 +36,32 @@ class TestPersistTSV < Test::Unit::TestCase
40
36
  end
41
37
  end
42
38
 
43
- def test_benchmark_tch
39
+ def _test_benchmark_tch
44
40
  engine = "HDB"
45
41
  run_bechmark(tsv_path, engine)
46
42
  end
47
43
 
48
- def test_benchmark_tcb
44
+ def _test_benchmark_tcb
49
45
  engine = "BDB"
50
46
  run_bechmark(tsv_path, engine)
51
47
  end
52
48
 
53
- def test_benchmark_kch
49
+ def _test_benchmark_kch
54
50
  engine = "kch"
55
51
  run_bechmark(tsv_path, engine)
56
52
  end
57
53
 
58
- def test_benchmark_kcb
54
+ def _test_benchmark_kcb
59
55
  engine = "kct"
60
56
  run_bechmark(tsv_path, engine)
61
57
  end
62
58
 
63
- def test_benchmark_cdb
59
+ def _test_benchmark_cdb
64
60
  engine = "CDB"
65
61
  run_bechmark(tsv_path, engine)
66
62
  end
67
63
 
68
- def test_benchmark_leveldb
64
+ def _test_benchmark_leveldb
69
65
  engine = "LevelDB"
70
66
  run_bechmark(tsv_path, engine)
71
67
  end
@@ -5,8 +5,6 @@ require 'rbbt/annotations'
5
5
  require 'rbbt/util/tmpfile'
6
6
  require 'test/unit'
7
7
 
8
- require 'rbbt/sources/organism'
9
-
10
8
  module TestAnnotation
11
9
  extend Annotation
12
10
 
@@ -23,7 +21,7 @@ class TestPersistTSVKC < Test::Unit::TestCase
23
21
  end
24
22
 
25
23
 
26
- def test_organism_kct
24
+ def _test_organism_kct
27
25
  require 'rbbt/sources/organism'
28
26
  TmpFile.with_file do |tmp_file|
29
27
  tsv = Organism.identifiers("Hsa").tsv :key_field => "Associated Gene Name", :fields => ["Ensembl Gene ID"], :type => :single, :persist => true, :persist_engine => "kct", :persist_dir => tmp_file
@@ -17,7 +17,6 @@ module AnnotatedString2
17
17
  include AnnotatedString
18
18
  self.annotation :annotation_str2
19
19
  end
20
- puts AnnotatedString.annotations.inspect
21
20
 
22
21
  class TestAnnotations < Test::Unit::TestCase
23
22
 
@@ -8,13 +8,6 @@ require 'rbbt/entity'
8
8
  require 'rbbt/association'
9
9
  require 'rbbt/knowledge_base'
10
10
 
11
- gem 'rbbt-sources'
12
- gem 'rbbt-phgx'
13
-
14
- Log.severity=0
15
- Workflow.require_workflow "Genomics"
16
- require 'rbbt/entity/gene'
17
- require 'rbbt/sources/pina'
18
11
 
19
12
  TEST_ASSOCIATIONS =<<-EOF
20
13
  #: :sep=" "#:namespace=Hsa/jan2013
@@ -42,6 +35,7 @@ class TestAssociations < Test::Unit::TestCase
42
35
 
43
36
  def test_simple_open
44
37
  database = Association.open(FAssocs, {}, :dir => DAssocs)
38
+ database.unnamed = false
45
39
  assert_equal ["C", "K"], database["c"]["Entity2"]
46
40
  end
47
41
 
@@ -57,7 +51,24 @@ class TestAssociations < Test::Unit::TestCase
57
51
  assert_equal ["kk", "c", "4", "PTEN"], database["K"].flatten
58
52
  end
59
53
 
60
- def test_target_open
54
+
55
+ def test_gene_open
56
+ database = Association.open(FAssocs, {:source => "Gene=~Associated Gene Name", :target => "Entity3", :zipped => true}, :dir => DAssocs)
57
+ assert_equal ["aa"], database["TP53"].first
58
+ end
59
+
60
+
61
+ def __test_ICGC
62
+ assoc = Association.open(Open.open('ftp://data.dcc.icgc.org/current/Chronic_Lymphocytic_Leukemia-ISC_MICINN-ES/simple_somatic_mutation.CLLE-ES.tsv.gz'),
63
+ { :source => "gene_affected=~Ensembl Gene ID=>Associated Gene Name", :target => "icgc_donor_id=~Sample",
64
+ :fields => ['consequence_type'],
65
+ :namespace => 'Hsa/jan2013',
66
+ :merge => true, :header_hash=>''}, :persist => false)
67
+
68
+ assert_equal 9, assoc["SF3B1"]["Sample"].uniq.length
69
+ end
70
+
71
+ def __test_target_open
61
72
 
62
73
  database = Association.open(Pina.protein_protein,{
63
74
  :undirected => false,
@@ -74,34 +85,16 @@ class TestAssociations < Test::Unit::TestCase
74
85
  assert database["Q13547"][0].include? "O15379"
75
86
  end
76
87
 
77
-
78
- def test_gene_open
79
- database = Association.open(FAssocs, {:source => "Gene=~Associated Gene Name", :target => "Entity3", :zipped => true}, :dir => DAssocs)
80
- assert_equal ["aa"], database["TP53"].first
81
- end
82
-
83
- def test_gene_open_translate
88
+ def __test_gene_open_translate
84
89
  tp53 = Gene.setup("TP53", "Associated Gene Name", "Hsa/jan2013")
85
90
  database = Association.open(FAssocs, {:source => "Gene=~Associated Gene Name", :source_format => "Ensembl Gene ID", :target => "Entity3", :zipped => true}, :dir => DAssocs)
86
91
  assert_equal ["aa"], database[tp53.ensembl].first
87
92
  end
88
93
 
89
- def test_gene_target_open_translate
94
+ def __test_gene_target_open_translate
90
95
  tp53 = Gene.setup("TP53", "Associated Gene Name", "Hsa/jan2013")
91
96
  database = Association.open(FAssocs, {:target => "Gene=~Associated Gene Name=>Ensembl Gene ID", :source => "Entity3", :zipped => true}, :dir => DAssocs)
92
97
  assert_equal [tp53.ensembl], database["aa"].first
93
98
  end
94
99
 
95
- def test_ICGC
96
- assoc = Association.open(Open.open('ftp://data.dcc.icgc.org/current/Chronic_Lymphocytic_Leukemia-ISC_MICINN-ES/simple_somatic_mutation.CLLE-ES.tsv.gz'),
97
- { :source => "gene_affected=~Ensembl Gene ID=>Associated Gene Name", :target => "icgc_donor_id=~Sample",
98
- :fields => ['consequence_type'],
99
- :namespace => 'Hsa/jan2013',
100
- :merge => true, :header_hash=>''}, :persist => false)
101
-
102
- assert_equal 9, assoc["SF3B1"]["Sample"].uniq.length
103
-
104
- end
105
-
106
-
107
100
  end
@@ -167,55 +167,12 @@ class TestEntity < Test::Unit::TestCase
167
167
  assert_equal string.length, string.annotation_list.length
168
168
  end
169
169
 
170
- def __test_performance
171
- require 'rbbt/entity/gene'
172
- Misc.profile(:min_percent => 2) do
173
- 1000.times do
174
- TestA.new "foo", "bar"
175
- end
176
- end
177
-
178
- Misc.profile(:min_percent => 2) do
179
- 1000.times do
180
- Gene.setup_positional("", "foo", "bar")
181
- end
182
- end
183
-
184
- Misc.benchmark(100000) do
185
- Gene.setup("", :foo => "foo", :bar => "bar")
186
- end
187
-
188
- Misc.benchmark(100000) do
189
- TestA.new "foo", "bar"
190
- end
191
- end
192
-
193
- def __test_clean_annotations
194
- Workflow.require_workflow "StudyExplorer"
195
-
196
- s = Study.setup("CLL")
197
- mutations = s.cohort.metagenotype
170
+ def test_clean_annotations
198
171
 
199
- mis = mutations.mutated_isoforms.compact.flatten
172
+ string = "test_string"
173
+ ReversableString.setup string
174
+ assert string.respond_to?(:reverse_text_single)
175
+ assert ! string.clean_annotations.respond_to?(:reverse_text_single)
200
176
 
201
- Misc.profile(:min_percent => 1) do
202
- mis.each{|m| m}
203
- end
204
-
205
-
206
- Misc.benchmark(10) do
207
- mis.each{|m| m}
208
- end
209
-
210
- Misc.benchmark(10) do
211
- mis.clean_annotations.each{|m| m}
212
- end
213
-
214
- m = mutations.first
215
-
216
- assert_equal m.split(":")[1], m.position.to_s
217
- assert_raise NoMethodError do
218
- m.clean_annotations.position
219
- end
220
177
  end
221
178
  end
@@ -3,17 +3,15 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'test/unit'
4
4
  require 'rbbt/knowledge_base'
5
5
 
6
- gem 'rbbt-sources'
7
- gem 'rbbt-phgx'
8
- gem 'rest-client'
9
-
10
6
  require 'rbbt/sources/pina'
11
7
  require 'rbbt/workflow'
12
- Workflow.require_workflow "Genomics"
13
- require 'genomics_kb'
14
8
 
15
9
  class TestKnowledgeBase < Test::Unit::TestCase
16
10
  def setup
11
+ if not defined? Genomics
12
+ Workflow.require_workflow "Genomics"
13
+ require 'genomics_kb'
14
+ end
17
15
  KnowledgeBase.knowledge_base_dir = Rbbt.tmp.knowledge_base_test.find
18
16
  @kb = Genomics.knowledge_base
19
17
  end
@@ -57,7 +57,6 @@ row2 A B Id3
57
57
 
58
58
  TmpFile.with_file(content) do |filename|
59
59
  tsv = TSV.open(filename, :sep => /\s+/)
60
- puts tsv.to_s
61
60
  assert tsv.to_s =~ /row1\ta|aa|aaa/
62
61
  assert tsv.to_s =~ /:type=:double/
63
62
  end
@@ -469,7 +469,6 @@ A Id3
469
469
  tsv1 = tsv2 = index = nil
470
470
  TmpFile.with_file(content1) do |filename|
471
471
  tsv1 = TSV.open(File.open(filename), :flat, :fields => ["ValueA"], :sep => /\s+/)
472
- puts tsv1
473
472
  end
474
473
 
475
474
  TmpFile.with_file(content2) do |filename|
@@ -477,8 +476,7 @@ A Id3
477
476
  end
478
477
 
479
478
  res = tsv1.attach tsv2, :fields => ["OtherID"]
480
- puts res
481
-
479
+ assert_equal "Id3", res["row2"]["OtherID"]
482
480
  end
483
481
  end
484
482
 
@@ -38,6 +38,6 @@ aa xx
38
38
 
39
39
  def test_change_id
40
40
  @f1.identifiers = @id
41
- puts @f1.change_key "X"
41
+ assert @f1.change_key("X").include? "x"
42
42
  end
43
43
  end
@@ -4,7 +4,7 @@ require 'rbbt/tsv/field_index'
4
4
 
5
5
  class TestTSVFieldIndex < Test::Unit::TestCase
6
6
 
7
- def test_zipped
7
+ def test_field_index
8
8
  content =<<-EOF
9
9
  #Id ValueA ValueB ValueC
10
10
  rowA A|AA B|BB C|CC
@@ -13,7 +13,7 @@ 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
- puts tsv.field_index("ValueA")
16
+ assert_equal ["rowA"], tsv.field_index("ValueA")["A"]
17
17
  end
18
18
  end
19
19
  end
@@ -131,7 +131,6 @@ row2 A B
131
131
  tsv.filter
132
132
  tsv.add_filter "field:ValueA", ["A"], Rbbt.tmp.test.Filter.fieldValueA.find(:user)
133
133
 
134
- puts tsv
135
134
  elem = []
136
135
  tsv.through do |k,v| elem << k end
137
136
  assert_equal 1, elem.size
@@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helpe
2
2
  require 'rbbt/util/R'
3
3
 
4
4
  class TestR < Test::Unit::TestCase
5
- def test_sum
5
+ def _test_sum
6
6
  assert_equal "6", R.run('cat(3+3)').read.split(/\n/).last
7
7
  end
8
8
 
@@ -16,9 +16,7 @@ data = data + 1
16
16
 
17
17
  def test_format_tsv
18
18
  tsv = TSV.setup({"a" => [1], "b" => [2]}, :type => :list, :key_field => "Letter", :fields => ["Number"])
19
- puts tsv.transpose "Field"
20
- tsv.unnamed = true
21
- puts R.ruby2R tsv
19
+ assert tsv.transpose("Field").include? "Number"
22
20
  end
23
21
  end
24
22
 
@@ -3,7 +3,7 @@ require 'rbbt/util/log'
3
3
 
4
4
  class TestLog < Test::Unit::TestCase
5
5
  def test_color
6
- puts Log.color(:green, "green")
6
+ assert Log.color(:green, "green")
7
7
  end
8
8
  end
9
9
 
@@ -6,9 +6,6 @@ require 'rbbt/entity'
6
6
 
7
7
  class TestMisc < Test::Unit::TestCase
8
8
 
9
- def test_humanize
10
- assert_equal "mutation_enrichment", Misc.humanize("MutationEnrichment")
11
- end
12
9
 
13
10
  def test_fixutf8
14
11
  string = "abc\xffdef"
@@ -84,13 +81,6 @@ class TestMisc < Test::Unit::TestCase
84
81
  assert_equal('d', Misc.string2hash("a=b#c=d#:h='j'")["c"])
85
82
  assert_equal('j', Misc.string2hash("a=b#c=d#:h='j'")[:h])
86
83
  assert_equal(:j, Misc.string2hash("a=b#c=d#:h=:j")[:h])
87
-
88
- Misc.benchmark(1000) do
89
- Misc.string2hash_old("a=b#c=d#:h=:j#test='1'#:num=1#:sep=/#/")
90
- end
91
- Misc.benchmark(1000) do
92
- Misc.string2hash("a=b#c=d#:h=:j#test='1'#:num=1#:sep=/#/")
93
- end
94
84
  end
95
85
 
96
86
  def test_named_array
@@ -227,6 +217,8 @@ class TestMisc < Test::Unit::TestCase
227
217
  assert_equal "Test string", Misc.humanize(str1)
228
218
  assert_equal "TEST string", Misc.humanize(str2)
229
219
  assert_equal "Test", Misc.humanize(str3)
220
+
221
+ assert_equal "mutation_enrichment", Misc.snake_case("MutationEnrichment")
230
222
  end
231
223
 
232
224
  def test_snake_case
@@ -241,7 +233,7 @@ class TestMisc < Test::Unit::TestCase
241
233
  end
242
234
 
243
235
  def test_fingerprint
244
- puts Misc.fingerprint({:a => 1})
236
+ assert_equal '{a=>1}', Misc.fingerprint({:a => 1})
245
237
  end
246
238
 
247
239
  def test_tarize
@@ -266,7 +258,6 @@ class TestMisc < Test::Unit::TestCase
266
258
  t = 5
267
259
  stream = Misc.open_pipe do |sin|
268
260
  t.times do |i|
269
- puts "Calculating line #{ i }"
270
261
  sleep 0.5
271
262
  sin.puts "LINE #{ i }"
272
263
  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.6.10
4
+ version: 5.6.11
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-02-25 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: ZenTest
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '='
116
- - !ruby/object:Gem::Version
117
- version: '4.3'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '='
123
- - !ruby/object:Gem::Version
124
- version: '4.3'
125
111
  description: Utilities for handling tsv files, caches, etc
126
112
  email: miguel.vazquez@cnio.es
127
113
  executables: