aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-18 14:43:00 +0300
committerFrederick Muriuki Muriithi2024-01-18 14:43:00 +0300
commitaf485aff7d25c1f5128586c550ca36debe24fd66 (patch)
tree16593e9e7a11cbd2ae2f5ab228f6620520a0b1b2 /qc_app/db
parent0369fc21eaa54466bd64f3b12d1fe6a1dbc81de0 (diff)
downloadgn-uploader-af485aff7d25c1f5128586c550ca36debe24fd66.tar.gz
UI: Create new ProbeSet dataset.
Diffstat (limited to 'qc_app/db')
-rw-r--r--qc_app/db/averaging.py23
-rw-r--r--qc_app/db/datasets.py33
2 files changed, 56 insertions, 0 deletions
diff --git a/qc_app/db/averaging.py b/qc_app/db/averaging.py
new file mode 100644
index 0000000..62bbe67
--- /dev/null
+++ b/qc_app/db/averaging.py
@@ -0,0 +1,23 @@
+"""Functions for db interactions for averaging methods"""
+from typing import Optional
+
+import MySQLdb as mdb
+from MySQLdb.cursors import DictCursor
+
+def averaging_methods(conn: mdb.Connection) -> tuple[dict, ...]:
+ """Fetch all available averaging methods"""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute("SELECT * FROM AvgMethod")
+ return tuple(dict(row) for row in cursor.fetchall())
+
+def averaging_method_by_id(
+ conn: mdb.Connection, averageid: int) -> Optional[dict]:
+ """Fetch the averaging method by its ID"""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute("SELECT * FROM AvgMethod WHERE Id=%s",
+ (averageid,))
+ result = cursor.fetchone()
+ if bool(result):
+ return dict(result)
+
+ return None
diff --git a/qc_app/db/datasets.py b/qc_app/db/datasets.py
index 5f6a2d5..5816146 100644
--- a/qc_app/db/datasets.py
+++ b/qc_app/db/datasets.py
@@ -85,3 +85,36 @@ def probeset_create_study(conn: mdb.Connection,#pylint: disable=[too-many-argume
cursor.execute("UPDATE ProbeFreeze SET ProbeFreezeId=%s",
(studyid,))
return {**studydata, "studyid": studyid}
+
+def probeset_create_dataset(conn: mdb.Connection,#pylint: disable=[too-many-arguments]
+ studyid: int,
+ averageid: int,
+ datasetname: str,
+ datasetfullname: str,
+ datasetshortname: str="",
+ public: bool = True,
+ datascale="log2") -> dict:
+ """Create a new ProbeSet dataset."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ dataset = {
+ "studyid": studyid,
+ "averageid": averageid,
+ "name2": datasetname,
+ "fname": datasetfullname,
+ "name": datasetshortname,
+ "sname": datasetshortname,
+ "today": date.today().isoformat(),
+ "public": 2 if public else 0,
+ "datascale": datascale
+ }
+ cursor.execute(
+ """
+ insert into ProbeSetFreeze(
+ ProbeFreezeId, AvgId, Name, Name2, FullName, ShortName,
+ CreateTime, public, DataScale)
+ VALUES(
+ %(studyid)s, %(averageid)s, %(name)s, %(name2)s, %(fname)s,
+ %(sname)s, %(today)s, %(public)s, %(datascale)s)
+ """,
+ dataset)
+ return {**dataset, "datasetid": cursor.lastrowid}