diff options
author | Frederick Muriuki Muriithi | 2024-09-26 16:02:12 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-26 17:02:58 -0500 |
commit | d3122c73497650d7165afb8fc6c75f2650ef956c (patch) | |
tree | a395dcb34dbc54892f213cbeb9659c7c1765b730 /uploader/phenotypes/models.py | |
parent | e9c343766ac9ca5831b223960941a5fe8d837e30 (diff) | |
download | gn-uploader-d3122c73497650d7165afb8fc6c75f2650ef956c.tar.gz |
List the phenotype datasets.
Diffstat (limited to 'uploader/phenotypes/models.py')
-rw-r--r-- | uploader/phenotypes/models.py | 22 |
1 files changed, 22 insertions, 0 deletions
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()) |