From 7a3a54ec40fac9071a513487602957f8418f163e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 8 Jul 2022 07:32:58 +0300 Subject: Select the platform (GeneChipId) first --- qc_app/dbinsert.py | 49 ++++++++++++++++++++---- qc_app/static/js/select_platform.js | 59 ++++++++++++++++++++++++++++ qc_app/static/js/utils.js | 10 +++++ qc_app/templates/parse_results.html | 2 +- qc_app/templates/select_platform.html | 72 +++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 9 deletions(-) create mode 100644 qc_app/static/js/select_platform.js create mode 100644 qc_app/static/js/utils.js create mode 100644 qc_app/templates/select_platform.html (limited to 'qc_app') 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" diff --git a/qc_app/static/js/select_platform.js b/qc_app/static/js/select_platform.js new file mode 100644 index 0000000..d7541fa --- /dev/null +++ b/qc_app/static/js/select_platform.js @@ -0,0 +1,59 @@ +function radio_column(chip) { + col = document.createElement("td"); + radio = document.createElement("input"); + radio.setAttribute("type", "radio"); + radio.setAttribute("name", "genechipid"); + radio.setAttribute("value", chip["GeneChipId"]); + radio.setAttribute("required", "required"); + col.appendChild(radio); + return col; +} + +function setup_genechips(genechip_data) { + columns = ["GeneChipName", "Name", "GeoPlatform", "GO_tree_value"] + submit_button = document.querySelector( + "#select-platform-form input[type='submit']"); + elt = document.getElementById( + "genechips-table").getElementsByTagName("tbody")[0]; + remove_children(elt); + if((genechip_data === undefined) || genechip_data.length === 0) { + row = document.createElement("tr"); + col = document.createElement("td"); + col.setAttribute("colspan", "5"); + text = document.createTextNode("No chips found for selected species"); + col.appendChild(text); + row.appendChild(col); + elt.appendChild(row); + submit_button.setAttribute("disabled", true); + return false; + } + + submit_button.removeAttribute("disabled") + genechip_data.forEach(chip => { + row = document.createElement("tr"); + row.appendChild(radio_column(chip)); + columns.forEach(column => { + col = document.createElement("td"); + content = document.createTextNode(chip[column]); + col.appendChild(content); + row.appendChild(col); + }); + elt.appendChild(row); + }); +} + +function genechips() { + return JSON.parse( + document.getElementById("select-platform-form").getAttribute( + "data-genechips")); +} + +function update_genechips(event) { + genec = genechips(); + + species_elt = document.getElementById("species"); + + if(event.target == species_elt) { + setup_genechips(genec[species_elt.value.toLowerCase()]); + } +} diff --git a/qc_app/static/js/utils.js b/qc_app/static/js/utils.js new file mode 100644 index 0000000..045dd47 --- /dev/null +++ b/qc_app/static/js/utils.js @@ -0,0 +1,10 @@ +function remove_children(element) { + Array.from(element.children).forEach(child => { + element.removeChild(child); + }); +} + +function trigger_change_event(element) { + evt = new Event("change"); + element.dispatchEvent(evt); +} diff --git a/qc_app/templates/parse_results.html b/qc_app/templates/parse_results.html index 1a224e8..80d6a2d 100644 --- a/qc_app/templates/parse_results.html +++ b/qc_app/templates/parse_results.html @@ -13,7 +13,7 @@ {{errors_display(errors, "No errors found in the file", "We found the following errors")}} {%if errors | length == 0 %} -
+
diff --git a/qc_app/templates/select_platform.html b/qc_app/templates/select_platform.html new file mode 100644 index 0000000..f8db736 --- /dev/null +++ b/qc_app/templates/select_platform.html @@ -0,0 +1,72 @@ +{%extends "base.html"%} + +{%block title%}Select Dataset{%endblock%} + +{%block contents%} +

{{filename}}: select platform

+ +
+ + + +
+ + +
+ + + + + + + + + + + + + + {%for chip in genechips:%} + + + + + + + + {%else%} + + + + {%endfor%} + +
SelectGeneChip NameNameGeoPlatformGO Tree Value
+ + {{chip["GeneChipName"]}}{{chip["Name"]}}{{chip["GeoPlatform"]}}{{chip["GO_tree_value"]}}
No chips found for selected species
+ +
+ +
+
+{%endblock%} + +{%block javascript%} + + + +{%endblock%} -- cgit v1.2.3