forked from biobakery/firecloud-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.py
475 lines (373 loc) · 14.8 KB
/
schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# Schema for firecloud api to graphql
import json
import graphene
from graphene.types import generic
import utilities
import query_firecloud
from database import data
## Firecloud API ##
class entitiesWithType(graphene.ObjectType):
namespace = graphene.ID()
workspace = graphene.ID()
attributes = graphene.String()
class entity(graphene.ObjectType):
namespace = graphene.ID()
workspace = graphene.ID()
name = graphene.String()
entityType = graphene.String()
attributes = graphene.String()
## Portal API ##
class Sort(graphene.String):
pass
class FiltersArgument(generic.GenericScalar):
pass
class Count(graphene.ObjectType):
projects = graphene.String()
participants = graphene.String()
samples = graphene.String()
dataFormats = graphene.String()
rawFiles = graphene.String()
processedFiles = graphene.String()
class User(graphene.ObjectType):
username = graphene.String()
class Program(graphene.ObjectType):
name = graphene.String()
program_id = graphene.String()
id = graphene.String()
def resolve_program_id(self, info):
return self.name
def resolve_id(self, info):
return self.name
class DataCategories(graphene.ObjectType):
case_count = graphene.Int()
file_count = graphene.Int()
data_category = graphene.String()
class ExperimentalStrategies(graphene.ObjectType):
case_count = graphene.Int()
file_count = graphene.Int()
experimental_strategy = graphene.String()
class Summary(graphene.ObjectType):
case_count = graphene.Int()
file_count = graphene.Int()
file_size = graphene.Float()
data_categories = graphene.List(DataCategories)
experimental_strategies = graphene.List(ExperimentalStrategies)
class Project(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
project_id = graphene.String()
name = graphene.String()
program = graphene.Field(Program)
summary = graphene.Field(Summary)
primary_site = graphene.List(graphene.String)
@classmethod
def get_node(cls, info, id):
return data.get_project(id)
class Demographic(graphene.ObjectType):
ethnicity = graphene.String()
gender = graphene.String()
race = graphene.String()
class MetadataParticipant(graphene.ObjectType):
id = graphene.Int()
participant = graphene.Int()
age_2012 = graphene.Int()
totMETs1 = graphene.Float()
weight_lbs = graphene.Float()
class MetadataSample(graphene.ObjectType):
id = graphene.Int()
project = graphene.String()
sample = graphene.String()
participant = graphene.Int()
DaysSince1Jan12 = graphene.Int()
drAlcohol = graphene.Float()
drB12 = graphene.Float()
drCalories = graphene.Float()
drCarbs = graphene.Float()
drCholine = graphene.Float()
drFat = graphene.Float()
drFiber = graphene.Float()
drFolate = graphene.Float()
drIron = graphene.Float()
drProtein = graphene.Float()
participant = graphene.Int()
q2Alcohol = graphene.String()
q2B12 = graphene.String()
q2Calories = graphene.String()
q2Carbs = graphene.String()
q2Choline = graphene.String()
q2Fat = graphene.String()
q2Fiber = graphene.String()
q2Folate = graphene.String()
q2Iron = graphene.String()
q2Protein = graphene.String()
Time = graphene.String()
week = graphene.Int()
class FileCase(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
case_id = graphene.String()
project = graphene.Field(Project)
demographic = graphene.Field(Demographic)
metadata_participant = graphene.Field(MetadataParticipant)
primary_site = graphene.String()
class FileCaseConnection(graphene.relay.Connection):
class Meta:
node = FileCase
total = graphene.Int()
def resolve_total(self, info):
return len(self.edges)
class FileCases(graphene.ObjectType):
hits = graphene.relay.ConnectionField(FileCaseConnection,
first=graphene.Int(),
offset=graphene.Int(),
sort=graphene.List(Sort),
filters=FiltersArgument())
class File(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
name = graphene.String()
participant = graphene.String()
sample = graphene.String()
access = graphene.String()
file_size = graphene.Float()
data_category = graphene.String()
data_format = graphene.String()
platform = graphene.String()
experimental_strategy = graphene.String()
file_name = graphene.String()
cases = graphene.Field(FileCases)
file_id = graphene.String()
type = graphene.String()
def resolve_file_id(self, info):
return self.file_id
def resolve_type(self, info):
return self.data_format
@classmethod
def get_node(cls, info, id):
return data.get_file(id)
class ProjectConnection(graphene.relay.Connection):
class Meta:
node = Project
total = graphene.Int()
def resolve_total(self, info):
return len(self.edges)
class FileConnection(graphene.relay.Connection):
class Meta:
node = File
total = graphene.Int()
def resolve_total(self, info):
# return data.get_files_total()
return len(self.edges)
class Bucket(graphene.ObjectType):
doc_count = graphene.Int()
key = graphene.String()
key_as_string = graphene.String()
def resolve_key_as_string(self, info):
return str(key)
class Aggregations(graphene.ObjectType):
buckets = graphene.List(Bucket)
class FileAggregations(graphene.ObjectType):
data_category = graphene.Field(Aggregations)
experimental_strategy = graphene.Field(Aggregations)
data_format = graphene.Field(Aggregations)
platform = graphene.Field(Aggregations)
access = graphene.Field(Aggregations)
cases__project__project_id = graphene.Field(Aggregations)
cases__primary_site = graphene.Field(Aggregations)
class Files(graphene.ObjectType):
hits = graphene.relay.ConnectionField(FileConnection,
first=graphene.Int(),
offset=graphene.Int(),
score=graphene.String(),
sort=graphene.List(Sort),
filters=FiltersArgument())
facets = graphene.types.json.JSONString(filters=FiltersArgument(),
facets=graphene.List(graphene.String))
aggregations = graphene.Field(FileAggregations,
filters=FiltersArgument(),
aggregations_filter_themselves=graphene.Boolean())
def resolve_hits(self, info, first=None, score=None, offset=None, sort=None, filters=None):
all_files = [data.get_file(file_id) for file_id in self.hits]
filtered_files = utilities.filter_hits(all_files, filters, "files")
sorted_files = utilities.sort_hits(filtered_files, sort)
return sorted_files
def resolve_aggregations(self, info, filters=None, aggregations_filter_themselves=None):
all_files = [data.get_file(file_id) for file_id in self.hits]
filtered_files = utilities.filter_hits(all_files, filters, "files")
return data.get_file_aggregations(filtered_files)
def resolve_facets(self, info, filters=None, facets=None):
return data.get_facets()
class CaseAggregations(graphene.ObjectType):
demographic__ethnicity = graphene.Field(Aggregations)
demographic__gender = graphene.Field(Aggregations)
demographic__race = graphene.Field(Aggregations)
metadata_participant__age_2012 = graphene.Field(Aggregations)
metadata_participant__totMETs1 = graphene.Field(Aggregations)
metadata_participant__weight_lbs = graphene.Field(Aggregations)
primary_site = graphene.Field(Aggregations)
project__project_id = graphene.Field(Aggregations)
project__program__name = graphene.Field(Aggregations)
class CaseAnnotation(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
annotation_id = graphene.String()
def resolve_annotation_id(self, info):
return self.id
class CaseAnnotationConnection(graphene.relay.Connection):
class Meta:
node = CaseAnnotation
total = graphene.Int()
def resolve_total(self, info):
return len(self.edges)
class CaseAnnotations(graphene.ObjectType):
hits = graphene.relay.ConnectionField(CaseAnnotationConnection,
first=graphene.Int(),
offset=graphene.Int(),
score=graphene.String(),
sort=graphene.List(Sort),
filters=FiltersArgument())
def resolve_hits(self, info, first=None, score=None, offset=None, sort=None, filters=None):
# filters are not currently in use
return data.get_case_annotation()
class CaseFile(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
case_id = graphene.String()
experimental_strategy = graphene.String()
data_category = graphene.String()
data_format = graphene.String()
platform = graphene.String()
access = graphene.String()
class CaseFileConnection(graphene.relay.Connection):
class Meta:
node = CaseFile
total = graphene.Int()
def resolve_total(self, info):
return len(self.edges)
class CaseFiles(graphene.ObjectType):
hits = graphene.relay.ConnectionField(CaseFileConnection,
first=graphene.Int(),
offset=graphene.Int(),
sort=graphene.List(Sort),
filters=FiltersArgument())
class Case(graphene.ObjectType):
class Meta:
interfaces = (graphene.relay.Node,)
case_id = graphene.String()
primary_site = graphene.String()
submitter_id = graphene.String()
demographic = graphene.Field(Demographic)
metadata_participant = graphene.Field(MetadataParticipant)
metadata_sample = graphene.List(MetadataSample)
project = graphene.Field(Project)
summary = graphene.Field(Summary)
annotations = graphene.Field(CaseAnnotations)
files = graphene.Field(CaseFiles)
def resolve_submitter_id(self, info):
return self.case_id
class CaseConnection(graphene.relay.Connection):
class Meta:
node = Case
total = graphene.Int()
def resolve_total(self, info):
#return data.get_cases_total()
return len(self.edges)
class RepositoryCases(graphene.ObjectType):
hits = graphene.relay.ConnectionField(CaseConnection,
first=graphene.Int(),
offset=graphene.Int(),
sort=graphene.List(Sort),
score=graphene.String(),
filters=FiltersArgument())
aggregations = graphene.Field(CaseAggregations,
filters=FiltersArgument(),
aggregations_filter_themselves=graphene.Boolean())
facets = graphene.types.json.JSONString(filters=FiltersArgument(),
facets=graphene.List(graphene.String))
def resolve_hits(self, info, first=None, score=None, offset=None, sort=None, filters=None):
all_cases = [data.get_case(case_id) for case_id in self.hits]
filtered_cases = utilities.filter_hits(all_cases, filters, "cases")
sorted_cases = utilities.sort_hits(filtered_cases, sort)
return sorted_cases
def resolve_aggregations(self, info, filters=None, aggregations_filter_themselves=None):
all_cases = [data.get_case(case_id) for case_id in self.hits]
filtered_cases = utilities.filter_hits(all_cases, filters, "cases")
case_aggregations = data.get_case_aggregations(filtered_cases)
return case_aggregations
def resolve_facets(self, info, filters=None, facets=None):
return data.get_facets()
class Repository(graphene.ObjectType):
files = graphene.Field(Files)
cases = graphene.Field(RepositoryCases)
def resolve_files(self, info):
return data.get_current_files()
def resolve_cases(self, info):
return data.get_current_cases()
class ProjectAggregations(graphene.ObjectType):
primary_site = graphene.Field(Aggregations)
program__name = graphene.Field(Aggregations)
project_id = graphene.Field(Aggregations)
summary__experimental_strategies__experimental_strategy = graphene.Field(Aggregations)
summary__data_categories__data_category = graphene.Field(Aggregations)
class Projects(graphene.ObjectType):
aggregations = graphene.Field(ProjectAggregations,
filters=FiltersArgument(),
aggregations_filter_themselves=graphene.Boolean())
hits = graphene.relay.ConnectionField(ProjectConnection,
first=graphene.Int(),
offset=graphene.Int(),
sort=graphene.List(Sort),
filters=FiltersArgument())
def resolve_hits(self, info, first=None, offset=None, sort=None, filters=None):
projects = data.get_current_projects()
filtered_projects = utilities.filter_hits(projects, filters, "projects")
return filtered_projects
def resolve_aggregations(self, info, filters=None, aggregations_filter_themselves=None):
projects = data.get_current_projects()
filtered_projects = utilities.filter_hits(projects, filters, "projects")
project_aggregations = data.get_project_aggregations(filtered_projects)
return project_aggregations
class FileSize(graphene.ObjectType):
value = graphene.Float()
class CartSummaryAggs(graphene.ObjectType):
fs = graphene.Field(FileSize)
def resolve_fs(self, info):
return data.get_cart_file_size()
class CartSummary(graphene.ObjectType):
aggregations = graphene.Field(CartSummaryAggs,
filters=FiltersArgument())
class Root(graphene.ObjectType):
user = graphene.Field(User)
count = graphene.Field(Count)
repository = graphene.Field(Repository)
projects = graphene.Field(Projects)
cart_summary = graphene.Field(CartSummary)
def resolve_user(self, info):
return data.get_user()
def resolve_count(self, info):
return data.get_current_counts()
def resolve_repository(self, info):
return Repository(self)
def resolve_projects(self, info):
return Projects(self)
def resolve_cart_summary(self, info):
return CartSummary(self)
class Query(graphene.ObjectType):
## Portal API ##
viewer = graphene.Field(Root)
node = graphene.relay.Node.Field()
def resolve_viewer(self, info):
return Root(self,info)
## Firecloud API ##
entities_with_type = graphene.List(entitiesWithType, namespace=graphene.ID(required=True), workspace=graphene.ID(required=True))
samples = graphene.List(entity, namespace=graphene.ID(required=True), workspace=graphene.ID(required=True))
def resolve_entities_with_type(self, info, namespace, workspace):
url = "workspaces/{0}/{1}/entities_with_type".format(namespace, workspace)
json_result = query_firecloud.call_api(url)
obj_result = utilities.json2obj(json.dumps(json_result))
return obj_result
def resolve_samples(self, info, namespace, workspace):
url = "workspaces/{0}/{1}/entities/{type}".format(namespace, workspace, "sample")
json_result = query_firecloud.call_api(url)
obj_result = utilities.json2obj(json.dumps(json_result))
return obj_result