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

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 (53) hide show
  1. pertpy/__init__.py +3 -2
  2. pertpy/data/__init__.py +5 -1
  3. pertpy/data/_dataloader.py +2 -4
  4. pertpy/data/_datasets.py +203 -92
  5. pertpy/metadata/__init__.py +4 -0
  6. pertpy/metadata/_cell_line.py +826 -0
  7. pertpy/metadata/_compound.py +129 -0
  8. pertpy/metadata/_drug.py +242 -0
  9. pertpy/metadata/_look_up.py +582 -0
  10. pertpy/metadata/_metadata.py +73 -0
  11. pertpy/metadata/_moa.py +129 -0
  12. pertpy/plot/__init__.py +1 -9
  13. pertpy/plot/_augur.py +53 -116
  14. pertpy/plot/_coda.py +277 -677
  15. pertpy/plot/_guide_rna.py +17 -35
  16. pertpy/plot/_milopy.py +59 -134
  17. pertpy/plot/_mixscape.py +152 -391
  18. pertpy/preprocessing/_guide_rna.py +88 -4
  19. pertpy/tools/__init__.py +8 -13
  20. pertpy/tools/_augur.py +315 -17
  21. pertpy/tools/_cinemaot.py +143 -4
  22. pertpy/tools/_coda/_base_coda.py +1210 -65
  23. pertpy/tools/_coda/_sccoda.py +50 -21
  24. pertpy/tools/_coda/_tasccoda.py +27 -19
  25. pertpy/tools/_dialogue.py +164 -56
  26. pertpy/tools/_differential_gene_expression.py +240 -14
  27. pertpy/tools/_distances/_distance_tests.py +8 -8
  28. pertpy/tools/_distances/_distances.py +184 -34
  29. pertpy/tools/_enrichment.py +465 -0
  30. pertpy/tools/_milo.py +345 -11
  31. pertpy/tools/_mixscape.py +668 -50
  32. pertpy/tools/_perturbation_space/_clustering.py +5 -1
  33. pertpy/tools/_perturbation_space/_discriminator_classifiers.py +526 -0
  34. pertpy/tools/_perturbation_space/_perturbation_space.py +135 -43
  35. pertpy/tools/_perturbation_space/_simple.py +51 -10
  36. pertpy/tools/_scgen/__init__.py +1 -1
  37. pertpy/tools/_scgen/_scgen.py +701 -0
  38. pertpy/tools/_scgen/_utils.py +1 -3
  39. pertpy/tools/decoupler_LICENSE +674 -0
  40. {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/METADATA +31 -12
  41. pertpy-0.7.0.dist-info/RECORD +53 -0
  42. {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/WHEEL +1 -1
  43. pertpy/plot/_cinemaot.py +0 -81
  44. pertpy/plot/_dialogue.py +0 -91
  45. pertpy/plot/_scgen.py +0 -337
  46. pertpy/tools/_metadata/__init__.py +0 -0
  47. pertpy/tools/_metadata/_cell_line.py +0 -613
  48. pertpy/tools/_metadata/_look_up.py +0 -342
  49. pertpy/tools/_perturbation_space/_discriminator_classifier.py +0 -381
  50. pertpy/tools/_scgen/_jax_scgen.py +0 -370
  51. pertpy-0.6.0.dist-info/RECORD +0 -50
  52. /pertpy/tools/_scgen/{_jax_scgenvae.py → _scgenvae.py} +0 -0
  53. {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/licenses/LICENSE +0 -0
@@ -8,8 +8,7 @@ import numpy as np
8
8
  import numpyro as npy
9
9
  import numpyro.distributions as npd
10
10
  from anndata import AnnData
11
- from jax import random
12
- from jax.config import config
11
+ from jax import config, random
13
12
  from mudata import MuData
14
13
  from numpyro.infer import Predictive
15
14
  from rich import print
@@ -23,7 +22,6 @@ config.update("jax_enable_x64", True)
23
22
 
24
23
 
25
24
  class Sccoda(CompositionalModel2):
26
-
27
25
  """
28
26
  Statistical model for single-cell differential composition analysis with specification of a reference cell type.
29
27
  This is the standard scCODA model and recommended for all uses.
@@ -90,8 +88,11 @@ class Sccoda(CompositionalModel2):
90
88
  >>> import pertpy as pt
91
89
  >>> haber_cells = pt.dt.haber_2017_regions()
92
90
  >>> sccoda = pt.tl.Sccoda()
93
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
94
- sample_identifier="batch", covariate_obs=["condition"])
91
+ >>> mdata = sccoda.load(haber_cells,
92
+ >>> type="cell_level",
93
+ >>> generate_sample_level=True,
94
+ >>> cell_type_identifier="cell_label",
95
+ >>> sample_identifier="batch", covariate_obs=["condition"])
95
96
  """
96
97
  if type == "cell_level":
97
98
  if generate_sample_level:
@@ -144,8 +145,12 @@ class Sccoda(CompositionalModel2):
144
145
  >>> import pertpy as pt
145
146
  >>> haber_cells = pt.dt.haber_2017_regions()
146
147
  >>> sccoda = pt.tl.Sccoda()
147
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
148
- sample_identifier="batch", covariate_obs=["condition"])
148
+ >>> mdata = sccoda.load(haber_cells,
149
+ >>> type="cell_level",
150
+ >>> generate_sample_level=True,
151
+ >>> cell_type_identifier="cell_label",
152
+ >>> sample_identifier="batch",
153
+ >>> covariate_obs=["condition"])
149
154
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
150
155
  """
151
156
  if isinstance(data, MuData):
@@ -193,10 +198,14 @@ class Sccoda(CompositionalModel2):
193
198
  >>> import pertpy as pt
194
199
  >>> haber_cells = pt.dt.haber_2017_regions()
195
200
  >>> sccoda = pt.tl.Sccoda()
196
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
197
- sample_identifier="batch", covariate_obs=["condition"])
201
+ >>> mdata = sccoda.load(haber_cells,
202
+ >>> type="cell_level",
203
+ >>> generate_sample_level=True,
204
+ >>> cell_type_identifier="cell_label",
205
+ >>> sample_identifier="batch",
206
+ >>> covariate_obs=["condition"])
198
207
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
199
- >>> adata = sccoda.set_init_mcmc_states(rng_key=42, ref_index=0, sample_adata=mdata['coda'])
208
+ >>> adata = sccoda.set_init_mcmc_states(rng_key=42, ref_index=0, sample_adata=mdata["coda"])
200
209
  """
201
210
  # data dimensions
202
211
  N, D = sample_adata.obsm["covariate_matrix"].shape
@@ -312,8 +321,12 @@ class Sccoda(CompositionalModel2):
312
321
  >>> import pertpy as pt
313
322
  >>> haber_cells = pt.dt.haber_2017_regions()
314
323
  >>> sccoda = pt.tl.Sccoda()
315
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
316
- sample_identifier="batch", covariate_obs=["condition"])
324
+ >>> mdata = sccoda.load(haber_cells,
325
+ >>> type="cell_level",
326
+ >>> generate_sample_level=True,
327
+ >>> cell_type_identifier="cell_label",
328
+ >>> sample_identifier="batch",
329
+ >>> covariate_obs=["condition"])
317
330
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
318
331
  >>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
319
332
  >>> arviz_data = sccoda.make_arviz(mdata, num_prior_samples=100)
@@ -365,7 +378,7 @@ class Sccoda(CompositionalModel2):
365
378
 
366
379
  if rng_key is None:
367
380
  rng = np.random.default_rng()
368
- rng_key = random.PRNGKey(rng.integers(0, 10000))
381
+ rng_key = random.key(rng.integers(0, 10000))
369
382
 
370
383
  if use_posterior_predictive:
371
384
  posterior_predictive = Predictive(self.model, self.mcmc.get_samples())(
@@ -414,8 +427,12 @@ class Sccoda(CompositionalModel2):
414
427
  >>> import pertpy as pt
415
428
  >>> haber_cells = pt.dt.haber_2017_regions()
416
429
  >>> sccoda = pt.tl.Sccoda()
417
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
418
- sample_identifier="batch", covariate_obs=["condition"])
430
+ >>> mdata = sccoda.load(haber_cells,
431
+ >>> type="cell_level",
432
+ >>> generate_sample_level=True,
433
+ >>> cell_type_identifier="cell_label",
434
+ >>> sample_identifier="batch",
435
+ >>> covariate_obs=["condition"])
419
436
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
420
437
  >>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
421
438
  """
@@ -429,8 +446,12 @@ class Sccoda(CompositionalModel2):
429
446
  >>> import pertpy as pt
430
447
  >>> haber_cells = pt.dt.haber_2017_regions()
431
448
  >>> sccoda = pt.tl.Sccoda()
432
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
433
- sample_identifier="batch", covariate_obs=["condition"])
449
+ >>> mdata = sccoda.load(haber_cells,
450
+ >>> type="cell_level",
451
+ >>> generate_sample_level=True,
452
+ >>> cell_type_identifier="cell_label",
453
+ >>> sample_identifier="batch",
454
+ >>> covariate_obs=["condition"])
434
455
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
435
456
  >>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
436
457
  >>> credible_effects = sccoda.credible_effects(mdata)
@@ -445,8 +466,12 @@ class Sccoda(CompositionalModel2):
445
466
  >>> import pertpy as pt
446
467
  >>> haber_cells = pt.dt.haber_2017_regions()
447
468
  >>> sccoda = pt.tl.Sccoda()
448
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
449
- sample_identifier="batch", covariate_obs=["condition"])
469
+ >>> mdata = sccoda.load(haber_cells,
470
+ >>> type="cell_level",
471
+ >>> generate_sample_level=True,
472
+ >>> cell_type_identifier="cell_label",
473
+ >>> sample_identifier="batch",
474
+ >>> covariate_obs=["condition"])
450
475
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
451
476
  >>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
452
477
  >>> sccoda.summary(mdata)
@@ -461,8 +486,12 @@ class Sccoda(CompositionalModel2):
461
486
  >>> import pertpy as pt
462
487
  >>> haber_cells = pt.dt.haber_2017_regions()
463
488
  >>> sccoda = pt.tl.Sccoda()
464
- >>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
465
- sample_identifier="batch", covariate_obs=["condition"])
489
+ >>> mdata = sccoda.load(haber_cells,
490
+ >>> type="cell_level",
491
+ >>> generate_sample_level=True,
492
+ >>> cell_type_identifier="cell_label",
493
+ >>> sample_identifier="batch",
494
+ >>> covariate_obs=["condition"])
466
495
  >>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
467
496
  >>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
468
497
  >>> sccoda.set_fdr(mdata, est_fdr=0.4)
@@ -3,15 +3,13 @@ from __future__ import annotations
3
3
  from typing import TYPE_CHECKING, Literal
4
4
 
5
5
  import arviz as az
6
- import ete3 as ete
7
6
  import jax.numpy as jnp
8
7
  import numpy as np
9
8
  import numpyro as npy
10
9
  import numpyro.distributions as npd
11
10
  import toytree as tt
12
11
  from anndata import AnnData
13
- from jax import random
14
- from jax.config import config
12
+ from jax import config, random
15
13
  from mudata import MuData
16
14
  from numpyro.infer import Predictive
17
15
  from rich import print
@@ -105,7 +103,7 @@ class Tasccoda(CompositionalModel2):
105
103
 
106
104
  Examples:
107
105
  >>> import pertpy as pt
108
- >>> adata = pt.dt.smillie()
106
+ >>> adata = pt.dt.tasccoda_example()
109
107
  >>> tasccoda = pt.tl.Tasccoda()
110
108
  >>> mdata = tasccoda.load(
111
109
  >>> adata, type="sample_level",
@@ -148,17 +146,19 @@ class Tasccoda(CompositionalModel2):
148
146
  pen_args: dict = None,
149
147
  modality_key: str = "coda",
150
148
  ) -> AnnData | MuData:
151
- """Handles data preprocessing, covariate matrix creation, reference selection, and zero count replacement for tascCODA. Also sets model parameters, model type (tree_agg), effect selection type (sslaso) and performs tree processing.
149
+ """Handles data preprocessing, covariate matrix creation, reference selection, and zero count replacement for tascCODA.
152
150
 
153
151
  Args:
154
152
  data: Anndata object with cell counts as .X and covariates saved in .obs or a MuData object.
155
153
  formula: R-style formula for building the covariate matrix.
156
- Categorical covariates are handled automatically, with the covariate value of the first sample being used as the reference category.
157
- To set a different level as the base category for a categorical covariate, use "C(<CovariateName>, Treatment('<ReferenceLevelName>'))"
154
+ Categorical covariates are handled automatically, with the covariate value of the first sample being used as the reference category.
155
+ To set a different level as the base category for a categorical covariate, use "C(<CovariateName>, Treatment('<ReferenceLevelName>'))"
158
156
  reference_cell_type: Column name that sets the reference cell type.
159
- Reference the name of a column. If "automatic", the cell type with the lowest dispersion in relative abundance that is present in at least 90% of samlpes will be chosen. Defaults to "automatic".
160
- automatic_reference_absence_threshold: If using reference_cell_type = "automatic", determine the maximum fraction of zero entries for a cell type
161
- to be considered as a possible reference cell type. Defaults to 0.05.
157
+ If "automatic", the cell type with the lowest dispersion in relative abundance that is present in at least 90% of samlpes will be chosen.
158
+ Defaults to "automatic".
159
+ automatic_reference_absence_threshold: If using reference_cell_type = "automatic",
160
+ determine the maximum fraction of zero entries for a cell type
161
+ to be considered as a possible reference cell type. Defaults to 0.05.
162
162
  tree_key: Key in `adata.uns` that contains the tree structure
163
163
  pen_args: Dictionary with penalty arguments. With `reg="scaled_3"`, the parameters phi (aggregation bias), lambda_1, lambda_0 can be set here.
164
164
  See the tascCODA paper for an explanation of these parameters. Default: lambda_0 = 50, lambda_1 = 5, phi = 0.
@@ -175,7 +175,7 @@ class Tasccoda(CompositionalModel2):
175
175
 
176
176
  Examples:
177
177
  >>> import pertpy as pt
178
- >>> adata = pt.dt.smillie()
178
+ >>> adata = pt.dt.tasccoda_example()
179
179
  >>> tasccoda = pt.tl.Tasccoda()
180
180
  >>> mdata = tasccoda.load(
181
181
  >>> adata, type="sample_level",
@@ -199,6 +199,14 @@ class Tasccoda(CompositionalModel2):
199
199
  if tree_key is None:
200
200
  raise ValueError("Please specify the key in .uns that contains the tree structure!")
201
201
 
202
+ # Scoped import due to installation issues
203
+ try:
204
+ import ete3 as ete
205
+ except ImportError:
206
+ raise ImportError(
207
+ "To use tasccoda please install additional dependencies as `pip install pertpy[coda]`"
208
+ ) from None
209
+
202
210
  # toytree tree - only for legacy reasons, can be removed in the final version
203
211
  if isinstance(adata.uns[tree_key], tt.tree):
204
212
  # Collapse singularities in the tree
@@ -315,7 +323,7 @@ class Tasccoda(CompositionalModel2):
315
323
 
316
324
  Examples:
317
325
  >>> import pertpy as pt
318
- >>> adata = pt.dt.smillie()
326
+ >>> adata = pt.dt.tasccoda_example()
319
327
  >>> tasccoda = pt.tl.Tasccoda()
320
328
  >>> mdata = tasccoda.load(
321
329
  >>> adata, type="sample_level",
@@ -325,7 +333,7 @@ class Tasccoda(CompositionalModel2):
325
333
  >>> mdata = tasccoda.prepare(
326
334
  >>> mdata, formula="Health", reference_cell_type="automatic", tree_key="lineage", pen_args={"phi": 0}
327
335
  >>> )
328
- >>> adata = tasccoda.set_init_mcmc_states(rng_key=42, ref_index=[0,1], sample_adata=mdata['coda'])
336
+ >>> adata = tasccoda.set_init_mcmc_states(rng_key=42, ref_index=[0, 1], sample_adata=mdata["coda"])
329
337
  """
330
338
  N, D = sample_adata.obsm["covariate_matrix"].shape
331
339
  P = sample_adata.X.shape[1]
@@ -479,7 +487,7 @@ class Tasccoda(CompositionalModel2):
479
487
 
480
488
  Examples:
481
489
  >>> import pertpy as pt
482
- >>> adata = pt.dt.smillie()
490
+ >>> adata = pt.dt.tasccoda_example()
483
491
  >>> tasccoda = pt.tl.Tasccoda()
484
492
  >>> mdata = tasccoda.load(
485
493
  >>> adata, type="sample_level",
@@ -543,7 +551,7 @@ class Tasccoda(CompositionalModel2):
543
551
 
544
552
  if rng_key is None:
545
553
  rng = np.random.default_rng()
546
- rng_key = random.PRNGKey(rng.integers(0, 10000))
554
+ rng_key = random.key(rng.integers(0, 10000))
547
555
 
548
556
  if use_posterior_predictive:
549
557
  posterior_predictive = Predictive(self.model, self.mcmc.get_samples())(
@@ -590,7 +598,7 @@ class Tasccoda(CompositionalModel2):
590
598
  """
591
599
  Examples:
592
600
  >>> import pertpy as pt
593
- >>> adata = pt.dt.smillie()
601
+ >>> adata = pt.dt.tasccoda_example()
594
602
  >>> tasccoda = pt.tl.Tasccoda()
595
603
  >>> mdata = tasccoda.load(
596
604
  >>> adata, type="sample_level",
@@ -610,7 +618,7 @@ class Tasccoda(CompositionalModel2):
610
618
  """
611
619
  Examples:
612
620
  >>> import pertpy as pt
613
- >>> adata = pt.dt.smillie()
621
+ >>> adata = pt.dt.tasccoda_example()
614
622
  >>> tasccoda = pt.tl.Tasccoda()
615
623
  >>> mdata = tasccoda.load(
616
624
  >>> adata, type="sample_level",
@@ -631,7 +639,7 @@ class Tasccoda(CompositionalModel2):
631
639
  """
632
640
  Examples:
633
641
  >>> import pertpy as pt
634
- >>> adata = pt.dt.smillie()
642
+ >>> adata = pt.dt.tasccoda_example()
635
643
  >>> tasccoda = pt.tl.Tasccoda()
636
644
  >>> mdata = tasccoda.load(
637
645
  >>> adata, type="sample_level",
@@ -652,7 +660,7 @@ class Tasccoda(CompositionalModel2):
652
660
  """
653
661
  Examples:
654
662
  >>> import pertpy as pt
655
- >>> adata = pt.dt.smillie()
663
+ >>> adata = pt.dt.tasccoda_example()
656
664
  >>> tasccoda = pt.tl.Tasccoda()
657
665
  >>> mdata = tasccoda.load(
658
666
  >>> adata, type="sample_level",