aboutsummaryrefslogtreecommitdiff
path: root/qc_app/dbinsert.py
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app/dbinsert.py')
-rw-r--r--qc_app/dbinsert.py49
1 files changed, 41 insertions, 8 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 09dd3e1..ea47806 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -27,24 +27,57 @@ def make_menu_items_grouper(grouping_fn=lambda item: item):
return {**acc, grouping: (acc[grouping] + (row_values,))}
return __grouper__
+def species() -> tuple:
+ "Retrieve the species from the database."
+ with database_connection() as conn:
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(
+ "SELECT SpeciesId, SpeciesName, LOWER(Name) AS Name, MenuName "
+ "FROM Species")
+ return tuple(cursor.fetchall())
+
+ return tuple()
+
def genechips():
"Retrieve the genechip information from the database"
def __organise_by_species__(acc, chip):
- species = chip["species_name"]
- if acc.get(species) is None:
- return {**acc, species: (chip,)}
- return {**acc, species: acc[species] + (chip,)}
+ speciesid = chip["SpeciesId"]
+ if acc.get(speciesid) is None:
+ return {**acc, speciesid: (chip,)}
+ return {**acc, species: acc[speciesid] + (chip,)}
with database_connection() as conn:
with conn.cursor(cursorclass=DictCursor) as cursor:
- cursor.execute(
- "SELECT GeneChip.*, LOWER(Species.Name) AS species_name "
- "FROM GeneChip INNER JOIN Species "
- "ON GeneChip.SpeciesId=Species.SpeciesId")
+ cursor.execute("SELECT * FROM GeneChip ORDER BY GeneChipName ASC")
return reduce(__organise_by_species__, cursor.fetchall(), {})
return {}
+@dbinsertbp.route("/platform", methods=["POST"])
+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:
+ job = jobs.job(rconn, job_id)
+ if job:
+ filename = job["filename"]
+ filepath = f"{app.config['UPLOAD_FOLDER']}/{filename}"
+ if os.path.exists(filepath):
+ default_species = 1
+ gchips = genechips()
+ return render_template(
+ "select_platform.html", filename=filename,
+ filetype=job["filetype"], default_species=default_species,
+ species=species(), genechips=gchips[default_species],
+ genechips_data=json.dumps(gchips))
+ return render_error(f"File '{filename}' no longer exists.")
+ return render_error(f"Job '{job_id}' no longer exists.")
+ return render_error("Unknown error")
+
+@dbinsertbp.route("/study", methods=["POST"])
+def select_study():
+ return "Not implemented yet"
+
@dbinsertbp.route("/select-dataset", methods=["POST"])
def select_dataset():
"Select the dataset to add the file contents against"