cytogater 0.1.1__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.
Files changed (41) hide show
  1. cytogater-0.1.1/LICENSE +9 -0
  2. cytogater-0.1.1/PKG-INFO +153 -0
  3. cytogater-0.1.1/README.md +114 -0
  4. cytogater-0.1.1/pyproject.toml +59 -0
  5. cytogater-0.1.1/setup.cfg +4 -0
  6. cytogater-0.1.1/src/cytogater/__init__.py +110 -0
  7. cytogater-0.1.1/src/cytogater/core.py +474 -0
  8. cytogater-0.1.1/src/cytogater/data.py +23 -0
  9. cytogater-0.1.1/src/cytogater/gating/__init__.py +5 -0
  10. cytogater-0.1.1/src/cytogater/gating/gmm.py +15 -0
  11. cytogater-0.1.1/src/cytogater/gating/hierarchical.py +73 -0
  12. cytogater-0.1.1/src/cytogater/gating/soft.py +14 -0
  13. cytogater-0.1.1/src/cytogater/gating/tree.py +15 -0
  14. cytogater-0.1.1/src/cytogater/metrics.py +156 -0
  15. cytogater-0.1.1/src/cytogater/models/__init__.py +5 -0
  16. cytogater-0.1.1/src/cytogater/models/knn.py +365 -0
  17. cytogater-0.1.1/src/cytogater/models/neural_network.py +128 -0
  18. cytogater-0.1.1/src/cytogater/models/random_forest.py +145 -0
  19. cytogater-0.1.1/src/cytogater/pipeline.py +15 -0
  20. cytogater-0.1.1/src/cytogater/plotting.py +243 -0
  21. cytogater-0.1.1/src/cytogater/preprocessing.py +25 -0
  22. cytogater-0.1.1/src/cytogater/types.py +20 -0
  23. cytogater-0.1.1/src/cytogater/uncertainty.py +63 -0
  24. cytogater-0.1.1/src/cytogater/validation.py +18 -0
  25. cytogater-0.1.1/src/cytogater.egg-info/PKG-INFO +153 -0
  26. cytogater-0.1.1/src/cytogater.egg-info/SOURCES.txt +39 -0
  27. cytogater-0.1.1/src/cytogater.egg-info/dependency_links.txt +1 -0
  28. cytogater-0.1.1/src/cytogater.egg-info/requires.txt +20 -0
  29. cytogater-0.1.1/src/cytogater.egg-info/top_level.txt +1 -0
  30. cytogater-0.1.1/tests/test_core.py +82 -0
  31. cytogater-0.1.1/tests/test_gmm.py +16 -0
  32. cytogater-0.1.1/tests/test_gmm_zero_inflation.py +101 -0
  33. cytogater-0.1.1/tests/test_hierarchical.py +49 -0
  34. cytogater-0.1.1/tests/test_metrics.py +47 -0
  35. cytogater-0.1.1/tests/test_models.py +94 -0
  36. cytogater-0.1.1/tests/test_optional_features.py +53 -0
  37. cytogater-0.1.1/tests/test_plotting.py +39 -0
  38. cytogater-0.1.1/tests/test_r_parity.py +42 -0
  39. cytogater-0.1.1/tests/test_r_parity_tree_gating.py +179 -0
  40. cytogater-0.1.1/tests/test_soft_gating.py +10 -0
  41. cytogater-0.1.1/tests/test_tree_gating.py +13 -0
@@ -0,0 +1,9 @@
1
+ This package is free software; you can redistribute it and/or modify it under
2
+ the terms of the GNU General Public License version 2 as published by the Free
3
+ Software Foundation.
4
+
5
+ This package is distributed in the hope that it will be useful, but WITHOUT
6
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7
+ FOR A PARTICULAR PURPOSE. See https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8
+ for the complete license text.
9
+
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: cytogater
3
+ Version: 0.1.1
4
+ Summary: Python implementation of cytoGateR marker-aware cell annotation
5
+ Author-email: Matthew Li <mali0328@uni.sydney.edu.au>, Nikhil Karthik <nkar0221@uni.sydney.edu.au>, Harry Robertson <harry.robertson@sydney.edu.au>, Jean Yang <jean.yang@sydney.edu.au>, Lijia Yu <yulj2010@gmail.com>
6
+ Maintainer-email: Lijia Yu <yulj2010@gmail.com>
7
+ License-Expression: GPL-2.0-only
8
+ Project-URL: Homepage, https://github.com/SydneyBioX/cytoGateR
9
+ Project-URL: Repository, https://github.com/SydneyBioX/cytoGateR
10
+ Project-URL: Issues, https://github.com/SydneyBioX/cytoGateR/issues
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: anndata>=0.10
23
+ Requires-Dist: numpy>=1.24
24
+ Requires-Dist: pandas>=2.0
25
+ Requires-Dist: scikit-learn>=1.3
26
+ Requires-Dist: scipy>=1.10
27
+ Provides-Extra: plot
28
+ Requires-Dist: matplotlib>=3.7; extra == "plot"
29
+ Requires-Dist: seaborn>=0.13; extra == "plot"
30
+ Provides-Extra: torch
31
+ Requires-Dist: torch>=2.1; extra == "torch"
32
+ Provides-Extra: notebook
33
+ Requires-Dist: ipykernel>=6; extra == "notebook"
34
+ Requires-Dist: jupyterlab>=4; extra == "notebook"
35
+ Requires-Dist: nbclient>=0.10; extra == "notebook"
36
+ Provides-Extra: test
37
+ Requires-Dist: pytest>=8; extra == "test"
38
+ Dynamic: license-file
39
+
40
+ # cytoGateR Python
41
+
42
+ This is the Python implementation of `cytoGateR`. It uses an `AnnData` object
43
+ and keeps the R function names, parameter names, and defaults where Python
44
+ syntax permits.
45
+
46
+ Implemented modules include:
47
+
48
+ - marker GMMs, soft gating, and tree gating;
49
+ - hierarchical reference construction and recursive hierarchical kNN;
50
+ - weighted kNN consensus cleaning and prediction;
51
+ - random-forest consensus cleaning and prediction;
52
+ - optional PyTorch training and prediction;
53
+ - confidence labels, cutoffs, F1, confusion, and agreement metrics;
54
+ - probability and spatial uncertainty;
55
+ - Matplotlib spatial, marker, label, metric, and tree plots.
56
+
57
+ ## Installation
58
+
59
+ Install the latest release from PyPI:
60
+
61
+ ```bash
62
+ pip install cytogater
63
+ ```
64
+
65
+ Plotting, neural-network, and notebook support are available as optional extras:
66
+
67
+ ```bash
68
+ pip install 'cytogater[plot]'
69
+ pip install 'cytogater[torch]'
70
+ pip install 'cytogater[notebook]'
71
+ ```
72
+
73
+ To install from source for development, clone the repository and create the
74
+ provided Conda environment:
75
+
76
+ ```bash
77
+ git clone https://github.com/SydneyBioX/cytoGateR.git
78
+ cd cytoGateR/python
79
+ conda env create -f environment.yml
80
+ conda activate cytogater-python
81
+ pytest
82
+ ```
83
+
84
+ ## Data layout
85
+
86
+ Python `AnnData` stores cells in rows and markers in columns. Put the expression
87
+ matrix used by the R `assay_name = "exprs"` default in:
88
+
89
+ ```python
90
+ adata.layers["exprs"]
91
+ ```
92
+
93
+ The lineage table is a pandas data frame with `cell_type`, `pos_markers`, and
94
+ `neg_markers` columns. The marker columns contain Python lists.
95
+
96
+ ## Example
97
+
98
+ ```python
99
+ import pandas as pd
100
+ import cytogater
101
+
102
+ lineage_table = pd.DataFrame({
103
+ "cell_type": ["Tcell", "Bcell"],
104
+ "pos_markers": [["CD3e"], ["CD20"]],
105
+ "neg_markers": [["CD20"], ["CD3e"]],
106
+ })
107
+
108
+ result = cytogater.run_tree_gating(
109
+ adata,
110
+ lineage_table,
111
+ assay_name="exprs",
112
+ max_depth=1,
113
+ min_cells=100,
114
+ min_score=0.1,
115
+ workers=1,
116
+ )
117
+
118
+ result["hard_label"]
119
+ result["prob_mat"]
120
+ ```
121
+
122
+ Results are returned with the same main keys as R. Labels and `P_*` columns are
123
+ also stored in `adata.obs`; probability matrices are stored in `adata.obsm`.
124
+
125
+ The package is intentionally flat at its public surface:
126
+
127
+ ```python
128
+ cytogater.run_soft_gating(...)
129
+ cytogater.run_tree_gating(...)
130
+ cytogater.train_custom_knn(...)
131
+ cytogater.train_custom_randomforest(...)
132
+ cytogater.calculate_uncertainty(...)
133
+ ```
134
+
135
+ The implementations are also grouped under `cytogater.gating`,
136
+ `cytogater.models`, `cytogater.metrics`, `cytogater.uncertainty`, and
137
+ `cytogater.plotting`.
138
+
139
+ ## R compatibility note
140
+
141
+ The Python implementation uses a deterministic two-component Gaussian-mixture
142
+ fit. R uses `mclust`, so fitted cutoffs can differ slightly even though the
143
+ pipeline, parameters, defaults, scoring, and output structure are aligned.
144
+ The Python `lambda_` argument corresponds to the R `lambda` argument because
145
+ `lambda` is reserved syntax in Python. `num_trees` corresponds to R's
146
+ `num.trees`; `train_custom_randomforest()` also accepts `**{"num.trees": 200}`.
147
+
148
+ Run tests with:
149
+
150
+ ```bash
151
+ cd cytoGateR/python
152
+ pytest
153
+ ```
@@ -0,0 +1,114 @@
1
+ # cytoGateR Python
2
+
3
+ This is the Python implementation of `cytoGateR`. It uses an `AnnData` object
4
+ and keeps the R function names, parameter names, and defaults where Python
5
+ syntax permits.
6
+
7
+ Implemented modules include:
8
+
9
+ - marker GMMs, soft gating, and tree gating;
10
+ - hierarchical reference construction and recursive hierarchical kNN;
11
+ - weighted kNN consensus cleaning and prediction;
12
+ - random-forest consensus cleaning and prediction;
13
+ - optional PyTorch training and prediction;
14
+ - confidence labels, cutoffs, F1, confusion, and agreement metrics;
15
+ - probability and spatial uncertainty;
16
+ - Matplotlib spatial, marker, label, metric, and tree plots.
17
+
18
+ ## Installation
19
+
20
+ Install the latest release from PyPI:
21
+
22
+ ```bash
23
+ pip install cytogater
24
+ ```
25
+
26
+ Plotting, neural-network, and notebook support are available as optional extras:
27
+
28
+ ```bash
29
+ pip install 'cytogater[plot]'
30
+ pip install 'cytogater[torch]'
31
+ pip install 'cytogater[notebook]'
32
+ ```
33
+
34
+ To install from source for development, clone the repository and create the
35
+ provided Conda environment:
36
+
37
+ ```bash
38
+ git clone https://github.com/SydneyBioX/cytoGateR.git
39
+ cd cytoGateR/python
40
+ conda env create -f environment.yml
41
+ conda activate cytogater-python
42
+ pytest
43
+ ```
44
+
45
+ ## Data layout
46
+
47
+ Python `AnnData` stores cells in rows and markers in columns. Put the expression
48
+ matrix used by the R `assay_name = "exprs"` default in:
49
+
50
+ ```python
51
+ adata.layers["exprs"]
52
+ ```
53
+
54
+ The lineage table is a pandas data frame with `cell_type`, `pos_markers`, and
55
+ `neg_markers` columns. The marker columns contain Python lists.
56
+
57
+ ## Example
58
+
59
+ ```python
60
+ import pandas as pd
61
+ import cytogater
62
+
63
+ lineage_table = pd.DataFrame({
64
+ "cell_type": ["Tcell", "Bcell"],
65
+ "pos_markers": [["CD3e"], ["CD20"]],
66
+ "neg_markers": [["CD20"], ["CD3e"]],
67
+ })
68
+
69
+ result = cytogater.run_tree_gating(
70
+ adata,
71
+ lineage_table,
72
+ assay_name="exprs",
73
+ max_depth=1,
74
+ min_cells=100,
75
+ min_score=0.1,
76
+ workers=1,
77
+ )
78
+
79
+ result["hard_label"]
80
+ result["prob_mat"]
81
+ ```
82
+
83
+ Results are returned with the same main keys as R. Labels and `P_*` columns are
84
+ also stored in `adata.obs`; probability matrices are stored in `adata.obsm`.
85
+
86
+ The package is intentionally flat at its public surface:
87
+
88
+ ```python
89
+ cytogater.run_soft_gating(...)
90
+ cytogater.run_tree_gating(...)
91
+ cytogater.train_custom_knn(...)
92
+ cytogater.train_custom_randomforest(...)
93
+ cytogater.calculate_uncertainty(...)
94
+ ```
95
+
96
+ The implementations are also grouped under `cytogater.gating`,
97
+ `cytogater.models`, `cytogater.metrics`, `cytogater.uncertainty`, and
98
+ `cytogater.plotting`.
99
+
100
+ ## R compatibility note
101
+
102
+ The Python implementation uses a deterministic two-component Gaussian-mixture
103
+ fit. R uses `mclust`, so fitted cutoffs can differ slightly even though the
104
+ pipeline, parameters, defaults, scoring, and output structure are aligned.
105
+ The Python `lambda_` argument corresponds to the R `lambda` argument because
106
+ `lambda` is reserved syntax in Python. `num_trees` corresponds to R's
107
+ `num.trees`; `train_custom_randomforest()` also accepts `**{"num.trees": 200}`.
108
+
109
+ Run tests with:
110
+
111
+ ```bash
112
+ cd cytoGateR/python
113
+ pytest
114
+ ```
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cytogater"
7
+ version = "0.1.1"
8
+ description = "Python implementation of cytoGateR marker-aware cell annotation"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "GPL-2.0-only"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ {name = "Matthew Li", email = "mali0328@uni.sydney.edu.au"},
15
+ {name = "Nikhil Karthik", email = "nkar0221@uni.sydney.edu.au"},
16
+ {name = "Harry Robertson", email = "harry.robertson@sydney.edu.au"},
17
+ {name = "Jean Yang", email = "jean.yang@sydney.edu.au"},
18
+ {name = "Lijia Yu", email = "yulj2010@gmail.com"},
19
+ ]
20
+ maintainers = [
21
+ {name = "Lijia Yu", email = "yulj2010@gmail.com"},
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 3 - Alpha",
25
+ "Intended Audience :: Science/Research",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
32
+ ]
33
+ dependencies = [
34
+ "anndata>=0.10",
35
+ "numpy>=1.24",
36
+ "pandas>=2.0",
37
+ "scikit-learn>=1.3",
38
+ "scipy>=1.10",
39
+ ]
40
+
41
+ [project.optional-dependencies]
42
+ plot = ["matplotlib>=3.7", "seaborn>=0.13"]
43
+ torch = ["torch>=2.1"]
44
+ notebook = ["ipykernel>=6", "jupyterlab>=4", "nbclient>=0.10"]
45
+ test = ["pytest>=8"]
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/SydneyBioX/cytoGateR"
49
+ Repository = "https://github.com/SydneyBioX/cytoGateR"
50
+ Issues = "https://github.com/SydneyBioX/cytoGateR/issues"
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
57
+ markers = [
58
+ "slow: needs the shared PRJ-cytogater data and runs for ~1 minute per dataset",
59
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,110 @@
1
+ """Marker-aware cell annotation for Python."""
2
+
3
+ from .core import (
4
+ assign_soft_labels,
5
+ build_fullcoverage_tree,
6
+ calculate_soft_scores,
7
+ collect_path_scores,
8
+ fit_gmm_2,
9
+ fit_marker_stats,
10
+ gmm_equal_posterior_cutoff,
11
+ marker_separability,
12
+ neg_penalty,
13
+ run_soft_gating,
14
+ run_tree_gating,
15
+ score_marker_logistic,
16
+ score_marker_rank,
17
+ tree_prob,
18
+ )
19
+ from .gating.hierarchical import (
20
+ build_hierarchical_reference,
21
+ build_lineage_hierarchy,
22
+ )
23
+ from .metrics import (
24
+ apply_cutoff_labels,
25
+ assign_confident_labels,
26
+ calculate_f1,
27
+ class_metrics_from_fit,
28
+ compute_custom_labels,
29
+ custom_labels,
30
+ label_agreement_rates,
31
+ label_confusion_matrix,
32
+ prob_mad_cutoff,
33
+ prob_quantile_cutoff,
34
+ probability_label_matrix,
35
+ )
36
+ from .models.neural_network import predict_unknown_with_dl, train_custom_dl
37
+ from .plotting import (
38
+ plot_celltype_tree,
39
+ plot_class_metrics,
40
+ plot_confusion_matrix,
41
+ plot_ct_marker_intensity,
42
+ plot_label_agreement,
43
+ plot_label_cardinality,
44
+ plot_label_confusion_matrix,
45
+ plot_label_counts,
46
+ plot_label_dotplot,
47
+ plot_labelled_cells,
48
+ plot_marker_density,
49
+ plot_marker_priority_tree,
50
+ plot_probability_map,
51
+ plot_pseudobulk_heatmap,
52
+ plot_rand_cell_probs,
53
+ plot_score_hist,
54
+ print_celltype_tree,
55
+ tree_to_df,
56
+ )
57
+
58
+ try:
59
+ from .models.knn import (
60
+ predict_hierarchical_knn_recursive,
61
+ predict_unknown_with_knn,
62
+ predict_wknn_multi,
63
+ train_custom_knn,
64
+ )
65
+ from .models.random_forest import (
66
+ predict_unknown_with_randomforest,
67
+ rf_metric_table,
68
+ rf_metric_text,
69
+ train_custom_randomforest,
70
+ )
71
+ from .uncertainty import calculate_spatial_prior_labels, calculate_uncertainty
72
+ except ImportError:
73
+ # Gating remains importable in lightweight environments. A normal package
74
+ # installation installs scikit-learn and exposes these functions.
75
+ pass
76
+
77
+ __all__ = [
78
+ "assign_soft_labels",
79
+ "build_fullcoverage_tree",
80
+ "calculate_soft_scores",
81
+ "collect_path_scores",
82
+ "fit_gmm_2",
83
+ "fit_marker_stats",
84
+ "gmm_equal_posterior_cutoff",
85
+ "marker_separability",
86
+ "neg_penalty",
87
+ "run_soft_gating",
88
+ "run_tree_gating",
89
+ "score_marker_logistic",
90
+ "score_marker_rank",
91
+ "tree_prob",
92
+ "apply_cutoff_labels", "assign_confident_labels",
93
+ "build_hierarchical_reference", "build_lineage_hierarchy",
94
+ "calculate_f1", "calculate_spatial_prior_labels", "calculate_uncertainty",
95
+ "class_metrics_from_fit", "compute_custom_labels", "custom_labels",
96
+ "label_agreement_rates", "label_confusion_matrix",
97
+ "predict_hierarchical_knn_recursive", "predict_unknown_with_dl",
98
+ "predict_unknown_with_knn", "predict_unknown_with_randomforest",
99
+ "predict_wknn_multi", "prob_mad_cutoff", "prob_quantile_cutoff",
100
+ "probability_label_matrix", "rf_metric_table", "rf_metric_text",
101
+ "train_custom_dl", "train_custom_knn", "train_custom_randomforest",
102
+ "plot_celltype_tree", "plot_class_metrics", "plot_confusion_matrix",
103
+ "plot_ct_marker_intensity", "plot_label_agreement",
104
+ "plot_label_cardinality", "plot_label_confusion_matrix",
105
+ "plot_label_counts", "plot_label_dotplot", "plot_labelled_cells",
106
+ "plot_marker_density", "plot_marker_priority_tree",
107
+ "plot_probability_map", "plot_pseudobulk_heatmap",
108
+ "plot_rand_cell_probs", "plot_score_hist", "print_celltype_tree",
109
+ "tree_to_df",
110
+ ]