rbbt-sources 3.0.32 → 3.0.33

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f704985c78e876aa8b63b7cc2367ae788bc35f61
4
- data.tar.gz: 8e13c2f15915d79206b611196734fbf254488966
3
+ metadata.gz: 1f7fdfe0006f7704b66f77aadeed785f2cd1ec4a
4
+ data.tar.gz: bda1ec6492f1dcb961d0bc5b1b2775a78a19c16c
5
5
  SHA512:
6
- metadata.gz: dd4ce9e020394422ad53405c60bd56824135014aed64374c6b8c54321d4a9f8e728c6d0345d80d08b1009fe74be5959b3dd9bfa5d8b524385b8f394c1400fc54
7
- data.tar.gz: b9db1418b814865ae52f6600e3a634af63fba02b4b3f652257312f6645d484cb4b21168a8d38e2c94cb99ad399767a6d590b2321065d44638e67796f4d40f753
6
+ metadata.gz: aab537323d616bf284b5f54231179a808bb054d50f60fce8afd3a7b596aee4925063f737bdbc1d87ba749e786bbfec7d45356995b35c38414a614c049a37810d
7
+ data.tar.gz: dbb2e870406ea8cb7bd5bc7571b64e9c57841cb364d1553165a8510612607079917e054794e448fcdb8b70a81066c6c469463d774195a522d9bce431e02c296c
@@ -1,4 +1,4 @@
1
- require 'rbbt'
1
+ require 'rbbt-util'
2
2
  require 'rbbt/resource'
3
3
  require 'rbbt/persist/tsv'
4
4
 
@@ -83,6 +83,80 @@ module GO
83
83
  info[id]['namespace']
84
84
  end
85
85
  end
86
+
87
+ def self.ancestors_in(term, valid)
88
+ ancestors = id2ancestors(term)
89
+ return ancestors if FalseClass === valid
90
+ valid_ancestors = ancestors & valid
91
+ return valid_ancestors if valid_ancestors.any?
92
+ valid_ancestors.inject([]) do |acc,ancestor|
93
+ valid_a = ancestors_in ancestor, valid
94
+ acc = acc + valid_a
95
+ end
96
+ end
97
+
98
+ def self.group_genes(list, valid = nil)
99
+ valid = %w(GO:0005886 GO:0005634 GO:0005730 GO:0005829) if valid.nil?
100
+
101
+ compartment_leaves = {}
102
+ list.zip(list.go_cc_terms).each do |gene,terms|
103
+ valid_terms = terms.collect{|term|
104
+ (valid.include?(term) ? term : ancestors_in(term, valid))
105
+ }.flatten
106
+ valid_terms - GOTerm.setup(valid_terms).flat_ancestry.flatten
107
+ valid_terms.each do |term|
108
+ compartment_leaves[term] ||= []
109
+ compartment_leaves[term].push(gene)
110
+ end
111
+ end
112
+
113
+ groups = {}
114
+ while compartment_leaves.length > 1
115
+
116
+ # Group common
117
+ group = false
118
+ new_compartment_leaves = {}
119
+ compartment_leaves.each do |c,l|
120
+ if l.length > 1
121
+ groups[c] = l
122
+ group = true
123
+ new_compartment_leaves[c] = [c]
124
+ else
125
+ new_compartment_leaves[c] = l
126
+ end
127
+ end
128
+ compartment_leaves = new_compartment_leaves
129
+
130
+ # Pull-up leaves
131
+ if group == false
132
+ new_compartment_leaves = {}
133
+ final = compartment_leaves.keys
134
+ compartment_leaves.each do |c,l|
135
+ final = final - GOTerm.setup(c.dup).flat_ancestry
136
+ end
137
+
138
+ compartment_leaves.each do |c,l|
139
+ if final.include? c
140
+ valid_an = ancestors_in c, valid
141
+ valid_an.each do |ancestor|
142
+ ancestor = valid.first
143
+ next if ancestor.nil?
144
+ new_compartment_leaves[ancestor] ||= []
145
+ new_compartment_leaves[ancestor].concat(l)
146
+ end
147
+ else
148
+ new_compartment_leaves[c] = l
149
+ end
150
+ end
151
+ compartment_leaves = new_compartment_leaves
152
+ end
153
+ end
154
+ ng = {}
155
+ groups.keys.reverse.each do |k|
156
+ ng[k] = {items: groups[k], id: k, name: id2name(k)}
157
+ end
158
+ ng
159
+ end
86
160
  end
87
161
 
88
162
  if defined? Entity
@@ -112,6 +186,31 @@ if defined? Entity
112
186
  description
113
187
  end
114
188
 
189
+ property :ancestors => :single2array do
190
+ GOTerm.setup(GO.id2ancestors(self))
191
+ end
192
+
193
+ property :ancestor => :single2array do
194
+ ancestors.first
195
+ end
196
+
197
+ property :ancestry => :single2array do
198
+ ancestry = {}
199
+ self.ancestors.each do |ancestor|
200
+ prev = ancestor.ancestry
201
+ ancestry[ancestor] = prev
202
+ end
203
+ ancestry
204
+ end
205
+
206
+ property :flat_ancestry => :single2array do
207
+ ancestry = []
208
+ self.ancestors.each do |ancestor|
209
+ prev = ancestor.flat_ancestry
210
+ ancestry = ancestry + [ancestor] + prev
211
+ end
212
+ ancestry
213
+ end
115
214
  end
116
215
 
117
216
  if defined? Gene and Entity === Gene
@@ -131,7 +230,7 @@ if defined? Entity
131
230
  property :go_mf_terms => :array2single do
132
231
  @go_mf_terms ||= Organism.gene_go_mf(organism).tsv(:persist => true, :key_field => "Ensembl Gene ID", :fields => ["GO ID"], :type => :flat, :merge => true, :namespace => organism).chunked_values_at self.ensembl
133
232
  end
134
-
233
+
135
234
  end
136
235
  end
137
236
  end
@@ -1,21 +1,76 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
2
 
3
+ require 'rbbt/workflow'
4
+ Workflow.require_workflow "Genomics"
5
+
6
+ require 'rbbt/entity/gene'
3
7
  require 'rbbt/sources/go'
4
8
  require 'test/unit'
5
9
 
10
+
6
11
  class TestGo < Test::Unit::TestCase
7
- def test_go
12
+ def _test_go
8
13
  assert_match('vacuole inheritance',GO::id2name('GO:0000011'))
9
14
  assert_equal(['vacuole inheritance','alpha-glucoside transport'], GO::id2name(['GO:0000011','GO:0000017']))
10
15
  end
11
16
 
12
- def test_ancestors
17
+ def _test_ancestors
13
18
  assert GO.id2ancestors('GO:0000001').include? 'GO:0048308'
14
19
  end
15
20
 
16
- def test_namespace
21
+ def _test_namespace
17
22
  assert_equal 'biological_process', GO.id2namespace('GO:0000001')
18
23
  end
24
+
25
+ def _test_ancestors
26
+ term = GOTerm.setup("GO:0005634")
27
+ end
28
+
29
+ def _test_ancestry
30
+ term = GOTerm.setup("GO:0005634")
31
+ term.ancestry.include? "GO:0005634"
32
+ end
33
+
34
+ def _test_ancestry_in
35
+ term = GOTerm.setup("GO:0005634")
36
+ valid = %w(GO:0005886 GO:0005634 GO:0005730 GO:0005829)
37
+ iii GO.ancestors_in(term, valid)
38
+ end
39
+
40
+ def test_groups
41
+ list = Gene.setup(%w(ENSG00000009413
42
+ ENSG00000038295
43
+ ENSG00000038427
44
+ ENSG00000047457
45
+ ENSG00000058668
46
+ ENSG00000065361
47
+ ENSG00000070778
48
+ ENSG00000072364
49
+ ENSG00000073711
50
+ ENSG00000075420
51
+ ENSG00000088387
52
+ ENSG00000096384
53
+ ENSG00000100345
54
+ ENSG00000102804
55
+ ENSG00000102910
56
+ ENSG00000103657
57
+ ENSG00000104043
58
+ ENSG00000106772
59
+ ENSG00000107186
60
+ ENSG00000108262
61
+ ENSG00000261163
62
+ ENSG00000263077
63
+ ENSG00000101654
64
+ ENSG00000111012), :organism => Organism.default_code("Hsa"))
65
+
66
+ valid = %w(GO:0005886 GO:0005634 GO:0005730 GO:0005829 )
67
+ iii GO.group_genes(list, valid)
68
+ end
69
+
70
+ def _test_nucleolus
71
+ nuo = "GO:0005730"
72
+ nu = "GO:0005634"
73
+ end
19
74
  end
20
75
 
21
76
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-sources
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.32
4
+ version: 3.0.33
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-07-06 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbbt-util