aboutsummaryrefslogtreecommitdiff
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
parenta21e759ac7a6b72a3d02814c2bfb26bc4f49204c (diff)
downloadgn-uploader-7a3a54ec40fac9071a513487602957f8418f163e.tar.gz
Select the platform (GeneChipId) first
-rw-r--r--qc_app/dbinsert.py49
-rw-r--r--qc_app/static/js/select_platform.js59
-rw-r--r--qc_app/static/js/utils.js10
-rw-r--r--qc_app/templates/parse_results.html2
-rw-r--r--qc_app/templates/select_platform.html72
5 files changed, 183 insertions, 9 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"
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 %}
-<form method="post" action="{{url_for('dbinsert.select_dataset')}}">
+<form method="post" action="{{url_for('dbinsert.select_platform')}}">
<input type="hidden" name="job_id" value="{{job_id}}" />
<input type="submit" value="update database" class="btn btn-main" />
</form>
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%}
+<h1 class="heading">{{filename}}: select platform</h2>
+
+<form method="POST" action="{{url_for('dbinsert.select_study')}}"
+ id="select-platform-form" data-genechips="{{genechips_data}}">
+ <input type="hidden" name="filename" value="{{filename}}" />
+ <input type="hidden" name="filetype" value="{{filetype}}" />
+
+ <fieldset>
+ <label for="species" class="form-col-1">species</label>
+ <select id="species" name="species" class="form-col-2">
+ {%for row in species:%}
+ <option value="{{row['SpeciesId']}}"
+ {%if row["Name"] == default_species:%}
+ selected="selected"
+ {%endif%}>
+ {{row["MenuName"]}}
+ </option>
+ {%endfor%}
+ </select>
+ </fieldset>
+
+ <table id="genechips-table">
+ <thead>
+ <tr>
+ <th>Select</th>
+ <th>GeneChip Name</th>
+ <th>Name</th>
+ <th>GeoPlatform</th>
+ <th>GO Tree Value</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {%for chip in genechips:%}
+ <tr>
+ <td>
+ <input type="radio" name="genechipid" value="{{chip['GeneChipId']}}"
+ required="required" />
+ </td>
+ <td>{{chip["GeneChipName"]}}</td>
+ <td>{{chip["Name"]}}</td>
+ <td>{{chip["GeoPlatform"]}}</td>
+ <td>{{chip["GO_tree_value"]}}</td>
+ </tr>
+ {%else%}
+ <tr>
+ <td colspan="5">No chips found for selected species</td>
+ </tr>
+ {%endfor%}
+ </tbody>
+ </table>
+
+ <fieldset>
+ <input type="submit" class="btn btn-main form-col-2"
+ value="submit platform" />
+ </fieldset>
+</form>
+{%endblock%}
+
+{%block javascript%}
+<script type="text/javascript" src="/static/js/utils.js"></script>
+<script type="text/javascript" src="/static/js/select_platform.js"></script>
+<script type="text/javascript">
+ document.getElementById(
+ "species").addEventListener("change", update_genechips);
+</script>
+{%endblock%}