# Genomic Prediction from Histology

> Predicting genomic status (MSI/MSS) from standard H&E pathology slides using Deep Learning

- HTML version: https://robbiepalmer.me/projects/genomic-prediction
- Status: completed
- Started: 2020-03-30
- Product: https://sonraianalytics.com/wp-content/uploads/2024/02/S003-019-003-Rev-0-Sonrai-Diagnostics-MSI-IFU_EN.pdf
- Technologies: Python, PyTorch, DVC, Shapely, GeoPandas

# Vision

The goal was to democratize access to personalized medicine by proving it is feasible to predict genomic biomarkers
directly from standard, low-cost pathology images.

# Problem Statement

Personalized medicine relies on knowing a patient's genomic status (e.g., Microsatellite Instable (MSI) vs
Microsatellite Stable (MSS)), but genomic testing is expensive, slow, and often inaccessible.
However, standard H\&E stained biopsies are routinely taken for almost every cancer patient.

If we could predict genomic status from these standard images, we could significantly reduce the cost and time required
to determine the correct treatment plan, effectively screening every patient for eligibility
for advanced immunotherapies.

# Methodology

I worked to recreate and industrialize the results of a prominent
[Nature Medicine paper](https://pubmed.ncbi.nlm.nih.gov/31160815/) (Kather et al.)
which proposed using Deep Learning for this task.

* **Multiple Instance Learning (MIL)**: Implemented a weakly-supervised deep learning approach because slide labels are known (MSI/MSS) but the specific regions of the tumor causing that status are not.
* **Geospatial Processing**: Used `Shapely` and `GeoPandas` to handle the geometry of tissue regions and tile management at a massive scale.
* **MLOps**: Established best practices for reproducibility using DVC (Data Version Control) to track experiments, data lineage, and model versions.

# How it worked

This reconstruction uses the surviving project description and the workflow in the cited paper. It ends at the research
outputs and does not describe the later Sonrai Diagnostics product.

```mermaid
flowchart TB
subgraph inputs["External research inputs"]
Slides["H&E whole-slide images"]
Labels["Patient-level MSI or MSS labels<br/>from reference testing"]
end

subgraph pipeline["Historical Sonrai research pipeline"]
Split["Patient-level partitioning<br/>before deriving validation tiles"]
Preprocess["Whole-slide preprocessing<br/>identify tissue and divide it into tiles"]
Spatial["Spatial feature records<br/>tile coordinates and tissue-region geometry<br/>with Shapely and GeoPandas"]
Predict["Weakly supervised prediction<br/>combine tile evidence into a slide-level<br/>MSI or MSS prediction"]
Validate["Leakage-aware validation<br/>compare held-out patient predictions<br/>with reference labels"]
Tracking["DVC records<br/>data lineage, experiments, and model versions"]
Split --> Preprocess
Preprocess --> Spatial
Spatial -->|"Located tissue tiles"| Predict
Predict --> Validate
Tracking -.-> Preprocess
Tracking -.-> Predict
Tracking -.-> Validate
end

subgraph outputs["Research outputs"]
Evidence["Feasibility evidence<br/>predictions and realistic performance estimates"]
Development["Proof of concept supporting<br/>further funded development"]
Evidence --> Development
end

Slides --> Split
Labels --> Split
Labels -->|"Weak supervision"| Predict
Labels -->|"Reference truth"| Validate
Validate --> Evidence
```

1. Research cohorts supplied H\&E whole-slide images and patient-level MSI or MSS results from reference testing. The
   work treated those genomic results as slide labels; it did not assume that each tile had its own known label.
2. Patients were partitioned before tiles entered validation. The pipeline then identified tissue, divided each slide
   into tiles, and represented tile locations and tissue-region geometry with `Shapely` and `GeoPandas`. Keeping every
   patient's derived tiles in one partition prevented tile leakage from inflating the reported performance.
3. The weakly supervised model combined evidence from the tiles into a slide-level MSI or MSS prediction. Held-out
   patient predictions were compared with the reference labels, while DVC recorded data lineage, experiments, and
   model versions.
4. The research outputs were slide-level predictions and leakage-aware performance estimates. Together they supported
   the feasibility result and the case for further funded development.

# Outcomes

* **Identified Critical Flaws**: During reproduction, I discovered foundational mistakes in the original paper's methodology concerning data leakage across slide tiles. Fixing this led to more realistic and robust performance estimates.
* **Commercial Success**: The successful proof-of-concept and rigorous validation unlocked a **£2M grant** for Sonrai Analytics to further develop the technology.
* **Feasibility Proven**: Demonstrated that high-accuracy classification is possible using only standard H\&E images, without requiring expensive immunofluorescence staining.

## Initiatives

- [Personalized Medicine](https://robbiepalmer.me/initiatives/personalized-medicine.md): Tested whether routine H&E images could reveal genomic status directly, reducing dependence on separate molecular tests.

---

Markdown index of this site: https://robbiepalmer.me/llms.txt
