aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
Diffstat (limited to 'uploader')
-rw-r--r--uploader/population/models.py26
-rw-r--r--uploader/population/views.py17
-rw-r--r--uploader/templates/populations/create-population.html89
-rw-r--r--uploader/templates/populations/view-population.html13
4 files changed, 137 insertions, 8 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",
diff --git a/uploader/templates/populations/create-population.html b/uploader/templates/populations/create-population.html
index 6a96148..12811fd 100644
--- a/uploader/templates/populations/create-population.html
+++ b/uploader/templates/populations/create-population.html
@@ -88,8 +88,7 @@
<p>
This is a short representative, but constrained name for your
population.
- </p>
- <p>
+ <br />
The field will only accept letters ('A-Za-z'), numbers (0-9), hyphens
and underscores. Any other character will cause the name to be
rejected.
@@ -97,6 +96,20 @@
</small>
</div>
+ <div class="form-group">
+ <label for="txt-population-code" class="form-label">Population Code</label>
+ <input type="text"
+ id="txt-population-code"
+ name="population_code"
+ maxLength="5"
+ minLength="3"
+ value="{{error_values.population_code or ''}}"
+ class="form-control" />
+ <small class="form-text text-muted">
+ … document what this field is for …
+ </small>
+ </div>
+
<div {%if errors.population_description%}
class="form-group has-error"
{%else%}
@@ -119,14 +132,82 @@
This is a more detailed description for your population. This is
useful to communicate with other researchers some details regarding
your population, and what its about.
- </p>
- <p>
+ <br />
Put, here, anything that describes your population but does not go
cleanly under metadata.
</p>
</small>
</div>
+ <div {%if errors.population_family%}
+ class="form-group has-error"
+ {%else%}
+ class="form-group"
+ {%endif%}>
+ <label for="select-population-family" class="form-label">Family</label>
+ <select id="select-population-family"
+ name="population_family"
+ class="form-control"
+ required="required">
+ <option value="">Please select a family</option>
+ {%for family in families%}
+ <option value="{{family}}"
+ {%if error_values.population_family == family%}
+ selected="selected"
+ {%endif%}>{{family}}</option>
+ {%endfor%}
+ </select>
+ <small class="form-text text-muted">
+ <p>… provide some documentation on what this field does …</p>
+ </small>
+ </div>
+
+ <div {%if errors.population_mapping_method_id%}
+ class="form-group has-error"
+ {%else%}
+ class="form-group"
+ {%endif%}>
+ <label for="select-population-mapping-methods"
+ class="form-label">Mapping Methods</label>
+
+ <select id="select-population-mapping-methods"
+ name="population_mapping_method_id"
+ class="form-control"
+ required="required">
+ <option value="">Select appropriate mapping methods</option>
+ {%for mmethod in mapping_methods%}
+ <option value="{{mmethod.id}}"
+ {%if error_values.population_mapping_method_id == mmethod.id%}
+ selected="selected"
+ {%endif%}>{{mmethod.value}}</option>
+ {%endfor%}
+ </select>
+
+ <small class="form-text text-muted">
+ <p>Select the mapping methods that your population will support.</p>
+ </small>
+ </div>
+
+ <div {%if errors.population_genetic_type%}
+ class="form-group has-error"
+ {%else%}
+ class="form-group"
+ {%endif%}>
+ <label for="select-population-genetic-type"
+ class="form-label">Genetic Type</label>
+ <select id="select-population-genetic-type"
+ name="population_genetic_type"
+ class="form-control">
+ <option value="">Select proper genetic type</option>
+ {%for gtype in genetic_types%}
+ <option value="{{gtype}}"
+ {%if error_values.population_genetic_type == gtype%}
+ selected="selected"
+ {%endif%}>{{gtype}}</option>
+ {%endfor%}
+ </select>
+ </div>
+
<div class="form-group">
<input type="submit"
value="create population"
diff --git a/uploader/templates/populations/view-population.html b/uploader/templates/populations/view-population.html
index 7eb1362..3ae76ab 100644
--- a/uploader/templates/populations/view-population.html
+++ b/uploader/templates/populations/view-population.html
@@ -29,12 +29,25 @@
<dt>FullName</dt>
<dd>{{population.FullName}}</dd>
+ <dt>Code</dt>
+ <dd>{{population.InbredSetCode}}</dd>
+
+ <dt>Genetic Type</dt>
+ <dd>{{population.GeneticType}}</dd>
+
+ <dt>Family</dt>
+ <dd>{{population.Family}}</dd>
+
<dt>Description</dt>
<dd><pre>{{population.Description or "-"}}</pre></dd>
</dl>
</div>
<div class="row">
+ … maybe provide a way to organise populations in the same family here …
+</div>
+
+<div class="row">
<h3>Actions</h3>
<p>