rbbt-entities 2.0.0 → 2.1.0
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.
- data/lib/rbbt/entity.rb +10 -22
- data/lib/rbbt/entity/genomic_mutation.rb +21 -9
- data/lib/rbbt/entity/genotype.rb +1 -1
- data/lib/rbbt/entity/transcript.rb +5 -1
- data/test/rbbt/entity/test_genomic_mutation.rb +7 -0
- data/test/rbbt/test_entity.rb +53 -25
- metadata +12 -12
data/lib/rbbt/entity.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rbbt/annotations'
|
2
2
|
|
3
|
-
module Entity
|
3
|
+
module Entity
|
4
|
+
|
4
5
|
class << self
|
5
6
|
attr_accessor :formats, :entity_property_cache, :entity_list_cache
|
6
7
|
end
|
@@ -12,33 +13,20 @@ module Entity
|
|
12
13
|
UNPERSISTED_PREFIX = "entity_unpersisted_property_"
|
13
14
|
|
14
15
|
def self.extended(base)
|
15
|
-
base.extend Annotation
|
16
|
-
|
17
|
-
|
16
|
+
base.extend Annotation
|
18
17
|
Entity.formats[base.to_s] = base
|
18
|
+
|
19
19
|
base.module_eval do
|
20
20
|
attr_accessor :_ary_property_cache
|
21
21
|
|
22
|
+
def _ary_property_cache
|
23
|
+
@_ary_property_cache ||= {}
|
24
|
+
end
|
25
|
+
|
22
26
|
if not methods.include? "prev_entity_extended"
|
23
27
|
class << self
|
24
28
|
attr_accessor :template, :list_template, :action_template, :list_action_template, :keep_id
|
25
|
-
alias prev_entity_extended extended
|
26
29
|
end
|
27
|
-
|
28
|
-
def self.extended(data)
|
29
|
-
prev_entity_extended(data)
|
30
|
-
|
31
|
-
data._ary_property_cache = {}
|
32
|
-
|
33
|
-
if Array === data and
|
34
|
-
not AnnotatedArray === data and
|
35
|
-
not (data.compact.first != nil and Annotated === data.compact.first and (data.annotation_types - data.compact.first.annotation_types).any?)
|
36
|
-
|
37
|
-
data.extend AnnotatedArray
|
38
|
-
end
|
39
|
-
|
40
|
-
data
|
41
|
-
end
|
42
30
|
end
|
43
31
|
|
44
32
|
def self.format=(formats)
|
@@ -69,7 +57,7 @@ module Entity
|
|
69
57
|
end
|
70
58
|
end
|
71
59
|
|
72
|
-
def
|
60
|
+
def clean_annotations_new
|
73
61
|
case
|
74
62
|
when self.nil?
|
75
63
|
nil
|
@@ -143,7 +131,7 @@ module Entity
|
|
143
131
|
case
|
144
132
|
when Array === self
|
145
133
|
self.send(ary_name, *args)
|
146
|
-
when (Array === self.container and self.container.respond_to? ary_name)
|
134
|
+
when (Array === self.container and not self.container_index.nil? and self.container.respond_to? ary_name)
|
147
135
|
cache_code = Misc.hash2md5({:name => ary_name, :args => args})
|
148
136
|
res = (self.container._ary_property_cache[cache_code] ||= self.container.send(name, *args))
|
149
137
|
if Hash === res
|
@@ -34,12 +34,16 @@ module GenomicMutation
|
|
34
34
|
#persist :guess_watson
|
35
35
|
|
36
36
|
def watson
|
37
|
-
if @
|
38
|
-
|
39
|
-
|
37
|
+
if @current_watson.nil?
|
38
|
+
current = annotation_values[:watson]
|
39
|
+
if current.nil? and Array === self
|
40
|
+
watson = current = guess_watson
|
41
|
+
else
|
42
|
+
current
|
43
|
+
end
|
44
|
+
@current_watson = current
|
40
45
|
end
|
41
|
-
@
|
42
|
-
@watson
|
46
|
+
@current_watson
|
43
47
|
end
|
44
48
|
|
45
49
|
def orig_watson
|
@@ -274,16 +278,21 @@ module GenomicMutation
|
|
274
278
|
genes = nil
|
275
279
|
genes = genes_tsv.chunked_values_at self
|
276
280
|
Gene.setup(genes, "Ensembl Gene ID", organism)
|
281
|
+
genes
|
277
282
|
end
|
278
283
|
#persist :_ary_genes
|
279
284
|
|
280
285
|
property :affected_genes => :array2single do
|
281
286
|
_mutated_isoforms = mutated_isoforms
|
287
|
+
|
282
288
|
mi_gene = Misc.process_to_hash(MutatedIsoform.setup(_mutated_isoforms.compact.flatten.uniq, organism)){|mis| mis.protein.gene}
|
283
|
-
|
289
|
+
|
290
|
+
_mutated_isoforms = _mutated_isoforms.clean_annotations if _mutated_isoforms.respond_to? :clean_annotations
|
291
|
+
from_protein = _mutated_isoforms.collect{|mis|
|
284
292
|
genes = mis.nil? ? [] : mi_gene.values_at(*mis).compact
|
285
293
|
Gene.setup(genes.uniq, "Ensembl Gene ID", organism)
|
286
294
|
}
|
295
|
+
|
287
296
|
is_exon_junction = self.in_exon_junction?.zip(self.type).collect{|in_ex,type| in_ex and type != "none"}
|
288
297
|
genes_with_altered_splicing = self.transcripts_with_affected_splicing.collect{|transcripts| transcripts.gene}
|
289
298
|
from_protein.each_with_index do |list, i|
|
@@ -292,11 +301,11 @@ module GenomicMutation
|
|
292
301
|
list.uniq!
|
293
302
|
end
|
294
303
|
end
|
304
|
+
|
295
305
|
Gene.setup(from_protein, "Ensembl Gene ID", organism)
|
296
306
|
end
|
297
307
|
#persist :_ary_affected_genes
|
298
308
|
|
299
|
-
|
300
309
|
property :relevant? => :array2single do
|
301
310
|
affected_genes.collect{|list| list and list.any?}
|
302
311
|
end
|
@@ -327,7 +336,10 @@ module GenomicMutation
|
|
327
336
|
property :mutated_isoforms => :array2single do
|
328
337
|
res = Sequence.job(:mutated_isoforms_for_genomic_mutations, jobname, :watson => watson, :organism => organism, :mutations => self.clean_annotations).run.chunked_values_at self
|
329
338
|
res.each{|list| list.organism = organism unless list.nil?}
|
330
|
-
|
339
|
+
if Annotated === (first = res.compact[0])
|
340
|
+
first.annotate(res)
|
341
|
+
res.extend AnnotatedArray
|
342
|
+
end
|
331
343
|
res
|
332
344
|
end
|
333
345
|
#persist :_ary_mutated_isoforms
|
@@ -468,6 +480,7 @@ module GenomicMutation
|
|
468
480
|
end
|
469
481
|
|
470
482
|
property :damaging? => :array2single do |*args|
|
483
|
+
|
471
484
|
all_mutated_isoforms = mutated_isoforms.compact.flatten
|
472
485
|
damaged_mutated_isoforms = all_mutated_isoforms.select{|mi| mi.damaged?(*args)}
|
473
486
|
exon_junctions.zip(mutated_isoforms, self.type).collect do |exs, mis, type|
|
@@ -475,7 +488,6 @@ module GenomicMutation
|
|
475
488
|
(Array === mis and (damaged_mutated_isoforms & mis).any?)
|
476
489
|
end
|
477
490
|
end
|
478
|
-
#persist :damaging?
|
479
491
|
|
480
492
|
property :worst_consequence => :array2single do |*args|
|
481
493
|
gene = args.first
|
data/lib/rbbt/entity/genotype.rb
CHANGED
@@ -63,7 +63,7 @@ module Genotype
|
|
63
63
|
|
64
64
|
def metagenotype
|
65
65
|
organism = self.collect{|g| g.organism}.compact.first
|
66
|
-
orig_watson = self.collect{|g| g.
|
66
|
+
orig_watson = self.collect{|g| g.watson}.compact.first
|
67
67
|
GenomicMutation.setup(self.dup.flatten, jobname, organism, orig_watson).extend Genotype
|
68
68
|
end
|
69
69
|
|
@@ -16,7 +16,11 @@ module Transcript
|
|
16
16
|
else
|
17
17
|
@@enst2ensg[organism][transcript]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
if defined? Gene
|
21
|
+
Gene.fast_setup(res, {:format => "Ensembl Gene ID", :organism => organism})
|
22
|
+
end
|
23
|
+
|
20
24
|
res
|
21
25
|
end
|
22
26
|
|
@@ -74,7 +74,14 @@ class TestGenomicMutation < Test::Unit::TestCase
|
|
74
74
|
assert(SPLICING2.transcripts_with_affected_splicing.empty?)
|
75
75
|
end
|
76
76
|
|
77
|
+
def test_genes_persist
|
77
78
|
|
79
|
+
GenomicMutation.with_persisted :genes do
|
80
|
+
|
81
|
+
m = MUTATION.annotate(MUTATION.dup)
|
82
|
+
assert AnnotatedArray === m.genes
|
83
|
+
end
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
87
|
|
data/test/rbbt/test_entity.rb
CHANGED
@@ -4,9 +4,19 @@ require 'rbbt/entity'
|
|
4
4
|
require 'rbbt/util/tmpfile'
|
5
5
|
require 'test/unit'
|
6
6
|
|
7
|
+
class TestA
|
8
|
+
attr_accessor :foo, :bar
|
9
|
+
def initialize(foo, bar)
|
10
|
+
@foo = foo
|
11
|
+
@bar = bar
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
module ReversableString
|
8
16
|
extend Entity
|
9
|
-
|
17
|
+
|
18
|
+
self.annotation :foo, :bar
|
19
|
+
|
10
20
|
property :reverse_text_ary => :array do
|
11
21
|
$count += 1
|
12
22
|
self.collect{|s| s.reverse}
|
@@ -54,9 +64,9 @@ end
|
|
54
64
|
|
55
65
|
class TestEntity < Test::Unit::TestCase
|
56
66
|
|
57
|
-
def
|
67
|
+
def test_property_ary
|
58
68
|
a = ["String1", "String2"]
|
59
|
-
a
|
69
|
+
ReversableString.setup(a)
|
60
70
|
|
61
71
|
$count = 0
|
62
72
|
|
@@ -74,9 +84,9 @@ class TestEntity < Test::Unit::TestCase
|
|
74
84
|
end
|
75
85
|
end
|
76
86
|
|
77
|
-
def
|
87
|
+
def test_property_single
|
78
88
|
a = ["String1", "String2"]
|
79
|
-
|
89
|
+
ReversableString.setup a
|
80
90
|
|
81
91
|
$count = 0
|
82
92
|
|
@@ -86,9 +96,9 @@ class TestEntity < Test::Unit::TestCase
|
|
86
96
|
assert_equal 3, $count
|
87
97
|
end
|
88
98
|
|
89
|
-
def
|
99
|
+
def test_property_ary_p
|
90
100
|
a = ["String1", "String2"]
|
91
|
-
|
101
|
+
ReversableString.setup a
|
92
102
|
|
93
103
|
$count = 0
|
94
104
|
|
@@ -97,9 +107,9 @@ class TestEntity < Test::Unit::TestCase
|
|
97
107
|
assert_equal 1, $count
|
98
108
|
end
|
99
109
|
|
100
|
-
def
|
110
|
+
def test_property_single_p
|
101
111
|
a = ["String1", "String2"]
|
102
|
-
|
112
|
+
ReversableString.setup a
|
103
113
|
|
104
114
|
$count = 0
|
105
115
|
|
@@ -109,9 +119,9 @@ class TestEntity < Test::Unit::TestCase
|
|
109
119
|
assert_equal 2, $count
|
110
120
|
end
|
111
121
|
|
112
|
-
def
|
122
|
+
def test_property_ary_p_array
|
113
123
|
a = ["String1", "String2"]
|
114
|
-
|
124
|
+
ReversableString.setup a
|
115
125
|
|
116
126
|
$count = 0
|
117
127
|
|
@@ -121,9 +131,9 @@ class TestEntity < Test::Unit::TestCase
|
|
121
131
|
assert_equal 1, $count
|
122
132
|
end
|
123
133
|
|
124
|
-
def
|
134
|
+
def test_unpersist
|
125
135
|
a = ["String1", "String2"]
|
126
|
-
|
136
|
+
ReversableString.setup a
|
127
137
|
|
128
138
|
# Before persist
|
129
139
|
assert(! ReversableString.persisted?(:random))
|
@@ -150,7 +160,7 @@ class TestEntity < Test::Unit::TestCase
|
|
150
160
|
|
151
161
|
end
|
152
162
|
|
153
|
-
def
|
163
|
+
def test_persist_annotations
|
154
164
|
string = 'aaabbbccc'
|
155
165
|
ReversableString.setup(string)
|
156
166
|
assert_equal string.length, string.annotation_list.length
|
@@ -158,14 +168,25 @@ class TestEntity < Test::Unit::TestCase
|
|
158
168
|
end
|
159
169
|
|
160
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
|
161
177
|
|
162
|
-
|
163
|
-
|
178
|
+
Misc.profile(:min_percent => 2) do
|
179
|
+
1000.times do
|
180
|
+
Gene.setup_positional("", "foo", "bar")
|
181
|
+
end
|
182
|
+
end
|
164
183
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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"
|
169
190
|
end
|
170
191
|
end
|
171
192
|
|
@@ -174,14 +195,21 @@ class TestEntity < Test::Unit::TestCase
|
|
174
195
|
Workflow.require_workflow "StudyExplorer"
|
175
196
|
|
176
197
|
s = Study.setup("CLL")
|
177
|
-
mutations = s.cohort.metagenotype
|
198
|
+
mutations = s.cohort.metagenotype
|
199
|
+
|
200
|
+
mis = mutations.mutated_isoforms.compact.flatten
|
201
|
+
|
202
|
+
Misc.profile(:min_percent => 1) do
|
203
|
+
mis.each{|m| m}
|
204
|
+
end
|
205
|
+
|
178
206
|
|
179
|
-
Misc.benchmark(
|
180
|
-
|
207
|
+
Misc.benchmark(10) do
|
208
|
+
mis.each{|m| m}
|
181
209
|
end
|
182
210
|
|
183
|
-
Misc.benchmark(
|
184
|
-
|
211
|
+
Misc.benchmark(10) do
|
212
|
+
mis.clean_annotations.each{|m| m}
|
185
213
|
end
|
186
214
|
|
187
215
|
m = mutations.first
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-entities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rbbt-util
|
@@ -65,13 +65,13 @@ files:
|
|
65
65
|
- lib/rbbt/entity/pmid.rb
|
66
66
|
- lib/rbbt/entity/protein.rb
|
67
67
|
- lib/rbbt/entity/transcript.rb
|
68
|
-
- test/
|
69
|
-
- test/rbbt/entity/test_gene.rb
|
70
|
-
- test/rbbt/entity/test_genomic_mutation.rb
|
71
|
-
- test/rbbt/entity/test_mutated_isoform.rb
|
68
|
+
- test/rbbt/test_entity.rb
|
72
69
|
- test/rbbt/entity/test_protein.rb
|
70
|
+
- test/rbbt/entity/test_mutated_isoform.rb
|
73
71
|
- test/rbbt/entity/test_pmid.rb
|
74
|
-
- test/rbbt/
|
72
|
+
- test/rbbt/entity/test_gene.rb
|
73
|
+
- test/rbbt/entity/test_genomic_mutation.rb
|
74
|
+
- test/test_helper.rb
|
75
75
|
homepage: http://github.com/mikisvaz/rbbt-util
|
76
76
|
licenses: []
|
77
77
|
post_install_message:
|
@@ -97,10 +97,10 @@ signing_key:
|
|
97
97
|
specification_version: 3
|
98
98
|
summary: Entities for the Ruby Bioinformatics Toolkit (rbbt)
|
99
99
|
test_files:
|
100
|
-
- test/
|
101
|
-
- test/rbbt/entity/test_gene.rb
|
102
|
-
- test/rbbt/entity/test_genomic_mutation.rb
|
103
|
-
- test/rbbt/entity/test_mutated_isoform.rb
|
100
|
+
- test/rbbt/test_entity.rb
|
104
101
|
- test/rbbt/entity/test_protein.rb
|
102
|
+
- test/rbbt/entity/test_mutated_isoform.rb
|
105
103
|
- test/rbbt/entity/test_pmid.rb
|
106
|
-
- test/rbbt/
|
104
|
+
- test/rbbt/entity/test_gene.rb
|
105
|
+
- test/rbbt/entity/test_genomic_mutation.rb
|
106
|
+
- test/test_helper.rb
|