From 27eec3300eddbc17214b3ff3ffbd8bea867db401 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 20 Sep 2024 16:10:50 -0500 Subject: Initialise UI for managing genotype datasets. --- uploader/genotypes/models.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'uploader/genotypes/models.py') diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index 29acd0b..1fe5929 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -44,19 +44,26 @@ def genotype_markers( def genotype_dataset( conn: mdb.Connection, species_id: int, - population_id: int + population_id: int, + dataset_id: Optional[int] = None ) -> Optional[dict]: """Retrieve genotype datasets from the database. Apparently, you should only ever have one genotype dataset for a population. """ + _query = ( + "SELECT gf.* FROM Species AS s INNER JOIN InbredSet AS iset " + "ON s.Id=iset.SpeciesId INNER JOIN GenoFreeze AS gf " + "ON iset.Id=gf.InbredSetId " + "WHERE s.Id=%s AND iset.Id=%s") + _params = (species_id, population_id) + if bool(dataset_id): + _query = _query + " AND gf.Id=%s" + _params = _params + (dataset_id,) + with conn.cursor(cursorclass=DictCursor) as cursor: - cursor.execute( - "SELECT gf.* FROM Species AS s INNER JOIN InbredSet AS iset " - "ON s.Id=iset.SpeciesId INNER JOIN GenoFreeze AS gf " - "ON iset.Id=gf.InbredSetId " - "WHERE s.Id=%s AND iset.Id=%s", - (species_id, population_id)) + cursor.execute(_query, _params) + debug_query(cursor) result = cursor.fetchone() if bool(result): return dict(result) -- cgit v1.2.3