Skip to content

QTIM-Lab/tme-wsi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TME-WSI: Deep Learning-based Prediction of Breast Cancer Tumor and Immune Phenotypes from Histopathology

This repository contains the code for predicting Tumor Microenvironment (TME) phenotypes from Whole Slide Images (WSIs) using deep learning, specifically Multi-Instance Learning (MIL) models.

Project Structure

The project is structured as a Python package tme_wsi with supporting scripts:

tme-wsi/
├── tme_wsi/
│       ├── preprocessing/   # WSI Segmentation and Patching
│       ├── features/        # Feature Extraction (CLAM, PLIP)
│       ├── models/          # MIL Models (CLAM, TransMIL)
│       ├── engine/          # Training and Evaluation Engine
│       ├── visualization/   # Attention Heatmap Generation
│       └── utils/           # Datasets and Utilities
├── scripts/
│   ├── run_preprocessing.py   # Script to patch WSIs
│   ├── run_feature_extraction.py # Script to extract features
│   ├── train_model.py         # Script to train models
│   └── eval_model.py          # Script to evaluate models
├── configs/                   # Configuration files (YAML)
└── README.md

Installation

  1. Clone the repository.
  2. Install dependencies:
    pip install -r requirements.txt
    (Note: Ensure you have openslide-python and appropriate system libraries installed).

Usage

1. Preprocessing (Patching)

Patch WSIs into small images (tiles).

python scripts/run_preprocessing.py \
  --source /path/to/wsis \
  --save_dir /path/to/output/patches \
  --patch_size 256 --step_size 256 --patch_level 0

2. Feature Extraction

Extract features from patches using CLAM (ResNet50) or PLIP.

python scripts/run_feature_extraction.py \
  --source_dir /path/to/wsis \
  --h5_dir /path/to/output/patches \
  --save_dir /path/to/output/features \
  --model_type clam \
  --gpu_id 0

3. Training

Train a MIL model to predict phenotypes (e.g., Angiogenesis, Glycolysis).

  1. Edit configs/default_config.yaml to point to your data and choosing the label.
  2. Run training:
python scripts/train_model.py \
  --config configs/default_config.yaml \
  --fold 0 \
  --gpu_id 0

4. Evaluation

Evaluate a trained model.

python scripts/eval_model.py \
  --config configs/default_config.yaml \
  --checkpoint results/experiment_name/fold_0/model_fold_0.pt \
  --fold 0

Methodology

The pipeline follows these steps:

  1. Preprocessing: Automatic segmentation of tissue from background and patching into 256x256 tiles at 20x magnification.
  2. Feature Extraction:
    • CLAM: ResNet50 pre-trained on ImageNet (or custom weights).
    • PLIP: Pathology Language-Image Pre-training model.
  3. MIL Modeling: Aggregating patch features into slide-level predictions using attention-based MIL (CLAM-SB, CLAM-MB) or Transformer-based MIL (TransMIL).
  4. Prediction: Predicting gene expression signatures (ssGSEA scores) or clinical subtypes.
  5. Visualization: Generating attention heatmaps to identify morphological regions associated with the phenotypes.

License

[License Information]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages