diff options
author | Frederick Muriuki Muriithi | 2024-09-03 14:55:48 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-03 16:51:26 -0500 |
commit | 61688c00e8734adee4d825571a9c43d926dca001 (patch) | |
tree | 0a53c7eff5ec2bb1376be2eb2bdd2333c606ba11 /uploader/db | |
parent | 2876fe6251bd4dfceef06f638ee74c2728ad1207 (diff) | |
download | gn-uploader-61688c00e8734adee4d825571a9c43d926dca001.tar.gz |
Initialise the populations package and update references.
Diffstat (limited to 'uploader/db')
-rw-r--r-- | uploader/db/__init__.py | 6 | ||||
-rw-r--r-- | uploader/db/populations.py | 54 |
2 files changed, 0 insertions, 60 deletions
diff --git a/uploader/db/__init__.py b/uploader/db/__init__.py index 36e93e8..d2b1d9d 100644 --- a/uploader/db/__init__.py +++ b/uploader/db/__init__.py @@ -1,8 +1,2 @@ """Database functions""" -from .species import species, species_by_id -from .populations import ( - save_population, - population_by_id, - populations_by_species, - population_by_species_and_id) from .datasets import geno_datasets_by_species_and_population diff --git a/uploader/db/populations.py b/uploader/db/populations.py deleted file mode 100644 index 4485e52..0000000 --- a/uploader/db/populations.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Functions for accessing the database relating to species populations.""" -import MySQLdb as mdb -from MySQLdb.cursors import DictCursor - -def population_by_id(conn: mdb.Connection, population_id) -> dict: - """Get the grouping/population by id.""" - with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT * FROM InbredSet WHERE InbredSetId=%s", - (population_id,)) - return cursor.fetchone() - -def population_by_species_and_id( - conn: mdb.Connection, species_id, population_id) -> dict: - """Retrieve a population by its identifier and species.""" - with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute("SELECT * FROM InbredSet WHERE SpeciesId=%s AND Id=%s", - (species_id, population_id)) - return cursor.fetchone() - -def populations_by_species(conn: mdb.Connection, speciesid) -> tuple: - "Retrieve group (InbredSet) information from the database." - with conn.cursor(cursorclass=DictCursor) as cursor: - query = "SELECT * FROM InbredSet WHERE SpeciesId=%s" - cursor.execute(query, (speciesid,)) - return tuple(cursor.fetchall()) - - return tuple() - -def save_population(conn: mdb.Connection, population_details: dict) -> dict: - """Save the population details to the db.""" - with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute( - "INSERT INTO InbredSet(" - "InbredSetId, InbredSetName, Name, SpeciesId, FullName, " - "MenuOrderId, Description" - ") " - "VALUES (" - "%(InbredSetId)s, %(InbredSetName)s, %(Name)s, %(SpeciesId)s, " - "%(FullName)s, %(MenuOrderId)s, %(Description)s" - ")", - { - "MenuOrderId": 0, - "InbredSetId": 0, - **population_details - }) - new_id = cursor.lastrowid - cursor.execute("UPDATE InbredSet SET InbredSetId=%s WHERE Id=%s", - (new_id, new_id)) - return { - **population_details, - "Id": new_id, - "InbredSetId": new_id, - "population_id": new_id - } |