From 2754bc1ef1abe98ef9e41237fd170a0e50e8a5f7 Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Thu, 6 Jul 2023 08:45:05 -0600 Subject: [PATCH] #81 Combined GATEWAY_ENABLE_ANNOTATIONS and GATEWAY_ENABLE_GENE_SETS flags --- Changelog.md | 2 +- README.md | 3 +-- cellxgene_gateway/cache_entry.py | 1 - cellxgene_gateway/env.py | 7 ------- cellxgene_gateway/gateway.py | 2 -- cellxgene_gateway/items/file/fileitem_source.py | 7 +++++-- cellxgene_gateway/subprocess_backend.py | 10 +--------- 7 files changed, 8 insertions(+), 24 deletions(-) diff --git a/Changelog.md b/Changelog.md index b8d8239..10aad9b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,6 @@ # 0.3.11 -* #81 added support for gene sets via GATEWAY_ENABLE_GENE_SETS +* #81 added support for gene sets # 0.3.10 diff --git a/README.md b/README.md index eed75f6..13ba916 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,7 @@ Optional environment variables: * `GATEWAY_PORT` - local port that the gateway should bind to, defaults to 5005 * `GATEWAY_EXPIRE_SECONDS` - time in seconds that a cellxgene process will remain idle before being terminated. Defaults to 3600 (one hour) * `GATEWAY_EXTRA_SCRIPTS` - JSON array of script paths, will be embedded into each page and forwarded with `--scripts` to cellxgene server -* `GATEWAY_ENABLE_ANNOTATIONS` - Set to `true` or to `1` to enable cellxgene annotations. -* `GATEWAY_ENABLE_GENE_SETS` - Set to `true` or to `1` to enable cellxgene gene sets. Also enables `GATEWAY_ENABLE_ANNOTATIONS`. +* `GATEWAY_ENABLE_ANNOTATIONS` - Set to `true` or to `1` to enable cellxgene annotations and gene sets. * `GATEWAY_ENABLE_BACKED_MODE` - Set to `true` or to `1` to load AnnData in file-backed mode. This saves memory and speeds up launch time but may reduce overall performance. * `GATEWAY_LOG_LEVEL` - default is `INFO`. set to `DEBUG` to increase logging and to `WARNING` to decrease logging. * `S3_ENABLE_LISTINGS_CACHE` - Set to `true` or to `1` to cache listings of S3 folders for performance. If the cache becomes stale, set `filecrawl.html?refresh=true` query parameter to refresh the cache. diff --git a/cellxgene_gateway/cache_entry.py b/cellxgene_gateway/cache_entry.py index aa3bb0c..8c72efc 100644 --- a/cellxgene_gateway/cache_entry.py +++ b/cellxgene_gateway/cache_entry.py @@ -58,7 +58,6 @@ class CacheEntry: @classmethod def for_key(cls, key, port): - return cls( None, key, diff --git a/cellxgene_gateway/env.py b/cellxgene_gateway/env.py index 4d8c4db..5cf0c1b 100644 --- a/cellxgene_gateway/env.py +++ b/cellxgene_gateway/env.py @@ -26,16 +26,10 @@ extra_scripts = os.environ.get("GATEWAY_EXTRA_SCRIPTS") expire_seconds = int( os.environ.get("GATEWAY_EXPIRE_SECONDS", os.environ.get("GATEWAY_TTL", "3600")) ) -enable_gene_sets = os.environ.get("GATEWAY_ENABLE_GENE_SETS", "").lower() in [ - "true", - "1", -] enable_annotations = os.environ.get("GATEWAY_ENABLE_ANNOTATIONS", "").lower() in [ "true", "1", ] -# Enable annotations if gene sets are enabled: -enable_annotations = enable_annotations or enable_gene_sets enable_backed_mode = os.environ.get("GATEWAY_ENABLE_BACKED_MODE", "").lower() in [ "true", "1", @@ -60,7 +54,6 @@ optional_env_vars = { "GATEWAY_EXTRA_SCRIPTS": extra_scripts, "GATEWAY_EXPIRE_SECONDS": expire_seconds, "GATEWAY_ENABLE_ANNOTATIONS": enable_annotations, - "GATEWAY_ENABLE_GENE_SETS": enable_gene_sets, "GATEWAY_ENABLE_BACKED_MODE": enable_backed_mode, "GATEWAY_LOG_LEVEL": log_level, "CELLXGENE_ARGS": cellxgene_args, diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index c930974..1b9c14e 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -80,7 +80,6 @@ cache = BackendCache() @app.errorhandler(CellxgeneException) def handle_invalid_usage(error): - message = f"{error.http_status} Error : {error.message}" return ( @@ -95,7 +94,6 @@ def handle_invalid_usage(error): @app.errorhandler(ProcessException) def handle_invalid_process(error): - message = [] message.append(error.message) diff --git a/cellxgene_gateway/items/file/fileitem_source.py b/cellxgene_gateway/items/file/fileitem_source.py index 38d0a8f..407f3a8 100644 --- a/cellxgene_gateway/items/file/fileitem_source.py +++ b/cellxgene_gateway/items/file/fileitem_source.py @@ -35,8 +35,11 @@ class FileItemSource(ItemSource): def name(self): return self._name or f"Files:{self.base_path}" - def is_gene_set(self, path:str) -> bool: - return ('_gene_sets' in path or '-gene-sets' in path) and path.endswith(self.annotation_file_suffix) + def is_gene_set(self, path: str) -> bool: + return ("_gene_sets" in path or "-gene-sets" in path) and path.endswith( + self.annotation_file_suffix + ) + def is_h5ad_file(self, path: str) -> bool: return path.endswith(self.h5ad_suffix) and os.path.isfile(path) diff --git a/cellxgene_gateway/subprocess_backend.py b/cellxgene_gateway/subprocess_backend.py index 8825875..0dc87be 100644 --- a/cellxgene_gateway/subprocess_backend.py +++ b/cellxgene_gateway/subprocess_backend.py @@ -18,7 +18,6 @@ from cellxgene_gateway.env import ( cellxgene_args, enable_annotations, enable_backed_mode, - enable_gene_sets, ) from cellxgene_gateway.process_exception import ProcessException @@ -35,17 +34,10 @@ class SubprocessBackend: extra_args = f" --annotations-dir {make_annotations(file_path)}" else: extra_args = f" --annotations-file {annotation_file_path}" - else: - extra_args = " --disable-annotations" - if enable_gene_sets and not annotation_file_path is None: - if annotation_file_path == "": - raise Exception( - "GATEWAY_ENABLE_GENE_SETS is true but --annotation_file_path not set" - ) - else: gene_sets_file_path = annotation_file_path[:-4] + "_gene_sets.csv" extra_args += f" --gene-sets-file {gene_sets_file_path}" else: + extra_args = " --disable-annotations" extra_args += " --disable-gene-sets-save" if enable_backed_mode: extra_args += " --backed"