sonata-learn 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Park Lab at Harvard Medical School
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: sonata-learn
3
+ Version: 0.1.0
4
+ Summary: A Python toolkit for fitting and analyzing mutational signatures
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: AnnData,bioinformatics,cancer genomics,mutational signatures,NMF
8
+ Author: Benedikt Geiger
9
+ Author-email: benedikt_geiger@g.harvard.edu
10
+ Maintainer: Benedikt Geiger
11
+ Maintainer-email: benedikt_geiger@g.harvard.edu
12
+ Requires-Python: >=3.10,<3.14
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
21
+ Requires-Dist: adjustText (>=1.3,<2)
22
+ Requires-Dist: anndata (>=0.11,<0.13)
23
+ Requires-Dist: fastcluster (>=1.2.6,<2)
24
+ Requires-Dist: matplotlib (>=3.8,<4)
25
+ Requires-Dist: numba (>=0.61,<0.63)
26
+ Requires-Dist: numpy (>=1.26,<3)
27
+ Requires-Dist: pandas (>=2.2,<3)
28
+ Requires-Dist: scikit-learn (>=1.6,<2)
29
+ Requires-Dist: scipy (>=1.13,<2)
30
+ Requires-Dist: seaborn (>=0.13,<0.14)
31
+ Requires-Dist: umap-learn (>=0.5.7,<0.6)
32
+ Project-URL: Documentation, https://github.com/parklab/Sonata/blob/main/docs/tutorial.md
33
+ Project-URL: Homepage, https://github.com/parklab/Sonata
34
+ Project-URL: Repository, https://github.com/parklab/Sonata
35
+ Description-Content-Type: text/markdown
36
+
37
+ # Sonata
38
+
39
+ [![Python versions supported][python-image]][python-url]
40
+ [![License][license-image]][license-url]
41
+ [![Code style][style-image]][style-url]
42
+
43
+ [python-image]: https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue.svg
44
+ [python-url]: https://github.com/parklab/Sonata
45
+ [license-image]: https://img.shields.io/badge/License-MIT-yellow.svg
46
+ [license-url]: https://github.com/parklab/Sonata/blob/main/LICENSE
47
+ [style-image]: https://img.shields.io/badge/code%20style-black-000000.svg
48
+ [style-url]: https://github.com/psf/black
49
+
50
+ Sonata is a Python toolkit for fitting and analyzing mutational signatures. It
51
+ fits signatures and exposures in
52
+ [AnnData](https://anndata.readthedocs.io/en/latest/) objects and provides
53
+ analysis and plotting APIs for signature workflows.
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install sonata-learn
59
+ ```
60
+
61
+ The package is installed as `sonata-learn` and imported as `sonata`.
62
+
63
+ ## Quickstart
64
+
65
+ ```python
66
+ import sonata as so
67
+
68
+ model = so.models.NMF(n_signatures=6)
69
+ model.fit(adata)
70
+
71
+ so.pl.barplot(model.asignatures)
72
+ so.pl.stacked_barplot(model.exposures)
73
+
74
+ so.tl.reduce_dimension(
75
+ model.adata,
76
+ basis="exposures",
77
+ method="umap",
78
+ )
79
+ so.pl.embedding(model.adata, basis="umap")
80
+ ```
81
+
82
+ ## Data Format
83
+
84
+ Sonata expects mutation counts in an `AnnData` object:
85
+
86
+ - `adata.X`: count matrix with shape `n_samples x n_mutation_types`.
87
+ - `adata.obs`: optional sample annotations.
88
+ - `adata.var`: optional mutation-type annotations.
89
+
90
+ After fitting, the model stores learned signatures in `model.asignatures` and
91
+ sample exposures in `model.adata.obsm["exposures"]`.
92
+
93
+ ## Documentation
94
+
95
+ For a complete workflow covering data preparation, NMF, visualization,
96
+ fixed signatures, Cornet, and simple model selection, see the
97
+ [Markdown tutorial][tutorial-md]. A runnable notebook with the same analysis and
98
+ figure-generation code is available at [docs/tutorial.ipynb][tutorial-ipynb].
99
+
100
+ ## Models
101
+
102
+ Sonata currently exposes three algorithms:
103
+
104
+ - `so.models.NMF`: NMF with the generalized Kullback-Leibler divergence.
105
+ - `so.models.MvNMF`: minimum-volume NMF.
106
+ - `so.models.Cornet`: correlated NMF with joint sample and signature embeddings.
107
+
108
+ ## License
109
+
110
+ MIT
111
+
112
+ [tutorial-md]: https://github.com/parklab/Sonata/blob/main/docs/tutorial.md
113
+ [tutorial-ipynb]: https://github.com/parklab/Sonata/blob/main/docs/tutorial.ipynb
114
+
@@ -0,0 +1,77 @@
1
+ # Sonata
2
+
3
+ [![Python versions supported][python-image]][python-url]
4
+ [![License][license-image]][license-url]
5
+ [![Code style][style-image]][style-url]
6
+
7
+ [python-image]: https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12%20|%203.13-blue.svg
8
+ [python-url]: https://github.com/parklab/Sonata
9
+ [license-image]: https://img.shields.io/badge/License-MIT-yellow.svg
10
+ [license-url]: https://github.com/parklab/Sonata/blob/main/LICENSE
11
+ [style-image]: https://img.shields.io/badge/code%20style-black-000000.svg
12
+ [style-url]: https://github.com/psf/black
13
+
14
+ Sonata is a Python toolkit for fitting and analyzing mutational signatures. It
15
+ fits signatures and exposures in
16
+ [AnnData](https://anndata.readthedocs.io/en/latest/) objects and provides
17
+ analysis and plotting APIs for signature workflows.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install sonata-learn
23
+ ```
24
+
25
+ The package is installed as `sonata-learn` and imported as `sonata`.
26
+
27
+ ## Quickstart
28
+
29
+ ```python
30
+ import sonata as so
31
+
32
+ model = so.models.NMF(n_signatures=6)
33
+ model.fit(adata)
34
+
35
+ so.pl.barplot(model.asignatures)
36
+ so.pl.stacked_barplot(model.exposures)
37
+
38
+ so.tl.reduce_dimension(
39
+ model.adata,
40
+ basis="exposures",
41
+ method="umap",
42
+ )
43
+ so.pl.embedding(model.adata, basis="umap")
44
+ ```
45
+
46
+ ## Data Format
47
+
48
+ Sonata expects mutation counts in an `AnnData` object:
49
+
50
+ - `adata.X`: count matrix with shape `n_samples x n_mutation_types`.
51
+ - `adata.obs`: optional sample annotations.
52
+ - `adata.var`: optional mutation-type annotations.
53
+
54
+ After fitting, the model stores learned signatures in `model.asignatures` and
55
+ sample exposures in `model.adata.obsm["exposures"]`.
56
+
57
+ ## Documentation
58
+
59
+ For a complete workflow covering data preparation, NMF, visualization,
60
+ fixed signatures, Cornet, and simple model selection, see the
61
+ [Markdown tutorial][tutorial-md]. A runnable notebook with the same analysis and
62
+ figure-generation code is available at [docs/tutorial.ipynb][tutorial-ipynb].
63
+
64
+ ## Models
65
+
66
+ Sonata currently exposes three algorithms:
67
+
68
+ - `so.models.NMF`: NMF with the generalized Kullback-Leibler divergence.
69
+ - `so.models.MvNMF`: minimum-volume NMF.
70
+ - `so.models.Cornet`: correlated NMF with joint sample and signature embeddings.
71
+
72
+ ## License
73
+
74
+ MIT
75
+
76
+ [tutorial-md]: https://github.com/parklab/Sonata/blob/main/docs/tutorial.md
77
+ [tutorial-ipynb]: https://github.com/parklab/Sonata/blob/main/docs/tutorial.ipynb
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "sonata-learn"
3
+ version = "0.1.0"
4
+ description = "A Python toolkit for fitting and analyzing mutational signatures"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10,<3.14"
7
+ license = "MIT"
8
+ authors = [
9
+ { name = "Benedikt Geiger", email = "benedikt_geiger@g.harvard.edu" },
10
+ ]
11
+ maintainers = [
12
+ { name = "Benedikt Geiger", email = "benedikt_geiger@g.harvard.edu" },
13
+ ]
14
+ keywords = [
15
+ "AnnData",
16
+ "bioinformatics",
17
+ "cancer genomics",
18
+ "mutational signatures",
19
+ "NMF",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 4 - Beta",
23
+ "Intended Audience :: Science/Research",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
30
+ ]
31
+ dependencies = [
32
+ "adjustText>=1.3,<2",
33
+ "anndata>=0.11,<0.13",
34
+ "fastcluster>=1.2.6,<2",
35
+ "matplotlib>=3.8,<4",
36
+ "numba>=0.61,<0.63",
37
+ "numpy>=1.26,<3",
38
+ "pandas>=2.2,<3",
39
+ "scikit-learn>=1.6,<2",
40
+ "scipy>=1.13,<2",
41
+ "seaborn>=0.13,<0.14",
42
+ "umap-learn>=0.5.7,<0.6",
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/parklab/Sonata"
47
+ Repository = "https://github.com/parklab/Sonata"
48
+ Documentation = "https://github.com/parklab/Sonata/blob/main/docs/tutorial.md"
49
+
50
+ [tool.poetry]
51
+ packages = [{ include = "sonata", from = "src" }]
52
+
53
+ [tool.poetry.group.dev.dependencies]
54
+ mypy = ">=1.15,<2"
55
+ pandas-stubs = ">=2.2,<3"
56
+ pytest = ">=8.3,<9"
57
+ pre-commit = ">=4.2,<5"
58
+ tox = ">=4.25,<5"
59
+ types-seaborn = ">=0.13,<0.14"
60
+ twine = "^6.2.0"
61
+
62
+ [tool.pytest.ini_options]
63
+ # /site-packages/umap/__init__.py:36: DeprecationWarning: pkg_resources is deprecated as an API.
64
+ filterwarnings = [
65
+ "ignore::DeprecationWarning:umap.*:",
66
+ ]
67
+
68
+ [build-system]
69
+ requires = ["poetry-core"]
70
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,19 @@
1
+ """
2
+ Sonata: a non-negative matrix factorization toolkit for signature analysis
3
+ ==========================================================================
4
+ """
5
+
6
+ from . import models
7
+ from . import plot as pl
8
+ from . import tools as tl
9
+
10
+ __version__ = "0.1.0"
11
+
12
+ pl.set_sonata_style()
13
+
14
+ __all__ = [
15
+ "__version__",
16
+ "models",
17
+ "pl",
18
+ "tl",
19
+ ]
@@ -0,0 +1,95 @@
1
+ from matplotlib.colors import LinearSegmentedColormap
2
+
3
+ NUCLEOTIDES = ["A", "C", "G", "T"]
4
+
5
+ SBS_TYPES_6 = ["C>A", "C>G", "C>T", "T>A", "T>C", "T>G"]
6
+ SBS_TYPES_96 = [
7
+ f"{n1}[{sbs_6}]{n2}"
8
+ for sbs_6 in SBS_TYPES_6
9
+ for n1 in NUCLEOTIDES
10
+ for n2 in NUCLEOTIDES
11
+ ]
12
+
13
+ # fmt: off
14
+ INDEL_TYPES_83 = [
15
+ "DEL.C.1.1", "DEL.C.1.2", 'DEL.C.1.3', "DEL.C.1.4", "DEL.C.1.5", "DEL.C.1.6+",
16
+ "DEL.T.1.1", "DEL.T.1.2", 'DEL.T.1.3', "DEL.T.1.4", "DEL.T.1.5", "DEL.T.1.6+",
17
+ "INS.C.1.0", "INS.C.1.1", 'INS.C.1.2', "INS.C.1.3", "INS.C.1.4", "INS.C.1.5+",
18
+ "INS.T.1.0", "INS.T.1.1", 'INS.T.1.2', "INS.T.1.3", "INS.T.1.4", "INS.T.1.5+",
19
+ "DEL.repeats.2.1", "DEL.repeats.2.2", "DEL.repeats.2.3",
20
+ "DEL.repeats.2.4", "DEL.repeats.2.5", "DEL.repeats.2.6+",
21
+ "DEL.repeats.3.1", "DEL.repeats.3.2", "DEL.repeats.3.3",
22
+ "DEL.repeats.3.4", "DEL.repeats.3.5", "DEL.repeats.3.6+",
23
+ "DEL.repeats.4.1", "DEL.repeats.4.2", "DEL.repeats.4.3",
24
+ "DEL.repeats.4.4", "DEL.repeats.4.5", "DEL.repeats.4.6+",
25
+ "DEL.repeats.5+.1", "DEL.repeats.5+.2", "DEL.repeats.5+.3",
26
+ "DEL.repeats.5+.4", "DEL.repeats.5+.5", "DEL.repeats.5+.6+",
27
+ "INS.repeats.2.0", "INS.repeats.2.1", "INS.repeats.2.2",
28
+ "INS.repeats.2.3", "INS.repeats.2.4", "INS.repeats.2.5+",
29
+ "INS.repeats.3.0", "INS.repeats.3.1", "INS.repeats.3.2",
30
+ "INS.repeats.3.3", "INS.repeats.3.4", "INS.repeats.3.5+",
31
+ "INS.repeats.4.0", "INS.repeats.4.1", "INS.repeats.4.2",
32
+ "INS.repeats.4.3", "INS.repeats.4.4", "INS.repeats.4.5+",
33
+ "INS.repeats.5+.0", "INS.repeats.5+.1", "INS.repeats.5+.2",
34
+ "INS.repeats.5+.3", "INS.repeats.5+.4", "INS.repeats.5+.5+",
35
+ "DEL.MH.2.1",
36
+ "DEL.MH.3.1", "DEL.MH.3.2",
37
+ "DEL.MH.4.1", "DEL.MH.4.2", "DEL.MH.4.3",
38
+ "DEL.MH.5+.1", "DEL.MH.5+.2", "DEL.MH.5+.3", "DEL.MH.5+.4", "DEL.MH.5+.5+"
39
+ ]
40
+ # fmt: on
41
+
42
+ # 10 colors
43
+ COLORS_MATHEMATICA = [
44
+ (0.368417, 0.506779, 0.709798),
45
+ (0.880722, 0.611041, 0.142051),
46
+ (0.560181, 0.691569, 0.194885),
47
+ (0.922526, 0.385626, 0.209179),
48
+ (0.528288, 0.470624, 0.701351),
49
+ (0.772079, 0.431554, 0.102387),
50
+ (0.363898, 0.618501, 0.782349),
51
+ (1.0, 0.75, 0.0),
52
+ (0.280264, 0.715, 0.429209),
53
+ (0.0, 0.0, 0.0),
54
+ ]
55
+
56
+ # Trinucleotide colors for the 96 dimensional mutation spectrum
57
+ COLORS_TRINUCLEOTIDES = [
58
+ "#427aa1ff",
59
+ (0.0, 0.0, 0.0),
60
+ "#d1664aff",
61
+ (0.78, 0.78, 0.78),
62
+ "#64b3aaff",
63
+ (0.89, 0.67, 0.72),
64
+ ]
65
+
66
+ COLORS_SBS96 = [COLORS_TRINUCLEOTIDES[i // 16] for i in range(96)]
67
+
68
+ DIVERGING_PALETTE = LinearSegmentedColormap.from_list(
69
+ "sonata_diverging",
70
+ ["#427aa1ff", "#FAFAFA", "#e07a5fff"],
71
+ )
72
+
73
+ COLORS_INDEL = [
74
+ "#FCBD6F", # 1bp Del C
75
+ "#FD8001", # 1bp Del T
76
+ "#B0DC8B", # 1bp Ins C
77
+ "#35A02E", # 1bp Ins T
78
+ "#FCC9B4", # 2bp Del Repeats
79
+ "#FC896B", # 3bp Del Repeats
80
+ "#F04432", # 4bp Del Repeats
81
+ "#BC1A1A", # 5+ bp Del Repeats
82
+ "#CFE0F0", # 2bp Ins Repeats
83
+ "#94C3DF", # 3bp Ins Repeats
84
+ "#4A98C8", # 4bp Ins Repeats
85
+ "#1665AA", # 5+ bp Ins Repeats
86
+ "#E1E0ED", # 2bp Del MH
87
+ "#B5B5D8", # 3bp Del MH
88
+ "#8683BC", # 4bp Del MH
89
+ "#624099", # 5+bp Del MH
90
+ ]
91
+
92
+ # 12 * 6 + 11 = 83 colors
93
+ n_times = 12 * [6] + [1, 2, 3, 5]
94
+ COLORS_INDEL83 = [n * [col] for n, col in zip(n_times, COLORS_INDEL)]
95
+ COLORS_INDEL83 = [col for color_list in COLORS_INDEL83 for col in color_list]