Cellxgene Gateway allows you to use the Cellxgene Server provided by the Chan Zuckerberg Institute (https://github.com/chanzuckerberg/cellxgene) with multiple datasets.
Overview
Cellxgene Gateway allows you to use the Cellxgene Server provided by the Chan Zuckerberg Institute (https://github.com/chanzuckerberg/cellxgene) with multiple datasets. It displays an index of available h5ad (anndata) files. When a user clicks on a file name, it launches a Cellxgene Server instance that loads that particular data file and once it is available proxies requests to that server.
Running locally
Prequisites
- This project requires python 3.6 or higher. Please check your version with
$ python --version
- It is also a good idea to set up a venv
python -m venv .cellxgene-gateway
source .cellxgene-gateway/bin/activate # type deactivate to deactivate the venv
Install cellxgene-gateway
Option 1: Pip Install from Github
pip install git+https://github.com/Novartis/cellxgene-gateway
Note: you may need to downgrade h5py with pip install h5py==2.9.0 due to an issue in a dependency.
Option 2: Install from PyPI
pip install cellxgene-gateway
Running cellxgene gateway
- Prepare a folder with .h5ad files, for example
mkdir ../cellxgene_data
wget https://raw.githubusercontent.com/chanzuckerberg/cellxgene/master/example-dataset/pbmc3k.h5ad -O ../cellxgene_data/pbmc3k.h5ad
- Set your environment variables correctly:
export CELLXGENEDATA=../cellxgenedata # change this directory if you put data in a different place.
export CELLXGENE_LOCATION=which cellxgene
- Now, execute the cellxgene gateway:
cellxgene-gateway
Here's what the environment variables mean:
CELLXGENE_LOCATION- the location of the cellxgene executable, e.g.~/anaconda2/envs/cellxgene/bin/cellxgene
CELLXGENEDATA - a directory that can contain subdirectories with .h5ad data files, without* trailing slash, e.g. /mnt/cellxgenedata
CELLXGENE_BUCKET- an s3 bucket that can contain keys with.h5addata files, e.g.my-cellxgene-data-bucket
Optional environment variables:
CELLXGENE_ARGS- catch-all variable that can be used to pass additional command line args to cellxgene serverEXTERNALHOST- the hostname and port from the perspective of the web browser, typicallylocalhost:5005if running locally. Defaults to "localhost:{GATEWAYPORT}"EXTERNAL_PROTOCOL- typically http when running locally, can be https when deployed if the gateway is behind a load balancer or reverse proxy that performs https termination. Default value "http"GATEWAY_IP- ip addess of instance gateway is running on, mostly used to display SSH instructions. Defaults tosocket.gethostbyname(socket.gethostname())GATEWAY_PORT- local port that the gateway should bind to, defaults to 5005GATEWAYEXPIRESECONDS- time in seconds that a cellxgene process will remain idle before being terminated. Defaults to 3600 (one hour)GATEWAYEXTRASCRIPTS- JSON array of script paths, will be embedded into each page and forwarded with--scriptsto cellxgene serverGATEWAYENABLEANNOTATIONS- Set totrueor to1to enable cellxgene annotations and gene sets.GATEWAYENABLEBACKED_MODE- Set totrueor to1to load AnnData in file-backed mode. This saves memory and speeds up launch time but may reduce overall performance.GATEWAYLOGLEVEL- default isINFO. set toDEBUGto increase logging and toWARNINGto decrease logging.S3ENABLELISTINGS_CACHE- Set totrueor to1to cache listings of S3 folders for performance. If the cache becomes stale, setfilecrawl.html?refresh=truequery parameter to refresh the cache.
PROXYFIXFOR- Number of upstream proxies setting X-Forwarded-ForPROXYFIXPROTO- Number of upstream proxies setting X-Forwarded-ProtoPROXYFIXHOST- Number of upstream proxies setting X-Forwarded-HostPROXYFIXPORT- Number of upstream proxies setting X-Forwarded-PortPROXYFIXPREFIX- Number of upstream proxies setting X-Forwarded-Prefix
Running cellxgene-gateway with Docker
First, build Docker image:
docker build -t cellxgene-gateway .
Then, cellxgene-gateway can be launched as such:
docker run -it --rm \
-v <localdatadir>:/cellxgene-data \
-p 5005:5005 \
cellxgene-gateway
Additional environment variables can be provided with the -e parameter:
docker run -it --rm \
-v ../cellxgene_data:/cellxgene-data \
-e GATEWAY_PORT=8080 \
-p 8080:8080 \
cellxgene-gateway
Running cellxgene gateway with start scripts
For your convenience, we provide start scripts for flask, gunicorn and uwsgi.
First, set up a .env
cp env_example .env edit .env
open .env
Then run the scripts in a subshell
( ./start_flask.sh )
Customization
The current paradigm for customization is to modify files during a build or deployment phase:
- To modify CSS or JS on particular gateway pages, overwrite or append to the templates
- To add script tags such as for user analytics to all pages, set GATEWAYEXTRASCRIPTS
Currently we use a bash script that copies the gateway to a "build" directory before modifying templates with sed and the like. There is probably a better way.
Development
We’re actively developing. Please see the "future work" section of the wiki. If you’re interested in being a contributor please reach out to @alokito.
Developer Install
If you want to develop the code, you will need to clone the repo. Make sure you have the prequesite listed above, then:
- Clone the repo
git clone https://github.com/Novartis/cellxgene-gateway.git
cd cellxgene-gateway
- Install requirements with
pip install -r requirements.txt
- Install the gateway in developer mode
python setup.py develop
For convenience, the code repo includes a run.sh.example shell script to run the gateway.
- Install pre-commit hooks
conda install -c conda-forge pre-commit
pre-commit install
Running Tests
python -m unittest discover tests
Code Coverage
coverage run -m unittest discover tests
coverage html
Running Linters
pip install isort flake8 black
isort -rc . # rc means recursive, and was deprecated in dev version of isort
black .
Getting Help
If you need help for any reason, please make a github ticket. One of the contributors should help you out.
Releasing New Versions
How to prepare for release
- Update Changelog.md and version number in init.py
- Cut a release on github
How to publish to PyPI
Make sure your .pypirc is set up for testpypi and pypi index servers.
rm -rf dist
python setup.py sdist bdist_wheel
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*
Contributors
- Niket Patel - https://github.com/NiketPatel9
- Alok Saldanha - https://github.com/alokito
- Yohann Potier - https://github.com/ypotier