diff options
-rw-r--r-- | gn3/auth/authorisation/data/phenotypes.py | 2 | ||||
-rw-r--r-- | gn3/auth/authorisation/data/views.py | 2 | ||||
-rw-r--r-- | scripts/search_phenotypes.py | 15 |
3 files changed, 11 insertions, 8 deletions
diff --git a/gn3/auth/authorisation/data/phenotypes.py b/gn3/auth/authorisation/data/phenotypes.py index 3ba478a..db16699 100644 --- a/gn3/auth/authorisation/data/phenotypes.py +++ b/gn3/auth/authorisation/data/phenotypes.py @@ -17,6 +17,8 @@ def linked_phenotype_data( authcursor.execute("SELECT * FROM linked_phenotype_data") linked = tuple(tuple(row[key] for key in authkeys) for row in authcursor.fetchall()) + if len(linked) <= 0: + return (item for item in tuple()) paramstr = "".join(["(%s, %s, %s, %s)"] * len(linked)) query = ( "SELECT spc.SpeciesId, spc.SpeciesName, iset.InbredSetId, " diff --git a/gn3/auth/authorisation/data/views.py b/gn3/auth/authorisation/data/views.py index a14e78b..a9861d2 100644 --- a/gn3/auth/authorisation/data/views.py +++ b/gn3/auth/authorisation/data/views.py @@ -163,7 +163,7 @@ def __search_phenotypes__(): f"--gn3-db-uri={app.config['SQL_URI']}", f"--redis-uri={redisuri}", f"--per-page={__request_key__('per_page')}"] +( - [f"--selected='{json.dumps(selected)}"] + [f"--selected={json.dumps(selected)}"] if len(selected) > 0 else []) jobs.create_job(redisconn, { "job_id": job_id, "command": command, "status": "queued", diff --git a/scripts/search_phenotypes.py b/scripts/search_phenotypes.py index 7049834..2f7fcf3 100644 --- a/scripts/search_phenotypes.py +++ b/scripts/search_phenotypes.py @@ -11,6 +11,7 @@ from datetime import datetime, timedelta import click import redis import requests +from MySQLdb.cursors import DictCursor from gn3 import jobs from gn3.auth import db as authdb @@ -92,13 +93,13 @@ def search(# pylint: disable=[too-many-arguments, too-many-locals] try: search_query = f"species:{species}" + ( f" AND ({query})" if bool(query) else "") - filter_keys = ("SpeciesName", "InbredSetName", "dataset_name", - "PublishXRefId") - selected_traits = tuple(tuple(item[key] for key in filter_keys) - for item in json.loads(selected)) - linked = tuple(tuple(row[key] for key in filter_keys) - for row in linked_phenotype_data( - authconn, gn3conn, species)) + selected_traits = tuple( + (item["species"], item["group"], item["dataset"], item["name"]) + for item in json.loads(selected)) + linked = tuple( + (row["SpeciesName"], row["InbredSetName"], row["dataset_name"], + row["PublishXRefId"]) + for row in linked_phenotype_data(authconn, gn3conn, species)) page = 1 count = 0 while count < per_page: |