Skip to main content

CELLULAR: CELLUlar contrastive Learning for Annotation and Representation

Summary

Batch effects are a significant concern in single-cell RNA sequencing (scRNA-Seq) data analysis, where variations in the data can be attributed to factors unrelated to cell types. This can make downstream analysis a challenging task. In this study, we present a novel deep learning approach using contrastive learning and a carefully designed loss function for learning an generalizable embedding space from scRNA-Seq data. We call this model CELLULAR: CELLUlar contrastive Learning for Annotation and Representation. When benchmarked against multiple established methods for scRNA-Seq integration, CELLULAR outperforms existing methods in learning a generalizable embedding space on multiple datasets. Cell annotation was also explored as a downstream application for the learned embedding space. When compared against multiple well-established methods, CELLULAR demonstrates competitive performance with top cell classification methods in terms of accuracy, balanced accuracy, and F1 score. CELLULAR is also capable of performing novel cell type detection. These findings aim to quantify the meaningfulness of the embedding space learned by the model by highlighting the robust performance of our learned cell representations in various applications. The model has been structured into an open-source Python package, specifically designed to simplify and streamline its usage for bioinformaticians and other scientists interested in cell representation learning.

Necessary Python version

  • Python version >= 3.10.5

Setup

pip install --extra-index-url https://download.pytorch.org/whl/cu118 torch==2.2.1
pip install CELLULAR-CL

Functionality

The following functions have been included:

  • Training function for the embedding space model.
  • Training function for the classifier model.
  • Predict function for generating an embedding space.
  • Predict function for performing cell type annotation.
  • Function for novel cell type detection.
  • Function for creating cell type representation vectors.
  • Function for applying the same normalization strategy as was used in this study, giving the end user the option of using the same strategy or implementing their own.
  • Function for automatic preprocessing, although it is still recommended for end users to use their own preprocessing pipeline to make sure it is appropriate for their data.

Data

Data for the tutorials is available to download from Zenodo.

You will need to unpack the data. You can do that as follows:

tar -`vf data.rar  # Data for reproducing the work
tar -xvf tutorial.rar  # Data for the tutorials

Usage

Before using the model one first needs to obtain data to use as input. An example on how to divide data into training and test data can be found in the tutorial folder. In the code examples below it is assumed that the user has already created training data ("train_data.h5ad") and testing data ("test_data.h5ad").

For creating a learned embedding space

import scanpy as sc
import CELLULAR_CL as CELLULAR

adata_train = sc.read("train_data.h5ad", cache=True)
CELLULAR.train(adata=adata_train, target_key="cell_type", batch_key="batch")

adata_test = sc.read("test_data.h5ad", cache=True)
predictions = CELLULAR.predict(adata=adata_test)

For cell type annotation

import scanpy as sc
import CELLULAR_CL as CELLULAR

adata_train = sc.read("train_data.h5ad", cache=True)
CELLULAR.train(adata=adata_train, train_classifier=True, target_key="cell_type", batch_key="batch")

adata_test = sc.read("test_data.h5ad", cache=True)
predictions = CELLULAR.predict(adata=adata_test, use_classifier=True)

For novel cell type detection

import scanpy as sc
import CELLULAR_CL as CELLULAR

adata_train = sc.read("train_data.h5ad", cache=True)
CELLULAR.train(adata=adata_train, target_key="cell_type", batch_key="batch")

adata_test = sc.read("test_data.h5ad", cache=True)
CELLULAR.novel_cell_type_detection(adata=adata_test)

For making cell type representations

import scanpy as sc
import CELLULAR_CL as CELLULAR

adata_train = sc.read("train_data.h5ad", cache=True)
CELLULAR.train(adata=adata_train, target_key="cell_type", batch_key="batch")

adata_test = sc.read("test_data.h5ad", cache=True)
representations = CELLULAR.generate_representations(adata=adata_test, target_key="cell_type")

Tutorials

See the following tutorials, structureed as Python notebooks:

Citation

Coming soon!

Metadata

Release files for CELLULAR-CL 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CELLULAR-CL 0.0.4
File Size Uploaded
CELLULAR_CL-0.0.4.tar.gz 26.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CELLULAR-CL 0.0.4
File Interpreter ABI Platform
CELLULAR_CL-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 57.2 kB

Release files / CELLULAR_CL-0.0.4.tar.gz

Download URL CELLULAR_CL-0.0.4.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8ff28a5523d84c6f07fcd7cd38422f81c8484c73b56bd08437b98a4cc25fec14
BLAKE2b-256 checksum
How to use checksums
5b47fb60d97917325d45b36ac63b1fd3aa4f3fec47636b2224020e1986eb3593
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.0 CPython/3.10.5

Release files / CELLULAR_CL-0.0.4-py3-none-any.whl

Download URL CELLULAR_CL-0.0.4-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a807de4c96558c7f7404b7abc20ffa0ad9281d724253deebce7821af1e2fb715
BLAKE2b-256 checksum
How to use checksums
00a93444b7ad5ded73ab46c9fe772bfe12ef1452fbe9fc6e3c7cc686d0c96027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.0 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page