From d3122c73497650d7165afb8fc6c75f2650ef956c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 26 Sep 2024 16:02:12 -0500 Subject: List the phenotype datasets. --- uploader/phenotypes/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 uploader/phenotypes/models.py (limited to 'uploader/phenotypes/models.py') diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py new file mode 100644 index 0000000..1f72dbd --- /dev/null +++ b/uploader/phenotypes/models.py @@ -0,0 +1,22 @@ +"""Database and utility functions for phenotypes.""" +from typing import Optional + +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +from uploader.db_utils import debug_query + +def datasets_by_population( + conn: mdb.Connection, + species_id: int, + population_id: int +) -> tuple[dict, ...]: + """Retrieve all of a population's phenotype studies.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT s.SpeciesId, pf.* FROM Species AS s " + "INNER JOIN InbredSet AS iset ON s.Id=iset.SpeciesId " + "INNER JOIN PublishFreeze AS pf ON iset.Id=pf.InbredSetId " + "WHERE s.Id=%s AND iset.Id=%s;", + (species_id, population_id)) + return tuple(dict(row) for row in cursor.fetchall()) -- cgit v1.2.3