Skip to main content

COMPASS: Generalizable AI predicts immunotherapy outcomes across cancers and treatments.

Project description

COMPASS: Generalizable AI predicts immunotherapy outcomes across cancers and treatments

PyPI version PyPI Downloads

COMPASS Paper ProjectPage COMPASS Dataset & Model COMPASS Personalized Response Maps Online COMPASS Predictor


An example2run.ipynb under the example folder is provided to run below experiments. Navigate to the example folder to run the code below:

1. Installing and Importing COMPASS

Installation

conda create -n compass python=3.12
conda activate compass
pip install immuno-compass -U

Importing COMPASS

Now, you can import COMPASS and its key components:

import compass
from compass import PreTrainer, FineTuner, loadcompass

2. Making Predictions with a Compass Model

You can download all available COMPASS fine-tuned models here for prediction.

The input df_tpm is gene expression tabular data. Please refer here for details on generating input data. The first column represents the cancer code, while the remaining 15,672 columns correspond to genes. Each row represents one patient. An example input file can be downloaded here.

The output df_pred contains two columns: 0 indicates non-response and 1 indicates response.

df_tpm = pd.read_csv('./data/compass_gide_tpm.tsv', sep='\t', index_col=0)
# OR directly load the compass model from https://www.immuno-compass.com/download/model/LOCO/pft_leave_Gide.pt 
model = loadcompass('./model/pft_leave_Gide.pt', map_location = 'cpu')
# Use map_location = 'cpu' if you dont have a GPU card
_, df_pred = model.predict(df_tpm, batch_size=128)

3. Extracting Features with a COMPASS Model

COMPASS models can function as feature extractors. The extracted features-gene-level, geneset-level, or cell type/pathway-level-can be used for downstream tasks such as building a logistic regression model for response prediction or a Cox regression model for survival prediction.

# Load COMPASS model and extract the features for a new cohort
model = loadcompass('https://www.immuno-compass.com/download/model/finetuner_pft_all.pt') 
dfgn, dfgs, dfct = model.extract(df_tpm, batch_size=128, with_gene_level=True)

The outputs dfgn, dfgs, and dfct correspond to gene-level (15,672), geneset-level (133), and concept-level (44) features, respectively. The extracted features are scalar scores. If you need vector features (dim=32), use the following method:

dfgs, dfct = model.project(df_tpm, batch_size=128)

4. Fine-Tuning COMPASS on Your Own Data

If you have in-house data and would like to fine-tune a COMPASS model with your own data, you can use any COMPASS model for fine-tuning. You can either load the pre-trained COMPASS model or a publicly available fine-tuned COMPASS model.

Important Note: If you choose a fine-tuned model for further fine-tuning (multi-stage FT), ensure that the load_decoder parameter in ft_args is set to True:

ft_args = {'load_decoder': True}

Select one of the fine-tuning modes: 'FFT', 'PFT', or 'LFT'. For very small datasets (n<30), 'LFT' is recommended.

Example Fine-Tuning Process

model = loadcompass('https://www.immuno-compass.com/download/model/LOCO/pft_leave_Gide.pt')  
ft_args = {'mode': 'PFT', 'lr': 1e-3, 'batch_size': 16, 'max_epochs': 100, 'load_decoder': True}

finetuner = FineTuner(model, **ft_args)

# Load the true labels
df_cln = pd.read_csv('./data/compass_gide_clinical.tsv', sep='\t', index_col=0)
dfy = pd.get_dummies(df_cln.response_label)

# Fine-tune the model
finetuner.tune(df_tpm, dfy)
finetuner.save('./model/my_finetuner.pt')

This process fine-tunes the COMPASS model on your data and saves the updated model for future use.

5. Pre-training COMPASS from Scratch

# Load the example dataset for pretraining
# We provide sample datasets that include gene expression data for training and testing
# Ensure the data is preprocessed appropriately before use
tcga_train_sample = pd.read_csv('./data/tcga_example_train.tsv', sep='\t', index_col=0)
tcga_test_sample = pd.read_csv('./data/tcga_example_test.tsv', sep='\t', index_col=0)

# Define pre-training hyperparameters
pt_args = {'lr': 1e-3, 'batch_size': 128, 'epochs': 20}
pretrainer = PreTrainer(**pt_args)

# Train the model using the provided training and test datasets
# - dfcx_train: Training dataset
# - dfcx_test: Validation dataset to monitor performance
pretrainer.train(dfcx_train=tcga_train_sample,
                 dfcx_test=tcga_test_sample)

# Save the trained pretrainer model for future use
pretrainer.save('./model/my_pretrainer.pt')

6. Baseline Methods Usage Examples

You can also extract features using baseline immune score methods. These features can be used to build models for response prediction.

# Import baseline immune score methods
import sys
sys.path.insert(0, '../')
from baseline.immune_score import immune_score_methods

# Extract features using baseline methods
# These features can be used to develop a logistic regression model for response prediction
res = []
for method_name, method_function in immune_score_methods.items():
    baseline_model = method_function(cancer_type='SKCM', drug_target='PD1')
    scores = baseline_model(df_tpm)
    res.append(scores)

# Combine results into a single DataFrame
pd.concat(res, axis=1).head()

7. Additional Information

This section provides detailed information to help you get started with the COMPASS project. We explain how to generate the necessary inputs from raw FASTQ data and introduce our online web server that supports both prediction and feature extraction using our pre-trained COMPASS models.

Generating COMPASS Inputs from Raw FASTQ Data

Generating high-quality inputs is crucial for the optimal performance of the COMPASS models. Our comprehensive Compass Data Pre-Processing Guide walks you through the entire workflow, ensuring that your raw FASTQ data is processed into a robust format ready for accurate predictions and feature extraction.

Online Web Server for Prediction and Feature Extraction

To simplify the use of our models, we offer an online web server that enables you to interact directly with the COMPASS models without local installations. The web server provides two primary functionalities:

These user-friendly services are designed to streamline your workflow and integrate COMPASS into your analytical processes.

Contributing Your Own COMPASS Models

We welcome contributions from the community. If you have developed a COMPASS model that can enhance our project, we encourage you to share it. By contributing your model, you help enrich the COMPASS ecosystem and promote collaborative innovation. For details on how to submit your model, please refer to our contribution guidelines. You can also join our Slack channel to discuss and collaborate with other users.

Citing Our Work

If you use our resources, please cite our work as follows:

Wanxiang Shen, Thinh H. Nguyen, Michelle M. Li, Yepeng Huang, Intae Moon, Nitya Nair, Daniel Marbach‡, and Marinka Zitnik‡. Generalizable AI predicts immunotherapy outcomes across cancers and treatments [J]. medRxiv.


We hope this information helps you make the most of the COMPASS project. If you have any questions or need further assistance, please do not hesitate to contact our support team.

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

immuno_compass-2.3.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

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

immuno_compass-2.3-py3-none-any.whl (4.3 MB view details)

Uploaded Python 3

File details

Details for the file immuno_compass-2.3.tar.gz.

File metadata

  • Download URL: immuno_compass-2.3.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for immuno_compass-2.3.tar.gz
Algorithm Hash digest
SHA256 6247ae0ade8c731b1012fbed54f4d9cb5e051f04a99fb7efe59277e7112212dd
MD5 0efb6858cf9ae0364bc96bc9c3c1e278
BLAKE2b-256 a0b4d19f71ca6a8cdf5346b64024d00362b55f6b2d2a5719eacfce49baca0444

See more details on using hashes here.

File details

Details for the file immuno_compass-2.3-py3-none-any.whl.

File metadata

  • Download URL: immuno_compass-2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for immuno_compass-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f05cd7120b392e4fb7763ca3265b9f51aa4e45654cd15bc4e65c942e0767b1bd
MD5 a6759158634ca92995b83438d7d05689
BLAKE2b-256 9afc8176e13adfdd2ce8a912a268611a454c19a1b6814b4dd766abc59c2c7e03

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