Skip to content

Commit

Permalink
Rename to decipher
Browse files Browse the repository at this point in the history
  • Loading branch information
xiachenrui committed Oct 20, 2024
1 parent 979cf44 commit 51035d3
Show file tree
Hide file tree
Showing 83 changed files with 264 additions and 267 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ exclude =
docs/_build,
dist,
experiments,
spider/wsi/hover_net
per-file-ignores =
tests/*: D
*/__init__.py: F401
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
name: Bug report
about: Spider doesn’t do what it should? Please help us fix it!
about: DECIPHER doesn’t do what it should? Please help us fix it!
title: ''
labels: bug
assignees: ''
---

### Please ensure:

- [ ] I have confirmed this bug exists on the **latest** version of Spider. See https://github.com/gao-lab/spider
- [ ] I follow the tutorial from the [Spider tutorial](https://github.com/gao-lab/spider).
- [ ] I have confirmed this bug exists on the **latest** version of DECIPHER. See https://github.com/gao-lab/decipher
- [ ] I follow the tutorial from the [DECIPHER tutorial](https://github.com/gao-lab/decipher).

-----------

Expand All @@ -24,7 +24,7 @@ assignees: ''
- Python version: <!-- e.g. 3.9.1 -->
- Torch version: <!-- e.g. 2.0.1 -->
- Pytorch geometric version: <!-- e.g. 2.3.0 -->
- Spider version: <!-- e.g. 0.1.0 -->
- DECIPHER version: <!-- e.g. 0.1.0 -->
- Others: <!-- Other unconventional env setup -->

**Data information:**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement-request.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Enhancement request
about: Anything you’d like to see in Spider?
about: Anything you’d like to see in DECIPHER?
title: ''
labels: enhancement
assignees: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
context: .
dockerfile: ./Dockerfile
push: true
tags: huhansan666666/spider:latest
tags: huhansan666666/decipher:latest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ experiments/**/*.yaml
!resource/README.md
!.vscode/*
!Dockerfile
!spider/data/*
!decipher/data/*
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ fail_fast: false
default_language_version:
python: python3
default_stages:
- commit
- push
- pre-commit
- pre-push
minimum_pre_commit_version: 2.16.0
repos:
- repo: https://github.com/psf/black
Expand Down
6 changes: 3 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Full install
```sh
git clone [email protected]:gao-lab/Spider-dev.git && cd Spider-dev
git clone [email protected]:gao-lab/DECIPHER.git && cd DECIPHER
mamba create -p ./conda -c conda-forge -c rapidsai -c nvidia -c bioconda python=3.11 rapids=24.04 cuda-version=11.8 cudnn cutensor cusparselt pandoc snakemake==7.32.4 -y && conda activate ./conda
pip install -e ".[dev, docs]"
install_pyg_dependencies
Expand Down Expand Up @@ -35,6 +35,6 @@ py-spy record -o profile.svg -- python -m <YOUR_SCRIPT.py>

## Build docker image
```sh
cd Spider-dev/
docker image build --no-cache . -t huhansan666666/spider:v0.1.0 --network=host
# cd DECIPHER/
docker image build --no-cache . -t huhansan666666/decipher:v0.1.0 --network=host
```
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Copy Spider package and install
# Copy DECIPHER package and install
USER rapids
WORKDIR /app
COPY ./spider ./spider
COPY ./decipher ./decipher
COPY ./README.md ./README.md
COPY ./pyproject.toml ./pyproject.toml
RUN pip --no-cache-dir install -e "." && install_pyg_dependencies && rm -rf /tmp/*
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
<!-- [![stars-badge](https://img.shields.io/github/stars/gao-lab/Spider-dev?logo=GitHub&color=yellow)](https://github.com/gao-lab/Spider-dev/stargazers) -->
<!-- [![stars-badge](https://img.shields.io/github/stars/gao-lab/DECIPHER?logo=GitHub&color=yellow)](https://github.com/gao-lab/DECIPHER/stargazers) -->
[![build-badge](https://github.com/gao-lab/DECIPHER/actions/workflows/build.yml/badge.svg)](https://github.com/gao-lab/DECIPHER/actions/workflows/build.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![build-badge](https://github.com/gao-lab/Spider-dev/actions/workflows/build.yml/badge.svg)](https://github.com/gao-lab/Spider-dev/actions/workflows/build.yml)
[![license-badge](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Python 3.10|3.11|3.12](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue.svg)


# Spider: SPatial IDentity and Environment Representation
# DECIPHER
<div align="center">

[Installation](#Installation)[Documentation](#Documentation)[Citation](#Citation)[FAQ](#FAQ)[Acknowledgement](#Acknowledgement)
[Installation](#Installation)[Documentation](#Documentation)[Manuscript](#Manuscript)[FAQ](#FAQ)[Acknowledgement](#Acknowledgement)

</div>

`Spider` aims to learn cells’ embeddings from omics feature and spatial environment aspects independently, from single-cell spatial omics data.
`DECIPHER` aims to learn cells’ disentangled embeddings from intracellular state and extracellular contexts view based on single-cell spatial omics data.

![DECIPHER](./docs/_static/Model.png)

## Installation
> [!IMPORTANT]
> Requires Python >= 3.10 and CUDA-enabled GPU (not recommend using CPU because it‘s too slow).
### PyPI
We recommend to install `Spider` to a new conda environment with [RAPIDS](https://docs.rapids.ai/install) dependencies.
We recommend to install `cell-decipher` to a new conda environment with [RAPIDS](https://docs.rapids.ai/install) dependencies.

```sh
mamba create -p ./conda -c conda-forge -c rapidsai -c nvidia python=3.11 rapids=24.04 cuda-version=11.8 cudnn cutensor cusparselt -y && conda activate ./conda
pip install spider
pip install cell-decipher
install_pyg_dependencies
```

### Docker
Build docker image from [Dockerfile](./Dockerfile) or pull the latest image from Docker Hub by:
```sh
docker pull huhansan666666/spider:latest
docker pull huhansan666666/decipher:latest
```

## Documentation
Here is a minimal example for quick start. Please check our [**documentation**](https://slat.readthedocs.io/en/latest/) for detailed tutorial and information.
Here is a minimal example for quick start. Please check our [**documentation**](https://slat.readthedocs.io/en/latest/) for advanced tutorials.

```python
import scanpy as sc
from spider import Spider
from decipher import DECIPHER

# Init model
model = Spider(work_dir='/path/to/work_dir')
model = DECIPHER(work_dir='/path/to/work_dir')

# Register data
adata = sc.read_h5ad('/path/to/adata.h5ad')
Expand All @@ -50,12 +52,12 @@ model.register_data(adata)
# Fit model
model.fit_omics()

# Get independent omics and spatial embeddings
# Get disentangled omics and spatial embeddings
omics_emb = model.center_emb
spatial_emb = model.nbr_emb
```

## Citation
## Manuscript
TBD

> If you want to repeat our benchmarks and case studies, please check the [**benchmark**](./benchmark/README.md) and [**experiments**](./experiments/README.md) folder.
Expand Down
6 changes: 3 additions & 3 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ All datasets used in benchmark are public available. Here is a summary:


## Methods
- Spider
- DECIPHER
- SLAT
- BANKSY
- STAGATE
Expand All @@ -24,15 +24,15 @@ All datasets used in benchmark are public available. Here is a summary:
## Reproducibility

### Setup environment
Following the [guide](./env/README.md). You can also check absolute version of install packages in [conda.yaml](env/conda.yaml) file.
Follow the [guide](./env/README.md) to set up the environment. The absolute version of packages is also provided in [conda.yaml](env/conda.yaml).

### Prepare data

Download the datasets and move them into `./input` folder.

### Run the workflow in slurm cluster

> Take about 12 hours when using 4 GPU nodes (64 cores, 1TB mem and 8 A100-GPUs).
> Take about 12 hours when using 32 A100 GPUs.
We use `snakemake` to run benchmark workflows in Slurm cluster. Firstly, you need modify `partition` name in [`config`](./profiles/hpc/hpc.yaml) according to your cluster settings, then run:

Expand Down
6 changes: 3 additions & 3 deletions benchmark/analysis/benchmark_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library(patchwork)

# %% vscode={"languageId": "r"}
data <- read_csv('../results/benchmark_results.csv')
data$method <- factor(data$method, levels = c('spider', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))
data$method <- factor(data$method, levels = c('decipher', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))

# # replace ':' by '-' in all column names
# data <- data %>% rename_all(~ gsub(":", "__", .))
Expand Down Expand Up @@ -98,7 +98,7 @@ ggbarplot(data, x="method", y='run_time', fill='method', color='method', add="me

# %% vscode={"languageId": "r"}
data <- read_csv('../results/benchmark_results.csv')
data$method <- factor(data$method, levels = c('spider', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))
data$method <- factor(data$method, levels = c('decipher', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))
data <- data %>% filter(dataset == 'human_brainaging_merfish') %>% filter(method != 'harmony')

head(data)
Expand Down Expand Up @@ -144,7 +144,7 @@ p_list[[1]] | p_list[[2]]

# %% vscode={"languageId": "r"}
data <- read_csv('../results/benchmark_results.csv')
data$method <- factor(data$method, levels = c('spider', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))
data$method <- factor(data$method, levels = c('decipher', 'scvi', 'harmony', 'scanpy', 'banksy', 'stagate', 'slat'))
data <- data %>% filter(dataset == 'human_breastcancer_xenium') %>% filter(method != 'harmony')


Expand Down
2 changes: 1 addition & 1 deletion benchmark/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dataset:

#--------------------------- Benchmark Methods -----------------------------#
method:
- spider
- decipher
# # spatial
- banksy
- stagate
Expand Down
4 changes: 2 additions & 2 deletions benchmark/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mamba create -p ./conda -y -c conda-forge -c rapidsai -c nvidia -c bioconda pyth
rapids=24.04 cuda-version=11.8 cudnn cutensor cusparselt \
snakemake==7.32.4 && conda activate ./conda

# spider & scanpy
# cd /path/to/spider
# decipher & scanpy
# cd /path/to/decipher
pip install '.[dev]'
install_pyg_dependencies

Expand Down
2 changes: 1 addition & 1 deletion benchmark/env/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ dependencies:
- seaborn==0.13.2
- session-info==1.0.0
- spagcn==1.2.7
- spider==0.1.0
- decipher==0.1.0
- stack-data==0.6.3
- stagate-pyg==1.0.0
- statsmodels==0.14.2
Expand Down
6 changes: 3 additions & 3 deletions benchmark/profiles/cls/cls.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__default__:
jobname: "Spider-{rule}"
jobname: "DECIPHER-{rule}"
output: ".slurm/{rule}.out"
error: ".slurm/{rule}.err"
account: gaog_g1
Expand All @@ -10,7 +10,7 @@ __default__:
qos: gaogcns
gres: ""

run_spider:
run_decipher:
partition: gpu_4l
qos: gaogg4c
gres: "--gres=gpu:1"
Expand All @@ -25,7 +25,7 @@ run_scvi:
qos: gaogg4c
gres: "--gres=gpu:1"

search_spider:
search_decipher:
partition: gpu_4l
qos: gaogg4c
gres: "--gres=gpu:1"
6 changes: 3 additions & 3 deletions benchmark/profiles/hpc/hpc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__default__:
jobname: "Spider-{rule}"
jobname: "DECIPHER-{rule}"
output: ".slurm/{rule}.out"
error: ".slurm/{rule}.err"
account: gglab
Expand All @@ -9,7 +9,7 @@ __default__:
n_cpu: "{threads}"
gres: ""

run_spider:
run_decipher:
partition: gpu32,gpu2
gres: "--gres=gpu:1"

Expand All @@ -21,6 +21,6 @@ run_scvi:
partition: gpu32,gpu2
gres: "--gres=gpu:1"

search_spider:
search_decipher:
partition: gpu32,gpu2
gres: "--gres=gpu:1"
4 changes: 2 additions & 2 deletions benchmark/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ localrules:
summary_benchmark,
summary_hyper_search,
link_data,
# run_spider,
# run_decipher,
# run_scvi,
# run_stagate,
# calc_metrics,
Expand Down Expand Up @@ -40,7 +40,7 @@ rule summary_hyper_search:
output:
"results/hyper_search.csv",
params:
pattern=lambda wildcards: "results/{dataset}/seed:{seed}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/metrics.yaml"
pattern=lambda wildcards: "results/{dataset}/seed:{seed}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/metrics.yaml"
threads: 1
script:
"scripts/summarize.py"
Expand Down
18 changes: 9 additions & 9 deletions benchmark/workflow/rules/hyper_search.smk
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

rule search_spider:
rule search_decipher:
input:
data = "{path}/data.h5ad",
script = "workflow/scripts/search_spider.py",
script = "workflow/scripts/search_decipher.py",
output:
center_emb = "{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/center_emb.npy",
nbr_emb = "{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/nbr_emb.npy",
time = "{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/time.yaml",
center_emb = "{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/center_emb.npy",
nbr_emb = "{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/nbr_emb.npy",
time = "{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/time.yaml",
params:
notebook_in = "workflow/scripts/search_spider.ipynb",
notebook_out = "{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/search_spider.ipynb",
work_dir = "{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}",
notebook_in = "workflow/scripts/search_decipher.ipynb",
notebook_out = "{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/search_decipher.ipynb",
work_dir = "{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}",
log:
"{path}/search_spider/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/search_spider.log"
"{path}/search_decipher/dropout_gex:{dropout_gex}-k:{k}-center_emb_dim:{center_emb_dim}-nbr_emb_dim:{nbr_emb_dim}-epochs:{epochs}-dropout:{dropout}-transformer_layers:{transformer_layers}-temperature_center:{temperature_center}-temperature_nbr:{temperature_nbr}-batch_size:{batch_size}/search_decipher.log"
threads:8
resources: gpu=1
shell:
Expand Down
18 changes: 9 additions & 9 deletions benchmark/workflow/rules/methods.smk
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

rule run_spider:
rule run_decipher:
input:
data = "{path}/data.h5ad",
script = "workflow/scripts/run_spider.py",
script = "workflow/scripts/run_decipher.py",
output:
center_emb = "{path}/spider/center_emb.npy",
nbr_emb = "{path}/spider/nbr_emb.npy",
time = "{path}/spider/time.yaml",
center_emb = "{path}/decipher/center_emb.npy",
nbr_emb = "{path}/decipher/nbr_emb.npy",
time = "{path}/decipher/time.yaml",
params:
notebook_in = "workflow/scripts/run_spider.ipynb",
notebook_out = "{path}/spider/run_spider.ipynb",
work_dir = "{path}/spider",
notebook_in = "workflow/scripts/run_decipher.ipynb",
notebook_out = "{path}/decipher/run_decipher.ipynb",
work_dir = "{path}/decipher",
log:
"{path}/spider/run_spider.log",
"{path}/decipher/run_decipher.log",
threads:8
resources: gpu=1
shell:
Expand Down
Loading

0 comments on commit 51035d3

Please sign in to comment.