Skip to main content

A multimodal foundation model for T cell receptor and transcriptome analysis

Project description

TCRfoundation

Documentation Status PyPI version License: MIT Python 3.8+

A multimodal foundation model for single-cell immune profiling

Overview

TCRfoundation integrates gene expression and TCR sequences (α and β chains) from paired single-cell measurements through self-supervised pretraining with masked reconstruction and cross-modal contrastive learning.

Input and Pretraining Architecture

Gene expression profiles are encoded through feed-forward layers with multi-head attention, while TCR sequences are tokenized and processed through transformer blocks. The fused representations are learned via three objectives: masked gene expression reconstruction, masked TCR sequence reconstruction, and cross-modal alignment.

Input and Pretraining

Fine-tuning Tasks

The pretrained model supports three downstream applications:

  • T-cell state classification: Predict tissue origin, disease state, and cellular phenotype
  • Binding specificity detection: Identify TCR-antigen interactions and quantify binding avidity
  • Cross-modal prediction: Infer gene expression from TCR sequences

Fine-tuning Tasks

Installation

From PyPI (Recommended)

pip install tcrfoundation

From Source

git clone https://github.com/Liao-Xu/TCRfoundation.git
cd TCRfoundation
pip install -e .

Requirements: Python 3.8+, PyTorch 1.10.0+

Quick Start

import tcrfoundation as tcrf
import scanpy as sc

# Load your data
adata = sc.read("your_data.h5ad")

# Pretrain the foundation model
model, history = tcrf.pretrain.train(
    adata,
    epochs=500,
    batch_size=2048,
    save_dir='models/'
)

# Fine-tune for classification
results, adata_new = tcrf.finetune.classification.train_classifier(
    adata,
    label_column="cell_type",
    checkpoint_path="models/foundation_model_best.pt",
    num_epochs=50
)

Documentation

Tutorials

Complete Jupyter notebook tutorials are available:

  1. Pretraining - Train the foundation model
  2. Classification - T cell state classification
  3. Specificity - Antigen specificity prediction
  4. Avidity - Binding avidity regression
  5. Cross-modal - TCR-to-gene prediction

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tcrfoundation-0.1.3.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tcrfoundation-0.1.3-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

File details

Details for the file tcrfoundation-0.1.3.tar.gz.

File metadata

  • Download URL: tcrfoundation-0.1.3.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for tcrfoundation-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f32d28de7027fb46882f5d3e9ecf2213ee1f4eaf0714728d24ea91fce0dd3f07
MD5 0d6e31c53b2d5d1b378ea6a5bedcbff2
BLAKE2b-256 527c068a81df5b301730f3566a89dd6a8ceee32091482ef4e3a6f3dbbe834900

See more details on using hashes here.

File details

Details for the file tcrfoundation-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tcrfoundation-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 56.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for tcrfoundation-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bcfaeb5e8dfbc7fde8ab487960b48fc1e3c0037f5e2033aee5e2c0c85594baa5
MD5 a84d6e3604b7fbdd23d2725bb668000c
BLAKE2b-256 1e2fec3fe51f246505995955f31b3a53c65905b8aa351a49e37346d578db94ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page