From af485aff7d25c1f5128586c550ca36debe24fd66 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 18 Jan 2024 14:43:00 +0300 Subject: UI: Create new ProbeSet dataset. --- qc_app/db/averaging.py | 23 ++++++ qc_app/db/datasets.py | 33 +++++++++ .../rqtl2/create-probe-dataset-success.html | 60 ++++++++++++++++ .../templates/rqtl2/select-probeset-dataset.html | 82 +++++++++++++++++++++- qc_app/upload/rqtl2.py | 65 ++++++++++++++++- 5 files changed, 260 insertions(+), 3 deletions(-) create mode 100644 qc_app/db/averaging.py create mode 100644 qc_app/templates/rqtl2/create-probe-dataset-success.html 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} diff --git a/qc_app/templates/rqtl2/create-probe-dataset-success.html b/qc_app/templates/rqtl2/create-probe-dataset-success.html new file mode 100644 index 0000000..33612c4 --- /dev/null +++ b/qc_app/templates/rqtl2/create-probe-dataset-success.html @@ -0,0 +1,60 @@ +{%extends "base.html"%} +{%from "flash_messages.html" import flash_messages%} + +{%block title%}Upload R/qtl2 Bundle{%endblock%} + +{%block contents%} +
You successfully created the ProbeSet dataset with the following + information. +
Under Construction
+OR
+{%endif%} + + {%endblock%} diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py index fc4e0e8..0b446ac 100644 --- a/qc_app/upload/rqtl2.py +++ b/qc_app/upload/rqtl2.py @@ -22,6 +22,7 @@ from qc_app.db_utils import with_db_connection, database_connection from qc_app.db.tissues import all_tissues, tissue_by_id from qc_app.db.platforms import platform_by_id, platforms_by_species +from qc_app.db.averaging import averaging_methods, averaging_method_by_id from qc_app.db import ( species_by_id, save_population, @@ -33,6 +34,7 @@ from qc_app.db.datasets import ( probeset_study_by_id, probeset_create_study, + probeset_create_dataset, probeset_datasets_by_study, probeset_studies_by_species_and_population) @@ -349,7 +351,7 @@ def select_probeset_dataset(species_id: int, population_id: int): population_id=population_id), code=307) if not bool(probeset_study_by_id(conn, int(request.form["probe-study-id"]))): - flash("Invalid dataset selected!", "alert-error alert-rqtl2") + flash("Invalid study selected!", "alert-error alert-rqtl2") return summary_page return summary_page @@ -397,6 +399,64 @@ def create_probeset_study(species_id: int, population_id: int): int(request.form["geno-dataset-id"])), study=study) +@rqtl2.route(("/upload/species/