aboutsummaryrefslogtreecommitdiff
path: root/qc_app/dbinsert.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-07-08 07:32:58 +0300
committerFrederick Muriuki Muriithi2022-07-19 04:46:09 +0300
commit7a3a54ec40fac9071a513487602957f8418f163e (patch)
tree4acec2accb54bcb1c2f9c25c39d8f82c4b81be20 /qc_app/dbinsert.py
parenta21e759ac7a6b72a3d02814c2bfb26bc4f49204c (diff)
downloadgn-uploader-7a3a54ec40fac9071a513487602957f8418f163e.tar.gz
Select the platform (GeneChipId) first
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"