# ronisnotasianfr/cologrowth-ml architecture

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

- Interactive diagram: https://gitdiagram.com/ronisnotasianfr/cologrowth-ml
- Repository: https://github.com/ronisnotasianfr/cologrowth-ml

## Overview

1. **Repository purpose**
   This repo is an end-to-end machine learning research pipeline for predicting colon cancer proliferation class, with an emphasis on leakage-free modeling and cross-cohort validation. It is organized more like a scientific workflow than a production service.

2. **Core data sources and domains**
   The architecture centers on two public genomics cohorts: GEO GSE39582 as the main training/validation cohort and TCGA-COAD as an external validation cohort. Inputs combine high-dimensional gene expression with a small set of clinical variables such as age, sex, and tumor stage.

3. **Preprocessing boundary**
   `src/preprocess.py` is the main ingestion and feature-engineering layer. It handles probe/gene mapping, expression normalization/alignment, target construction from a proliferation score, and filtering out the 10 hallmark cell-cycle genes used to define the label. This is the key boundary where target leakage is actively prevented.

4. **Modeling layer**
   `src/model.py` defines the candidate classifiers used throughout the project: logistic regression, random forest, XGBoost, and an MLP. The file likely serves as a model factory or helper layer so training and evaluation can reuse consistent estimator definitions.

5. **Training orchestration**
   `src/train.py` is the main training driver. It runs nested cross-validation and wraps preprocessing steps such as scaling, variance filtering, and feature selection inside a scikit-learn pipeline so that all learned transformations stay fold-local. This is the repo’s main anti-leakage control point during model selection.

6. **Internal evaluation**
   `src/evaluate.py` consumes trained models and holdout data to generate standard classification outputs such as ROC curves, confusion matrices, and interpretability artifacts like SHAP plots. This is the post-training analysis layer for the internal GEO cohort.

7. **External generalization and calibration**
   `src/external_validation.py` is a distinct deployment-style evaluation path: models trained on GEO are applied to TCGA, then calibrated with Platt scaling using a calibration/evaluation split. This module bridges the cross-platform domain shift between microarray and RNA-seq and measures whether the model transfers beyond its training distribution.

8. **Clinical outcome analysis**
   `src/survival.py` connects predicted or derived proliferation groups to patient survival outcomes. It produces Kaplan-Meier plots and log-rank statistics, making survival analysis a separate downstream validation subsystem rather than part of classification training.

9. **Scientific workflow notebooks**
   The `notebooks/` directory contains the exploratory and iterative research workflow: EDA, preprocessing exploration, model training experiments, and evaluation. These are not the production path, but they document how the pipeline was developed and validated interactively.

10. **Research artifact generation**
   The `paper/` directory is a publication-generation subsystem. `build_paper.py`, `build_pdf.py`, and `paper_metrics.py` turn computed experiment metrics and figures into a Word document, LaTeX source, and PDF manuscript. In the architecture, this sits downstream of modeling and evaluation and consumes the results products.

11. **Outputs and artifacts**
   Although not fully shown in the tree, the README indicates a typical artifact flow into saved models, result plots/tables, and paper outputs. The expected storage boundaries are processed data in memory or under `data/`, persisted model checkpoints, and analysis artifacts under `results/` and `paper/`.

12. **Technology stack**
   The codebase is Python 3.8–3.12 and is built around scikit-learn, with XGBoost as an additional estimator backend. The overall runtime is a local research environment rather than a server or distributed system, and the repo’s structure is driven by reproducible ML experiments, external validation, and manuscript generation.

Main entry points: [`src/preprocess.py`](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/preprocess.py) (Preprocess), [`src/train.py`](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/train.py) (Training), [`paper/paper_metrics.py`](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/paper_metrics.py) (Paper metrics), [`src/external_validation.py`](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/external_validation.py) (External val)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_data["Data & targets"]
  node_n_gse39582[("GSE39582<br/>GEO cohort")]
  node_n_tcga_coad[("TCGA-COAD<br/>external cohort")]
  node_n_clinical["Clinical vars<br/>covariates"]
end

subgraph group_grp_ml["Modeling pipeline"]
  node_n_preprocess["Preprocess<br/>feature engineering<br/>[preprocess.py]"]
  node_n_model["Model defs<br/>estimator factory<br/>[model.py]"]
  node_n_train["Training<br/>nested CV<br/>[train.py]"]
  node_n_evaluate["Evaluate<br/>metrics & plots<br/>[evaluate.py]"]
end

subgraph group_grp_ext["Generalization"]
  node_n_extval["External val<br/>cross-cohort eval"]
end

subgraph group_grp_out["Downstream analysis"]
  node_n_survival["Survival<br/>outcome analysis<br/>[survival.py]"]
  node_n_metrics["Paper metrics<br/>results assembly<br/>[paper_metrics.py]"]
  node_n_build_paper["Build paper<br/>manuscript builder<br/>[build_paper.py]"]
  node_n_build_pdf["Build PDF<br/>latex builder<br/>[build_pdf.py]"]
  node_n_docx["Manuscript docx<br/>paper artifact"]
  node_n_tex["Manuscript tex<br/>paper artifact"]
  node_n_pdf["Manuscript pdf<br/>paper artifact"]
end

subgraph group_grp_work["Exploration"]
  node_n_nb_eda["EDA notebook<br/>[01_eda.ipynb]"]
  node_n_nb_prep["Prep notebook"]
  node_n_nb_train["Train notebook"]
  node_n_nb_eval["Eval notebook"]
end

node_n_gse39582 -->|"ingest"| node_n_preprocess
node_n_tcga_coad -->|"align"| node_n_preprocess
node_n_clinical -->|"join"| node_n_preprocess
node_n_preprocess -->|"features"| node_n_train
node_n_model -->|"estimators"| node_n_train
node_n_train -->|"best model"| node_n_evaluate
node_n_train -->|"trained model"| node_n_extval
node_n_extval -->|"risk groups"| node_n_survival
node_n_evaluate -->|"results"| node_n_metrics
node_n_extval -->|"external results"| node_n_metrics
node_n_survival -->|"survival stats"| node_n_metrics
node_n_metrics -->|"input"| node_n_build_paper
node_n_metrics -->|"input"| node_n_build_pdf
node_n_build_paper -->|"writes"| node_n_docx
node_n_build_paper -->|"writes"| node_n_tex
node_n_build_pdf -->|"writes"| node_n_pdf
node_n_nb_eda -.->|"explore"| node_n_preprocess
node_n_nb_prep -.->|"prototype"| node_n_preprocess
node_n_nb_train -.->|"prototype"| node_n_train
node_n_nb_eval -.->|"explore"| node_n_evaluate

click node_n_preprocess "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/preprocess.py"
click node_n_model "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/model.py"
click node_n_train "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/train.py"
click node_n_evaluate "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/evaluate.py"
click node_n_extval "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/external_validation.py"
click node_n_survival "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/survival.py"
click node_n_metrics "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/paper_metrics.py"
click node_n_build_paper "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/build_paper.py"
click node_n_build_pdf "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/build_pdf.py"
click node_n_docx "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.docx"
click node_n_tex "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.tex"
click node_n_pdf "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.pdf"
click node_n_nb_eda "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/01_eda.ipynb"
click node_n_nb_prep "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/02_preprocessing.ipynb"
click node_n_nb_train "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/03_model_training.ipynb"
click node_n_nb_eval "https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/04_evaluation.ipynb"

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_n_gse39582,node_n_tcga_coad,node_n_clinical toneBlue
class node_n_preprocess,node_n_model,node_n_train,node_n_evaluate toneAmber
class node_n_extval toneMint
class node_n_survival,node_n_metrics,node_n_build_paper,node_n_build_pdf,node_n_docx,node_n_tex,node_n_pdf toneRose
class node_n_nb_eda,node_n_nb_prep,node_n_nb_train,node_n_nb_eval toneIndigo
```

## Components

### Data & targets

Cohorts and clinical inputs used to build the prediction problem.

- **GSE39582**: GEO cohort · Main training and internal validation cohort from GEO.
- **TCGA-COAD**: external cohort · Independent validation cohort used to test transfer across platforms.
- **Clinical vars**: covariates · Age, sex, stage, and other low-dimensional clinical features.

### Modeling pipeline

Leakage-aware preprocessing, training, and internal evaluation for the GEO cohort.

- [Preprocess](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/preprocess.py): feature engineering · Ingestion, probe/gene mapping, normalization, target construction, and leakage prevention. · `src/preprocess.py`
- [Model defs](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/model.py): estimator factory · Reusable classifier definitions for logistic regression, random forest, XGBoost, and MLP. · `src/model.py`
- [Training](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/train.py): nested CV · Leakage-safe training driver with fold-local scaling, filtering, and feature selection. · `src/train.py`
- [Evaluate](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/evaluate.py): metrics & plots · Internal holdout evaluation with ROC curves, confusion matrices, and SHAP artifacts. · `src/evaluate.py`

### Generalization

Cross-cohort validation and calibration on the external TCGA cohort.

- [External val](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/external_validation.py): cross-cohort eval · Applies GEO-trained models to TCGA and performs calibration with Platt scaling. · `src/external_validation.py`

### Downstream analysis

Survival analysis and manuscript generation from experiment outputs.

- [Survival](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/src/survival.py): outcome analysis · Kaplan-Meier analysis and log-rank testing on predicted or derived groups. · `src/survival.py`
- [Paper metrics](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/paper_metrics.py): results assembly · Collects experiment metrics and figures for manuscript generation. · `paper/paper_metrics.py`
- [Build paper](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/build_paper.py): manuscript builder · Assembles the Word manuscript from computed results and narrative content. · `paper/build_paper.py`
- [Build PDF](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/build_pdf.py): latex builder · Compiles the LaTeX manuscript into a PDF artifact. · `paper/build_pdf.py`
- [Manuscript docx](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.docx): paper artifact · Generated Word document for the research paper. · `paper/colon_cancer_growth_prediction_research_paper.docx`
- [Manuscript tex](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.tex): paper artifact · Generated LaTeX source for the research paper. · `paper/colon_cancer_growth_prediction_research_paper.tex`
- [Manuscript pdf](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/paper/colon_cancer_growth_prediction_research_paper.pdf): paper artifact · Generated PDF version of the research paper. · `paper/colon_cancer_growth_prediction_research_paper.pdf`

### Exploration

Interactive notebooks used for iterative research and documentation.

- [EDA notebook](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/01_eda.ipynb): notebook · Exploratory analysis and cohort understanding. · `notebooks/01_eda.ipynb`
- [Prep notebook](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/02_preprocessing.ipynb): notebook · Interactive preprocessing and feature-engineering exploration. · `notebooks/02_preprocessing.ipynb`
- [Train notebook](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/03_model_training.ipynb): notebook · Model training experiments and comparison workflow. · `notebooks/03_model_training.ipynb`
- [Eval notebook](https://github.com/ronisnotasianfr/cologrowth-ml/blob/main/notebooks/04_evaluation.ipynb): notebook · Evaluation and interpretation exploration. · `notebooks/04_evaluation.ipynb`

## Connections

- GSE39582 → Preprocess: ingest · Main cohort is cleaned and transformed into model-ready data.
- TCGA-COAD → Preprocess: align · External cohort is mapped into a compatible feature space.
- Clinical vars → Preprocess: join · Clinical covariates are merged with expression-derived features.
- Preprocess → Training: features · Leakage-safe feature tables feed nested cross-validation.
- Model defs → Training: estimators · Training selects among the candidate classifiers.
- Training → Evaluate: best model · Selected models are scored and interpreted on internal data.
- Training → External val: trained model · GEO-trained model is exported to the external validation path.
- External val → Survival: risk groups · Transferred predictions can be used for downstream outcome analysis.
- Evaluate → Paper metrics: results · Internal metrics and figures are collected for reporting.
- External val → Paper metrics: external results · Cross-cohort performance contributes to manuscript metrics.
- Survival → Paper metrics: survival stats · Kaplan-Meier and log-rank outputs are summarized for the paper.
- Paper metrics → Build paper: input · Aggregated metrics drive Word manuscript assembly.
- Paper metrics → Build PDF: input · Aggregated metrics drive LaTeX/PDF assembly.
- Build paper → Manuscript docx: writes · Creates the Word manuscript artifact.
- Build paper → Manuscript tex: writes · Creates the LaTeX manuscript source.
- Build PDF → Manuscript pdf: writes · Compiles the final PDF manuscript.
- EDA notebook → Preprocess: explore · Notebook work informs preprocessing decisions.
- Prep notebook → Preprocess: prototype · Interactive preprocessing experiments reflect the main ingestion logic.
- Train notebook → Training: prototype · Training experiments mirror the scripted pipeline.
- Eval notebook → Evaluate: explore · Notebook work informs evaluation and interpretation.
