aboutsummaryrefslogtreecommitdiff
path: root/uploader/population
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-06 16:38:04 -0500
committerFrederick Muriuki Muriithi2024-09-06 16:38:04 -0500
commitb74911f15a9f9a9ff3cca0e25fcd761bf41652b5 (patch)
tree9f17ca43a8da7e7bcaf7a2990f32e5e792d629be /uploader/population
parente13a694540ee65f401652d9ebdb5f845c15fb97e (diff)
downloadgn-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')
-rw-r--r--uploader/population/models.py26
-rw-r--r--uploader/population/views.py17
2 files changed, 39 insertions, 4 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
diff --git a/uploader/population/views.py b/uploader/population/views.py
index 84dffdb..5be19ae 100644
--- a/uploader/population/views.py
+++ b/uploader/population/views.py
@@ -18,7 +18,9 @@ from uploader.species.models import (all_species,
order_species_by_family)
from .models import (save_population,
+ population_families,
populations_by_species,
+ population_genetic_types,
population_by_species_and_id)
__active_link__ = "populations"
@@ -100,6 +102,14 @@ def create_population(species_id: int):
return render_template(
"populations/create-population.html",
species=species,
+ families = population_families(conn),
+ genetic_types = population_genetic_types(conn),
+ mapping_methods=(
+ {"id": "0", "value": "No mapping support"},
+ {"id": "1", "value": "GEMMA, QTLReaper, R/qtl"},
+ {"id": "2", "value": "GEMMA"},
+ {"id": "3", "value": "R/qtl"},
+ {"id": "4", "value": "GEMMA, PLINK"}),
activelink="create-population",
**error_values)
@@ -142,8 +152,11 @@ def create_population(species_id: int):
"Name": population_name,
"InbredSetName": population_fullname,
"FullName": population_fullname,
- "Family": request.form.get("inbredset_family") or None,
- "Description": request.form.get("population_description") or None
+ "InbredSetCode": request.form.get("population_code") or None,
+ "Description": request.form.get("population_description") or None,
+ "Family": request.form.get("population_family") or None,
+ "MappingMethodId": request.form.get("population_mapping_method_id"),
+ "GeneticType": request.form.get("population_genetic_type") or None
})
return redirect(url_for("species.populations.view_population",