rbbt-util 5.17.86 → 5.17.87
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/index.rb +37 -0
- data/test/rbbt/association/test_index.rb +38 -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: 7689fb8913a735ad844a7375011fadc522af2bd1
|
4
|
+
data.tar.gz: 55d639ec2c1b722ae054c643fc53c19cca0677dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd8c83197f8a67d00129a27b3bf04a4d9518bb43cee0c20dad31e9cb1ae781466090ef1af0380219c98711ea2db8822427e40a4aa9dbb35b6faa23e77bc1f6f
|
7
|
+
data.tar.gz: d455058547e7e3d111ea74a15a7b0e1b2e1196d7320169207f0199a1add2a91b9bcad0d1b4898b534dc8965f57486df83266c4ad81253a8ffd0af8e4eaaad5ad
|
@@ -184,6 +184,43 @@ module Association
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
+
def filter(value_field = nil, target_value = nil, &block)
|
188
|
+
if block_given?
|
189
|
+
matches = []
|
190
|
+
if value_field
|
191
|
+
through :key, value_field do |key,values|
|
192
|
+
pass = block.call values
|
193
|
+
matches << key if pass
|
194
|
+
end
|
195
|
+
else
|
196
|
+
through do |key,values|
|
197
|
+
pass = block.call [key, values]
|
198
|
+
matches << key if pass
|
199
|
+
end
|
200
|
+
end
|
201
|
+
matches
|
202
|
+
|
203
|
+
else
|
204
|
+
matches = []
|
205
|
+
if target_value
|
206
|
+
target_value = [target_value] unless Array === target_value
|
207
|
+
through :key, value_field do |key,values|
|
208
|
+
pass = (values & target_value).any?
|
209
|
+
matches << key if pass
|
210
|
+
end
|
211
|
+
else
|
212
|
+
through :key, value_field do |key,values|
|
213
|
+
pass = false
|
214
|
+
values.each do |value|
|
215
|
+
pass = true unless value.nil? or value.empty? or value.downcase == 'false'
|
216
|
+
end
|
217
|
+
matches << key if pass
|
218
|
+
end
|
219
|
+
end
|
220
|
+
matches
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
187
224
|
def to_matrix(value_field = nil, &block)
|
188
225
|
value_field = fields.first if value_field.nil? and fields.length == 1
|
189
226
|
value_pos = identify_field value_field if value_field and String === value_field
|
@@ -85,5 +85,43 @@ TP53 NFKB1|GLI1 activation|activation true|true
|
|
85
85
|
assert(tsv.to_matrix(false))
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_filter_no_block
|
89
|
+
require 'rbbt/sources/tfacts'
|
90
|
+
file = TFacts.regulators
|
91
|
+
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => false, :source => "SG=~Associated Gene Name", :target => "TG=~Associated Gene Name"), :persist => true)
|
92
|
+
tsv.unnamed = false
|
93
|
+
matches = tsv.filter :directed?
|
94
|
+
assert_equal 2, matches.length
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_filter_no_block_value
|
98
|
+
require 'rbbt/sources/tfacts'
|
99
|
+
file = TFacts.regulators
|
100
|
+
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => false, :source => "SG=~Associated Gene Name", :target => "TG=~Associated Gene Name"), :persist => true)
|
101
|
+
tsv.unnamed = false
|
102
|
+
matches = tsv.filter :Effect, "inhibition"
|
103
|
+
assert_equal ["MDM2~TP53"], matches
|
104
|
+
end
|
88
105
|
|
106
|
+
def test_filter_block_value_field
|
107
|
+
require 'rbbt/sources/tfacts'
|
108
|
+
file = TFacts.regulators
|
109
|
+
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => false, :source => "SG=~Associated Gene Name", :target => "TG=~Associated Gene Name"), :persist => true)
|
110
|
+
tsv.unnamed = false
|
111
|
+
matches = tsv.filter :Effect do |value|
|
112
|
+
return value.include? "inhibition"
|
113
|
+
end
|
114
|
+
assert_equal ["MDM2~TP53"], matches
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_filter_block_no_value_field
|
118
|
+
require 'rbbt/sources/tfacts'
|
119
|
+
file = TFacts.regulators
|
120
|
+
tsv = Association.index(EFFECT, EFFECT_OPTIONS.merge(:undirected => false, :source => "SG=~Associated Gene Name", :target => "TG=~Associated Gene Name"), :persist => true)
|
121
|
+
tsv.unnamed = false
|
122
|
+
matches = tsv.filter do |key,values|
|
123
|
+
return values.flatten.include? "inhibition"
|
124
|
+
end
|
125
|
+
assert_equal ["MDM2~TP53"], matches
|
126
|
+
end
|
89
127
|
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.17.
|
4
|
+
version: 5.17.87
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|