rbbt-rest 1.3.26 → 1.3.27

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: fa6886b8b129262fc201896d29bd6a345d4ddde0
4
- data.tar.gz: 935dcbc86551da3d7d9365f6b8922cc976929542
3
+ metadata.gz: 03be0a1aa7c52a31f0138eecba03ebe8565f1b85
4
+ data.tar.gz: 80aeef50fc37891f40518f0e9d56654b846d2d24
5
5
  SHA512:
6
- metadata.gz: 44bd9aeb20e7c9d460022306f9847eb4b3cb8b10620b3a12b5ded1ad248548944645bedbd509dc271b4165dc79cd03532e063c7cf26029cc5137ae86826e4b34
7
- data.tar.gz: 41919d85980fdb41364e75aeee13ac10ed6a3d10990373749e70448156b8215fbe7c81a3b0a05d0248b3d467ecca6e239b66418870022b0f24d891d2fd4092b8
6
+ metadata.gz: 5a7faedf99cebb0e4e173f74bdf2974794d81afe55f3806a20bff814595192380150b9f9038a3ad69870c1bab19fdbebcb5f45f47cd25364efe4dd1251365dc9
7
+ data.tar.gz: ec5b0e0eabf50b62ed9750fce4b5bce7eaa11f723e9286e06d997035edb8bb8bfffa6d527b2e724e31b0f7f8d6a8db894a50420bbe561f4dbcfa923dd201ae04
@@ -11,6 +11,8 @@ module Sinatra
11
11
  base.module_eval do
12
12
  helpers KnowledgeBaseRESTHelpers
13
13
 
14
+ #{{{ Single entity
15
+
14
16
  get '/knowledge_base/:name/:database/children/:entity' do
15
17
  name = consume_parameter :name
16
18
  database = consume_parameter :database
@@ -110,6 +112,156 @@ module Sinatra
110
112
  end
111
113
  end
112
114
 
115
+
116
+ #{{{ Collection
117
+
118
+ post '/knowledge_base/:name/:database/collection_children' do
119
+ name = consume_parameter :name
120
+ database = consume_parameter :database
121
+ collection = consume_parameter :collection
122
+ raise ParameterException, "No collection specified" if collection.nil?
123
+ collection = JSON.parse(collection)
124
+
125
+ kb = get_knowledge_base name
126
+ matches = collection.keys.inject({}){|acc,type|
127
+ entities = collection[type]
128
+ entities.each do |entity|
129
+ _matches = kb.children(database, entity)
130
+ acc.merge!({ _matches.target_type => _matches}) if _matches and _matches.any?
131
+ end
132
+ acc
133
+ }
134
+ case @format
135
+ when :tsv
136
+ content_type "text/tab-separated-values"
137
+ matches = matches.sort_by{|k,list| list.length }.last.last
138
+ halt 200, matches.tsv.to_s
139
+ when :html
140
+ template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Children: #{ [name, database] }")
141
+ when :json
142
+ content_type :json
143
+ _matches = {}
144
+ matches.each{|type,list|
145
+ _matches[type] = list.target
146
+ }
147
+ halt 200, _matches.to_json
148
+ else
149
+ content_type :text
150
+ matches = matches.sort_by{|k,list| list.length }.last.last
151
+ halt 200, matches.target * "\n"
152
+ end
153
+ end
154
+
155
+ post '/knowledge_base/:name/:database/collection_parents' do
156
+ name = consume_parameter :name
157
+ database = consume_parameter :database
158
+ collection = consume_parameter :collection
159
+ raise ParameterException, "No collection specified" if collection.nil?
160
+ collection = JSON.parse(collection)
161
+
162
+ kb = get_knowledge_base name
163
+ matches = collection.keys.inject({}){|acc,type|
164
+ entities = collection[type]
165
+ entities.each do |entity|
166
+ _matches = kb.parents(database, entity)
167
+ acc.merge!({ _matches.target_type => _matches}) if _matches and _matches.any?
168
+ end
169
+ acc
170
+ }
171
+ case @format
172
+ when :tsv
173
+ content_type "text/tab-separated-values"
174
+ matches = matches.sort_by{|k,list| list.length }.last.last
175
+ halt 200, matches.tsv.to_s
176
+ when :html
177
+ template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
178
+ when :json
179
+ content_type :json
180
+ _matches = {}
181
+ matches.each{|type,list|
182
+ _matches[type] = list.target
183
+ }
184
+ halt 200, _matches.to_json
185
+ else
186
+ content_type :text
187
+ matches = matches.sort_by{|k,list| list.length }.last.last
188
+ halt 200, matches.target * "\n"
189
+ end
190
+ end
191
+
192
+ post '/knowledge_base/:name/:database/collection_neighbours' do
193
+ name = consume_parameter :name
194
+ database = consume_parameter :database
195
+ collection = consume_parameter :collection
196
+ raise ParameterException, "No collection specified" if collection.nil?
197
+ collection = JSON.parse(collection)
198
+
199
+ kb = get_knowledge_base name
200
+ matches = collection.keys.inject({}){|acc,type|
201
+ entities = collection[type]
202
+ entities.each do |entity|
203
+ _matches_h = kb.neighbours(database, entity)
204
+ _matches_h.each do |key, _matches|
205
+ target_type = case key
206
+ when :children
207
+ _matches.target_type
208
+ when :parents
209
+ _matches.source_type
210
+ end
211
+ _matches = acc[target_type].concat _matches if acc[target_type] and acc[target_type].any?
212
+ acc.merge!({ target_type => _matches}) if _matches and _matches.any?
213
+ end
214
+ end
215
+ acc
216
+ }
217
+ case @format
218
+ when :tsv
219
+ content_type "text/tab-separated-values"
220
+ matches = matches.sort_by{|k,list| list.length }.last.last
221
+ halt 200, matches.tsv.to_s
222
+ when :html
223
+ template_render('knowledge_base_partials/matches', {:matches => matches}, "Collection Parents: #{ [name, database] }")
224
+ when :json
225
+ content_type :json
226
+ _matches = {}
227
+ matches.each{|type,list|
228
+ _matches[type] = list.target
229
+ }
230
+ halt 200, _matches.to_json
231
+ else
232
+ content_type :text
233
+ matches = matches.sort_by{|k,list| list.length }.last.last
234
+ halt 200, matches.target * "\n"
235
+ end
236
+ end
237
+
238
+ get '/knowledge_base/:name/:database/subset' do
239
+ name = consume_parameter :name
240
+ database = consume_parameter :database
241
+ source = consume_parameter :source
242
+ target = consume_parameter :target
243
+
244
+ source = source == "all" ? :all : source.split(@array_separator) if source
245
+ target = target == "all" ? :all : target.split(@array_separator) if target
246
+ entities = { :source => source, :target => target }
247
+
248
+ kb = get_knowledge_base name
249
+ subset = kb.subset(database, entities)
250
+ case @format
251
+ when :tsv
252
+ content_type "text/tab-separated-values"
253
+ halt 200, subset.tsv.to_s
254
+ when :html
255
+ template_render('knowledge_base_partials/subset', {:subset => subset}, "Subset: #{ [name, database] }")
256
+ when :json
257
+ content_type :json
258
+ halt 200, subset.source.to_json
259
+ else
260
+ content_type :text
261
+ halt 200, subset.source * "\n"
262
+ end
263
+ end
264
+
113
265
  #{{{ Info
114
266
 
115
267
  get '/knowledge_base/info/:name/:database/:pair' do
@@ -44,8 +44,12 @@ module KnowledgeBaseRESTHelpers
44
44
 
45
45
  kb.syndicate Genomics.knowledge_base, :genomics
46
46
 
47
+ TSV.traverse user_studies[user], :cpus => 10 do |study|
48
+ Study.setup(study)
49
+ study.sample_genes
50
+ end
51
+
47
52
  user_studies[user].each do |study|
48
- next if study.all_mutations.length > 50_000
49
53
  kb.syndicate study.knowledge_base, study
50
54
  end
51
55
 
@@ -1,22 +1,30 @@
1
1
  - values = index[pair]
2
- - fields = index.fields
3
- - tsv = TSV.setup({}, :key_field => "Num", :fields => fields, :type => :list)
4
- - values.zip(fields).each_with_index do |p,i|
5
- - value, field = p
6
- - value.split(";;").each_with_index do |part,j|
7
- - tsv[j] ||= [nil] * fields.length
8
- - tsv[j][i] = part
9
- - tsv.entity_options = kb.entity_options
10
- - tsv.namespace = kb.namespace
11
-
12
- - if tsv.fields.include? "PMID"
13
- - tsv.add_field "Title" do |k,v|
14
- - v["PMID"].title
15
2
 
16
3
  - source = pair.source_entity
17
4
  - target = pair.target_entity
18
5
  - source_name = source.respond_to?(:name) ? source.name || name : source
19
6
  - target_name = target.respond_to?(:name) ? target.name || name : target
20
7
  - name = [source_name, target_name] * "~"
21
- = tsv2html(tsv, :table_id => name)
8
+ - kb_name = File.basename pair.knowledge_base.dir
9
+
10
+ %h3== #{name} in #{pair.database} #{kb_name}
11
+
12
+ - fields = index.fields
13
+ - if fields.any?
14
+ - tsv = TSV.setup({}, :key_field => "Num", :fields => fields, :type => :list)
15
+ - values.zip(fields).each_with_index do |p,i|
16
+ - value, field = p
17
+ - value.split(";;").each_with_index do |part,j|
18
+ - tsv[j] ||= [nil] * fields.length
19
+ - tsv[j][i] = part
20
+ - tsv.entity_options = kb.entity_options
21
+ - tsv.namespace = kb.namespace
22
+
23
+ - if tsv.fields.include? "PMID"
24
+ - tsv.add_field "Title" do |k,v|
25
+ - v["PMID"].title
26
+
27
+ = tsv2html(tsv, :table_id => "#{pair} in #{pair.database} #{kb_name}")
22
28
 
29
+ - else
30
+ No information for this association: #{pair}
@@ -11,4 +11,5 @@
11
11
  - else
12
12
  = table do
13
13
  - matches = matches.values.sort{|v| v.length}.last if Hash === matches
14
+
14
15
  - matches.tsv
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.26
4
+ version: 1.3.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake