scFormer: A Universal Representation Learning Approach for Single-Cell Data Using Transformers

Haotian Cui, Xiaoming Wang, Hassaan Maan, Nan Duan, Bo Wang

Abstract

Single-cell sequencing has emerged as a promising technique to decode cellular heterogeneity and analyze gene functions. With the high throughput of modern techniques and resulting large-scale sequencing data, deep learning has been used extensively to learn representations of individual cells for downstream tasks. However, most existing methods rely on fully connected networks and are unable to model complex relationships between both cell and gene representations. We hereby propose scFormer, a novel transformer-based deep learning framework to jointly optimize cell and gene embeddings for single-cell biology in an unsupervised manner. By drawing parallels between natural language processing and genomics, scFormer applies self-attention to learn salient gene and cell embeddings through masked gene modelling. scFormer provides a unified framework to readily address a variety of downstream tasks such as data integration, analysis of gene function, and perturbation response prediction. Extensive experiments using scFormer show state-of-the-art performance on seven datasets across the relevant tasks.

Introduction

Single-cell RNA sequencing (scRNA-seq) provides a high-resolution map of biology by revealing which genes are active in individual cells. However, analyzing this data is complex due to high dimensionality and technical noise. Traditional deep learning models, such as Variational Autoencoders (VAEs) using Multi-Layer Perceptrons (MLPs), often compress cellular information into small latent vectors. This approach struggles to capture the intricate, web-like interactions between thousands of genes, limiting their effectiveness in predicting cellular responses to genetic modifications.

Methodology: The Transformer Approach to Genomics

scFormer introduces a transformer-based framework that treats a cell as a "sentence" and genes as "words." This architecture allows the model to explicitly learn gene-gene relationships through self-attention mechanisms.

The scFormer architecture consists of three main components: Input Embeddings, the Transformer Module, and specialized Task Heads for joint learning.

Technical Innovations

  • Gene-as-Tokens: Each gene is assigned a unique token with a learned embedding. A cell is represented as a sequence of these tokens.
  • Value Binning: To mitigate noise from varying sequencing depths, scFormer uses "value binning" to convert expression levels into relative ranks, ensuring consistency across datasets.
  • Joint Learning Heads: The model is optimized using four specialized heads:
  • Masked Gene Modeling (MGM): Predicts hidden gene values based on the context of other genes.
  • Masked Value for Cell (MVC): Ensures cell-level representations can reconstruct individual gene values.
  • Elastic Cell Similarity (ECS): A contrastive learning tool to refine the latent space by grouping similar cells.
  • Domain Adaptation (DAR): A reverse classifier that helps the model ignore technical "batch effects" while preserving biological signals.

Key Results

The authors validated scFormer across seven diverse datasets, including single-dataset clustering, multi-donor data integration, and genetic perturbation prediction.

UMAP visualizations demonstrate scFormer's ability to cluster cells by biological type while successfully integrating data across different technical batches.

Performance Highlights

  • State-of-the-Art Clustering: On the Cortex dataset, scFormer outperformed established methods like scVI and Seurat by 8–17% in biological conservation metrics (AvgBIO).
  • Superior Perturbation Prediction: In the Norman et al. dataset, scFormer achieved a Pearson correlation of 0.921 for predicting gene expression after CRISPR editing, surpassing the previous state-of-the-art model, GEARS.
  • Ablation Studies: Removing the MGM and MVC heads resulted in a 29% drop in cell-type identification accuracy, proving these components are critical to the model's success.

Discussion and Future Work

scFormer demonstrates that learning gene and cell embeddings simultaneously enhances the representational power of both. By prioritizing relative ranks over raw counts, the model becomes robust to technical noise. While currently focused on transcriptomics, future iterations of scFormer aim to incorporate multi-omics data, such as ATAC-seq and spatial transcriptomics, to create a universal foundation model for single-cell biology.

Summary updated

BibTeX
@misc{cui2022scformer,
  author = {Haotian Cui and Xiaoming Wang and Hassaan Maan and Nan Duan and Bo Wang},
  title = {{scFormer: A Universal Representation Learning Approach for Single-Cell Data Using Transformers}},
  year = {2022},
  doi = {10.1101/2022.11.20.517285},
  howpublished = {bioRxiv},
}
Figure