diff options
author | Frederick Muriuki Muriithi | 2024-09-06 16:38:04 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-06 16:38:04 -0500 |
commit | b74911f15a9f9a9ff3cca0e25fcd761bf41652b5 (patch) | |
tree | 9f17ca43a8da7e7bcaf7a2990f32e5e792d629be /uploader/population/models.py | |
parent | e13a694540ee65f401652d9ebdb5f845c15fb97e (diff) | |
download | gn-uploader-b74911f15a9f9a9ff3cca0e25fcd761bf41652b5.tar.gz |
Add more fields when creating a population
Add more of the missing fields when creating a population, to ensure
that the created population works as expected.
Diffstat (limited to 'uploader/population/models.py')
-rw-r--r-- | uploader/population/models.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/uploader/population/models.py b/uploader/population/models.py index 4485e52..782bc9f 100644 --- a/uploader/population/models.py +++ b/uploader/population/models.py @@ -26,21 +26,43 @@ def populations_by_species(conn: mdb.Connection, speciesid) -> tuple: return tuple() + +def population_families(conn) -> tuple: + """Fetch the families under which populations are grouped.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT DISTINCT(Family) FROM InbredSet WHERE Family IS NOT NULL") + return tuple(row["Family"] for row in cursor.fetchall()) + + +def population_genetic_types(conn) -> tuple: + """Fetch the families under which populations are grouped.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT DISTINCT(GeneticType) FROM InbredSet WHERE GeneticType IS " + "NOT NULL") + return tuple(row["GeneticType"] for row in cursor.fetchall()) + + def save_population(conn: mdb.Connection, population_details: dict) -> dict: """Save the population details to the db.""" with conn.cursor(cursorclass=DictCursor) as cursor: + #TODO: Handle FamilyOrder here cursor.execute( "INSERT INTO InbredSet(" "InbredSetId, InbredSetName, Name, SpeciesId, FullName, " - "MenuOrderId, Description" + "public, MappingMethodId, GeneticType, Family, MenuOrderId, " + "InbredSetCode, Description" ") " "VALUES (" "%(InbredSetId)s, %(InbredSetName)s, %(Name)s, %(SpeciesId)s, " - "%(FullName)s, %(MenuOrderId)s, %(Description)s" + "%(FullName)s, %(public)s, %(MappingMethodId)s, %(GeneticType)s, " + "%(Family)s, %(MenuOrderId)s, %(InbredSetCode)s, %(Description)s" ")", { "MenuOrderId": 0, "InbredSetId": 0, + "public": 2, **population_details }) new_id = cursor.lastrowid |