about summary refs log tree commit diff
path: root/uploader/population/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/population/models.py')
-rw-r--r--uploader/population/models.py26
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