aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--uploader/__init__.py3
-rw-r--r--uploader/phenotypes/models.py7
-rw-r--r--uploader/phenotypes/views.py66
-rw-r--r--uploader/templates/phenotypes/bulk-edit-upload.html3
4 files changed, 74 insertions, 5 deletions
diff --git a/uploader/__init__.py b/uploader/__init__.py
index 4f3538c..734bdcd 100644
--- a/uploader/__init__.py
+++ b/uploader/__init__.py
@@ -8,6 +8,8 @@ from flask import Flask, request
from flask_session import Session
from cachelib import FileSystemCache
+from gn_libs import jobs
+
from uploader.oauth2.client import user_logged_in, authserver_authorise_uri
from . import session
@@ -94,4 +96,5 @@ def create_app():
app.register_blueprint(speciesbp, url_prefix="/species")
register_error_handlers(app)
+ jobs.init_app(app)
return app
diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py
index ce7720c..4a229e6 100644
--- a/uploader/phenotypes/models.py
+++ b/uploader/phenotypes/models.py
@@ -262,8 +262,11 @@ def phenotypes_data_by_ids(
) -> tuple[dict, ...]:
"""Fetch all phenotype data, filtered by the `inbred_pheno_xref` mapping."""
_paramstr = ",".join(["(%s, %s, %s)"] * len(inbred_pheno_xref))
- _query = ("SELECT pheno.*, pxr.*, pd.*, str.*, iset.InbredSetCode "
- "FROM Phenotype AS pheno "
+ _query = ("SELECT "
+ "pub.PubMed_ID, pheno.*, pxr.*, pd.*, str.*, iset.InbredSetCode "
+ "FROM Publication AS pub "
+ "RIGHT JOIN PublishXRef AS pxr0 ON pub.Id=pxr0.PublicationId "
+ "INNER JOIN Phenotype AS pheno ON pxr0.PhenotypeId=pheno.id "
"INNER JOIN PublishXRef AS pxr ON pheno.Id=pxr.PhenotypeId "
"INNER JOIN PublishData AS pd ON pxr.DataId=pd.Id "
"INNER JOIN Strain AS str ON pd.StrainId=str.Id "
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 3d2ff76..00da78b 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -920,7 +920,8 @@ def edit_download_phenotype_data(# pylint: disable=[unused-argument]
"Pre_publication_abbreviation",
"Pre_publication_description",
"Original_description",
- "Post_publication_abbreviation"
+ "Post_publication_abbreviation",
+ "PubMed_ID"
] + samples_list,
dialect="excel-tab")
writer.writeheader()
@@ -957,4 +958,65 @@ def edit_upload_phenotype_data(# pylint: disable=[unused-argument]
dataset=dataset,
activelink="edit-phenotype")
- return "NOT Implemented: Would do actual edit."
+ edit_file = save_file(request.files["file-upload-bulk-edit-upload"],
+ Path(app.config["UPLOAD_FOLDER"]))
+
+ from gn_libs import jobs as gnlibs_jobs
+ from gn_libs import sqlite3
+ jobs_db = app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]
+ with sqlite3.connection(jobs_db) as conn:
+ job_id = uuid.uuid4()
+ _job = gnlibs_jobs.launch_job(
+ gnlibs_jobs.initialise_job(conn,
+ job_id,
+ [
+ sys.executable,
+ "-m",
+ "scripts.phenotypes_bulk_edit",
+ jobs_db,
+ str(job_id)
+ ],
+ "phenotype-bulk-edit",
+ extra_meta = {
+ "edit-file": str(edit_file)
+ }),
+ jobs_db,
+ f"{app.config['UPLOAD_FOLDER']}/job_errors",
+ worker_manager="gn_libs.scripts.worker")
+
+
+ return """
+ <p>The following steps need to be performed:
+ <ol>
+ <li>Check that all IDs exist</li>
+ <li>Check for mandatory values</li>
+ <li>Update descriptions in the database (where changed)</li>
+ <li>Update publications in the database (where changed):
+ <ol>
+ <li>If <strong>PubMed_ID</strong> exists in our database, simply update the
+ 'PublicationId' value in the 'PublishXRef' table.</li>
+ <li>If <strong>PubMed_ID</strong> does not exists in our database:
+ <ol>
+ <li>fetch the publication's details from PubMed using the new
+ <strong>PubMed_ID</strong> value.</li>
+ <li>create a new publication in our database using the fetched data</li>
+ <li>Update 'PublicationId' value in 'PublishXRef' with ID of newly created
+ publication</li>
+ </ol>
+ </ol>
+ </li>
+ <li>Update values in the database (where changed)</li>
+ </ol>
+ </p>
+
+ <p><strong>Note:</strong>
+ <ul>
+ <li>If a strain that did not have a value is given a value, then we need to
+ add a new cross-reference for the new DataId created.</li>
+ <li>If a strain that had a value has its value deleted and left blank, we
+ need to remove the cross-reference for the existing DataId — or, should we
+ enter the NULL value instead? Removing the cross-reference might be more
+ trouble than it is worth.</li>
+ </ul>
+ </p>
+ """
diff --git a/uploader/templates/phenotypes/bulk-edit-upload.html b/uploader/templates/phenotypes/bulk-edit-upload.html
index 926bcf5..d0f38f5 100644
--- a/uploader/templates/phenotypes/bulk-edit-upload.html
+++ b/uploader/templates/phenotypes/bulk-edit-upload.html
@@ -42,9 +42,10 @@
Edited File</label>
<div class="col-sm-10">
<input id="file-upload-bulk-edit-upload"
- name="file_upload_bulk_edit_upload"
+ name="file-upload-bulk-edit-upload"
class="form-control"
type="file"
+ accept="text/tab-separated-values"
required="required" />
</div>
</div>