pertpy 0.9.5__py3-none-any.whl → 0.11.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.
- pertpy/__init__.py +5 -1
- pertpy/_doc.py +2 -5
- pertpy/_types.py +6 -0
- pertpy/data/_dataloader.py +68 -24
- pertpy/data/_datasets.py +9 -9
- pertpy/metadata/__init__.py +2 -1
- pertpy/metadata/_cell_line.py +136 -30
- pertpy/metadata/_look_up.py +13 -19
- pertpy/metadata/_moa.py +1 -1
- pertpy/preprocessing/_guide_rna.py +221 -39
- pertpy/preprocessing/_guide_rna_mixture.py +177 -0
- pertpy/tools/__init__.py +1 -1
- pertpy/tools/_augur.py +138 -142
- pertpy/tools/_cinemaot.py +75 -117
- pertpy/tools/_coda/_base_coda.py +150 -174
- pertpy/tools/_coda/_sccoda.py +66 -69
- pertpy/tools/_coda/_tasccoda.py +71 -79
- pertpy/tools/_dialogue.py +60 -56
- pertpy/tools/_differential_gene_expression/_base.py +25 -43
- pertpy/tools/_differential_gene_expression/_checks.py +4 -6
- pertpy/tools/_differential_gene_expression/_dge_comparison.py +5 -6
- pertpy/tools/_differential_gene_expression/_edger.py +6 -10
- pertpy/tools/_differential_gene_expression/_pydeseq2.py +1 -1
- pertpy/tools/_differential_gene_expression/_simple_tests.py +3 -3
- pertpy/tools/_differential_gene_expression/_statsmodels.py +8 -5
- pertpy/tools/_distances/_distance_tests.py +1 -2
- pertpy/tools/_distances/_distances.py +86 -92
- pertpy/tools/_enrichment.py +8 -25
- pertpy/tools/_milo.py +23 -27
- pertpy/tools/_mixscape.py +261 -175
- pertpy/tools/_perturbation_space/_clustering.py +4 -4
- pertpy/tools/_perturbation_space/_comparison.py +4 -4
- pertpy/tools/_perturbation_space/_discriminator_classifiers.py +83 -32
- pertpy/tools/_perturbation_space/_perturbation_space.py +10 -10
- pertpy/tools/_perturbation_space/_simple.py +13 -17
- pertpy/tools/_scgen/_scgen.py +17 -20
- pertpy/tools/_scgen/_scgenvae.py +2 -2
- pertpy/tools/_scgen/_utils.py +3 -1
- {pertpy-0.9.5.dist-info → pertpy-0.11.0.dist-info}/METADATA +37 -21
- pertpy-0.11.0.dist-info/RECORD +58 -0
- {pertpy-0.9.5.dist-info → pertpy-0.11.0.dist-info}/licenses/LICENSE +1 -0
- pertpy/tools/_kernel_pca.py +0 -50
- pertpy-0.9.5.dist-info/RECORD +0 -57
- {pertpy-0.9.5.dist-info → pertpy-0.11.0.dist-info}/WHEEL +0 -0
pertpy/tools/_milo.py
CHANGED
@@ -51,14 +51,16 @@ class Milo:
|
|
51
51
|
Args:
|
52
52
|
input: AnnData
|
53
53
|
feature_key: Key to store the cell-level AnnData object in the MuData object
|
54
|
+
|
54
55
|
Returns:
|
55
|
-
|
56
|
+
:class:`mudata.MuData` object with original AnnData.
|
56
57
|
|
57
58
|
Examples:
|
58
59
|
>>> import pertpy as pt
|
59
60
|
>>> adata = pt.dt.bhattacherjee()
|
60
61
|
>>> milo = pt.tl.Milo()
|
61
62
|
>>> mdata = milo.load(adata)
|
63
|
+
|
62
64
|
"""
|
63
65
|
mdata = MuData({feature_key: input, "milo": AnnData()})
|
64
66
|
|
@@ -113,6 +115,7 @@ class Milo:
|
|
113
115
|
>>> mdata = milo.load(adata)
|
114
116
|
>>> sc.pp.neighbors(mdata["rna"])
|
115
117
|
>>> milo.make_nhoods(mdata["rna"])
|
118
|
+
|
116
119
|
"""
|
117
120
|
if isinstance(data, MuData):
|
118
121
|
adata = data[feature_key]
|
@@ -177,10 +180,7 @@ class Milo:
|
|
177
180
|
adata.obs["nhood_ixs_random"] = adata.obs["nhood_ixs_random"].astype("int")
|
178
181
|
adata.uns["nhood_neighbors_key"] = neighbors_key
|
179
182
|
# Store distance to K-th nearest neighbor (used for spatial FDR correction)
|
180
|
-
if neighbors_key is None
|
181
|
-
knn_dists = adata.obsp["distances"]
|
182
|
-
else:
|
183
|
-
knn_dists = adata.obsp[neighbors_key + "_distances"]
|
183
|
+
knn_dists = adata.obsp["distances"] if neighbors_key is None else adata.obsp[neighbors_key + "_distances"]
|
184
184
|
|
185
185
|
nhood_ixs = adata.obs["nhood_ixs_refined"] == 1
|
186
186
|
dist_mat = knn_dists[np.asarray(nhood_ixs), :]
|
@@ -223,6 +223,7 @@ class Milo:
|
|
223
223
|
>>> sc.pp.neighbors(mdata["rna"])
|
224
224
|
>>> milo.make_nhoods(mdata["rna"])
|
225
225
|
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
226
|
+
|
226
227
|
"""
|
227
228
|
if isinstance(data, MuData):
|
228
229
|
adata = data[feature_key]
|
@@ -297,6 +298,7 @@ class Milo:
|
|
297
298
|
>>> milo.make_nhoods(mdata["rna"])
|
298
299
|
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
299
300
|
>>> milo.da_nhoods(mdata, design="~label")
|
301
|
+
|
300
302
|
"""
|
301
303
|
try:
|
302
304
|
sample_adata = mdata["milo"]
|
@@ -428,7 +430,7 @@ class Milo:
|
|
428
430
|
feature_key: If input data is MuData, specify key to cell-level AnnData object.
|
429
431
|
|
430
432
|
Returns:
|
431
|
-
|
433
|
+
Adds in place.
|
432
434
|
- `milo_mdata['milo'].var["nhood_annotation"]`: assigning a label to each nhood
|
433
435
|
- `milo_mdata['milo'].var["nhood_annotation_frac"]` stores the fraciton of cells in the neighbourhood with the assigned label
|
434
436
|
- `milo_mdata['milo'].varm['frac_annotation']`: stores the fraction of cells from each label in each nhood
|
@@ -444,6 +446,7 @@ class Milo:
|
|
444
446
|
>>> milo.make_nhoods(mdata["rna"])
|
445
447
|
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
446
448
|
>>> milo.annotate_nhoods(mdata, anno_col="cell_type")
|
449
|
+
|
447
450
|
"""
|
448
451
|
try:
|
449
452
|
sample_adata = mdata["milo"]
|
@@ -482,7 +485,7 @@ class Milo:
|
|
482
485
|
feature_key: If input data is MuData, specify key to cell-level AnnData object.
|
483
486
|
|
484
487
|
Returns:
|
485
|
-
|
488
|
+
Adds in place.
|
486
489
|
- `milo_mdata['milo'].var["nhood_{anno_col}"]`: assigning a continuous value to each nhood
|
487
490
|
|
488
491
|
Examples:
|
@@ -567,7 +570,7 @@ class Milo:
|
|
567
570
|
sample_adata.obs = sample_obs.loc[sample_adata.obs_names]
|
568
571
|
|
569
572
|
def build_nhood_graph(self, mdata: MuData, basis: str = "X_umap", feature_key: str | None = "rna"):
|
570
|
-
"""Build graph of neighbourhoods used for visualization of DA results
|
573
|
+
"""Build graph of neighbourhoods used for visualization of DA results.
|
571
574
|
|
572
575
|
Args:
|
573
576
|
mdata: MuData object
|
@@ -625,6 +628,7 @@ class Milo:
|
|
625
628
|
>>> milo.make_nhoods(mdata["rna"])
|
626
629
|
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
627
630
|
>>> milo.add_nhood_expression(mdata)
|
631
|
+
|
628
632
|
"""
|
629
633
|
try:
|
630
634
|
sample_adata = mdata["milo"]
|
@@ -652,7 +656,7 @@ class Milo:
|
|
652
656
|
def _setup_rpy2(
|
653
657
|
self,
|
654
658
|
):
|
655
|
-
"""Set up rpy2 to run edgeR"""
|
659
|
+
"""Set up rpy2 to run edgeR."""
|
656
660
|
from rpy2.robjects import numpy2ri, pandas2ri
|
657
661
|
from rpy2.robjects.packages import importr
|
658
662
|
|
@@ -715,7 +719,7 @@ class Milo:
|
|
715
719
|
sample_adata.var.loc[keep_nhoods, "SpatialFDR"] = adjp
|
716
720
|
|
717
721
|
@_doc_params(common_plot_args=doc_common_plot_args)
|
718
|
-
def plot_nhood_graph(
|
722
|
+
def plot_nhood_graph( # pragma: no cover # noqa: D417
|
719
723
|
self,
|
720
724
|
mdata: MuData,
|
721
725
|
*,
|
@@ -727,11 +731,10 @@ class Milo:
|
|
727
731
|
color_map: Colormap | str | None = None,
|
728
732
|
palette: str | Sequence[str] | None = None,
|
729
733
|
ax: Axes | None = None,
|
730
|
-
show: bool = True,
|
731
734
|
return_fig: bool = False,
|
732
735
|
**kwargs,
|
733
736
|
) -> Figure | None:
|
734
|
-
"""Visualize DA results on abstracted graph (wrapper around sc.pl.embedding)
|
737
|
+
"""Visualize DA results on abstracted graph (wrapper around sc.pl.embedding).
|
735
738
|
|
736
739
|
Args:
|
737
740
|
mdata: MuData object
|
@@ -803,14 +806,13 @@ class Milo:
|
|
803
806
|
**kwargs,
|
804
807
|
)
|
805
808
|
|
806
|
-
if show:
|
807
|
-
plt.show()
|
808
809
|
if return_fig:
|
809
810
|
return fig
|
811
|
+
plt.show()
|
810
812
|
return None
|
811
813
|
|
812
814
|
@_doc_params(common_plot_args=doc_common_plot_args)
|
813
|
-
def plot_nhood(
|
815
|
+
def plot_nhood( # pragma: no cover # noqa: D417
|
814
816
|
self,
|
815
817
|
mdata: MuData,
|
816
818
|
ix: int,
|
@@ -820,7 +822,6 @@ class Milo:
|
|
820
822
|
color_map: Colormap | str | None = None,
|
821
823
|
palette: str | Sequence[str] | None = None,
|
822
824
|
ax: Axes | None = None,
|
823
|
-
show: bool = True,
|
824
825
|
return_fig: bool = False,
|
825
826
|
**kwargs,
|
826
827
|
) -> Figure | None:
|
@@ -866,14 +867,13 @@ class Milo:
|
|
866
867
|
**kwargs,
|
867
868
|
)
|
868
869
|
|
869
|
-
if show:
|
870
|
-
plt.show()
|
871
870
|
if return_fig:
|
872
871
|
return fig
|
872
|
+
plt.show()
|
873
873
|
return None
|
874
874
|
|
875
875
|
@_doc_params(common_plot_args=doc_common_plot_args)
|
876
|
-
def plot_da_beeswarm(
|
876
|
+
def plot_da_beeswarm( # pragma: no cover # noqa: D417
|
877
877
|
self,
|
878
878
|
mdata: MuData,
|
879
879
|
*,
|
@@ -882,10 +882,9 @@ class Milo:
|
|
882
882
|
alpha: float = 0.1,
|
883
883
|
subset_nhoods: list[str] = None,
|
884
884
|
palette: str | Sequence[str] | dict[str, str] | None = None,
|
885
|
-
show: bool = True,
|
886
885
|
return_fig: bool = False,
|
887
886
|
) -> Figure | None:
|
888
|
-
"""Plot beeswarm plot of logFC against nhood labels
|
887
|
+
"""Plot beeswarm plot of logFC against nhood labels.
|
889
888
|
|
890
889
|
Args:
|
891
890
|
mdata: MuData object
|
@@ -994,21 +993,19 @@ class Milo:
|
|
994
993
|
plt.legend(loc="upper left", title=f"< {int(alpha * 100)}% SpatialFDR", bbox_to_anchor=(1, 1), frameon=False)
|
995
994
|
plt.axvline(x=0, ymin=0, ymax=1, color="black", linestyle="--")
|
996
995
|
|
997
|
-
if show:
|
998
|
-
plt.show()
|
999
996
|
if return_fig:
|
1000
997
|
return plt.gcf()
|
998
|
+
plt.show()
|
1001
999
|
return None
|
1002
1000
|
|
1003
1001
|
@_doc_params(common_plot_args=doc_common_plot_args)
|
1004
|
-
def plot_nhood_counts_by_cond(
|
1002
|
+
def plot_nhood_counts_by_cond( # pragma: no cover # noqa: D417
|
1005
1003
|
self,
|
1006
1004
|
mdata: MuData,
|
1007
1005
|
test_var: str,
|
1008
1006
|
*,
|
1009
1007
|
subset_nhoods: list[str] = None,
|
1010
1008
|
log_counts: bool = False,
|
1011
|
-
show: bool = True,
|
1012
1009
|
return_fig: bool = False,
|
1013
1010
|
) -> Figure | None:
|
1014
1011
|
"""Plot boxplot of cell numbers vs condition of interest.
|
@@ -1050,8 +1047,7 @@ class Milo:
|
|
1050
1047
|
plt.xticks(rotation=90)
|
1051
1048
|
plt.xlabel(test_var)
|
1052
1049
|
|
1053
|
-
if show:
|
1054
|
-
plt.show()
|
1055
1050
|
if return_fig:
|
1056
1051
|
return plt.gcf()
|
1052
|
+
plt.show()
|
1057
1053
|
return None
|