# sinatabakhi/magnet architecture

> Architecture diagram of the GitHub repository sinatabakhi/magnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sinatabakhi/magnet
- Repository: https://github.com/sinatabakhi/magnet

## Overview

MAGNET classifies cancer subtypes from multimodal patient data when some modalities are missing. The workflow preprocesses TCGA data, creates paired/unpaired train-validation-test splits with training-only feature selection, then loads each split, encodes modalities, attends across available modalities, and classifies patients on a similarity graph. Inference evaluates and saves results; a separate Ray Tune workflow searches hyperparameters. Preprocessing details and some runtime behavior are documented but not sampled, so those links are shown only where the README supports them.

Main entry points: [`main_inference.py`](https://github.com/sinatabakhi/magnet/blob/main/main_inference.py) (Inference runner), [`main_tune.py`](https://github.com/sinatabakhi/magnet/blob/main/main_tune.py) (Tuning runner), [`trainer/trainer.py`](https://github.com/sinatabakhi/magnet/blob/main/trainer/trainer.py) (MAGNET training), [`dataloader/dataloader.py`](https://github.com/sinatabakhi/magnet/blob/main/dataloader/dataloader.py) (Multimodal dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data_prep["Data preparation"]
  node_preprocess["TCGA preprocessing"]
  node_splitter["Split and select<br/>[main_data_split.py]"]
  node_feature_select["Feature selection"]
  node_split_data[("Prepared splits")]
end

subgraph group_runtime["Training and inference"]
  node_config["Configuration<br/>[config.py]"]
  node_inference["Inference runner<br/>[main_inference.py]"]
  node_tuning["Tuning runner<br/>[main_tune.py]"]
end

subgraph group_magnet["MAGNET model"]
  node_dataset["Multimodal dataset<br/>[dataloader.py]"]
  node_utilities["Data and metrics utilities<br/>[utils.py]"]
  node_encoder["Modality encoders<br/>[base_models.py]"]
  node_attention["Patient-modality attention<br/>[base_models.py]"]
  node_graph_decoder["Graph decoder<br/>[base_models.py]"]
  node_trainer["MAGNET training<br/>[trainer.py]"]
end

subgraph group_ops["Experiment outputs"]
  node_outputs["Metrics and plots<br/>[utils.py]"]
end

node_tcga(("TCGA data"))
node_ray["Ray Tune"]
node_comet["Comet ML"]

node_tcga -.->|"provides data"| node_preprocess
node_preprocess -.->|"prepares inputs"| node_splitter
node_splitter -->|"selects features"| node_feature_select
node_splitter -->|"writes splits"| node_split_data
node_inference -->|"loads defaults"| node_config
node_tuning -->|"loads defaults"| node_config
node_inference -.->|"loads split path"| node_split_data
node_tuning -.->|"loads split path"| node_split_data
node_inference -->|"constructs dataset"| node_dataset
node_tuning -->|"constructs dataset"| node_dataset
node_dataset -->|"loads and aligns data"| node_utilities
node_inference -->|"builds encoders"| node_encoder
node_inference -->|"builds attention"| node_attention
node_inference -->|"builds decoder"| node_graph_decoder
node_inference -->|"constructs trainer"| node_trainer
node_tuning -->|"builds encoders"| node_encoder
node_tuning -->|"builds attention"| node_attention
node_tuning -->|"builds decoder"| node_graph_decoder
node_tuning -->|"constructs trainer"| node_trainer
node_trainer -->|"builds graph data"| node_dataset
node_trainer -->|"encodes modalities"| node_encoder
node_trainer -->|"fuses embeddings"| node_attention
node_trainer -->|"classifies graph"| node_graph_decoder
node_inference -->|"saves and plots results"| node_utilities
node_tuning -->|"runs search"| node_ray
node_inference -.->|"logs experiments"| node_comet
node_tuning -.->|"logs experiments"| node_comet

click node_preprocess "https://github.com/sinatabakhi/magnet/blob/main/preprocess/tcga_preprocessing.ipynb"
click node_splitter "https://github.com/sinatabakhi/magnet/blob/main/main_data_split.py"
click node_feature_select "https://github.com/sinatabakhi/magnet/blob/main/preprocess/feature_selection.py"
click node_split_data "https://github.com/sinatabakhi/magnet/tree/main/data/split_data"
click node_config "https://github.com/sinatabakhi/magnet/blob/main/configs/config.py"
click node_inference "https://github.com/sinatabakhi/magnet/blob/main/main_inference.py"
click node_tuning "https://github.com/sinatabakhi/magnet/blob/main/main_tune.py"
click node_dataset "https://github.com/sinatabakhi/magnet/blob/main/dataloader/dataloader.py"
click node_utilities "https://github.com/sinatabakhi/magnet/blob/main/utils.py"
click node_encoder "https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py"
click node_attention "https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py"
click node_graph_decoder "https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py"
click node_trainer "https://github.com/sinatabakhi/magnet/blob/main/trainer/trainer.py"
click node_outputs "https://github.com/sinatabakhi/magnet/blob/main/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_preprocess,node_splitter,node_feature_select,node_split_data toneBlue
class node_config,node_inference,node_tuning toneAmber
class node_dataset,node_utilities,node_encoder,node_attention,node_graph_decoder,node_trainer toneMint
class node_outputs toneRose
class node_tcga,node_ray,node_comet toneIndigo
```

## Components

### Data preparation

- [TCGA preprocessing](https://github.com/sinatabakhi/magnet/blob/main/preprocess/tcga_preprocessing.ipynb): `preprocess/tcga_preprocessing.ipynb`
- [Split and select](https://github.com/sinatabakhi/magnet/blob/main/main_data_split.py): `main_data_split.py`
- [Feature selection](https://github.com/sinatabakhi/magnet/blob/main/preprocess/feature_selection.py): `preprocess/feature_selection.py`
- [Prepared splits](https://github.com/sinatabakhi/magnet/tree/main/data/split_data): `data/split_data`

### Training and inference

- [Configuration](https://github.com/sinatabakhi/magnet/blob/main/configs/config.py): `configs/config.py`
- [Inference runner](https://github.com/sinatabakhi/magnet/blob/main/main_inference.py): `main_inference.py`
- [Tuning runner](https://github.com/sinatabakhi/magnet/blob/main/main_tune.py): `main_tune.py`

### MAGNET model

- [Multimodal dataset](https://github.com/sinatabakhi/magnet/blob/main/dataloader/dataloader.py): `dataloader/dataloader.py`
- [Data and metrics utilities](https://github.com/sinatabakhi/magnet/blob/main/utils.py): `utils.py`
- [Modality encoders](https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py): `model/base_models.py`
- [Patient-modality attention](https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py): `model/base_models.py`
- [Graph decoder](https://github.com/sinatabakhi/magnet/blob/main/model/base_models.py): `model/base_models.py`
- [MAGNET training](https://github.com/sinatabakhi/magnet/blob/main/trainer/trainer.py): `trainer/trainer.py`

### Experiment outputs

- [Metrics and plots](https://github.com/sinatabakhi/magnet/blob/main/utils.py): `utils.py`

### Other components

- **TCGA data**
- **Ray Tune**
- **Comet ML**

## Connections

- TCGA data → TCGA preprocessing: provides data (evidence: `README.md`)
- TCGA preprocessing → Split and select: prepares inputs (evidence: `README.md`)
- Split and select → Feature selection: selects features (evidence: `main_data_split.py`)
- Split and select → Prepared splits: writes splits (evidence: `main_data_split.py`)
- Inference runner → Configuration: loads defaults (evidence: `main_inference.py`)
- Tuning runner → Configuration: loads defaults (evidence: `main_tune.py`)
- Inference runner → Prepared splits: loads split path
- Tuning runner → Prepared splits: loads split path
- Inference runner → Multimodal dataset: constructs dataset (evidence: `main_inference.py`)
- Tuning runner → Multimodal dataset: constructs dataset (evidence: `main_tune.py`)
- Multimodal dataset → Data and metrics utilities: loads and aligns data (evidence: `dataloader/dataloader.py`)
- Inference runner → Modality encoders: builds encoders (evidence: `main_inference.py`)
- Inference runner → Patient-modality attention: builds attention (evidence: `main_inference.py`)
- Inference runner → Graph decoder: builds decoder (evidence: `main_inference.py`)
- Inference runner → MAGNET training: constructs trainer (evidence: `main_inference.py`)
- Tuning runner → Modality encoders: builds encoders (evidence: `main_tune.py`)
- Tuning runner → Patient-modality attention: builds attention (evidence: `main_tune.py`)
- Tuning runner → Graph decoder: builds decoder (evidence: `main_tune.py`)
- Tuning runner → MAGNET training: constructs trainer (evidence: `main_tune.py`)
- MAGNET training → Multimodal dataset: builds graph data (evidence: `trainer/trainer.py`)
- MAGNET training → Modality encoders: encodes modalities (evidence: `trainer/trainer.py`)
- MAGNET training → Patient-modality attention: fuses embeddings (evidence: `trainer/trainer.py`)
- MAGNET training → Graph decoder: classifies graph (evidence: `trainer/trainer.py`)
- Inference runner → Data and metrics utilities: saves and plots results (evidence: `main_inference.py`)
- Tuning runner → Ray Tune: runs search (evidence: `main_tune.py`)
- Inference runner → Comet ML: logs experiments (evidence: `README.md`)
- Tuning runner → Comet ML: logs experiments (evidence: `README.md`)
