35
35
MetaPGeneFunction ,
36
36
MetaTGeneFunction ,
37
37
Table ,
38
+ _table_model_map ,
38
39
workflow_execution_tables ,
39
40
)
40
41
@@ -107,7 +108,13 @@ def join(self, target_table: Table, query: Query) -> Query:
107
108
raise NotImplementedError ()
108
109
109
110
def _join_omics_processing_related_tables (self , target_table : Table , query : Query ) -> Query :
110
- if target_table != Table .omics_processing :
111
+ if target_table in workflow_execution_tables :
112
+ association_table = models .workflow_activity_to_data_generation_map [target_table .value ]
113
+ query = query .join (association_table ).join (
114
+ models .OmicsProcessing ,
115
+ models .OmicsProcessing .id == association_table .c .data_generation_id ,
116
+ )
117
+ elif target_table != Table .omics_processing :
111
118
query = query .join (models .OmicsProcessing )
112
119
113
120
return self .join_omics_processing (query )
@@ -252,10 +259,25 @@ def join_study(self, query: Query) -> Query:
252
259
)
253
260
254
261
255
- workflow_filter_classes : List [Type [OmicsProcessingFilter ]] = []
262
+ class WorkflowExecutionFilter (OmicsProcessingFilter ):
263
+ table = Table .reads_qc
264
+
265
+ def join_omics_processing (self , query : Query ) -> Query :
266
+ association_table = models .workflow_activity_to_data_generation_map [self .table .value ]
267
+ model = _table_model_map [self .table ]
268
+ q = query .join (
269
+ association_table ,
270
+ association_table .c .data_generation_id == models .OmicsProcessing .id ,
271
+ ).join (
272
+ model , model .id == association_table .c [f"{ self .table .value } _id" ] # type: ignore
273
+ )
274
+ return q
275
+
276
+
277
+ workflow_filter_classes : List [Type [WorkflowExecutionFilter ]] = []
256
278
for table in workflow_execution_tables :
257
279
workflow_filter_classes .append (
258
- type (f"{ table .value } _filter" , (OmicsProcessingFilter ,), {"table" : table })
280
+ type (f"{ table .value } _filter" , (WorkflowExecutionFilter ,), {"table" : table })
259
281
)
260
282
261
283
@@ -274,10 +296,19 @@ def join(self, target_table: Table, query: Query) -> Query:
274
296
)
275
297
276
298
query = super ().join (target_table , query )
299
+ # Use the association table to join from OmicsProcessing/DataGeneration to
300
+ # MetagenomeAnnotation. Due to how the association table(s) are generated
301
+ # dynamically, mypy does not know what the columns are.
302
+ association_table = models .metagenome_annotation_data_generation_association
277
303
return (
278
304
query .join (
305
+ association_table ,
306
+ association_table .data_generation_id == models .OmicsProcessing .id , # type: ignore
307
+ )
308
+ .join (
279
309
models .MetagenomeAnnotation ,
280
- models .MetagenomeAnnotation .omics_processing_id == models .OmicsProcessing .id ,
310
+ models .MetagenomeAnnotation .id
311
+ == association_table .metagenome_annotation_id , # type: ignore
281
312
)
282
313
.join (
283
314
models .MGAGeneFunctionAggregation ,
@@ -325,10 +356,16 @@ def join(self, target_table: Table, query: Query) -> Query:
325
356
)
326
357
327
358
query = super ().join (target_table , query )
359
+ association_table = models .metaproteomic_analysis_data_generation_association
328
360
return (
329
361
query .join (
362
+ association_table ,
363
+ association_table .data_generation_id == models .OmicsProcessing .id , # type: ignore
364
+ )
365
+ .join (
330
366
models .MetaproteomicAnalysis ,
331
- models .MetaproteomicAnalysis .omics_processing_id == models .OmicsProcessing .id ,
367
+ models .MetaproteomicAnalysis .id
368
+ == association_table .metaproteomic_analysis_id , # type: ignore
332
369
)
333
370
.join (
334
371
models .MetaPGeneFunctionAggregation ,
@@ -359,10 +396,16 @@ def join(self, target_table: Table, query: Query) -> Query:
359
396
MetaTGeneFunction .id == models .MetaTGeneFunctionAggregation .gene_function_id ,
360
397
)
361
398
query = super ().join (target_table , query )
399
+ association_table = models .metatranscriptome_annotation_data_generation_association
362
400
return (
363
401
query .join (
402
+ association_table ,
403
+ association_table .data_generation_id == models .OmicsProcessing .id , # type: ignore
404
+ )
405
+ .join (
364
406
models .MetatranscriptomeAnnotation ,
365
- models .MetatranscriptomeAnnotation .omics_processing_id == models .OmicsProcessing .id ,
407
+ models .MetatranscriptomeAnnotation .id
408
+ == association_table .metatranscriptome_annotation_id , # type: ignore
366
409
)
367
410
.join (
368
411
models .MetaTGeneFunctionAggregation ,
@@ -383,7 +426,14 @@ class MetaproteomicAnalysisFilter(OmicsProcessingFilter):
383
426
table = Table .metaproteomic_analysis
384
427
385
428
def join_omics_processing (self , query : Query ) -> Query :
386
- return query .join (self .table .model )
429
+ association_table = models .metaproteomic_analysis_data_generation_association
430
+ return query .join (
431
+ association_table ,
432
+ association_table .c .data_generation_id == models .OmicsProcessing .id ,
433
+ ).join (
434
+ models .MetaproteomicAnalysis ,
435
+ models .MetaproteomicAnalysis .id == association_table .c .metaproteomic_analysis_id ,
436
+ )
387
437
388
438
def join_biosample (self , query : Query ) -> Query :
389
439
return (
0 commit comments