pertpy 0.6.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pertpy/__init__.py +3 -2
- pertpy/data/__init__.py +5 -1
- pertpy/data/_dataloader.py +2 -4
- pertpy/data/_datasets.py +203 -92
- pertpy/metadata/__init__.py +4 -0
- pertpy/metadata/_cell_line.py +826 -0
- pertpy/metadata/_compound.py +129 -0
- pertpy/metadata/_drug.py +242 -0
- pertpy/metadata/_look_up.py +582 -0
- pertpy/metadata/_metadata.py +73 -0
- pertpy/metadata/_moa.py +129 -0
- pertpy/plot/__init__.py +1 -9
- pertpy/plot/_augur.py +53 -116
- pertpy/plot/_coda.py +277 -677
- pertpy/plot/_guide_rna.py +17 -35
- pertpy/plot/_milopy.py +59 -134
- pertpy/plot/_mixscape.py +152 -391
- pertpy/preprocessing/_guide_rna.py +88 -4
- pertpy/tools/__init__.py +8 -13
- pertpy/tools/_augur.py +315 -17
- pertpy/tools/_cinemaot.py +143 -4
- pertpy/tools/_coda/_base_coda.py +1210 -65
- pertpy/tools/_coda/_sccoda.py +50 -21
- pertpy/tools/_coda/_tasccoda.py +27 -19
- pertpy/tools/_dialogue.py +164 -56
- pertpy/tools/_differential_gene_expression.py +240 -14
- pertpy/tools/_distances/_distance_tests.py +8 -8
- pertpy/tools/_distances/_distances.py +184 -34
- pertpy/tools/_enrichment.py +465 -0
- pertpy/tools/_milo.py +345 -11
- pertpy/tools/_mixscape.py +668 -50
- pertpy/tools/_perturbation_space/_clustering.py +5 -1
- pertpy/tools/_perturbation_space/_discriminator_classifiers.py +526 -0
- pertpy/tools/_perturbation_space/_perturbation_space.py +135 -43
- pertpy/tools/_perturbation_space/_simple.py +51 -10
- pertpy/tools/_scgen/__init__.py +1 -1
- pertpy/tools/_scgen/_scgen.py +701 -0
- pertpy/tools/_scgen/_utils.py +1 -3
- pertpy/tools/decoupler_LICENSE +674 -0
- {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/METADATA +31 -12
- pertpy-0.7.0.dist-info/RECORD +53 -0
- {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/WHEEL +1 -1
- pertpy/plot/_cinemaot.py +0 -81
- pertpy/plot/_dialogue.py +0 -91
- pertpy/plot/_scgen.py +0 -337
- pertpy/tools/_metadata/__init__.py +0 -0
- pertpy/tools/_metadata/_cell_line.py +0 -613
- pertpy/tools/_metadata/_look_up.py +0 -342
- pertpy/tools/_perturbation_space/_discriminator_classifier.py +0 -381
- pertpy/tools/_scgen/_jax_scgen.py +0 -370
- pertpy-0.6.0.dist-info/RECORD +0 -50
- /pertpy/tools/_scgen/{_jax_scgenvae.py → _scgenvae.py} +0 -0
- {pertpy-0.6.0.dist-info → pertpy-0.7.0.dist-info}/licenses/LICENSE +0 -0
pertpy/tools/_coda/_sccoda.py
CHANGED
@@ -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,
|
94
|
-
|
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,
|
148
|
-
|
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,
|
197
|
-
|
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[
|
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,
|
316
|
-
|
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.
|
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,
|
418
|
-
|
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,
|
433
|
-
|
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,
|
449
|
-
|
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,
|
465
|
-
|
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)
|
pertpy/tools/_coda/_tasccoda.py
CHANGED
@@ -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.
|
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.
|
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
|
-
|
157
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
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.
|
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.
|
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[
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
663
|
+
>>> adata = pt.dt.tasccoda_example()
|
656
664
|
>>> tasccoda = pt.tl.Tasccoda()
|
657
665
|
>>> mdata = tasccoda.load(
|
658
666
|
>>> adata, type="sample_level",
|