mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-03 11:28:12 +08:00
This adds the flag `GATEWAY_ENABLE_GENE_SETS` to enable support for gene sets. To simplify implementation, activating this flag also activates `GATEWAY_ENABLE_ANNOTATIONS`. The gene sets are saved in a file that has the same name as the annotations `csv` but with `_gene_sets` appended to the file name (before the extension). This file is hidden in filecrawler, and the gene sets are loaded when the associated annotations file is loaded. If the annotations file is missing, then an Exception is raised. I have updated one unit test to make it expect `--disable-gene-sets-save` in the default case (i.e. if `GATEWAY_ENABLE_ANNOTATIONS = 0`). All units tests pass. I have updated the README to document `GATEWAY_ENABLE_GENE_SETS`.
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
# Copyright 2019 Novartis Institutes for BioMedical Research Inc. Licensed
|
|
# under the Apache License, Version 2.0 (the "License"); you may not use
|
|
# this file except in compliance with the License. You may obtain a copy
|
|
# of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless
|
|
# required by applicable law or agreed to in writing, software distributed
|
|
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
|
# the specific language governing permissions and limitations under the License.
|
|
|
|
import logging
|
|
import os
|
|
|
|
cellxgene_location = os.environ.get("CELLXGENE_LOCATION")
|
|
cellxgene_data = os.environ.get("CELLXGENE_DATA", "")
|
|
cellxgene_args = os.environ.get("CELLXGENE_ARGS", None)
|
|
gateway_port = int(os.environ.get("GATEWAY_PORT", "5005"))
|
|
external_host = os.environ.get(
|
|
"EXTERNAL_HOST",
|
|
os.environ.get("GATEWAY_HOST", f"localhost:{gateway_port}"),
|
|
)
|
|
external_protocol = os.environ.get(
|
|
"EXTERNAL_PROTOCOL", os.environ.get("GATEWAY_PROTOCOL", None)
|
|
)
|
|
ip = os.environ.get("GATEWAY_IP")
|
|
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",
|
|
]
|
|
log_level = logging.getLevelName(os.environ.get("GATEWAY_LOG_LEVEL", "INFO"))
|
|
|
|
env_vars = {
|
|
"CELLXGENE_LOCATION": cellxgene_location,
|
|
}
|
|
|
|
proxy_fix_for = int(os.environ.get("PROXY_FIX_FOR", "0"))
|
|
proxy_fix_proto = int(os.environ.get("PROXY_FIX_PROTO", "0"))
|
|
proxy_fix_host = int(os.environ.get("PROXY_FIX_HOST", "0"))
|
|
proxy_fix_port = int(os.environ.get("PROXY_FIX_PORT", "0"))
|
|
proxy_fix_prefix = int(os.environ.get("PROXY_FIX_PREFIX", "0"))
|
|
|
|
optional_env_vars = {
|
|
"EXTERNAL_HOST": external_host,
|
|
"EXTERNAL_PROTOCOL": external_protocol,
|
|
"GATEWAY_IP": ip,
|
|
"GATEWAY_PORT": gateway_port,
|
|
"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,
|
|
"CELLXGENE_DATA": cellxgene_data,
|
|
"PROXY_FIX_FOR": proxy_fix_for,
|
|
"PROXY_FIX_PROTO": proxy_fix_proto,
|
|
"PROXY_FIX_HOST": proxy_fix_host,
|
|
"PROXY_FIX_PORT": proxy_fix_port,
|
|
"PROXY_FIX_PREFIX": proxy_fix_prefix,
|
|
}
|
|
|
|
|
|
def validate():
|
|
if not all(env_vars.values()):
|
|
raise ValueError(
|
|
f"""
|
|
Please ensure that environment variables are set correctly.
|
|
The ones with None below are missing and need to be set.
|
|
|
|
{env_vars}
|
|
|
|
Set them at the terminal before running the gateway.
|
|
An example is:
|
|
|
|
export CELLXGENE_LOCATION=~/anaconda/envs/cellxgene-dev/bin/cellxgene
|
|
export CELLXGENE_DATA=../cellxgene_data
|
|
"""
|
|
)
|
|
else:
|
|
logging.getLogger("cellxgene_gateway").info(
|
|
f"Got required env: {env_vars}",
|
|
)
|
|
logging.getLogger("cellxgene_gateway").info(
|
|
f"Got optional env: {optional_env_vars}"
|
|
)
|