Sonata is a Python toolkit for fitting and analyzing mutational signatures. It fits signatures and exposures in AnnData objects and provides analysis and plotting APIs for signature workflows.
pip install sonata-toolsThe package is installed as sonata-tools and imported as sonata.
import sonata as so
model = so.models.NMF(n_signatures=6)
model.fit(adata)
so.pl.barplot(model.asignatures)
so.pl.stacked_barplot(model.exposures)
so.tl.reduce_dimension(
model.adata,
basis="exposures",
method="umap",
)
so.pl.embedding(model.adata, basis="umap")Sonata expects mutation counts in an AnnData object:
adata.X: count matrix with shapen_samples x n_mutation_types.adata.obs: optional sample annotations.adata.var: optional mutation-type annotations.
After fitting, the model stores learned signatures in model.asignatures and
sample exposures in model.adata.obsm["exposures"].
For a complete workflow covering data preparation, NMF, visualization, fixed signatures, Cornet, and simple model selection, see the Markdown tutorial. A runnable notebook with the same analysis and figure-generation code is available at docs/tutorial.ipynb.
Sonata currently exposes three algorithms:
so.models.NMF: NMF with the generalized Kullback-Leibler divergence.so.models.MvNMF: minimum-volume NMF.so.models.Cornet: correlated NMF with joint sample and signature embeddings.
MIT