aboutsummaryrefslogtreecommitdiff
path: root/qc_app/upload/rqtl2.py
blob: 06edfee1a241ccaefb787c466f6db4d575829680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Module to handle uploading of R/qtl2 bundles."""

from flask import (
    flash,
    request,
    url_for,
    redirect,
    Blueprint,
    render_template)

from qc_app.dbinsert import species as all_species
from qc_app.dbinsert import species_by_id, groups_by_species
from qc_app.db_utils import with_db_connection

rqtl2 = Blueprint("rqtl2", __name__)

@rqtl2.route("/", methods=["GET", "POST"])
@rqtl2.route("/select-species", methods=["POST"])
def select_species():
    """Select the species."""
    if request.method == "GET":
        return render_template("rqtl2/index.html", species=all_species())

    species_id = request.form.get("species_id")
    species = with_db_connection(
        lambda conn: species_by_id(conn, species_id))
    if bool(species):
        return redirect(url_for(
            "upload.rqtl2.select_population", species_id=species_id))
    flash("Invalid species or no species selected!", "alert-error error-rqtl2")
    return redirect(url_for("upload.rqtl2.select_species"))

@rqtl2.route("/upload/species/<int:species_id>/select-population",
             methods=["GET", "POST"])
def select_population(species_id: int):
    """Select/Create the population to organise data under."""
    species = with_db_connection(lambda conn: species_by_id(conn, species_id))
    if not bool(species):
        flash("Invalid species selected!", "alert-error error-rqtl2")
        return redirect(url_for("upload.rqtl2.select_species"))

    if request.method == "GET":
        return render_template(
            "rqtl2/select-population.html",
            species=species,
            populations=groups_by_species(species_id))

    return "WOULD PROCESS DATA"