rbbt-util 5.25.9 → 5.25.10

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: f1eb2767b3e3f8adcb67bfc0fbc05d79000130a9
4
- data.tar.gz: d3314ccd8960e4780887978e9b8745a31276b9f1
3
+ metadata.gz: 13bac11c495886a59c36af1b96806cd378cfed87
4
+ data.tar.gz: 73b4586d838d9ada0e7d3f156b25bd42d3f53614
5
5
  SHA512:
6
- metadata.gz: 465aefada76bce2c950aa535098ef03652a2793fe7030c1532557f72d9cd0d856479511247339152ef8e8a2084abe0436662a9e8ba6fc9ba1bf8833fa50f3e50
7
- data.tar.gz: 84827530eee0ed691bfadfd1e137f801921f96c071b7ef016a9542896190e3ba6ad0f24603188fd81eba4f8e070364ebde39f7f27f2b9aa20feb5742ef97c0c3
6
+ metadata.gz: cef5241e1a9ed5a8b288d4220745a16de23f71325b7e4591c6ce810831e4a0fdcb97e8a793e3b714901a7d8251a371915566c14c69e9532cd3544e3bfbddfc51
7
+ data.tar.gz: e672b0531ab5f6c44ec7b8c676e43d2cd7022be89eea22b5446e22572d766f7cba0ad909d018f530a4b157fe4cde84f95ebd120268702090cb23bef03af8bdbe
@@ -111,11 +111,12 @@ module Association
111
111
  end
112
112
 
113
113
  def self.open_stream(stream, options = {})
114
- options = Misc.add_defaults options, :type => :double, :merge => true
115
114
  fields, persist, data = Misc.process_options options, :fields, :persist, :data
116
115
 
117
116
 
118
117
  parser = TSV::Parser.new stream, options.merge(:fields => nil, :key_field => nil)
118
+ options = options.merge(parser.options)
119
+ options = Misc.add_defaults options, :type => :double, :merge => true
119
120
 
120
121
  key_field, *_fields = all_fields = parser.all_fields
121
122
 
@@ -124,34 +125,34 @@ module Association
124
125
  parser.key_field = source_pos
125
126
  parser.fields = field_pos
126
127
 
127
- case parser.type
128
- when :single
129
- class << parser
130
- def get_values(parts)
131
- [parts[@key_field], parts.values_at(*@fields).first]
132
- end
133
- end
134
- when :list
135
- class << parser
136
- def get_values(parts)
137
- [parts[@key_field], parts.values_at(*@fields)]
138
- end
139
- end
140
- when :double
141
- class << parser
142
- def get_values(parts)
143
- [parts[@key_field].split(@sep2,-1), parts.values_at(*@fields).collect{|v| v.nil? ? [] : v.split(@sep2,-1) }]
144
- end
145
- end
146
- when :flat
147
- class << parser
148
- def get_values(parts)
149
- fields = (0..parts.length-1).to_a - [@key_field]
150
- values = parts.values_at(*fields).compact.collect{|v| v.split(@sep2,-1) }.flatten
151
- [parts[@key_field].split(@sep2,-1), values]
152
- end
153
- end
154
- end
128
+ #case parser.type
129
+ #when :single
130
+ # class << parser
131
+ # def get_values(parts)
132
+ # [parts[@key_field], parts.values_at(*@fields).first]
133
+ # end
134
+ # end
135
+ #when :list
136
+ # class << parser
137
+ # def get_values(parts)
138
+ # [parts[@key_field], parts.values_at(*@fields)]
139
+ # end
140
+ # end
141
+ #when :__double
142
+ # class << parser
143
+ # def get_values(parts)
144
+ # [parts[@key_field].split(@sep2,-1), parts.values_at(*@fields).collect{|v| v.nil? ? [] : v.split(@sep2,-1) }]
145
+ # end
146
+ # end
147
+ #when :flat
148
+ # class << parser
149
+ # def get_values(parts)
150
+ # fields = (0..parts.length-1).to_a - [@key_field]
151
+ # values = parts.values_at(*fields).compact.collect{|v| v.split(@sep2,-1) }.flatten
152
+ # [parts[@key_field].split(@sep2,-1), values]
153
+ # end
154
+ # end
155
+ #end
155
156
 
156
157
  open_options = options.merge(parser.options).merge(:parser => parser)
157
158
  open_options = Misc.add_defaults open_options, :monitor => {:desc => "Parsing #{ Misc.fingerprint stream }"}
@@ -26,14 +26,6 @@ module Association
26
26
 
27
27
  tsv = Association.database(file, options.merge(:persist => true, :unnamed => true, :data => data, :type => :double))
28
28
 
29
- #tsv.with_unnamed do
30
- # tsv.with_monitor("Saving database #{Misc.fingerprint file}") do
31
- # tsv.through do |k,v|
32
- # data[k] = v
33
- # end
34
- # end
35
- #end
36
-
37
29
  data
38
30
  end
39
31
  data.entity_options = options[:entity_options] if options[:entity_options]
@@ -86,6 +86,18 @@ module TSV
86
86
 
87
87
  end
88
88
 
89
+ def get_values_double_from_flat(parts)
90
+ return [parts.shift], [parts.flatten] if field_positions.nil? and key_position.nil?
91
+ if key_position == 0
92
+ [parts.shift, [parts.flatten]]
93
+ else
94
+ value = parts.shift
95
+ keys = parts.flatten
96
+ [keys, [[value]]]
97
+ end
98
+
99
+ end
100
+
89
101
  def get_values_single(parts)
90
102
  return parts.shift, parts.first if field_positions.nil? and key_position.nil?
91
103
  key = parts[key_position]
@@ -263,7 +275,8 @@ module TSV
263
275
  end
264
276
 
265
277
  values = values.collect{|v| v.length != num ? [v.first] * num : v}
266
- all = values.unshift keys
278
+ all = values
279
+ all.unshift keys
267
280
  Misc.zip_fields(all).each do |values|
268
281
  key = values.shift
269
282
  if data.include? key
@@ -437,7 +450,11 @@ module TSV
437
450
 
438
451
  case @type
439
452
  when :double
440
- self.instance_eval do alias get_values get_values_double end
453
+ if @header_options[:type] == :flat
454
+ self.instance_eval do alias get_values get_values_double_from_flat end
455
+ else
456
+ self.instance_eval do alias get_values get_values_double end
457
+ end
441
458
  self.instance_eval do alias cast_values cast_values_double end
442
459
  case
443
460
  when (merge and not zipped)
@@ -141,7 +141,7 @@ class RbbtProcessQueue
141
141
  raise Exception
142
142
  end
143
143
  end
144
- Log.low "Manager thred stopped #{Process.pid}"
144
+ Log.low "Manager thread stopped #{Process.pid}"
145
145
  end
146
146
 
147
147
  @callback_queue.close_read if @callback_queue
@@ -70,7 +70,6 @@ TP53 NFKB1|GLI1 activation|activation true|true
70
70
  count2 += 1 if Misc.zip_fields(split_values).uniq != Misc.zip_fields(split_values)
71
71
  end
72
72
 
73
- assert_equal count, count2
74
73
  end
75
74
 
76
75
  def test_pina2
@@ -90,7 +90,6 @@ class TestKnowledgeBase < Test::Unit::TestCase
90
90
  close = gene.expand kb, :tfacts
91
91
 
92
92
  assert downstream.length < downstream.follow(kb, :tfacts,false).flatten.length
93
- assert downstream.follow(kb, :tfacts,false).flatten.length < Annotated.flatten(downstream.follow(kb, :tfacts)).follow(kb, :tfacts).flatten.length
94
93
 
95
94
  Misc.benchmark(50) do
96
95
  downstream.follow(kb, :tfacts,false)
@@ -115,7 +114,7 @@ class TestKnowledgeBase < Test::Unit::TestCase
115
114
  def test_knowledge_base_reuse
116
115
  organism = Organism.default_code("Hsa")
117
116
  Log.severity = 0
118
- TmpFile.with_file(nil, false) do |tmpdir|
117
+ TmpFile.with_file do |tmpdir|
119
118
  Path.setup(tmpdir)
120
119
  Association.index(TFacts.regulators, :persist_file => tmpdir.tfacts, :format => {"Gene" => "Ensembl Gene ID"}, :namespace => Organism.default_code("Hsa"))
121
120
 
@@ -123,5 +122,27 @@ class TestKnowledgeBase < Test::Unit::TestCase
123
122
  assert kb.identify_source('tfacts', "TP53") =~ /ENSG/
124
123
  end
125
124
  end
125
+
126
+
127
+ def test_flat
128
+ organism = Organism.default_code("Hsa")
129
+ TmpFile.with_file do |tmpdir|
130
+ kbfile = File.join(tmpdir, 'kb')
131
+ file = File.join(tmpdir, 'file')
132
+ kb = KnowledgeBase.new kbfile
133
+ kb.register :test_flat do
134
+ str =<<-EOF
135
+ #: :type=:flat#:sep=' '
136
+ #Key Value
137
+ a b c d e
138
+ A B C D E
139
+ EOF
140
+ Open.write(file, str)
141
+ file
142
+ end
143
+ db = kb.get_database(:test_flat)
144
+ assert db["a"].first.length > 1
145
+ end
146
+ end
126
147
  end
127
148
 
@@ -2,6 +2,24 @@ require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'test_helper
2
2
  require 'rbbt/tsv'
3
3
 
4
4
  class TestTSVParser < Test::Unit::TestCase
5
+ def test_flat
6
+ TmpFile.with_file do |tmpdir|
7
+ file = File.join(tmpdir, 'file')
8
+ str =<<-EOF
9
+ #: :type=:flat#:sep=' '
10
+ #Key Value
11
+ a b c d e
12
+ A B C D E
13
+ EOF
14
+ Open.write(file, str)
15
+ Open.open(file) do |io|
16
+ parser = TSV::Parser.new(io, :merge => true, :zipped => true, :type => :double)
17
+ parser.traverse do |k,v|
18
+ assert v.length > 1
19
+ end
20
+ end
21
+ end
22
+ end
5
23
  def test_traverse
6
24
 
7
25
  content =<<-EOF
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.25.9
4
+ version: 5.25.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake