Inspired by maftools::oncoplot, this is a collection of tools to control genomic waterfall layouts in Matplotlib.
it provides granular control over matrix sorting, marginal bar charts, and clinical annotation tracks.
The OncoMatrix class handles the heavy lifting of pivoting raw MAF data and managing hierarchical sorting.
prepare(): Pivots data into a Gene x Sample matrix.sort_genes(): Ranks genes by mutation frequency.sort_samples(): Executes the waterfall logic. Use thesortbyparameter to prioritize clinical annotations (e.g., Subtype) before the mutation staircase.
The library splits the oncoplot into modular components that can be used independently or through the run_oncoplot wrapper:
plot_waterfall: The central mutation heatmap.plot_tmb: Top bar plot for sample mutation burden.plot_genes: Right-side bar plot for gene mutation frequency.plot_annot: Bottom tracks for clinical/categorical data.
To maintain perfect alignment across the subplot grid, the internal matrices follow this structure:
| Component | Rows | Columns | Alignment |
|---|---|---|---|
| TMB | Mutation Types | Samples | Heatmap X-axis |
| Waterfall | Genes | Samples | Central Grid |
| Gene Summary | Genes | Mutation Types | Heatmap Y-axis |
from oncoplotpy import OncoMatrix, run_oncoplot
# Prepare data to follow or adjust default logic
om = OncoMatrix(maf_df, annotation_columns)
om.prepare().sort_genes().sort_samples(sortby=['Subtype'])
# Or simply render in one go
run_oncoplot(om, annot_cols=['Subtype'])