diff options
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, |
