aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--scripts/insert_samples.py3
5 files changed, 29 insertions, 15 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(
diff --git a/scripts/insert_samples.py b/scripts/insert_samples.py
index 6b6faf1..8431462 100644
--- a/scripts/insert_samples.py
+++ b/scripts/insert_samples.py
@@ -9,9 +9,8 @@ from redis import Redis
from qc_app.db_utils import database_connection
from qc_app.check_connections import check_db, check_redis
+from qc_app.db import species_by_id, population_by_id
from qc_app.samples import (
- species_by_id,
- population_by_id,
save_samples_data,
read_samples_file,
cross_reference_samples)