aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/dbinsert.py22
-rw-r--r--qc_app/static/js/dbinsert.js156
-rw-r--r--qc_app/templates/dbupdate_hidden_fields.html9
-rw-r--r--qc_app/templates/select_dataset.html168
-rw-r--r--qc_app/templates/select_study.html2
5 files changed, 98 insertions, 259 deletions
diff --git a/qc_app/dbinsert.py b/qc_app/dbinsert.py
index 4fbd0d3..523152d 100644
--- a/qc_app/dbinsert.py
+++ b/qc_app/dbinsert.py
@@ -177,6 +177,17 @@ def create_study():
flash(f"Missing data: {aserr.args[0]}", "alert-error")
return redirect(url_for("dbinsert.select_study"), code=307)
+def datasets_by_study(studyid:int) -> tuple:
+ "Retrieve datasets associated with a study with the ID `studyid`."
+ with database_connection() as conn:
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ query = "SELECT * FROM ProbeSetFreeze WHERE ProbeFreezeId=%s"
+ print(f"QUERY: {query}\n\tPARAMS: ({studyid},)")
+ cursor.execute(query, (studyid,))
+ return tuple(cursor.fetchall())
+
+ return tuple()
+
@dbinsertbp.route("/dataset", methods=["POST"])
def select_dataset():
"Select the dataset to add the file contents against"
@@ -186,15 +197,14 @@ def select_dataset():
assert form.get("filetype"), "filetype"
assert form.get("species"), "species"
assert form.get("genechipid"), "platform"
- assert (form.get("studyid") or form.get(studyname)), ""
- assert form.get(""), ""
- assert form.get(""), ""
- assert form.get(""), ""
- assert form.get(""), ""
+ assert (form.get("studyid") or request.args.get("studyid")), "study"
+ studyid=(form.get("studyid") or request.args.get("studyid"))
+ datasets = datasets_by_study(studyid)
return render_template(
"select_dataset.html", filename=form["filename"],
- filetype=form["filetype"], species=speciesid, genechipid=genechipid)
+ filetype=form["filetype"], species=form["species"],
+ genechipid=form["genechipid"], studyid=studyid, datasets=datasets)
except AssertionError as aserr:
return render_error(f"Missing data: {aserr.args[0]}")
diff --git a/qc_app/static/js/dbinsert.js b/qc_app/static/js/dbinsert.js
deleted file mode 100644
index 63d2c86..0000000
--- a/qc_app/static/js/dbinsert.js
+++ /dev/null
@@ -1,156 +0,0 @@
-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);
-}
-
-function setup_groups(group_data) {
- elt = document.getElementById("group");
- remove_children(elt);
- the_groups = group_data.reduce(
- function(acc, row) {
- grouping = row[2].slice(7).trim();
- if(acc[grouping] === undefined) {
- acc[grouping] = [];
- }
- acc[grouping].push([row[0], row[1]]);
- return acc;
- },
- {});
- for(grouping in the_groups) {
- optgrp = document.createElement("optgroup");
- optgrp.setAttribute("label", grouping);
- the_groups[grouping].forEach(group => {
- opt = document.createElement("option");
- opt.setAttribute("value", group[0]);
- opt.appendChild(document.createTextNode(group[1]));
- optgrp.appendChild(opt);
- });
- elt.appendChild(optgrp);
- }
- trigger_change_event(elt);
-}
-
-function setup_types(type_data) {
- elt = document.getElementById("type");
- remove_children(elt);
- the_types = type_data.reduce(function(acc, row) {
- grp = row[2];
- if(acc[grp] === undefined) {
- acc[grp] = [];
- }
- acc[grp].push([row[0], row[1]]);
- return acc;
- }, {});
- for(type_group in the_types) {
- optgrp = document.createElement("optgroup");
- optgrp.setAttribute("label", type_group);
- the_types[type_group].forEach(type => {
- opt = document.createElement("option");
- opt.setAttribute("value", type[0]);
- opt.appendChild(document.createTextNode(type[1]));
- optgrp.appendChild(opt);
- });
- elt.appendChild(optgrp);
- }
- trigger_change_event(elt);
-}
-
-function setup_datasets(dataset_data) {
- elt = document.getElementById("dataset");
- remove_children(elt);
- dataset_data.forEach(dataset => {
- opt = document.createElement("option");
- opt.setAttribute("value", dataset[0]);
- opt.appendChild(document.createTextNode(
- "[" + dataset[1] + "] " + dataset[2]));
- elt.appendChild(opt);
- });
- trigger_change_event(elt);
-}
-
-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-dataset-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 menu_contents() {
- return JSON.parse(
- document.getElementById("select-dataset-form").getAttribute(
- "data-menu-content"));
-}
-
-function genechips() {
- return JSON.parse(
- document.getElementById("select-dataset-form").getAttribute(
- "data-genechips"));
-}
-
-function update_menu(event) {
- menu = menu_contents();
- genec = genechips();
-
- species_elt = document.getElementById("species");
- group_elt = document.getElementById("group");
- type_elt = document.getElementById("type");
- dataset_elt = document.getElementById("dataset");
-
- if(event.target == species_elt) {
- setup_groups(menu["groups"][species_elt.value]);
- setup_genechips(genec[species_elt.value.toLowerCase()]);
- }
-
- if(event.target == group_elt) {
- setup_types(menu["types"][species_elt.value][group_elt.value]);
- }
-
- if(event.target == type_elt) {
- setup_datasets(
- menu["datasets"][species_elt.value][group_elt.value][type_elt.value]
- );
- }
-}
diff --git a/qc_app/templates/dbupdate_hidden_fields.html b/qc_app/templates/dbupdate_hidden_fields.html
index ec31202..c66ebba 100644
--- a/qc_app/templates/dbupdate_hidden_fields.html
+++ b/qc_app/templates/dbupdate_hidden_fields.html
@@ -10,5 +10,14 @@
{%if kwargs.get("genechipid"):%}
<input type="hidden" name="genechipid" value="{{kwargs['genechipid']}}" />
{%endif%}
+{%if kwargs.get("inbredsetid"):%}
+<input type="hidden" name="inbredsetid" value="{{kwargs['inbredsetid']}}" />
+{%endif%}
+{%if kwargs.get("tissueid"):%}
+<input type="hidden" name="tissueid" value="{{kwargs['tissueid']}}" />
+{%endif%}
+{%if kwargs.get("studyid"):%}
+<input type="hidden" name="studyid" value="{{kwargs['studyid']}}" />
+{%endif%}
{%endmacro%}
diff --git a/qc_app/templates/select_dataset.html b/qc_app/templates/select_dataset.html
index 4846f2c..59ead59 100644
--- a/qc_app/templates/select_dataset.html
+++ b/qc_app/templates/select_dataset.html
@@ -1,111 +1,87 @@
{%extends "base.html"%}
+{%from "dbupdate_hidden_fields.html" import hidden_fields%}
{%block title%}Select Dataset{%endblock%}
+{%block css%}
+<link rel="stylesheet" href="/static/css/two-column-with-separator.css" />
+{%endblock%}
+
{%block contents%}
<h1 class="heading">{{filename}}: select dataset</h2>
-<form method="POST" action="{{url_for('dbinsert.insert_data')}}"
- id="select-dataset-form"
- data-menu-content="{{menu_contents}}"
- 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[0]}}"
- {%if row[0] == default_species:%}
- selected="selected"
+<div class="two-column-with-separator">
+ <form method="POST" action="{{url_for('dbinsert.insert_data')}}"
+ id="select-dataset-form" class="two-col-sep-col1">
+ <legend>choose existing dataset</legend>
+ {{hidden_fields(
+ filename, filetype, species=species, genechipid=genechipid,
+ studyid=studyid)}}
+
+ <fieldset>
+ <label for="dataset" class="form-col-1">dataset:</label>
+ <select id="dataset" name="dataset" class="form-col-2"
+ {%if datasets | length == 0:%}
+ disabled="disabled"
{%endif%}>
- {{row[1]}}
- </option>
- {%endfor%}
- </select>
- </fieldset>
-
- <fieldset>
- <label for="group" class="form-col-1">group:</label>
- <select id="group" name="group" class="form-col-2">
- {%for grouping, grps in groups.items():%}
- <optgroup label="{{grouping}}">
- {%for group in grps:%}
- <option value="{{group[0]}}">{{group[1]}}</option>
- {%endfor%}
- </optgroup>
- {%endfor%}
- </select>
- </fieldset>
-
- <fieldset>
- <label for="type" class="form-col-1">type:</label>
- <select id="type" name="type" class="form-col-2">
- {%for grouping, typs in types.items():%}
- <optgroup label="{{grouping}}">
- {%for type in typs:%}
- <option value="{{type[0]}}">{{type[1]}}</option>
+ {%for dataset in datasets:%}
+ <option value="{{dataset['Id']}}">
+ [{{dataset["Name"]}}] - {{dataset["FullName"]}}
+ </option>
{%endfor%}
- </optgroup>
- {%endfor%}
- </select>
- </fieldset>
-
- <fieldset>
- <label for="dataset" class="form-col-1">dataset:</label>
- <select id="dataset" name="dataset" class="form-col-2">
- {%for dataset_id, name1, name2 in datasets:%}
- <option value="{{dataset_id}}">[{{name1}}] {{name2}}</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="update database" />
- </fieldset>
-
-</form>
+ </select>
+ </fieldset>
+
+ <fieldset>
+ <input type="submit" class="btn btn-main form-col-2"
+ value="update database"
+ {%if datasets | length == 0:%}
+ disabled="disabled"
+ {%endif%} />
+ </fieldset>
+ </form>
+
+ <p class="two-col-sep-separator">OR</p>
+
+ <form method="POST" id="create-dataset-form"
+ class="two-col-sep-col2">
+ <legend>create new dataset</legend>
+ {{hidden_fields(
+ filename, filetype, species=species, genechipid=genechipid,
+ studyid=studyid)}}
+
+ <fieldset>
+ <label for="avgid">average:</label>
+ <select id="avgid" name="avgid" required="required">
+ <option value="">Select averaging method</option>
+ </select>
+ </fieldset>
+
+ <fieldset>
+ <label for="datasetname">name:</label>
+ <input id="datasetname" name="datasetname" type="text" />
+ </fieldset>
+
+ <fieldset>
+ <label for="datasetname2">name 2:</label>
+ <input id="datasetname2" name="datasetname2" type="text" />
+ </fieldset>
+
+ <fieldset>
+ <label for="datasetfullname">full name:</label>
+ <input id="datasetfullname" name="datasetfullname" type="text" />
+ </fieldset>
+
+ <fieldset>
+ <label for="datasetshortname">full name:</label>
+ <input id="datasetshortname" name="datasetshortname" type="text" />
+ </fieldset>
+ </form>
+
+</div>
{%endblock%}
{%block javascript%}
<script type="text/javascript" src="/static/js/dbinsert.js"></script>
-<script type="text/javascript">
- document.getElementById("species").addEventListener("change", update_menu);
- document.getElementById("group").addEventListener("change", update_menu);
- document.getElementById("type").addEventListener("change", update_menu);
-</script>
{%endblock%}
diff --git a/qc_app/templates/select_study.html b/qc_app/templates/select_study.html
index e4b629c..d8bdcf0 100644
--- a/qc_app/templates/select_study.html
+++ b/qc_app/templates/select_study.html
@@ -11,7 +11,7 @@
<h2 class="heading">{{filename}}: select study</h2>
<div class="two-column-with-separator">
- <form method="POST" action="{{url_for('dbinsert.select_study')}}"
+ <form method="POST" action="{{url_for('dbinsert.select_dataset')}}"
id="select-platform-form" data-genechips="{{genechips_data}}"
class="two-col-sep-col1">
<legend>Select from existing study</legend>