aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-08 05:50:24 +0300
committerFrederick Muriuki Muriithi2024-01-08 05:52:07 +0300
commit951c3c2fd343eec4b3743ac313ad6ce49082dda3 (patch)
treeb215b0b79b1bea5e8a51bd9d37033ed0b47a5fa8 /qc_app
parentcace7a50a45c6d227bce52569fcfc2944fbcbe92 (diff)
downloadgn-uploader-951c3c2fd343eec4b3743ac313ad6ce49082dda3.tar.gz
Use extracted functions and fix bugs
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/dbinsert.py14
-rw-r--r--qc_app/entry.py12
-rw-r--r--qc_app/samples.py13
-rw-r--r--qc_app/upload/rqtl2.py2
4 files changed, 28 insertions, 13 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 881c913..a878ff5 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -11,8 +11,10 @@ from flask import (
flash, request, url_for, Blueprint, redirect, render_template,
current_app as app)
+from qc_app.db_utils import with_db_connection, database_connection
+from qc_app.db import species, species_by_id, populations_by_species
+
from . import jobs
-from .db_utils import with_db_connection, database_connection
dbinsertbp = Blueprint("dbinsert", __name__)
@@ -91,7 +93,8 @@ def tissues() -> tuple:
def select_platform():
"Select the platform (GeneChipId) used for the data."
job_id = request.form["job_id"]
- with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn:
+ with (Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn,
+ database_connection(app.config["SQL_URI"]) as conn):
job = jobs.job(rconn, job_id)
if job:
filename = job["filename"]
@@ -102,7 +105,7 @@ def select_platform():
return render_template(
"select_platform.html", filename=filename,
filetype=job["filetype"], totallines=int(job["currentline"]),
- default_species=default_species, species=species(),
+ default_species=default_species, species=species(conn),
genechips=gchips[default_species],
genechips_data=json.dumps(gchips))
return render_error(f"File '{filename}' no longer exists.")
@@ -124,7 +127,10 @@ def select_study():
the_studies = studies_by_species_and_platform(speciesid, genechipid)
the_groups = reduce(
- organise_groups_by_family, groups_by_species(speciesid), {})
+ organise_groups_by_family,
+ with_db_connection(
+ lambda conn: populations_by_species(conn, speciesid)),
+ {})
return render_template(
"select_study.html", filename=form["filename"],
filetype=form["filetype"], totallines=form["totallines"],
diff --git a/qc_app/entry.py b/qc_app/entry.py
index bf78037..0cd34c5 100644
--- a/qc_app/entry.py
+++ b/qc_app/entry.py
@@ -14,7 +14,8 @@ from flask import (
render_template,
current_app as app)
-from .dbinsert import species
+from qc_app.db import species
+from qc_app.db_utils import with_db_connection
entrybp = Blueprint("entry", __name__)
@@ -78,14 +79,16 @@ def zip_file_errors(filepath, upload_dir) -> Tuple[str, ...]:
def upload_file():
"""Enables uploading the files"""
if request.method == "GET":
- return render_template("index.html", species = species())
+ return render_template(
+ "index.html", species=with_db_connection(species))
upload_dir = app.config["UPLOAD_FOLDER"]
request_errors = errors(request)
if request_errors:
for error in request_errors:
flash(error, "alert-error")
- return render_template("index.html", species = species()), 400
+ return render_template(
+ "index.html", species=with_db_connection(species)), 400
filename = secure_filename(request.files["qc_text_file"].filename)
if not os.path.exists(upload_dir):
@@ -98,7 +101,8 @@ def upload_file():
if zip_errors:
for error in zip_errors:
flash(error, "alert-error")
- return render_template("index.html", species = species()), 400
+ return render_template(
+ "index.html", species=with_db_connection(species)), 400
return redirect(url_for(
"parse.parse", filename=filename,
diff --git a/qc_app/samples.py b/qc_app/samples.py
index 107e889..8f56ee1 100644
--- a/qc_app/samples.py
+++ b/qc_app/samples.py
@@ -22,11 +22,15 @@ from quality_control.parsing import take
from qc_app import jobs
from qc_app.files import save_file
-from qc_app.dbinsert import species_by_id, groups_by_species
from qc_app.db_utils import (
with_db_connection,
database_connection,
with_redis_connection)
+from qc_app.db import (
+ species_by_id,
+ save_population,
+ population_by_id,
+ populations_by_species)
samples = Blueprint("samples", __name__)
@@ -43,7 +47,8 @@ def select_species():
return render_template(
"samples/select-population.html",
species=species,
- populations=groups_by_species(species_id))
+ populations=with_db_connection(
+ lambda conn: populations_by_species(conn, species_id)))
flash("Invalid species selected!", "alert-error")
flash("You need to select a species", "alert-error")
return index_page
@@ -65,7 +70,7 @@ def create_population():
"alert-error error-create-population")
return species_page
- pop_id = save_population(conn, {
+ pop = save_population(conn, {
"SpeciesId": species["SpeciesId"],
"Name": pop_name,
"InbredSetName": pop_fullname,
@@ -79,7 +84,7 @@ def create_population():
"samples/upload-samples.html",
species=species,
population=with_db_connection(
- lambda conn: population_by_id(conn, pop_id)))
+ lambda conn: population_by_id(conn, pop["population_id"])))
@samples.route("/upload/select-population", methods=["POST"])
def select_population():
diff --git a/qc_app/upload/rqtl2.py b/qc_app/upload/rqtl2.py
index 06edfee..aabcea9 100644
--- a/qc_app/upload/rqtl2.py
+++ b/qc_app/upload/rqtl2.py
@@ -19,7 +19,7 @@ rqtl2 = Blueprint("rqtl2", __name__)
def select_species():
"""Select the species."""
if request.method == "GET":
- return render_template("rqtl2/index.html", species=all_species())
+ return render_template("rqtl2/index.html", species=with_db_connection(all_species))
species_id = request.form.get("species_id")
species = with_db_connection(