diff options
author | Frederick Muriuki Muriithi | 2024-09-25 12:09:46 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-25 12:11:58 -0500 |
commit | 3e028bf0e9f8239b552bcd4b2d6133bb7965abd9 (patch) | |
tree | 9a58c1b95748c99c04bec5e5f34d70f7070af287 /uploader/genotypes/models.py | |
parent | 44a07c95a3ae77441e1b45b9f5fba9c6d77a2871 (diff) | |
download | gn-uploader-3e028bf0e9f8239b552bcd4b2d6133bb7965abd9.tar.gz |
Create new genotype datasets.
Diffstat (limited to 'uploader/genotypes/models.py')
-rw-r--r-- | uploader/genotypes/models.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index db8cc3e..44c98b1 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -1,8 +1,9 @@ """Functions for handling genotypes.""" from typing import Optional +from datetime import datetime import MySQLdb as mdb -from MySQLdb.cursors import DictCursor +from MySQLdb.cursors import Cursor, DictCursor from uploader.db_utils import debug_query @@ -68,3 +69,33 @@ def genotype_dataset( if bool(result): return dict(result) return None + + +def save_new_dataset( + cursor: Cursor, + population_id: int, + name: str, + fullname: str, + shortname: str +) -> dict: + """Save a new genotype dataset into the database.""" + params = { + "InbredSetId": population_id, + "Name": name, + "FullName": fullname, + "ShortName": shortname, + "CreateTime": datetime.now().date().isoformat(), + "public": 2, + "confidentiality": 0, + "AuthorisedUsers": None + } + cursor.execute( + "INSERT INTO GenoFreeze(" + "Name, FullName, ShortName, CreateTime, public, InbredSetId, " + "confidentiality, AuthorisedUsers" + ") VALUES (" + "%(Name)s, %(FullName)s, %(ShortName)s, %(CreateTime)s, %(public)s, " + "%(InbredSetId)s, %(confidentiality)s, %(AuthorisedUsers)s" + ")", + params) + return {**params, "Id": cursor.lastrowid} |