Metadata-Version: 2.4
Name: CellNiche
Version: 0.1.8
Summary: CellNiche represents cellular microenvironments in atlas-scale spatial omics data with contrastive learning
Author-email: Zhongming Liang <liangzhongming21@mails.ucas.ac.cn>
License: 
        MIT License
        
        Copyright (c) [2025] [Zhongming Liang]
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/Super-LzzZ/CellNiche
Project-URL: Issues, https://github.com/Super-LzzZ/CellNiche/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=1.12.1
Requires-Dist: torch-geometric>=2.6.1
Requires-Dist: torch-scatter>=2.1.0
Requires-Dist: torch-sparse>=0.6.15
Requires-Dist: torch-cluster>=1.6.0
Requires-Dist: torch-spline-conv>=1.2.1
Requires-Dist: scanpy>=1.9.8
Requires-Dist: anndata>=0.9.2
Requires-Dist: scikit-learn>=1.3.2
Requires-Dist: numpy>=1.22.4
Requires-Dist: scipy>=1.10.1
Requires-Dist: pandas>=2.0.3
Requires-Dist: tqdm>=4.67.1
Requires-Dist: networkx>=3.1
Requires-Dist: h5py>=3.11.0
Requires-Dist: natsort>=8.4.0
Requires-Dist: pyyaml>=6.0
Dynamic: license-file


# CellNiche

## Overview ✨
**CellNiche** is a lightweight and scalable representation learning framework for **atlas-scale spatial omics** that **identifies and characterizes cellular microenvironments**. It flexibly accommodates multiple forms of cellular identity representations, including **expression matrices, pretrained embeddings, and discrete cell labels**, making it well suited for **heterogeneous spatial omics data**. With efficient computation and strong robustness across input types, CellNiche supports **cross-sample analysis of cancer spatial omics cohorts** and the **construction of large-scale virtual organ atlases**.

Please check our paper *CellNiche represents cellular microenvironments in atlas-scale spatial omics data with contrastive learning* on [Nature Communications](https://www.nature.com/articles/s41467-026-71759-4).

## Installation ⚙️
### From Source (recommend)
```bash
git clone https://github.com/Super-LzzZ/CellNiche.git
cd CellNiche
```
### From PyPI
```bash
pip install CellNiche
```

## Requirements
- Python ≥ 3.9  
- PyTorch ≥ 1.12  
- PyTorch Geometric (torch-geometric, torch-scatter, torch-sparse, torch-cluster, torch-spline-conv)  
- Scanpy ≥ 1.9  
- Anndata ≥ 0.9  
- scikit-learn ≥ 1.3  
- numpy ≥ 1.22  
- scipy ≥ 1.10  
- pandas ≥ 2.0  
- networkx ≥ 3.1   
- tqdm ≥ 4.67.1  

You can install most dependencies with:

```bash
pip install torch torchvision torchaudio
pip install torch-geometric torch-scatter torch-sparse torch-cluster torch-spline-conv
pip install scanpy anndata scikit-learn numpy scipy pandas networkx tqdm
```

A successful example
```bash
conda create -n cellniche python=3.9
conda activate cellniche
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2
pip install torch_cluster-1.6.3+pt20cu117-cp39-cp39-linux_x86_64.whl
pip install torch_scatter-2.1.2+pt20cu117-cp39-cp39-linux_x86_64.whl
pip install torch_sparse-0.6.18+pt20cu117-cp39-cp39-linux_x86_64.whl
pip install torch_spline_conv-1.2.2+pt20cu117-cp39-cp39-linux_x86_64.whl
pip install torch-geometric==2.6.1
pip install CellNiche

pip install pyyaml
...
```


## Tutorials 📚
#### Spatial proteomics data or single-cell spatial transcriptomics data

The data required to run tutorials is located in `data/`. Please note that due to Github size limitations, you have to download the relevant data for analysis from [Google Drive](https://drive.google.com/drive/folders/1pw_TrjsHIWAXnz1Qzfir-DJOv4IGI4Y5?usp=sharing). 

CellNiche for single-slice
* [CellNiche's demonstration on cortex osmFISH data](tutorial/cortex.ipynb)
* [CellNiche's demonstration on mouse_spleen CODEX data](tutorial/spleen.ipynb)
* [CellNiche's demonstration on mouse_brain STAPmap data](tutorial/brain_STARmap.ipynb)

CellNiche for integrated multiple slices from the same experiment
* [CellNiche's demonstration on NSCLC data](tutorial/NSCLC.ipynb)

CellNiche for integrated multiple slices across different technologies
* [Constructing a cross-technique integrated mouse brain dataset](tutorial/create_mergedBrainDataset.ipynb)
* [CellNiche's demonstration of batch effects on mergedBrain data](tutorial/mergedBrain_batch.ipynb)
* [CellNiche's demonstration on mergedBrain data (part1: Atlas1)](tutorial/mergedBrain_patr1.ipynb)
* [CellNiche's demonstration on mergedBrain data (part2: Atlas2, 3, 4)](tutorial/mergedBrain_part2.ipynb)



## Getting Started 🚀
### bash (recommend)
```bash
python -m cellniche.main --config ./configs/cortex_osmFISH.yaml

```
### python
```python
# way 1: If you download from source (better suited for personalized use)
sys.path.append('/share/home/liangzhongming/phd_code/530/CellNiche/release')
import cellniche as cn

# way 2: If you download from PyPI (better suited for stable use)
# import cellniche as cn


# Parse arguments from a YAML config
# Run training/inference
adata = cn.cli(["--config", "./configs/cortex_osmFISH.yaml"])
```

## Contribution

For questions or comments, please use the [issue tracker](https://github.com/Super-LzzZ/CellNiche/issues) and/or email Zhongming Liang (liangzhongming21@mails.ucas.ac.cn).
