pertpy 0.6.0__py3-none-any.whl → 0.8.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. pertpy/__init__.py +4 -2
  2. pertpy/data/__init__.py +66 -1
  3. pertpy/data/_dataloader.py +28 -26
  4. pertpy/data/_datasets.py +261 -92
  5. pertpy/metadata/__init__.py +6 -0
  6. pertpy/metadata/_cell_line.py +795 -0
  7. pertpy/metadata/_compound.py +128 -0
  8. pertpy/metadata/_drug.py +238 -0
  9. pertpy/metadata/_look_up.py +569 -0
  10. pertpy/metadata/_metadata.py +70 -0
  11. pertpy/metadata/_moa.py +125 -0
  12. pertpy/plot/__init__.py +0 -13
  13. pertpy/preprocessing/__init__.py +2 -0
  14. pertpy/preprocessing/_guide_rna.py +89 -6
  15. pertpy/tools/__init__.py +48 -15
  16. pertpy/tools/_augur.py +329 -32
  17. pertpy/tools/_cinemaot.py +145 -6
  18. pertpy/tools/_coda/_base_coda.py +1237 -116
  19. pertpy/tools/_coda/_sccoda.py +66 -36
  20. pertpy/tools/_coda/_tasccoda.py +46 -39
  21. pertpy/tools/_dialogue.py +180 -77
  22. pertpy/tools/_differential_gene_expression/__init__.py +20 -0
  23. pertpy/tools/_differential_gene_expression/_base.py +657 -0
  24. pertpy/tools/_differential_gene_expression/_checks.py +41 -0
  25. pertpy/tools/_differential_gene_expression/_dge_comparison.py +86 -0
  26. pertpy/tools/_differential_gene_expression/_edger.py +125 -0
  27. pertpy/tools/_differential_gene_expression/_formulaic.py +189 -0
  28. pertpy/tools/_differential_gene_expression/_pydeseq2.py +95 -0
  29. pertpy/tools/_differential_gene_expression/_simple_tests.py +162 -0
  30. pertpy/tools/_differential_gene_expression/_statsmodels.py +72 -0
  31. pertpy/tools/_distances/_distance_tests.py +29 -24
  32. pertpy/tools/_distances/_distances.py +584 -98
  33. pertpy/tools/_enrichment.py +460 -0
  34. pertpy/tools/_kernel_pca.py +1 -1
  35. pertpy/tools/_milo.py +406 -49
  36. pertpy/tools/_mixscape.py +677 -55
  37. pertpy/tools/_perturbation_space/_clustering.py +10 -3
  38. pertpy/tools/_perturbation_space/_comparison.py +112 -0
  39. pertpy/tools/_perturbation_space/_discriminator_classifiers.py +524 -0
  40. pertpy/tools/_perturbation_space/_perturbation_space.py +146 -52
  41. pertpy/tools/_perturbation_space/_simple.py +52 -11
  42. pertpy/tools/_scgen/__init__.py +1 -1
  43. pertpy/tools/_scgen/_base_components.py +2 -3
  44. pertpy/tools/_scgen/_scgen.py +706 -0
  45. pertpy/tools/_scgen/_utils.py +3 -5
  46. pertpy/tools/decoupler_LICENSE +674 -0
  47. {pertpy-0.6.0.dist-info → pertpy-0.8.0.dist-info}/METADATA +48 -20
  48. pertpy-0.8.0.dist-info/RECORD +57 -0
  49. {pertpy-0.6.0.dist-info → pertpy-0.8.0.dist-info}/WHEEL +1 -1
  50. pertpy/plot/_augur.py +0 -234
  51. pertpy/plot/_cinemaot.py +0 -81
  52. pertpy/plot/_coda.py +0 -1001
  53. pertpy/plot/_dialogue.py +0 -91
  54. pertpy/plot/_guide_rna.py +0 -82
  55. pertpy/plot/_milopy.py +0 -284
  56. pertpy/plot/_mixscape.py +0 -594
  57. pertpy/plot/_scgen.py +0 -337
  58. pertpy/tools/_differential_gene_expression.py +0 -99
  59. pertpy/tools/_metadata/__init__.py +0 -0
  60. pertpy/tools/_metadata/_cell_line.py +0 -613
  61. pertpy/tools/_metadata/_look_up.py +0 -342
  62. pertpy/tools/_perturbation_space/_discriminator_classifier.py +0 -381
  63. pertpy/tools/_scgen/_jax_scgen.py +0 -370
  64. pertpy-0.6.0.dist-info/RECORD +0 -50
  65. /pertpy/tools/_scgen/{_jax_scgenvae.py → _scgenvae.py} +0 -0
  66. {pertpy-0.6.0.dist-info → pertpy-0.8.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,11 +1,11 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: pertpy
3
- Version: 0.6.0
3
+ Version: 0.8.0
4
4
  Summary: Perturbation Analysis in the scverse ecosystem.
5
5
  Project-URL: Documentation, https://pertpy.readthedocs.io
6
- Project-URL: Source, https://github.com/theislab/pertpy
7
- Project-URL: Home-page, https://github.com/theislab/pertpy
8
- Author: Lukas Heumos, Yuge Ji, Alejandro Tejada, Johannes Köster, Emma Dann, Xinyue Zhang, Xichen Wu, Amir Moinfar, Sergei Rybakov, Tessa Green, Stefan Peidli, Antonia Schumacher
6
+ Project-URL: Source, https://github.com/scverse/pertpy
7
+ Project-URL: Home-page, https://github.com/scverse/pertpy
8
+ Author: Lukas Heumos, Yuge Ji, Lilly May, Alejandro Tejada, Johannes Köster, Emma Dann, Xinyue Zhang, Xichen Wu, Tessa Green, Stefan Peidli, Antonia Schumacher, Gregor Sturm
9
9
  Maintainer-email: Lukas Heumos <lukas.heumos@posteo.net>
10
10
  License: MIT License
11
11
 
@@ -29,18 +29,30 @@ License: MIT License
29
29
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
30
  SOFTWARE.
31
31
  License-File: LICENSE
32
- Requires-Python: >=3.9
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Environment :: Console
34
+ Classifier: Framework :: Jupyter
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: Science/Research
37
+ Classifier: License :: OSI Approved :: Apache Software License
38
+ Classifier: Natural Language :: English
39
+ Classifier: Operating System :: MacOS :: MacOS X
40
+ Classifier: Operating System :: POSIX :: Linux
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3.10
43
+ Classifier: Programming Language :: Python :: 3.11
44
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
45
+ Classifier: Topic :: Scientific/Engineering :: Visualization
46
+ Requires-Python: >=3.10
33
47
  Requires-Dist: adjusttext
34
- Requires-Dist: anndata
35
- Requires-Dist: arviz
48
+ Requires-Dist: blitzgsea
36
49
  Requires-Dist: decoupler
37
- Requires-Dist: ipywidgets
50
+ Requires-Dist: lamin-utils
38
51
  Requires-Dist: muon
39
- Requires-Dist: numba
40
- Requires-Dist: numpyro
41
52
  Requires-Dist: openpyxl
42
53
  Requires-Dist: ott-jax
43
- Requires-Dist: plotnine
54
+ Requires-Dist: pubchempy
55
+ Requires-Dist: pyarrow
44
56
  Requires-Dist: requests
45
57
  Requires-Dist: rich
46
58
  Requires-Dist: scanpy[leiden]
@@ -48,10 +60,14 @@ Requires-Dist: scikit-misc
48
60
  Requires-Dist: scipy
49
61
  Requires-Dist: scvi-tools
50
62
  Requires-Dist: sparsecca
51
- Requires-Dist: toytree
52
63
  Provides-Extra: coda
64
+ Requires-Dist: arviz; extra == 'coda'
53
65
  Requires-Dist: ete3; extra == 'coda'
54
66
  Requires-Dist: pyqt5; extra == 'coda'
67
+ Requires-Dist: toytree; extra == 'coda'
68
+ Provides-Extra: de
69
+ Requires-Dist: formulaic; extra == 'de'
70
+ Requires-Dist: pydeseq2; extra == 'de'
55
71
  Provides-Extra: dev
56
72
  Requires-Dist: pre-commit; extra == 'dev'
57
73
  Provides-Extra: doc
@@ -76,23 +92,23 @@ Requires-Dist: sphinx>=4; extra == 'doc'
76
92
  Requires-Dist: sphinxcontrib-bibtex>=1.0.0; extra == 'doc'
77
93
  Requires-Dist: sphinxext-opengraph; extra == 'doc'
78
94
  Provides-Extra: test
95
+ Requires-Dist: coverage; extra == 'test'
79
96
  Requires-Dist: pytest; extra == 'test'
80
- Requires-Dist: pytest-cov; extra == 'test'
81
97
  Description-Content-Type: text/markdown
82
98
 
83
99
  [![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
84
- [![Build](https://github.com/theislab/pertpy/actions/workflows/build.yml/badge.svg)](https://github.com/theislab/pertpy/actions/workflows/build.yml)
85
- [![Codecov](https://codecov.io/gh/theislab/pertpy/branch/master/graph/badge.svg)](https://codecov.io/gh/theislab/pertpy)
86
- [![License](https://img.shields.io/github/license/theislab/pertpy)](https://opensource.org/licenses/Apache2.0)
100
+ [![Build](https://github.com/scverse/pertpy/actions/workflows/build.yml/badge.svg)](https://github.com/scverse/pertpy/actions/workflows/build.yml)
101
+ [![codecov](https://codecov.io/gh/scverse/pertpy/graph/badge.svg?token=1dTpIPBShv)](https://codecov.io/gh/scverse/pertpy)
102
+ [![License](https://img.shields.io/github/license/scverse/pertpy)](https://opensource.org/licenses/Apache2.0)
87
103
  [![PyPI](https://img.shields.io/pypi/v/pertpy.svg)](https://pypi.org/project/pertpy/)
88
104
  [![Python Version](https://img.shields.io/pypi/pyversions/pertpy)](https://pypi.org/project/pertpy)
89
105
  [![Read the Docs](https://img.shields.io/readthedocs/pertpy/latest.svg?label=Read%20the%20Docs)](https://pertpy.readthedocs.io/)
90
- [![Test](https://github.com/theislab/pertpy/actions/workflows/test.yml/badge.svg)](https://github.com/theislab/pertpy/actions/workflows/test.yml)
106
+ [![Test](https://github.com/scverse/pertpy/actions/workflows/test.yml/badge.svg)](https://github.com/scverse/pertpy/actions/workflows/test.yml)
91
107
  [![PyPI](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
92
108
 
93
109
  # pertpy
94
110
 
95
- ![pertpy-wide1](https://user-images.githubusercontent.com/21954664/235677503-0c72f90d-3f6d-4a16-a1ff-ff8c11a540fb.png)
111
+ ![fig1](https://github.com/scverse/pertpy/assets/99650244/182fa9c3-6d23-4002-b86a-82bf2a243377)
96
112
 
97
113
  ## Documentation
98
114
 
@@ -103,7 +119,19 @@ Please read the [documentation](https://pertpy.readthedocs.io/en/latest).
103
119
  You can install _pertpy_ via [pip] from [PyPI]:
104
120
 
105
121
  ```console
106
- $ pip install pertpy
122
+ pip install pertpy
123
+ ```
124
+
125
+ if you want to use scCODA or tascCODA, please install pertpy as follows:
126
+
127
+ ```console
128
+ pip install pertpy[coda]
129
+ ```
130
+
131
+ If you want to use the differential gene expression interface, please install pertpy by running:
132
+
133
+ ```console
134
+ pip install pertpy[de]
107
135
  ```
108
136
 
109
137
  [pip]: https://pip.pypa.io/
@@ -0,0 +1,57 @@
1
+ pertpy/__init__.py,sha256=GMFyfRErEysnlkYKMqQxtO7QbqjGki7SpvgtLxIuG6o,658
2
+ pertpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pertpy/data/__init__.py,sha256=ah3yvoxkgbdMUNAWxS3SyqcUuVamBOSeuWkF2QRAEwM,2703
4
+ pertpy/data/_dataloader.py,sha256=fl16n82nun01gGiP7qhr5sShfcDchp0szzZp7aXkfBI,2495
5
+ pertpy/data/_datasets.py,sha256=I-keaJSTsRBySCPjiVonKmC9rRIM0AEgo0_0UlEX804,65616
6
+ pertpy/metadata/__init__.py,sha256=zoE_VXNyuKa4nlXlUk2nTgsHRW3jSQSpDEulcCnzOT0,222
7
+ pertpy/metadata/_cell_line.py,sha256=-8KSqmP5XjmLEmNX3TavxSM_MtIHwLWS_x3MVkk6JEw,38595
8
+ pertpy/metadata/_compound.py,sha256=JEFwP_TOTyMzfd2qFMb2VkJJvPhCVIvu6gs9Bq_stgs,4756
9
+ pertpy/metadata/_drug.py,sha256=8QDSyxiFl25JdS80EQJC_krg6fEe5LIQEE6BsV1r8nY,9006
10
+ pertpy/metadata/_look_up.py,sha256=DoWp6OxIk_HyyyOhW1p8z5E68IZ31_nZDnqxk1rJqps,28778
11
+ pertpy/metadata/_metadata.py,sha256=pvarnv3X5pblnvG8AQ8Omu5jQcC5ORzCxRk3FRhOLgs,3276
12
+ pertpy/metadata/_moa.py,sha256=u_OcMonjOeeoW5P9xOltquVSoTH3Vs80ztHsXf-X1DY,4701
13
+ pertpy/plot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ pertpy/preprocessing/__init__.py,sha256=VAPFaeq2_qCvdFkQTCj_Hm460HC4Tersu8Rig_tnp_Y,71
15
+ pertpy/preprocessing/_guide_rna.py,sha256=Xrv0cN16Ub1U1z-3LDNTkm98zs9JOjc2h1N7IAt_FaE,7612
16
+ pertpy/tools/__init__.py,sha256=yhDyv5J-nd3SDqc3T08Nzca8dzj3SpoVG2m9VU1rFUk,1481
17
+ pertpy/tools/_augur.py,sha256=UWro1nIEZe_rWtjlQCBv4ucqeh3Vt1m8IRzKlux72Z8,55683
18
+ pertpy/tools/_cinemaot.py,sha256=BD_oYC1TktbFMX7fpp0A57QAF6frLEgNQ_2wFUpxjyo,39509
19
+ pertpy/tools/_dialogue.py,sha256=f2fbhKWdm4Co79ZzVgtVq9xYwjYWFLdGNDeGFOO_pfM,51990
20
+ pertpy/tools/_enrichment.py,sha256=rjPHK9YBCJZfpa5Rvfxo3Ii7W5Mvm5dOdolAD7QazVg,21440
21
+ pertpy/tools/_kernel_pca.py,sha256=_EJ9WlBLjHOafF34sZGdyBgZL6Fj0WiJ1elVT1XMmo4,1579
22
+ pertpy/tools/_milo.py,sha256=kGnfx-CMOpYSl85fOW62J2X3utVjOsQFne7ixEptDmI,43691
23
+ pertpy/tools/_mixscape.py,sha256=FtH3PKvbLTe03LPgN4O9sS70oj_6AHz4Mz5otzEwRl8,52406
24
+ pertpy/tools/decoupler_LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ pertpy/tools/transferlearning_MMD_LICENSE,sha256=MUvDA-o_j9htRpI8fStVdCRuyLdPkQUuIH0a_EIc57w,1069
26
+ pertpy/tools/_coda/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ pertpy/tools/_coda/_base_coda.py,sha256=jnoLPFfluxB0_CK8-T-qolPa7xPIEb6NpeEpGwHPiNg,113058
28
+ pertpy/tools/_coda/_sccoda.py,sha256=gGmyd0MGpchulV9d4PxKSmGORyZ8fCDS9tQVPOuF_Og,22622
29
+ pertpy/tools/_coda/_tasccoda.py,sha256=vNk43OQHn7pBLsez2rmSj0bMZKOf8jZTI7G8TfBByRg,30665
30
+ pertpy/tools/_differential_gene_expression/__init__.py,sha256=sabAXym8mMLwp19ZjyBN7wp-oJh32iVj9plvJ-AbXlE,521
31
+ pertpy/tools/_differential_gene_expression/_base.py,sha256=qnQkK_hyIcViHBSkgJcAazC26JQ72bEyafKiytZikCY,23624
32
+ pertpy/tools/_differential_gene_expression/_checks.py,sha256=SxNHJDsCYZ6rWLTMEymEBpigs_B9cnXyw0kkAe1l6e0,1675
33
+ pertpy/tools/_differential_gene_expression/_dge_comparison.py,sha256=9HjmWkrqZhj_ZJeR-ymyEDzpRJNx7JiYJoStvCfKuCU,4188
34
+ pertpy/tools/_differential_gene_expression/_edger.py,sha256=JziiW5rkXuQBJISAD_LvB2HOZUgJ1_qoqiR5Q4hEoP0,4321
35
+ pertpy/tools/_differential_gene_expression/_formulaic.py,sha256=X4rPv4j8SDu5VJnf6_AIYJCCquUQka7G2LGtDLa8FhE,8715
36
+ pertpy/tools/_differential_gene_expression/_pydeseq2.py,sha256=JK7H7u4va0q_TLE_sqi4JEzoPBd_xNRycYGu1507HS4,4117
37
+ pertpy/tools/_differential_gene_expression/_simple_tests.py,sha256=tTSr0Z2Qbpxdy9bcO8Gi_up6R616IcoK_e4_rlanyx4,6621
38
+ pertpy/tools/_differential_gene_expression/_statsmodels.py,sha256=zSOwJYDJyrl3hsEhMI5Q9Pyw2XLuEuj7T0zSAVcP6tQ,2585
39
+ pertpy/tools/_distances/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ pertpy/tools/_distances/_distance_tests.py,sha256=mNmNu5cX0Wj5IegR6x5K-CbBSid8EhrH2jZPQxuvK4U,13521
41
+ pertpy/tools/_distances/_distances.py,sha256=iuHpBtWZbJhMZNSEjQkZUu6KPJXCjs_fX6YjopIWvwY,50343
42
+ pertpy/tools/_perturbation_space/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
+ pertpy/tools/_perturbation_space/_clustering.py,sha256=m52-J8c8OnIXRCf3NoFabIO2yMHIuy1X0m0amtsK2vE,3556
44
+ pertpy/tools/_perturbation_space/_comparison.py,sha256=rLO-EGU0I7t5MnLw4k1gYU-ypRu-JsDPLat1t4h2U2M,4329
45
+ pertpy/tools/_perturbation_space/_discriminator_classifiers.py,sha256=BNMP-2g4X_9jhs3Vf2rwlIjSCAcADkxBAFYGlsQ5Irw,21609
46
+ pertpy/tools/_perturbation_space/_metrics.py,sha256=y8-baP8WRdB1iDgvP3uuQxSCDxA2lcxvEHHM2C_vWHY,3248
47
+ pertpy/tools/_perturbation_space/_perturbation_space.py,sha256=cZPPzzK4_UZV7ktcD5BQVXEy6ITHrfkg1CLFov3TzsY,18497
48
+ pertpy/tools/_perturbation_space/_simple.py,sha256=LH5EYvcAbzFMvgd9bH7AUPKFmdioPiy2xG8xGaXzmq0,12624
49
+ pertpy/tools/_scgen/__init__.py,sha256=uERFlFyF88TH0uLiwmsUGEfHfLVCiZMFuk8gO5f7164,45
50
+ pertpy/tools/_scgen/_base_components.py,sha256=Qq8myRUm43q9XBrZ9gBggfa2cSV2wbz_KYoLgH7iF1A,3009
51
+ pertpy/tools/_scgen/_scgen.py,sha256=HPvFVjY9SS9bGqgTkCDuPYjmA4QHW7rKgHnI2yuI_Q4,30608
52
+ pertpy/tools/_scgen/_scgenvae.py,sha256=v_6tZ4wY-JjdMH1QVd_wG4_N0PoaqB-FM8zC2JsDu1o,3935
53
+ pertpy/tools/_scgen/_utils.py,sha256=1upgOt1FpadfvNG05YpMjYYG-IAlxrC3l_ZxczmIczo,2841
54
+ pertpy-0.8.0.dist-info/METADATA,sha256=cLAhPubizJ7vgCThHv-kHsAAvepUyRTnTHTKRKX9kYQ,6054
55
+ pertpy-0.8.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
56
+ pertpy-0.8.0.dist-info/licenses/LICENSE,sha256=OZ-ZkXM5CmExJiEMM90b_7dGNNvRpj7kdE-49AnrLuI,1070
57
+ pertpy-0.8.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.18.0
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
pertpy/plot/_augur.py DELETED
@@ -1,234 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Any
4
-
5
- from anndata import AnnData
6
- from matplotlib import pyplot as plt
7
-
8
- if TYPE_CHECKING:
9
- import pandas as pd
10
- from matplotlib.axes import Axes
11
- from matplotlib.figure import Figure
12
-
13
-
14
- class AugurpyPlot:
15
- """Plotting functions for Augurpy."""
16
-
17
- @staticmethod
18
- def dp_scatter(results: pd.DataFrame, top_n=None, ax: Axes = None, return_figure: bool = False) -> Figure | Axes:
19
- """Plot result of differential prioritization.
20
-
21
- Args:
22
- results: Results after running differential prioritization.
23
- top_n: optionally, the number of top prioritized cell types to label in the plot
24
- ax: optionally, axes used to draw plot
25
- return_figure: if `True` returns figure of the plot
26
-
27
- Returns:
28
- Axes of the plot.
29
-
30
- Examples:
31
- >>> import pertpy as pt
32
- >>> adata = pt.dt.bhattacherjee()
33
- >>> ag_rfc = pt.tl.Augur("random_forest_classifier")
34
-
35
- >>> data_15 = ag_rfc.load(adata, condition_label="Maintenance_Cocaine", treatment_label="withdraw_15d_Cocaine")
36
- >>> adata_15, results_15 = ag_rfc.predict(data_15, random_state=None, n_threads=4)
37
- >>> adata_15_permute, results_15_permute = ag_rfc.predict(data_15, augur_mode="permute", n_subsamples=100, random_state=None, n_threads=4)
38
-
39
- >>> data_48 = ag_rfc.load(adata, condition_label="Maintenance_Cocaine", treatment_label="withdraw_48h_Cocaine")
40
- >>> adata_48, results_48 = ag_rfc.predict(data_48, random_state=None, n_threads=4)
41
- >>> adata_48_permute, results_48_permute = ag_rfc.predict(data_48, augur_mode="permute", n_subsamples=100, random_state=None, n_threads=4)
42
-
43
- >>> pvals = ag_rfc.predict_differential_prioritization(augur_results1=results_15, augur_results2=results_48, \
44
- permuted_results1=results_15_permute, permuted_results2=results_48_permute)
45
- >>> pt.pl.ag.dp_scatter(pvals)
46
- """
47
- x = results["mean_augur_score1"]
48
- y = results["mean_augur_score2"]
49
-
50
- if ax is None:
51
- fig, ax = plt.subplots()
52
- scatter = ax.scatter(x, y, c=results.z, cmap="Greens")
53
-
54
- # adding optional labels
55
- top_n_index = results.sort_values(by="pval").index[:top_n]
56
- for idx in top_n_index:
57
- ax.annotate(
58
- results.loc[idx, "cell_type"],
59
- (results.loc[idx, "mean_augur_score1"], results.loc[idx, "mean_augur_score2"]),
60
- )
61
-
62
- # add diagonal
63
- limits = max(ax.get_xlim(), ax.get_ylim())
64
- (diag_line,) = ax.plot(limits, limits, ls="--", c=".3")
65
-
66
- # formatting and details
67
- plt.xlabel("Augur scores 1")
68
- plt.ylabel("Augur scores 2")
69
- legend1 = ax.legend(*scatter.legend_elements(), loc="center left", title="z-scores", bbox_to_anchor=(1, 0.5))
70
- ax.add_artist(legend1)
71
-
72
- return fig if return_figure else ax
73
-
74
- @staticmethod
75
- def important_features(
76
- data: dict[str, Any], key: str = "augurpy_results", top_n=10, ax: Axes = None, return_figure: bool = False
77
- ) -> Figure | Axes:
78
- """Plot a lollipop plot of the n features with largest feature importances.
79
-
80
- Args:
81
- results: results after running `predict()` as dictionary or the AnnData object.
82
- key: Key in the AnnData object of the results
83
- top_n: n number feature importance values to plot. Default is 10.
84
- ax: optionally, axes used to draw plot
85
- return_figure: if `True` returns figure of the plot, default is `False`
86
-
87
- Returns:
88
- Axes of the plot.
89
-
90
- Examples:
91
- >>> import pertpy as pt
92
- >>> adata = pt.dt.sc_sim_augur()
93
- >>> ag_rfc = pt.tl.Augur("random_forest_classifier")
94
- >>> loaded_data = ag_rfc.load(adata)
95
- >>> v_adata, v_results = ag_rfc.predict(loaded_data, subsample_size=20, select_variance_features=True, n_threads=4)
96
- >>> pt.pl.ag.important_features(v_results)
97
- """
98
- if isinstance(data, AnnData):
99
- results = data.uns[key]
100
- else:
101
- results = data
102
- # top_n features to plot
103
- n_features = (
104
- results["feature_importances"]
105
- .groupby("genes", as_index=False)
106
- .feature_importances.mean()
107
- .sort_values(by="feature_importances")[-top_n:]
108
- )
109
-
110
- if ax is None:
111
- fig, ax = plt.subplots()
112
- y_axes_range = range(1, top_n + 1)
113
- ax.hlines(
114
- y_axes_range,
115
- xmin=0,
116
- xmax=n_features["feature_importances"],
117
- )
118
-
119
- # drawing the markers (circle)
120
- ax.plot(n_features["feature_importances"], y_axes_range, "o")
121
-
122
- # formatting and details
123
- plt.xlabel("Mean Feature Importance")
124
- plt.ylabel("Gene")
125
- plt.yticks(y_axes_range, n_features["genes"])
126
-
127
- return fig if return_figure else ax
128
-
129
- @staticmethod
130
- def lollipop(
131
- data: dict[str, Any], key: str = "augurpy_results", ax: Axes = None, return_figure: bool = False
132
- ) -> Figure | Axes:
133
- """Plot a lollipop plot of the mean augur values.
134
-
135
- Args:
136
- results: results after running `predict()` as dictionary or the AnnData object.
137
- key: Key in the AnnData object of the results
138
- ax: optionally, axes used to draw plot
139
- return_figure: if `True` returns figure of the plot
140
-
141
- Returns:
142
- Axes of the plot.
143
-
144
- Examples:
145
- >>> import pertpy as pt
146
- >>> adata = pt.dt.sc_sim_augur()
147
- >>> ag_rfc = pt.tl.Augur("random_forest_classifier")
148
- >>> loaded_data = ag_rfc.load(adata)
149
- >>> v_adata, v_results = ag_rfc.predict(loaded_data, subsample_size=20, select_variance_features=True, n_threads=4)
150
- >>> pt.pl.ag.lollipop(v_results)
151
- """
152
- if isinstance(data, AnnData):
153
- results = data.uns[key]
154
- else:
155
- results = data
156
- if ax is None:
157
- fig, ax = plt.subplots()
158
- y_axes_range = range(1, len(results["summary_metrics"].columns) + 1)
159
- ax.hlines(
160
- y_axes_range,
161
- xmin=0,
162
- xmax=results["summary_metrics"].sort_values("mean_augur_score", axis=1).loc["mean_augur_score"],
163
- )
164
-
165
- # drawing the markers (circle)
166
- ax.plot(
167
- results["summary_metrics"].sort_values("mean_augur_score", axis=1).loc["mean_augur_score"],
168
- y_axes_range,
169
- "o",
170
- )
171
-
172
- # formatting and details
173
- plt.xlabel("Mean Augur Score")
174
- plt.ylabel("Cell Type")
175
- plt.yticks(y_axes_range, results["summary_metrics"].sort_values("mean_augur_score", axis=1).columns)
176
-
177
- return fig if return_figure else ax
178
-
179
- @staticmethod
180
- def scatterplot(
181
- results1: dict[str, Any], results2: dict[str, Any], top_n=None, return_figure: bool = False
182
- ) -> Figure | Axes:
183
- """Create scatterplot with two augur results.
184
-
185
- Args:
186
- results1: results after running `predict()`
187
- results2: results after running `predict()`
188
- top_n: optionally, the number of top prioritized cell types to label in the plot
189
- return_figure: if `True` returns figure of the plot
190
-
191
- Returns:
192
- Axes of the plot.
193
-
194
- Examples:
195
- >>> import pertpy as pt
196
- >>> adata = pt.dt.sc_sim_augur()
197
- >>> ag_rfc = pt.tl.Augur("random_forest_classifier")
198
- >>> loaded_data = ag_rfc.load(adata)
199
- >>> h_adata, h_results = ag_rfc.predict(loaded_data, subsample_size=20, n_threads=4)
200
- >>> v_adata, v_results = ag_rfc.predict(loaded_data, subsample_size=20, select_variance_features=True, n_threads=4)
201
- >>> pt.pl.ag.scatterplot(v_results, h_results)
202
- """
203
- cell_types = results1["summary_metrics"].columns
204
-
205
- fig, ax = plt.subplots()
206
- ax.scatter(
207
- results1["summary_metrics"].loc["mean_augur_score", cell_types],
208
- results2["summary_metrics"].loc["mean_augur_score", cell_types],
209
- )
210
-
211
- # adding optional labels
212
- top_n_cell_types = (
213
- (results1["summary_metrics"].loc["mean_augur_score"] - results2["summary_metrics"].loc["mean_augur_score"])
214
- .sort_values(ascending=False)
215
- .index[:top_n]
216
- )
217
- for txt in top_n_cell_types:
218
- ax.annotate(
219
- txt,
220
- (
221
- results1["summary_metrics"].loc["mean_augur_score", txt],
222
- results2["summary_metrics"].loc["mean_augur_score", txt],
223
- ),
224
- )
225
-
226
- # adding diagonal
227
- limits = max(ax.get_xlim(), ax.get_ylim())
228
- (diag_line,) = ax.plot(limits, limits, ls="--", c=".3")
229
-
230
- # formatting and details
231
- plt.xlabel("Augur scores 1")
232
- plt.ylabel("Augur scores 2")
233
-
234
- return fig if return_figure else ax
pertpy/plot/_cinemaot.py DELETED
@@ -1,81 +0,0 @@
1
- from typing import Optional
2
-
3
- import matplotlib.pyplot as plt
4
- import pandas as pd
5
- import scanpy as sc
6
- import seaborn as sns
7
- from anndata import AnnData
8
- from matplotlib.axes import Axes
9
- from scanpy.plotting import _utils
10
-
11
-
12
- class CinemaotPlot:
13
- """Plotting functions for CINEMA-OT. Only includes new functions beyond the scanpy.pl.embedding family."""
14
-
15
- @staticmethod
16
- def vis_matching(
17
- adata: AnnData,
18
- de: AnnData,
19
- pert_key: str,
20
- control: str,
21
- de_label: str,
22
- source_label: str,
23
- matching_rep: str = "ot",
24
- resolution: float = 0.5,
25
- normalize: str = "col",
26
- title: str = "CINEMA-OT matching matrix",
27
- min_val: float = 0.01,
28
- show: bool = True,
29
- save: Optional[str] = None,
30
- ax: Optional[Axes] = None,
31
- **kwargs,
32
- ) -> None:
33
- """Visualize the CINEMA-OT matching matrix.
34
-
35
- Args:
36
- adata: the original anndata after running cinemaot.causaleffect or cinemaot.causaleffect_weighted.
37
- de: The anndata output from Cinemaot.causaleffect() or Cinemaot.causaleffect_weighted().
38
- pert_key: The column of `.obs` with perturbation categories, should also contain `control`.
39
- control: Control category from the `pert_key` column.
40
- de_label: the label for differential response. If none, use leiden cluster labels at resolution 1.0.
41
- source_label: the confounder / cell type label.
42
- matching_rep: the place that stores the matching matrix. default de.obsm['ot'].
43
- normalize: normalize the coarse-grained matching matrix by row / column.
44
- title: the title for the figure.
45
- min_val: The min value to truncate the matching matrix.
46
- show: Show the plot, do not return axis.
47
- save: If `True` or a `str`, save the figure. A string is appended to the default filename.
48
- Infer the filetype if ending on {`'.pdf'`, `'.png'`, `'.svg'`}.
49
- **kwargs: Other parameters to input for seaborn.heatmap.
50
- """
51
- adata_ = adata[adata.obs[pert_key] == control]
52
-
53
- df = pd.DataFrame(de.obsm[matching_rep])
54
- if de_label is None:
55
- de_label = "leiden"
56
- sc.pp.neighbors(de, use_rep="X_embedding")
57
- sc.tl.leiden(de, resolution=resolution)
58
- df["de_label"] = de.obs[de_label].astype(str).values
59
- df["de_label"] = "Response " + df["de_label"]
60
- df = df.groupby("de_label").sum().T
61
- df["source_label"] = adata_.obs[source_label].astype(str).values
62
- df = df.groupby("source_label").sum()
63
-
64
- if normalize == "col":
65
- df = df / df.sum(axis=0)
66
- else:
67
- df = (df.T / df.sum(axis=1)).T
68
- df = df.clip(lower=min_val) - min_val
69
- if normalize == "col":
70
- df = df / df.sum(axis=0)
71
- else:
72
- df = (df.T / df.sum(axis=1)).T
73
-
74
- g = sns.heatmap(df, annot=True, ax=ax, **kwargs)
75
- plt.title(title)
76
- _utils.savefig_or_show("matching_heatmap", show=show, save=save)
77
- if not show:
78
- if ax is not None:
79
- return ax
80
- else:
81
- return g