File size: 2,489 Bytes
31fc60e
8850d81
 
 
 
 
 
 
 
 
31fc60e
8850d81
 
 
fc1771f
8850d81
7d9aca4
8850d81
 
 
 
fc1771f
8850d81
 
fc1771f
8850d81
75e5626
8850d81
 
fc1771f
8850d81
 
 
 
 
7d9aca4
8850d81
 
fc1771f
 
 
 
8850d81
 
fc1771f
 
 
 
 
8850d81
fc1771f
 
8850d81
 
 
fc1771f
 
8850d81
fc1771f
8850d81
 
fc1771f
 
 
8850d81
fc1771f
8850d81
fc1771f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
library_name: transformers
language:
- en
tags:
- computational-pathology
- multimodal
- survival-analysis
- feature-extraction
- custom_code
---

# MOSAIC

MOSAIC integrates histopathology, clinical information, and genomics for survival prediction. It accepts WSI patch features, clinical data, and/or SNV/CNV gene lists, and returns **OS and PFS risk scores**. When WSI features are provided, it also returns a **768-dimensional WSI embedding**.

For data preparation, treatment-response evaluation, prognosis-prediction and further documentation, see **[MAGIC-AI4Med/MOSAIC on GitHub](https://github.com/MAGIC-AI4Med/MOSAIC)**.

## Installation

```bash
pip install "torch>=2.6" "transformers==4.57.1" "nystrom-attention==0.0.14" "safetensors>=0.4" "numpy>=1.26" h5py
```

## Usage

WSI patch features should be extracted using [KEEP](https://huggingface.co/Astaxanthin/KEEP).

```python
import h5py
import torch
from transformers import AutoModel

device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModel.from_pretrained(
    "Astaxanthin/MOSAIC", trust_remote_code=True,
).to(device).eval()

# One slide: KEEP patch features and matching spatial coordinates.
with h5py.File("slide_features.h5", "r") as f:
    features = f["features"][:]  # [N, 768]
    coords = f["coords"][:]      # [N, 2]

output = model.predict(
    patch_features=features,
    patch_coords=coords,
    cancer_type="Lung Adenocarcinoma",
    clinical={"age": 65, "sex": "Male", "stage": "II"},
    genomics={"snv": ["TP53"], "cnv": ["CDKN2A"]},
)

print("WSI embedding:", output["wsi_features"].shape)  # [1, 768]
print("OS risk:", output["os_risk"].item())
print("PFS risk:", output["pfs_risk"].item())

# Clinical-only inference: omit WSI and genomic inputs.
clinical_output = model.predict(
    cancer_type="Lung Adenocarcinoma",
    clinical={"age": 65, "sex": "Male", "stage": "II"},
)

# Vision-only inference: omit all text inputs.
vision_output = model.predict(patch_features=features, patch_coords=coords)
```

`predict` handles spatial views automatically and independently max-pools OS/PFS risks across views. Higher scores indicate higher predicted risk, not calibrated survival probabilities. Without WSI, `wsi_features` is `None`.

For genomics, omitted fields or `-1` mean unknown; `[]` means no qualifying alteration in the evaluated gene set. See the [GitHub repository](https://github.com/MAGIC-AI4Med/MOSAIC) for input conventions and task-specific evaluation protocols.