Metadata-Version: 2.4
Name: refcm
Version: 0.1.0
Summary: RefCM is a computational method that combines optimal transport and integer programming to enhance the annotation of scRNA clusters using established reference datasets.
Author-email: Valerio Galanti <vg2551@columbia.edu>, Lingting Shi <ls3456@columbia.edu>, Elham Azizi <ea2690@columbia.edu>, Yining Liu <yl4536@columbia.edu>, "Andrew J. Blumberg" <ab4808@columbia.edu>
License: BSD 3-Clause License
        
        Copyright (c) 2025, Valerio Galanti
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: nbformat>=5.10.4
Requires-Dist: platformdirs>=4.3.8
Requires-Dist: plotly>=6.1.2
Requires-Dist: pot>=0.9.5
Requires-Dist: pulp>=3.2.1
Requires-Dist: scanpy>=1.11.2
Requires-Dist: tqdm>=4.67.1
Provides-Extra: dev
Requires-Dist: ipykernel>=6.29.5; extra == "dev"
Requires-Dist: matplotlib>=3.10.3; extra == "dev"
Dynamic: license-file

[![Python Versions](https://img.shields.io/badge/python-3.11-blue)](https://pypi.org/project/alpaca-py)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

<center> <h1>RefCM: Reference Cluster-Mapping</h1> </center>


RefCM is an automated tool enabling cell-type annotation across different scRNA-seq datasets. The model bases itself on the geometric properties of optimal transport to map cell-type clusters across tissues, sequencing methods, and species.

![overview](/vignettes/overview.jpeg)

## Table of Contents
- [Table of Contents](#table-of-contents)
- [About](#about)
- [Installation](#installation)
- [Requirements](#requirements)
- [Usage](#usage)
- [Examples ](#examples)

## About <a name="about"></a>

The primary purpose of this repository is to enable the reproduction of the results reported in the paper, and help others utilize this method towards their own work.


## Installation <a name="installation"></a>

We recommend using [uv](https://docs.astral.sh/uv/). After installation, simply run `uv sync` to install the required virtual environment and compatible python version.

For conda users, we have provided a [yaml file](./env.yml):
```shell
conda env create -n refcm -f env.yml
conda activate refcm
```

Additionally, users will need to install GLPK. On MacOS, this can be done via homebrew with `brew install glpk`. Windows users require a few more steps, described in [this guide](https://stackoverflow.com/questions/17513666/installing-glpk-gnu-linear-programming-kit-on-windows). Please restart your IDE after setup.

To download the datasets in our study, please visit our [Google Drive link](https://drive.google.com/drive/folders/1fWWaxBLUdacBT9r-1CymdyRICMPStvBJ?usp=share_link) and accompanying [data setup notebook](./data/setup.ipynb) which includes source links and data preprocessing instructions.

## Requirements <a name="requirements"></a>

The package has been tested on:

* macOS Sequoia (Apple M1 Pro, 32 GB RAM)
* Windows 11 (Intel i5 4-core CPU, 8 GB RAM)

There are no strict hardware requirements, aside from the ability to load the query and reference datasets into memory. All analyses, except for the large embryogenesis datasets, were reproducible on the 8 GB Windows system. On the M1 Pro, even the largest datasets completed in under 20 minutes.

Installation typically takes under 10 minutes (from cloning the repository to running example scripts), depending on network speed.


## Usage <a name="usage"></a>

Running RefCM on a given `query: AnnData` and `reference: AnnData` dataset pair, assuming clustering information under their respective `.obs['cluster']` attributes, can be achieved by running the following code and tweaking the remaining hyperparameters. The method expects raw counts to be provided under each dataset's `.X` attribute.

```python
    from refcm import RefCM
    
    rcm = RefCM()
    rcm.setref(reference, 'reference', 'cluster')
    m = rcm.annotate(query, 'query', 'cluster')
```

The resulting annotations are written out to the `.obs['refcm_annot']` field in the query's `AnnData` object, leaving the remaining fields unchanged.

For a graphical representation of the resulting matching/cluster-mapping:

```python
    m.display_matching_costs()
```

Provided a ground-truth `.obs` field, the matching's performance can be evaluated as follows:

```python
    m.display_matching_costs(ground_truth_obs_key='ground_truth_key')
    m.eval(ground_truth_obs_key='ground_truth_key')
```


### Examples <a name="examples"></a>

We’ve put together a few example Jupyter notebooks under [/vignettes](./vignettes/) to help you start using RefCM right away. Our starter example, [brain.ipynb](vignettes/brain.ipynb), walks you through applying the method to the Allen Brain Atlas datasets.
