# Automated Tumor Macrodissection

> AI-driven tissue selection for precise downstream genetic analysis

- HTML version: https://robbiepalmer.me/projects/automated-macrodissection
- Status: completed
- Started: 2020-07-01
- Product: https://www.qub.ac.uk/schools/mdbs/News/Queenspartof7millionconsortiumtoimproveoutcomesforpatientswithearlystagecancer.html
- Technologies: Python, PyTorch, DVC, Shapely, GeoPandas
- Ideas: Ontology Engineering (https://robbiepalmer.me/ideas/ontology-engineering.md)

# Vision

The goal was to automate the physical extraction of tumor tissue to drive operational efficiency, higher throughput, and faster clinical turnaround times. By preparing Deep Learning workflows for robotic dissection hardware, we aimed to standardize input quality for genetic testing and ultimately improve patient outcomes.

# Problem Statement

Genetic testing requires high-quality tissue samples. Manual dissection is subjective and high-variance; pathologists cannot feasibly count and classify millions of individual cells across a slide. This leads to "failed" tests due to insufficient tumor content or contamination.

The consequences of failure are severe: a wasted biopsy often means the patient must return for another invasive surgical procedure to acquire more tissue. The challenge was to match the nuance of human judgment with the quantitative precision of AI, satisfying complex physical and biological constraints to prevent this.

# Methodology

* **Deep Pathological Ontology**: Developed a comprehensive tissue ontology beyond just "tumor vs. normal," training an ensemble of models to distinguish nuances like immune infiltration, necrosis, and lymph nodes.
* **Robust Artifact Handling**: Engineered the system to handle common real-world noise, such as pen marks, stickers, and tissue artifacts (folds, freezing damage) which confuse standard models.
* **Hardware Readiness**: Built the path generation system to translate selected tissue regions into physical cutting coordinates, preparing for future integration with dissection hardware (e.g. Roche).
* **Constraint Optimization**: The AI didn't just segment regions; it solved an optimization problem to find regions that met multiple competing constraints:
  * **Machine Precision**: Respecting the minimum physical resolution the standard hardware could cut.
  * **Tissue Quantity**: Ensuring the total area extracted met the minimum mass required for the assay.
  * **Tumor Purity**: guaranteeing a minimum percentage of tumor cells within the extracted region.
  * **Contamination Avoidance**: strictly avoiding necrosis (which degrades DNA quality) and non-tumor structures like lymph nodes.

# How it works

The software selects tissue for genetic analysis from a digitised pathology slide and generates cutting
coordinates for a dissection device. Models output cell coordinates, cell classifications, and segmentation
masks. Downstream code turns those outputs into polygons, selects regions that meet the assay's requirements
and the cutting machine's physical limits, and generates cutting paths.

```mermaid
flowchart TB
Slide["H&E whole-slide image<br/>External laboratory input"]
Rules["Tissue and machine constraints<br/>Cutting resolution, minimum area,<br/>tumor purity, excluded tissue"]

subgraph software["Sonrai Analytics software"]
Models["Tissue models and artifact handling"]
Polygons["Polygon generation"]
Regions["Region optimisation"]
Paths["Path and cutting-coordinate generation"]
Models -->|"Cell coordinates, classifications,<br/>and segmentation masks"| Polygons
Polygons -->|"Tissue polygons"| Regions
Regions -->|"Selected tissue regions"| Paths
end

subgraph hardware["External hardware boundary, integration planned"]
Cutter["Dissection hardware"]
end

Slide -->|"Slide image"| Models
Rules -->|"Selection constraints"| Regions
Rules -->|"Minimum cutting resolution"| Paths
Paths -.->|"Cutting coordinates"| Cutter
```

1. A laboratory supplies a whole-slide image of tissue stained with hematoxylin and eosin, or H\&E. The tissue
   models distinguish tumor, immune infiltration, necrosis, and lymph nodes. They output cell coordinates,
   classifications, and segmentation masks. Artifact handling accounts for pen marks, stickers, folds, and
   freezing damage.
2. Downstream code creates polygons from the model outputs. Region optimisation selects polygons with enough tissue
   and a sufficient proportion of tumor cells, excludes necrosis and lymph nodes, and respects the hardware's
   minimum cutting resolution.
3. Selected regions feed path generation, which translates their boundaries into physical cutting
   coordinates subject to the machine's resolution.
4. The software delivered cutting coordinates. The dashed arrow shows the planned handoff to external
   dissection hardware for physical tissue extraction, followed by genetic testing in the laboratory.

# Impact

* **Foundation for Future AI**: Established a library of composable deep learning models for H\&E WSI analysis, along with a robust data annotation platform and MLOps workflows that generalized to future projects.
* **Strategic Partnership**: The success of this work solidified a continued **\~£1M partnership** between Sonrai Analytics, Roche, and Queen's University Belfast.
* **Hardware preparation**: Generated cutting coordinates from selected tissue regions for future dissection hardware integration.

## Initiatives

- [Personalized Medicine](https://robbiepalmer.me/initiatives/personalized-medicine.md): Extended tissue selection into an automated workflow designed to improve the consistency of samples sent for genetic testing.

---

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