aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-04-12 09:17:49 +0300
committerFrederick Muriuki Muriithi2024-04-12 09:48:58 +0300
commit8e4e15ae62989f07d3ca8512165ba2a93c42aa94 (patch)
tree6136b56b8ba8537cb54ea6d498f418b6bf81c733 /qc_app/db
parent09b4b70aae5e65516c766882118a897c75a44974 (diff)
downloadgn-uploader-8e4e15ae62989f07d3ca8512165ba2a93c42aa94.tar.gz
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.
Diffstat (limited to 'qc_app/db')
-rw-r--r--qc_app/db/datasets.py22
1 files changed, 10 insertions, 12 deletions
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)