From 6326357250711650bc8b4c0b90f8c0b94d72c39e Mon Sep 17 00:00:00 2001
From: Frederick Muriuki Muriithi
Date: Fri, 29 Mar 2024 13:14:14 +0300
Subject: Add UI to select/create tissue.
---
qc_app/db/tissues.py | 31 +++++-
qc_app/templates/rqtl2/create-tissue-success.html | 104 +++++++++++++++++++
.../templates/rqtl2/select-probeset-study-id.html | 20 +---
qc_app/templates/rqtl2/select-tissue.html | 112 +++++++++++++++++++++
qc_app/upload/rqtl2.py | 104 ++++++++++++++++++-
5 files changed, 349 insertions(+), 22 deletions(-)
create mode 100644 qc_app/templates/rqtl2/create-tissue-success.html
create mode 100644 qc_app/templates/rqtl2/select-tissue.html
diff --git a/qc_app/db/tissues.py b/qc_app/db/tissues.py
index ebf24fd..062e824 100644
--- a/qc_app/db/tissues.py
+++ b/qc_app/db/tissues.py
@@ -1,5 +1,5 @@
"""Handle db interactions for tissue."""
-from typing import Optional
+from typing import Union, Optional
import MySQLdb as mdb
from MySQLdb.cursors import DictCursor
@@ -10,6 +10,7 @@ def all_tissues(conn: mdb.Connection) -> tuple[dict, ...]:
cursor.execute("SELECT * FROM Tissue ORDER BY TissueName")
return tuple(dict(row) for row in cursor.fetchall())
+
def tissue_by_id(conn: mdb.Connection, tissueid: int) -> Optional[dict]:
"""Retrieve a tissue by its ID"""
with conn.cursor(cursorclass=DictCursor) as cursor:
@@ -20,3 +21,31 @@ def tissue_by_id(conn: mdb.Connection, tissueid: int) -> Optional[dict]:
return dict(result)
return None
+
+
+def create_new_tissue(
+ conn: mdb.Connection,
+ name: str,
+ shortname: str,
+ birnlexid: Optional[str] = None,
+ birnlexname: Optional[str] = None
+) -> dict[str, Union[int, str, None]]:
+ """Add a new tissue, organ or biological material to the database."""
+ with conn.cursor() as cursor:
+ cursor.execute(
+ "INSERT INTO "
+ "Tissue(TissueName, Name, Short_Name, BIRN_lex_ID, BIRN_lex_Name) "
+ "VALUES (%s, %s, %s, %s, %s)",
+ (name, name, shortname, birnlexid, birnlexname))
+ tissueid = cursor.lastrowid
+ cursor.execute("UPDATE Tissue SET TissueId=%s WHERE Id=%s",
+ (tissueid, tissueid))
+ return {
+ "Id": tissueid,
+ "TissueId": tissueid,
+ "TissueName": name,
+ "Name": name,
+ "Short_Name": shortname,
+ "BIRN_lex_ID": birnlexid,
+ "BIRN_lex_Name": birnlexname
+ }
diff --git a/qc_app/templates/rqtl2/create-tissue-success.html b/qc_app/templates/rqtl2/create-tissue-success.html
new file mode 100644
index 0000000..ea05624
--- /dev/null
+++ b/qc_app/templates/rqtl2/create-tissue-success.html
@@ -0,0 +1,104 @@
+{%extends "base.html"%}
+{%from "flash_messages.html" import flash_all_messages%}
+
+{%block title%}Upload R/qtl2 Bundle{%endblock%}
+
+{%block contents%}
+
Select Tissue
+
+
+
You have successfully added a new tissue, organ or biological material with
+ the following details:
+
+
+{{flash_all_messages()}}
+
+
+
+
+
+{%endblock%}
diff --git a/qc_app/templates/rqtl2/select-probeset-study-id.html b/qc_app/templates/rqtl2/select-probeset-study-id.html
index 3bbb94a..23bbbf0 100644
--- a/qc_app/templates/rqtl2/select-probeset-study-id.html
+++ b/qc_app/templates/rqtl2/select-probeset-study-id.html
@@ -26,6 +26,7 @@
+