aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db/datasets.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-18 05:52:52 +0300
committerFrederick Muriuki Muriithi2024-01-18 06:05:51 +0300
commitcf8d133b110d87aed5cb6695711616625a6669fd (patch)
tree2723f88cd1c1cd5b6c763c7030209d18975acffb /qc_app/db/datasets.py
parent33e106334a212853842c30f8c595da1099c3d84e (diff)
downloadgn-uploader-cf8d133b110d87aed5cb6695711616625a6669fd.tar.gz
Create new ProbeSet study.
Diffstat (limited to 'qc_app/db/datasets.py')
-rw-r--r--qc_app/db/datasets.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/qc_app/db/datasets.py b/qc_app/db/datasets.py
index 086c103..5f6a2d5 100644
--- a/qc_app/db/datasets.py
+++ b/qc_app/db/datasets.py
@@ -1,4 +1,6 @@
"""Functions for accessing the database relating to datasets."""
+from datetime import date
+
import MySQLdb as mdb
from MySQLdb.cursors import DictCursor
@@ -43,9 +45,43 @@ def probeset_datasets_by_study(conn: mdb.Connection,
(studyid,))
return tuple(dict(row) for row in cursor.fetchall())
-def probe_study_by_id(conn: mdb.Connection, studyid: int) -> dict:
+def probeset_study_by_id(conn: mdb.Connection, studyid: int) -> 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())
+
+def probeset_create_study(conn: mdb.Connection,#pylint: disable=[too-many-arguments]
+ populationid: int,
+ platformid: int,
+ tissueid: int,
+ studyname: str,
+ studyfullname: str = "",
+ studyshortname: str = ""):
+ """Create a new ProbeSet study."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ studydata = {
+ "platid": platformid,
+ "tissueid": tissueid,
+ "name": studyname,
+ "fname": studyfullname or studyname,
+ "sname": studyshortname,
+ "today": date.today().isoformat(),
+ "popid": populationid
+ }
+ cursor.execute(
+ """
+ INSERT INTO ProbeFreeze(
+ ChipId, TissueId, Name, FullName, ShortName, CreateTime,
+ InbredSetId
+ ) VALUES (
+ %(platid)s, %(tissueid)s, %(name)s, %(fname)s, %(sname)s,
+ %(today)s, %(popid)s
+ )
+ """,
+ studydata)
+ studyid = cursor.lastrowid
+ cursor.execute("UPDATE ProbeFreeze SET ProbeFreezeId=%s",
+ (studyid,))
+ return {**studydata, "studyid": studyid}