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 +4 -4
- data/lib/rbbt/association/database.rb +30 -29
- data/lib/rbbt/association/open.rb +0 -8
- data/lib/rbbt/tsv/parser.rb +19 -2
- data/lib/rbbt/util/concurrency/processes.rb +1 -1
- data/test/rbbt/knowledge_base/test_registry.rb +0 -1
- data/test/rbbt/test_knowledge_base.rb +23 -2
- data/test/rbbt/tsv/test_parser.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13bac11c495886a59c36af1b96806cd378cfed87
|
4
|
+
data.tar.gz: 73b4586d838d9ada0e7d3f156b25bd42d3f53614
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
when :list
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
when :
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
when :flat
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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]
|
data/lib/rbbt/tsv/parser.rb
CHANGED
@@ -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
|
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
|
-
|
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)
|
@@ -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
|
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.
|
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-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|