From 8e4e15ae62989f07d3ca8512165ba2a93c42aa94 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 12 Apr 2024 09:17:49 +0300 Subject: Consistently check for possibly non-existent data The "geno-dataset", "tissue", "pheno-study" and "pheno-dataset" data "objects" might not exist for a particular uploaded bundle, so we check in a consistent manner to ensure they are provided when needed. --- qc_app/db/datasets.py | 22 +++++++++----------- qc_app/templates/rqtl2/summary-info.html | 11 ++++++++++ qc_app/upload/rqtl2.py | 35 +++++++++++++------------------- 3 files changed, 35 insertions(+), 33 deletions(-) (limited to 'qc_app') diff --git a/qc_app/db/datasets.py b/qc_app/db/datasets.py index 448db18..b56dcf5 100644 --- a/qc_app/db/datasets.py +++ b/qc_app/db/datasets.py @@ -18,12 +18,12 @@ def geno_datasets_by_species_and_population( {"sid": speciesid, "pid": populationid}) return tuple(dict(row) for row in cursor.fetchall()) -def geno_dataset_by_id(conn: mdb.Connection, dataset_id: int) -> dict: +def geno_dataset_by_id(conn: mdb.Connection, dataset_id) -> Optional[dict]: """Retrieve genotype dataset by ID""" with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT * FROM GenoFreeze WHERE Id=%s", - (dataset_id,)) - return dict(cursor.fetchone()) + cursor.execute("SELECT * FROM GenoFreeze WHERE Id=%s", (dataset_id,)) + _dataset = cursor.fetchone() + return dict(_dataset) if bool(_dataset) else None def probeset_studies_by_species_and_population( conn: mdb.Connection, @@ -46,12 +46,12 @@ def probeset_datasets_by_study(conn: mdb.Connection, (studyid,)) return tuple(dict(row) for row in cursor.fetchall()) -def probeset_study_by_id(conn: mdb.Connection, studyid: int) -> dict: +def probeset_study_by_id(conn: mdb.Connection, studyid) -> Optional[dict]: """Retrieve ProbeSet study by ID""" with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT * FROM ProbeFreeze WHERE Id=%s", - (studyid,)) - return dict(cursor.fetchone()) + cursor.execute("SELECT * FROM ProbeFreeze WHERE Id=%s", (studyid,)) + _study = cursor.fetchone() + return dict(_study) if bool(_study) else None def probeset_create_study(conn: mdb.Connection,#pylint: disable=[too-many-arguments] populationid: int, @@ -120,12 +120,10 @@ def probeset_create_dataset(conn: mdb.Connection,#pylint: disable=[too-many-argu dataset) return {**dataset, "datasetid": cursor.lastrowid} -def probeset_dataset_by_id( - conn: mdb.Connection, datasetid: int) -> Optional[dict]: +def probeset_dataset_by_id(conn: mdb.Connection, datasetid) -> Optional[dict]: """Fetch a ProbeSet dataset by its ID""" with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT * FROM ProbeSetFreeze WHERE Id=%s", - (datasetid,)) + cursor.execute("SELECT * FROM ProbeSetFreeze WHERE Id=%s", (datasetid,)) result = cursor.fetchone() if bool(result): return dict(result) diff --git a/qc_app/templates/rqtl2/summary-info.html b/qc_app/templates/rqtl2/summary-info.html index 3882c9c..9a9b6dd 100644 --- a/qc_app/templates/rqtl2/summary-info.html +++ b/qc_app/templates/rqtl2/summary-info.html @@ -19,14 +19,25 @@