about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-06-26 16:16:43 -0500
committerFrederick Muriuki Muriithi2025-06-26 16:16:43 -0500
commit2abcce37b80e764e8b938bd639feb9a334151ee0 (patch)
tree3d2abd9b684371ae494a6400553418722b1f3fe8
parent898a7737a85fb70aafaaa9fb4f23d184dc7a1bb0 (diff)
downloadgn-uploader-2abcce37b80e764e8b938bd639feb9a334151ee0.tar.gz
Narrow search to only uploaded traits.
-rw-r--r--uploader/phenotypes/views.py41
-rw-r--r--uploader/templates/phenotypes/load-phenotypes-success.html2
2 files changed, 38 insertions, 5 deletions
diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py
index 70f375e..b176890 100644
--- a/uploader/phenotypes/views.py
+++ b/uploader/phenotypes/views.py
@@ -8,9 +8,9 @@ import tempfile
 from typing import Any
 from pathlib import Path
 from zipfile import ZipFile
-from urllib.parse import urljoin
 from functools import wraps, reduce
 from logging import INFO, ERROR, DEBUG, FATAL, CRITICAL, WARNING
+from urllib.parse import urljoin, urlparse, ParseResult, urlunparse, urlencode
 
 import datetime
 from datetime import timedelta
@@ -1153,15 +1153,48 @@ def load_data_success(
         job_id: uuid.UUID,
         **kwargs
 ):# pylint: disable=[unused-argument]
-    with sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"]) as conn:
+    with (database_connection(app.config["SQL_URI"]) as conn,
+          sqlite3.connection(app.config["ASYNCHRONOUS_JOBS_SQLITE_DB"])
+          as jobsconn):
         try:
-            job = gnlibs_jobs.job(conn, job_id, fulldetails=True)
+            gn2_uri = urlparse(app.config["GN2_SERVER_URL"])
+            job = gnlibs_jobs.job(jobsconn, job_id, fulldetails=True)
             app.logger.debug("THE JOB: %s", job)
+            _xref_ids = (str(item) for item
+                         in json.loads(job["metadata"].get("xref_ids", "[]")))
+            _publication = fetch_publication_by_id(
+                conn, int(job["metadata"].get("publication_id", "0")))
+            _search_terms = (item for item in
+                             (str(_publication["PubMed_ID"] or ""),
+                              _publication["Authors"],
+                              (_publication["Title"] or ""))
+                             if item != "")
             return render_template("phenotypes/load-phenotypes-success.html",
                                    species=species,
                                    population=population,
                                    dataset=dataset,
                                    job=job,
-                                   gn2_server_url=app.config["GN2_SERVER_URL"])
+                                   search_page_uri=urlunparse(ParseResult(
+                                       scheme=gn2_uri.scheme,
+                                       netloc=gn2_uri.netloc,
+                                       path="/search",
+                                       params="",
+                                       query=urlencode({
+                                           "species": species["Name"],
+                                           "group": population["Name"],
+                                           "type": "Phenotypes",
+                                           "dataset": dataset["Name"],
+                                           "search_terms_or": (
+                                               # Very long URLs will cause
+                                               # errors.
+                                               " ".join(_xref_ids)
+                                               if len(_xref_ids) <= 100
+                                               else ""),
+                                           "search_terms_and": " ".join(
+                                               _search_terms).strip(),
+                                           "accession_id": "None",
+                                           "FormID": "searchResult"
+                                       }),
+                                       fragment="")))
         except JobNotFound as jnf:
             return render_template("jobs/job-not-found.html", job_id=job_id)
diff --git a/uploader/templates/phenotypes/load-phenotypes-success.html b/uploader/templates/phenotypes/load-phenotypes-success.html
index 3baca5b..645be16 100644
--- a/uploader/templates/phenotypes/load-phenotypes-success.html
+++ b/uploader/templates/phenotypes/load-phenotypes-success.html
@@ -28,7 +28,7 @@
   <!-- TODO: Maybe notify user that they have sole access. -->
   <!-- TODO: Maybe provide a link to go to GeneNetwork to view the data. -->
   <p>View your data
-    <a href="{{gn2_server_url}}search?species={{species.Name}}&group={{population.Name}}&type=Phenotypes&dataset={{dataset.Name}}&search_terms_or=*%0D%0A&search_terms_and=*%0D%0A&accession_id=None&FormID=searchResult"
+    <a href="{{search_page_uri}}"
        target="_blank">on GeneNetwork2</a>.
     You might need to login to GeneNetwork2 to view specific traits.</p>
 </div>