aboutsummaryrefslogtreecommitdiff
path: root/uploader
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-07-01 13:14:36 -0500
committerFrederick Muriuki Muriithi2025-07-01 13:14:36 -0500
commitc2e33c39570191bec82076fe2394263f60add281 (patch)
tree4718599a494682d90613c9b12bcd5470e552739c /uploader
parent151358c5fcc8771f558f93497e6ae88bfa708294 (diff)
downloadgn-uploader-c2e33c39570191bec82076fe2394263f60add281.tar.gz
Remove unused feature
The feature is implemented elsewhere (GN2) in a better way.
Diffstat (limited to 'uploader')
-rw-r--r--uploader/phenotypes/views.py150
-rw-r--r--uploader/templates/phenotypes/view-dataset.html94
2 files changed, 0 insertions, 244 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index bc15f2d..97bcafe 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -987,156 +987,6 @@ def edit_phenotype_data(# pylint: disable=[unused-argument]
xref_id=xref_id))
-def process_phenotype_data_for_download(pheno: dict) -> dict:
- """Sanitise data for download."""
- return {
- "UniqueIdentifier": f"phId:{pheno['Id']}::xrId:{pheno['xref_id']}",
- **{
- key: val for key, val in pheno.items()
- if key not in ("Id", "xref_id", "data", "Units")
- },
- **{
- data_item["StrainName"]: data_item["value"]
- for data_item in pheno.get("data", {}).values()
- }
- }
-
-
-BULK_EDIT_COMMON_FIELDNAMES = [
- "UniqueIdentifier",
- "Post_publication_description",
- "Pre_publication_abbreviation",
- "Pre_publication_description",
- "Original_description",
- "Post_publication_abbreviation",
- "PubMed_ID"
-]
-
-
-@phenotypesbp.route(
- "<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
- "/<int:dataset_id>/edit-download",
- methods=["POST"])
-@require_login
-@with_dataset(
- species_redirect_uri="species.populations.phenotypes.index",
- population_redirect_uri="species.populations.phenotypes.select_population",
- redirect_uri="species.populations.phenotypes.list_datasets")
-def edit_download_phenotype_data(# pylint: disable=[unused-argument]
- species: dict,
- population: dict,
- dataset: dict,
- **kwargs
-):
- formdata = request.json
- with database_connection(app.config["SQL_URI"]) as conn:
- samples_list = [
- sample["Name"] for sample in samples_by_species_and_population(
- conn, species["SpeciesId"], population["Id"])]
- data = (
- process_phenotype_data_for_download(pheno)
- for pheno in phenotypes_data_by_ids(conn, tuple({
- "population_id": population["Id"],
- "phenoid": row["phenotype_id"],
- "xref_id": row["xref_id"]
- } for row in formdata)))
-
- with (tempfile.TemporaryDirectory(
- prefix=app.config["TEMPORARY_DIRECTORY"]) as tmpdir):
- filename = Path(tmpdir).joinpath("tempfile.tsv")
- with open(filename, mode="w") as outfile:
- outfile.write(
- "# **DO NOT** delete the 'UniqueIdentifier' row. It is used "
- "by the system to identify and edit the correct rows and "
- "columns in the database.\n")
- outfile.write(
- "# The '…_description' fields are useful for you to figure out "
- "what row you are working on. Changing any of this fields will "
- "also update the database, so do be careful.\n")
- outfile.write(
- "# Leave a field empty to delete the value in the database.\n")
- outfile.write(
- "# Any line beginning with a '#' character is considered a "
- "comment line. This line, and all the lines above it, are "
- "all comment lines. Comment lines will be ignored.\n")
- writer = csv.DictWriter(outfile,
- fieldnames= (
- BULK_EDIT_COMMON_FIELDNAMES +
- samples_list),
- dialect="excel-tab")
- writer.writeheader()
- writer.writerows(data)
- outfile.flush()
-
- return send_file(
- filename,
- mimetype="text/csv",
- as_attachment=True,
- download_name=secure_filename(f"{dataset['Name']}_data"))
-
-
-@phenotypesbp.route(
- "<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
- "/<int:dataset_id>/edit-upload",
- methods=["GET", "POST"])
-@require_login
-@with_dataset(
- species_redirect_uri="species.populations.phenotypes.index",
- population_redirect_uri="species.populations.phenotypes.select_population",
- redirect_uri="species.populations.phenotypes.list_datasets")
-def edit_upload_phenotype_data(# pylint: disable=[unused-argument]
- species: dict,
- population: dict,
- dataset: dict,
- **kwargs
-):
- if request.method == "GET":
- return render_template(
- "phenotypes/bulk-edit-upload.html",
- species=species,
- population=population,
- dataset=dataset,
- activelink="edit-phenotype")
-
- edit_file = save_file(request.files["file-upload-bulk-edit-upload"],
- Path(app.config["UPLOAD_FOLDER"]))
-
- jobs_db = app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]
- with sqlite3.connection(jobs_db) as conn:
- job_id = uuid.uuid4()
- job_cmd = [
- sys.executable, "-u",
- "-m", "scripts.phenotypes_bulk_edit",
- app.config["SQL_URI"],
- jobs_db,
- str(job_id),
- "--log-level",
- logging.getLevelName(
- app.logger.getEffectiveLevel()
- ).lower()
- ]
- app.logger.debug("Phenotype-edit, bulk-upload command: %s", job_cmd)
- _job = gnlibs_jobs.launch_job(
- gnlibs_jobs.initialise_job(conn,
- job_id,
- job_cmd,
- "phenotype-bulk-edit",
- extra_meta = {
- "edit-file": str(edit_file),
- "species-id": species["SpeciesId"],
- "population-id": population["Id"],
- "dataset-id": dataset["Id"]
- }),
- jobs_db,
- f"{app.config['UPLOAD_FOLDER']}/job_errors",
- worker_manager="gn_libs.jobs.launcher")
-
-
- return redirect(url_for("background-jobs.job_status",
- job_id=job_id,
- job_type="phenotype-bulk-edit"))
-
-
@phenotypesbp.route(
"<int:species_id>/populations/<int:population_id>/phenotypes/datasets"
"/<int:dataset_id>/load-data-success/<uuid:job_id>",
diff --git a/uploader/templates/phenotypes/view-dataset.html b/uploader/templates/phenotypes/view-dataset.html
index 21563d6..306dcce 100644
--- a/uploader/templates/phenotypes/view-dataset.html
+++ b/uploader/templates/phenotypes/view-dataset.html
@@ -133,100 +133,6 @@
{
select: "multi+shift",
layout: {
- top2: {
- buttons: [
- {
- extend: "selectAll",
- className: "btn btn-info",
- titleAttr: "Click to select ALL records in the table."
- },
- {
- extend: "selectNone",
- className: "btn btn-info",
- titleAttr: "Click to deselect ANY selected record(s) in the table."
- },
- {
- text: "Bulk Edit (Download Data)",
- className: "btn btn-info btn-bulk-edit",
- titleAttr: "Click to download data for editing.",
- action: (event, dt, node, config) => {
- var phenoids = [];
- var selected = dt.rows({selected: true, page: "all"}).data();
- for(var idx = 0; idx < selected.length; idx++) {
- phenoids.push({
- phenotype_id: selected[idx].Id,
- xref_id: selected[idx].xref_id
- });
- }
- if(phenoids.length == 0) {
- alert("No record selected. Nothing to do!");
- return false;
- }
-
- $(".btn-bulk-edit").prop("disabled", true);
- $(".btn-bulk-edit").addClass("d-none");
- var spinner = $(
- "<div id='bulk-edit-spinner' class='spinner-grow text-info'>");
- spinner_content = $(
- "<span class='visually-hidden'>");
- spinner_content.html(
- "Downloading data &hellip;");
- spinner.append(spinner_content)
- $(".btn-bulk-edit").parent().append(
- spinner);
-
- $.ajax(
- (`/species/${species_id}/populations/` +
- `${population_id}/phenotypes/datasets/` +
- `${dataset_id}/edit-download`),
- {
- method: "POST",
- data: JSON.stringify(phenoids),
- xhrFields: {
- responseType: "blob"
- },
- success: (data, textStatus, jqXHR) => {
- var link = document.createElement("a");
- uri = window.URL.createObjectURL(data);
- link.href = uri;
- link.download = `${dataset_name}_data.tsv`;
-
- document.body.appendChild(link);
- link.click();
- window.URL.revokeObjectURL(uri);
- link.remove();
- },
- error: (jQXHR, textStatus, errorThrown) => {
- console.log("Experienced an error: ", textStatus);
- console.log("The ERROR: ", errorThrown);
- },
- complete: (jqXHR, textStatus) => {
- $("#bulk-edit-spinner").remove();
- $(".btn-bulk-edit").removeClass(
- "d-none");
- $(".btn-bulk-edit").prop(
- "disabled", false);
- },
- contentType: "application/json"
- });
- }
- },
- {
- text: "Bulk Edit (Upload Data)",
- className: "btn btn-info btn-bulk-edit",
- titleAttr: "Click to upload edited data you got by clicking the `Bulk Edit (Download Data)` button.",
- action: (event, dt, node, config) => {
- window.location.assign(
- `${window.location.protocol}//` +
- `${window.location.host}` +
- `/species/${species_id}` +
- `/populations/${population_id}` +
- `/phenotypes/datasets/${dataset_id}` +
- `/edit-upload`)
- }
- }
- ]
- },
top1Start: {
pageLength: {
text: "Show _MENU_ of _TOTAL_"