CytoCommunity2
Contents
Overview
To enhance CytoCommunity (https://github.com/huBioinfo/CytoCommunity), we present CytoCommunity2, a unified weakly-supervised framework for identifying and comparing tissue cellular neighborhoods (TCNs or CNs) across large-scale spatial omics samples with single or multiple biological conditions.
Inspired by histopathology workflows, CytoCommunity2 first hierarchically partitions the large single-cell spatial map into small patches, performs graph construction and weakly supervised TCN learning for each patch, and finally merges results through KNN-based TCN reassignment at segmentation boundaries to ensure TCN spatial continuity. This strategy divides the original sample into patches for TCN learning, achieving memory efficiency (typical 24G graphics memory is enough) and also increased sample throughput. These optimizations significantly enhance the robustness of TCNs and cross-sample alignment performance.
Furthermore, to make CytoCommunity2 a unified framework that is also applicable for single-condition spatial omics datasets, pseudo-samples with artificial labels are generated, enabling automatic TCN alignment across real samples via contrastive learning.
In summary, the advantages of CytoCommunity2 include:
(1) Using significantly less memory for large-scale spatial omics samples with millions of cells.
(2) A unified weakly-supervised model applicable for both multi-condition and single-condition datasets.
(3) High TCN alignment performance makes it well-suited for comparative analysis in large cohort studies.
Installation
Hardware requirement
Graphics memory: 24G
Storage: 10GB or more
Install CytoCommunity2
CytoCommunity2 requires Python 3.10 or newer. We recommend creating and activating a Conda environment first:
conda create -n cytocommunity2 python=3.10
conda activate cytocommunity2
For an NVIDIA GPU on Windows or Linux, first install the appropriate CUDA-enabled PyTorch build from the official PyTorch installation page.
Install the package:
pip install cytocommunity2
To run the downstream analyses, install the optional downstream dependencies with:
pip install "cytocommunity2[downstream]"
This extra includes esda, libpysal, and Jupyter; they are not installed
by the basic command above.
Usage
1. Prepare input data
The input data to CytoCommunity2 includes four types of files :
(1) An image (sample) name list file, named as "ImageNameList.txt".
(2) A cell type label file for each image (sample), named as "[image name]_CellTypeLabel.txt". Note that [image_name] should be consistent with your customized image names listed in the "ImageNameList.txt". This file lists cell type names of all cells in an image (sample).
(3) A cell spatial coordinate file for each image (sample), named as "[image name]_Coordinates.txt". Note that [image_name] should be consistent with your customized image names listed in the "ImageNameList.txt". This file lists cell coordinates (tab-delimited x/y) of all cells in an image (sample). The cell orders should be exactly the same with "[image name]_CellTypeLabel.txt".
(4) A graph label file for each image (sample), named as "[image name]_GraphLabel.txt". For multi-condition datasets, this file must be provided for every image (sample) and contain one integer indicating its biological condition. For single-condition datasets, graph label files can be omitted for all images (samples), and CytoCommunity2 will generate pseudo-samples for weakly-supervised learning.
2. Configure CytoCommunity2
Before running CytoCommunity2, set input_dir and review all
model and downstream parameters in
hyperparameters.json. The Python workflow will use this configuration file.
3. Run CytoCommunity2
The tutorial uses a TNBC dataset as a worked example and demonstrates the entire CytoCommunity2 workflow, from model training and CN identification to downstream analysis:
jupyter notebook tutorial/TNBC_workflow.ipynb
4. Output files
The main output directories are:
CNLearning_Output/: CN-number screening, trained models and CN labels.CNVisualization_Output/: spatial plots and result tables.data/: downstream analysis results and intermediate data tables.plot/: figures generated by downstream analyses.
Maintainers
- Liukang Wu (yetong@stu.xidian.edu.cn)
- Yafei Xu (22031212416@stu.xidian.edu.cn)
- Yuxuan Hu (huyuxuan@xidian.edu.cn)
Citation
Yuxuan Hu, Jiazhen Rong, Yafei Xu, Runzhi Xie, Jacqueline Peng, Lin Gao, and Kai Tan. “Unsupervised and supervised discovery of tissue cellular neighborhoods from cell phenotypes.” Nature Methods 21 (2024): 267–278. https://doi.org/10.1038/s41592-023-02124-2
Release files for cytocommunity2 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cytocommunity2-0.1.5.tar.gz | 52.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cytocommunity2-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:117.7 kB
Release files / cytocommunity2-0.1.5.tar.gz
| Download URL | cytocommunity2-0.1.5.tar.gz |
|---|---|
| Size | 52.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcddef6e8ac6537ed79b7e81816192a08361521e145dcbc62d2ea22b41d4ae83
|
|
BLAKE2b-256 checksum How to use checksums |
26c6cf7621439a4ebd20f15379a4331fe285cdcd3604533ca2bb26b3051f058a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Release files / cytocommunity2-0.1.5-py3-none-any.whl
| Download URL | cytocommunity2-0.1.5-py3-none-any.whl |
|---|---|
| Size | 65.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
496c649b694977287fc24f20c35daa0f5d1a787312798ce56770999060cb6194
|
|
BLAKE2b-256 checksum How to use checksums |
2b7e2f01360c4d98f364bb1eed45942ffb8475a5a11e0b2adadf442a91f5915a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|