def test_query_multiomics(db: Session, value: int, result: bool): biosample = fakes.BiosampleFactory() fakes.OmicsProcessingFactory(annotations={"omics_type": "Metabolomics"}, biosample=biosample) fakes.OmicsProcessingFactory( annotations={"omics_type": "Metatranscriptome"}, biosample=biosample) db.commit() models.Biosample.populate_multiomics(db) db.commit() qs = query.BiosampleQuerySchema(conditions=[{ "table": "biosample", "field": "multiomics", "op": "has", "value": value }]) assert bool(list(qs.execute(db))) is result
def test_indirect_join(db: Session): study = fakes.StudyFactory(id="study1") fakes.OmicsProcessingFactory(id="omics_processing1", biosample__study=study) db.commit() q = query.StudyQuerySchema(conditions=[{ "table": "omics_processing", "field": "id", "value": "omics_processing1", "op": "==" }]) assert {s.id for s in q.execute(db)} == {"study1"}
def test_list_data_objects(db: Session, client: TestClient, endpoint: str): data_object = fakes.DataObjectFactory(id="do") omics_processing = fakes.OmicsProcessingFactory(id="1") reads_qc = fakes.ReadsQCFactory(id="1") assembly = fakes.MetagenomeAssemblyFactory(id="1") annotation = fakes.MetagenomeAnnotationFactory(id="1") analysis = fakes.MetaproteomicAnalysisFactory(id="1") omics_processing.outputs = [data_object] reads_qc.outputs = [data_object] assembly.outputs = [data_object] annotation.outputs = [data_object] analysis.outputs = [data_object] db.commit() resp = client.get(f"/api/{endpoint}/1/outputs") assert_status(resp) assert ["do"] == [r["id"] for r in resp.json()]
def test_basic_query(db: Session, table): tests: Dict[str, Tuple[fakes.AnnotatedFactory, query.BaseQuerySchema]] = { "study": (fakes.StudyFactory(), query.StudyQuerySchema()), "omics_processing": (fakes.OmicsProcessingFactory(), query.OmicsProcessingQuerySchema()), "biosample": (fakes.BiosampleFactory(), query.BiosampleQuerySchema()), "reads_qc": (fakes.ReadsQCFactory(), query.ReadsQCQuerySchema()), "metagenome_assembly": ( fakes.MetagenomeAssemblyFactory(), query.MetagenomeAssemblyQuerySchema(), ), "metagenome_annotation": ( fakes.MetagenomeAnnotationFactory(), query.MetagenomeAnnotationQuerySchema(), ), "metaproteomic_analysis": ( fakes.MetaproteomicAnalysisFactory(), query.MetaproteomicAnalysisQuerySchema(), ), } db.commit() q = tests[table][1].execute(db) assert tests[table][0].id in {r.id for r in q.all()}
def test_pipeline_query(db: Session, table): omics_processing1 = fakes.OmicsProcessingFactory(name="omics_processing1") omics_processing2 = fakes.OmicsProcessingFactory(name="omics_processing2") fakes.ReadsQCFactory(omics_processing=omics_processing1, name="reads_qc1") fakes.ReadsQCFactory(omics_processing=omics_processing1, name="reads_qc2") fakes.ReadsQCFactory(omics_processing=omics_processing2, name="reads_qc3") fakes.MetagenomeAssemblyFactory(omics_processing=omics_processing1, name="assembly1") fakes.MetagenomeAssemblyFactory(omics_processing=omics_processing1, name="assembly2") fakes.MetagenomeAssemblyFactory(omics_processing=omics_processing2, name="assembly3") fakes.MetagenomeAnnotationFactory(omics_processing=omics_processing1, name="annotation1") fakes.MetagenomeAnnotationFactory(omics_processing=omics_processing1, name="annotation2") fakes.MetagenomeAnnotationFactory(omics_processing=omics_processing2, name="annotation3") fakes.MetaproteomicAnalysisFactory(omics_processing=omics_processing1, name="analysis1") fakes.MetaproteomicAnalysisFactory(omics_processing=omics_processing1, name="analysis2") fakes.MetaproteomicAnalysisFactory(omics_processing=omics_processing2, name="analysis3") fakes.MAGsAnalysisFactory(omics_processing=omics_processing1, name="mags1") fakes.MAGsAnalysisFactory(omics_processing=omics_processing1, name="mags2") fakes.MAGsAnalysisFactory(omics_processing=omics_processing2, name="mags3") fakes.ReadBasedAnalysisFactory(omics_processing=omics_processing1, name="reads1") fakes.ReadBasedAnalysisFactory(omics_processing=omics_processing1, name="reads2") fakes.ReadBasedAnalysisFactory(omics_processing=omics_processing2, name="reads3") fakes.NOMAnalysisFactory(omics_processing=omics_processing1, name="nom1") fakes.NOMAnalysisFactory(omics_processing=omics_processing1, name="nom2") fakes.NOMAnalysisFactory(omics_processing=omics_processing2, name="nom3") fakes.MetabolomicsAnalysisFactory(omics_processing=omics_processing1, name="metab1") fakes.MetabolomicsAnalysisFactory(omics_processing=omics_processing1, name="metab2") fakes.MetabolomicsAnalysisFactory(omics_processing=omics_processing2, name="metab3") db.commit() # test omics_processing not associated with biosamples omics_processing1.biosample_id = None db.add(omics_processing1) # test omics_processing not associated with studies omics_processing2.study_id = None db.add(omics_processing2) db.commit() query_schema = { "reads_qc": query.ReadsQCQuerySchema, "assembly": query.MetagenomeAssemblyQuerySchema, "annotation": query.MetagenomeAnnotationQuerySchema, "analysis": query.MetaproteomicAnalysisQuerySchema, "mags": query.MAGsAnalysisQuerySchema, "reads": query.ReadBasedAnalysisQuerySchema, "nom": query.NOMAnalysisQuerySchema, "metab": query.MetabolomicsAnalysisQuerySchema, }[table] q = query_schema() assert {f"{table}{i}" for i in [1, 2, 3]} == {r.name for r in q.execute(db).all()} q = query_schema(conditions=[{ "table": "omics_processing", "field": "name", "value": "omics_processing1", }]) assert {f"{table}{i}" for i in [1, 2]} == {r.name for r in q.execute(db).all()} q = query.OmicsProcessingQuerySchema(conditions=[{ "table": q.table.value, "field": "name", "value": f"{table}1" }]) assert ["omics_processing1"] == [r.name for r in q.execute(db).all()]