diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 11:24:51 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-01 12:38:06 -0500 |
| commit | 76a840ea6535b75e094e4bc5bb8d86bb7b244c48 (patch) | |
| tree | 420fa09cd02c5d317f041f446b6f20be993d591c /uploader/genotypes/models.py | |
| parent | e0f15dc9352a588bdab0a7bdcc848efce696690a (diff) | |
| download | gn-uploader-76a840ea6535b75e094e4bc5bb8d86bb7b244c48.tar.gz | |
Fetch genotype dataset by species and population only.
Diffstat (limited to 'uploader/genotypes/models.py')
| -rw-r--r-- | uploader/genotypes/models.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index 92ac76c..f3e6798 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -9,7 +9,7 @@ from MySQLdb.cursors import Cursor, DictCursor from gn_libs.mysqldb import debug_query -from uploader.dataerrors import NotFoundError +from uploader.dataerrors import NotFoundError, TooManyResultsError logger = logging.getLogger(__name__) @@ -133,6 +133,28 @@ def genotype_records( _num_records) +def genotype_dataset_by_population( + conn: mdb.Connection, + species_id: int, + population_id: int +) -> dict: + """Retrieve all of a population's phenotype studies.""" + 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)) + result = cursor.fetchall() + if bool(result): + if len(result) == 1: + return dict(result[0]) + raise TooManyResultsError( + f"Expected only a single dataset. Got {len(result)}") + raise NotFoundError("Could not find dataset.") + + def genotype_dataset( conn: mdb.Connection, species_id: int, |
