aboutsummaryrefslogtreecommitdiff
path: root/uploader/population
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-24 09:48:46 -0500
committerFrederick Muriuki Muriithi2024-09-24 09:48:46 -0500
commitf5d34ea1e30daaabb5ab49735bec4353777c94d9 (patch)
tree1120babb6112adc576ab6e630abb73ef777dfe7c /uploader/population
parent500e743b7de841be6286735a19e2f9793ebfaa24 (diff)
downloadgn-uploader-f5d34ea1e30daaabb5ab49735bec4353777c94d9.tar.gz
Handle FamilyOrder when creating a population.
Diffstat (limited to 'uploader/population')
-rw-r--r--uploader/population/models.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/uploader/population/models.py b/uploader/population/models.py
index c6c77ae..6dcd85e 100644
--- a/uploader/population/models.py
+++ b/uploader/population/models.py
@@ -46,29 +46,41 @@ def population_genetic_types(conn) -> tuple:
def save_population(cursor: mdb.cursors.Cursor, population_details: dict) -> dict:
"""Save the population details to the db."""
- #TODO: Handle FamilyOrder here
+ cursor.execute("SELECT DISTINCT(Family), FamilyOrder FROM InbredSet "
+ "WHERE Family IS NOT NULL AND Family != '' "
+ "AND FamilyOrder IS NOT NULL "
+ "ORDER BY FamilyOrder ASC")
+ _families = {
+ row["Family"]: int(row["FamilyOrder"])
+ for row in cursor.fetchall()
+ }
+ params = {
+ "MenuOrderId": 0,
+ "InbredSetId": 0,
+ "public": 2,
+ **population_details,
+ "FamilyOrder": _families.get(
+ population_details["Family"],
+ max(_families.values())+1)
+ }
cursor.execute(
"INSERT INTO InbredSet("
"InbredSetId, InbredSetName, Name, SpeciesId, FullName, "
- "public, MappingMethodId, GeneticType, Family, MenuOrderId, "
- "InbredSetCode, Description"
+ "public, MappingMethodId, GeneticType, Family, FamilyOrder,"
+ " MenuOrderId, InbredSetCode, Description"
") "
"VALUES ("
"%(InbredSetId)s, %(InbredSetName)s, %(Name)s, %(SpeciesId)s, "
"%(FullName)s, %(public)s, %(MappingMethodId)s, %(GeneticType)s, "
- "%(Family)s, %(MenuOrderId)s, %(InbredSetCode)s, %(Description)s"
+ "%(Family)s, %(FamilyOrder)s, %(MenuOrderId)s, %(InbredSetCode)s, "
+ "%(Description)s"
")",
- {
- "MenuOrderId": 0,
- "InbredSetId": 0,
- "public": 2,
- **population_details
- })
+ params)
new_id = cursor.lastrowid
cursor.execute("UPDATE InbredSet SET InbredSetId=%s WHERE Id=%s",
(new_id, new_id))
return {
- **population_details,
+ **params,
"Id": new_id,
"InbredSetId": new_id,
"population_id": new_id