pertpy 0.7.0__py3-none-any.whl → 0.9.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pertpy/__init__.py +2 -1
- pertpy/data/__init__.py +61 -0
- pertpy/data/_dataloader.py +27 -23
- pertpy/data/_datasets.py +58 -0
- pertpy/metadata/__init__.py +2 -0
- pertpy/metadata/_cell_line.py +39 -70
- pertpy/metadata/_compound.py +3 -4
- pertpy/metadata/_drug.py +2 -6
- pertpy/metadata/_look_up.py +38 -51
- pertpy/metadata/_metadata.py +7 -10
- pertpy/metadata/_moa.py +2 -6
- pertpy/plot/__init__.py +0 -5
- pertpy/preprocessing/__init__.py +2 -0
- pertpy/preprocessing/_guide_rna.py +6 -7
- pertpy/tools/__init__.py +67 -6
- pertpy/tools/_augur.py +14 -15
- pertpy/tools/_cinemaot.py +2 -2
- pertpy/tools/_coda/_base_coda.py +118 -142
- pertpy/tools/_coda/_sccoda.py +16 -15
- pertpy/tools/_coda/_tasccoda.py +21 -22
- pertpy/tools/_dialogue.py +18 -23
- pertpy/tools/_differential_gene_expression/__init__.py +20 -0
- pertpy/tools/_differential_gene_expression/_base.py +657 -0
- pertpy/tools/_differential_gene_expression/_checks.py +41 -0
- pertpy/tools/_differential_gene_expression/_dge_comparison.py +86 -0
- pertpy/tools/_differential_gene_expression/_edger.py +125 -0
- pertpy/tools/_differential_gene_expression/_formulaic.py +189 -0
- pertpy/tools/_differential_gene_expression/_pydeseq2.py +95 -0
- pertpy/tools/_differential_gene_expression/_simple_tests.py +162 -0
- pertpy/tools/_differential_gene_expression/_statsmodels.py +72 -0
- pertpy/tools/_distances/_distance_tests.py +21 -16
- pertpy/tools/_distances/_distances.py +406 -70
- pertpy/tools/_enrichment.py +10 -15
- pertpy/tools/_kernel_pca.py +1 -1
- pertpy/tools/_milo.py +77 -54
- pertpy/tools/_mixscape.py +15 -11
- pertpy/tools/_perturbation_space/_clustering.py +5 -2
- pertpy/tools/_perturbation_space/_comparison.py +112 -0
- pertpy/tools/_perturbation_space/_discriminator_classifiers.py +21 -23
- pertpy/tools/_perturbation_space/_perturbation_space.py +23 -21
- pertpy/tools/_perturbation_space/_simple.py +3 -3
- pertpy/tools/_scgen/__init__.py +1 -1
- pertpy/tools/_scgen/_base_components.py +2 -3
- pertpy/tools/_scgen/_scgen.py +33 -28
- pertpy/tools/_scgen/_utils.py +2 -2
- {pertpy-0.7.0.dist-info → pertpy-0.9.1.dist-info}/METADATA +32 -14
- pertpy-0.9.1.dist-info/RECORD +57 -0
- {pertpy-0.7.0.dist-info → pertpy-0.9.1.dist-info}/WHEEL +1 -1
- pertpy/plot/_augur.py +0 -171
- pertpy/plot/_coda.py +0 -601
- pertpy/plot/_guide_rna.py +0 -64
- pertpy/plot/_milopy.py +0 -209
- pertpy/plot/_mixscape.py +0 -355
- pertpy/tools/_differential_gene_expression.py +0 -325
- pertpy-0.7.0.dist-info/RECORD +0 -53
- {pertpy-0.7.0.dist-info → pertpy-0.9.1.dist-info}/licenses/LICENSE +0 -0
pertpy/plot/_milopy.py
DELETED
@@ -1,209 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import warnings
|
4
|
-
from typing import TYPE_CHECKING
|
5
|
-
|
6
|
-
import matplotlib.pyplot as plt
|
7
|
-
import numpy as np
|
8
|
-
import pandas as pd
|
9
|
-
import scanpy as sc
|
10
|
-
import seaborn as sns
|
11
|
-
|
12
|
-
if TYPE_CHECKING:
|
13
|
-
from collections.abc import Sequence
|
14
|
-
|
15
|
-
from mudata import MuData
|
16
|
-
|
17
|
-
|
18
|
-
class MilopyPlot:
|
19
|
-
"""Plotting functions for Milopy."""
|
20
|
-
|
21
|
-
@staticmethod
|
22
|
-
def nhood_graph(
|
23
|
-
mdata: MuData,
|
24
|
-
alpha: float = 0.1,
|
25
|
-
min_logFC: float = 0,
|
26
|
-
min_size: int = 10,
|
27
|
-
plot_edges: bool = False,
|
28
|
-
title: str = "DA log-Fold Change",
|
29
|
-
show: bool | None = None,
|
30
|
-
save: bool | str | None = None,
|
31
|
-
**kwargs,
|
32
|
-
) -> None:
|
33
|
-
"""Visualize DA results on abstracted graph (wrapper around sc.pl.embedding)
|
34
|
-
|
35
|
-
Args:
|
36
|
-
mdata: MuData object
|
37
|
-
alpha: Significance threshold. (default: 0.1)
|
38
|
-
min_logFC: Minimum absolute log-Fold Change to show results. If is 0, show all significant neighbourhoods. (default: 0)
|
39
|
-
min_size: Minimum size of nodes in visualization. (default: 10)
|
40
|
-
plot_edges: If edges for neighbourhood overlaps whould be plotted. Defaults to False.
|
41
|
-
title: Plot title. Defaults to "DA log-Fold Change".
|
42
|
-
show: Show the plot, do not return axis.
|
43
|
-
save: If `True` or a `str`, save the figure. A string is appended to the default filename.
|
44
|
-
Infer the filetype if ending on {`'.pdf'`, `'.png'`, `'.svg'`}.
|
45
|
-
**kwargs: Additional arguments to `scanpy.pl.embedding`.
|
46
|
-
|
47
|
-
Examples:
|
48
|
-
>>> import pertpy as pt
|
49
|
-
>>> adata = pt.dt.bhattacherjee()
|
50
|
-
>>> milo = pt.tl.Milo()
|
51
|
-
>>> mdata = milo.load(adata)
|
52
|
-
>>> sc.pp.neighbors(mdata["rna"])
|
53
|
-
>>> sc.tl.umap(mdata["rna"])
|
54
|
-
>>> milo.make_nhoods(mdata["rna"])
|
55
|
-
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
56
|
-
>>> milo.da_nhoods(mdata,
|
57
|
-
>>> design='~label',
|
58
|
-
>>> model_contrasts='labelwithdraw_15d_Cocaine-labelwithdraw_48h_Cocaine')
|
59
|
-
>>> milo.build_nhood_graph(mdata)
|
60
|
-
>>> milo.plot_nhood_graph(mdata)
|
61
|
-
"""
|
62
|
-
warnings.warn(
|
63
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
64
|
-
" Please use the corresponding 'pt.tl' object",
|
65
|
-
FutureWarning,
|
66
|
-
stacklevel=2,
|
67
|
-
)
|
68
|
-
|
69
|
-
from pertpy.tools import Milo
|
70
|
-
|
71
|
-
milo = Milo()
|
72
|
-
|
73
|
-
return milo.plot_nhood_graph(
|
74
|
-
madata=mdata,
|
75
|
-
alpha=alpha,
|
76
|
-
min_logFC=min_logFC,
|
77
|
-
min_size=min_size,
|
78
|
-
plot_edges=plot_edges,
|
79
|
-
title=title,
|
80
|
-
show=show,
|
81
|
-
save=save,
|
82
|
-
**kwargs,
|
83
|
-
)
|
84
|
-
|
85
|
-
@staticmethod
|
86
|
-
def nhood(
|
87
|
-
mdata: MuData,
|
88
|
-
ix: int,
|
89
|
-
feature_key: str | None = "rna",
|
90
|
-
basis="X_umap",
|
91
|
-
show: bool | None = None,
|
92
|
-
save: bool | str | None = None,
|
93
|
-
**kwargs,
|
94
|
-
) -> None:
|
95
|
-
"""Visualize cells in a neighbourhood.
|
96
|
-
|
97
|
-
Args:
|
98
|
-
mdata: MuData object with feature_key slot, storing neighbourhood assignments in `mdata[feature_key].obsm['nhoods']`
|
99
|
-
ix: index of neighbourhood to visualize
|
100
|
-
basis: Embedding to use for visualization. Defaults to "X_umap".
|
101
|
-
show: Show the plot, do not return axis.
|
102
|
-
save: If True or a str, save the figure. A string is appended to the default filename. Infer the filetype if ending on {'.pdf', '.png', '.svg'}.
|
103
|
-
**kwargs: Additional arguments to `scanpy.pl.embedding`.
|
104
|
-
|
105
|
-
Examples:
|
106
|
-
>>> import pertpy as pt
|
107
|
-
>>> import scanpy as sc
|
108
|
-
>>> adata = pt.dt.bhattacherjee()
|
109
|
-
>>> milo = pt.tl.Milo()
|
110
|
-
>>> mdata = milo.load(adata)
|
111
|
-
>>> sc.pp.neighbors(mdata["rna"])
|
112
|
-
>>> sc.tl.umap(mdata["rna"])
|
113
|
-
>>> milo.make_nhoods(mdata["rna"])
|
114
|
-
>>> pt.pl.milo.nhood(mdata, ix=0)
|
115
|
-
"""
|
116
|
-
warnings.warn(
|
117
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
118
|
-
" Please use the corresponding 'pt.tl' object",
|
119
|
-
FutureWarning,
|
120
|
-
stacklevel=2,
|
121
|
-
)
|
122
|
-
|
123
|
-
from pertpy.tools import Milo
|
124
|
-
|
125
|
-
milo = Milo()
|
126
|
-
|
127
|
-
milo.plot_nhood(mdata=mdata, ix=ix, feature_key=feature_key, basis=basis, show=show, save=save, **kwargs)
|
128
|
-
|
129
|
-
@staticmethod
|
130
|
-
def da_beeswarm(
|
131
|
-
mdata: MuData,
|
132
|
-
feature_key: str | None = "rna",
|
133
|
-
anno_col: str = "nhood_annotation",
|
134
|
-
alpha: float = 0.1,
|
135
|
-
subset_nhoods: list[str] = None,
|
136
|
-
palette: str | Sequence[str] | dict[str, str] | None = None,
|
137
|
-
):
|
138
|
-
"""Plot beeswarm plot of logFC against nhood labels
|
139
|
-
|
140
|
-
Args:
|
141
|
-
mdata: MuData object
|
142
|
-
anno_col: Column in mdata['milo'].var to use as annotation. (default: 'nhood_annotation'.)
|
143
|
-
alpha: Significance threshold. (default: 0.1)
|
144
|
-
subset_nhoods: List of nhoods to plot. If None, plot all nhoods. (default: None)
|
145
|
-
palette: Name of Seaborn color palette for violinplots.
|
146
|
-
Defaults to pre-defined category colors for violinplots.
|
147
|
-
|
148
|
-
Examples:
|
149
|
-
>>> import pertpy as pt
|
150
|
-
>>> import scanpy as sc
|
151
|
-
>>> adata = pt.dt.bhattacherjee()
|
152
|
-
>>> milo = pt.tl.Milo()
|
153
|
-
>>> mdata = milo.load(adata)
|
154
|
-
>>> sc.pp.neighbors(mdata["rna"])
|
155
|
-
>>> milo.make_nhoods(mdata["rna"])
|
156
|
-
>>> mdata = milo.count_nhoods(mdata, sample_col="orig.ident")
|
157
|
-
>>> milo.da_nhoods(mdata, design="~label")
|
158
|
-
>>> milo.annotate_nhoods(mdata, anno_col="cell_type")
|
159
|
-
>>> milo.plot_da_beeswarm(mdata)
|
160
|
-
"""
|
161
|
-
warnings.warn(
|
162
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
163
|
-
" Please use the corresponding 'pt.tl' object",
|
164
|
-
FutureWarning,
|
165
|
-
stacklevel=2,
|
166
|
-
)
|
167
|
-
|
168
|
-
from pertpy.tools import Milo
|
169
|
-
|
170
|
-
milo = Milo()
|
171
|
-
|
172
|
-
milo.plot_da_beeswarm(
|
173
|
-
mdata=mdata,
|
174
|
-
feature_key=feature_key,
|
175
|
-
anno_col=anno_col,
|
176
|
-
alpha=alpha,
|
177
|
-
subset_nhoods=subset_nhoods,
|
178
|
-
palette=palette,
|
179
|
-
)
|
180
|
-
|
181
|
-
@staticmethod
|
182
|
-
def nhood_counts_by_cond(
|
183
|
-
mdata: MuData,
|
184
|
-
test_var: str,
|
185
|
-
subset_nhoods: list = None,
|
186
|
-
log_counts: bool = False,
|
187
|
-
):
|
188
|
-
"""Plot boxplot of cell numbers vs condition of interest
|
189
|
-
|
190
|
-
Args:
|
191
|
-
mdata: MuData object storing cell level and nhood level information
|
192
|
-
test_var: Name of column in adata.obs storing condition of interest (y-axis for boxplot)
|
193
|
-
subset_nhoods: List of obs_names for neighbourhoods to include in plot. If None, plot all nhoods. (default: None)
|
194
|
-
log_counts: Whether to plot log1p of cell counts. (default: False)
|
195
|
-
"""
|
196
|
-
warnings.warn(
|
197
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
198
|
-
" Please use the corresponding 'pt.tl' object",
|
199
|
-
FutureWarning,
|
200
|
-
stacklevel=2,
|
201
|
-
)
|
202
|
-
|
203
|
-
from pertpy.tools import Milo
|
204
|
-
|
205
|
-
milo = Milo()
|
206
|
-
|
207
|
-
milo.plot_nhood_counts_by_cond(
|
208
|
-
mdata=mdata, test_var=test_var, subset_nhoods=subset_nhoods, log_counts=log_counts
|
209
|
-
)
|
pertpy/plot/_mixscape.py
DELETED
@@ -1,355 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import warnings
|
4
|
-
from typing import TYPE_CHECKING, Literal
|
5
|
-
|
6
|
-
if TYPE_CHECKING:
|
7
|
-
from collections.abc import Sequence
|
8
|
-
|
9
|
-
from anndata import AnnData
|
10
|
-
from matplotlib.axes import Axes
|
11
|
-
|
12
|
-
|
13
|
-
class MixscapePlot:
|
14
|
-
"""Plotting functions for Mixscape."""
|
15
|
-
|
16
|
-
@staticmethod
|
17
|
-
def barplot( # pragma: no cover
|
18
|
-
adata: AnnData,
|
19
|
-
guide_rna_column: str,
|
20
|
-
mixscape_class_global="mixscape_class_global",
|
21
|
-
axis_text_x_size: int = 8,
|
22
|
-
axis_text_y_size: int = 6,
|
23
|
-
axis_title_size: int = 8,
|
24
|
-
strip_text_size: int = 6,
|
25
|
-
panel_spacing_x: float = 0.3,
|
26
|
-
panel_spacing_y: float = 0.3,
|
27
|
-
legend_title_size: int = 18,
|
28
|
-
legend_text_size: int = 18,
|
29
|
-
show: bool | None = None,
|
30
|
-
save: bool | str | None = None,
|
31
|
-
):
|
32
|
-
"""Barplot to visualize perturbation scores calculated from RunMixscape function.
|
33
|
-
|
34
|
-
Args:
|
35
|
-
adata: The annotated data object.
|
36
|
-
guide_rna_column: The column of `.obs` with guide RNA labels. The target gene labels.
|
37
|
-
The format must be <gene_target>g<#>. For example, 'STAT2g1' and 'ATF2g1'.
|
38
|
-
mixscape_class_global: The column of `.obs` with mixscape global classification result (perturbed, NP or NT).
|
39
|
-
show: Show the plot, do not return axis.
|
40
|
-
save: If True or a str, save the figure. A string is appended to the default filename.
|
41
|
-
Infer the filetype if ending on {'.pdf', '.png', '.svg'}.
|
42
|
-
|
43
|
-
Returns:
|
44
|
-
If show is False, return ggplot object used to draw the plot.
|
45
|
-
|
46
|
-
Examples:
|
47
|
-
>>> import pertpy as pt
|
48
|
-
>>> mdata = pt.dt.papalexi_2021()
|
49
|
-
>>> ms = pt.tl.Mixscape()
|
50
|
-
>>> ms.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate")
|
51
|
-
>>> ms.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
52
|
-
>>> ms.plot_barplot(mdata["rna"], guide_rna_column="NT")
|
53
|
-
"""
|
54
|
-
warnings.warn(
|
55
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
56
|
-
" Please use the corresponding 'pt.tl' object",
|
57
|
-
FutureWarning,
|
58
|
-
stacklevel=2,
|
59
|
-
)
|
60
|
-
|
61
|
-
from pertpy.tools import Mixscape
|
62
|
-
|
63
|
-
ms = Mixscape()
|
64
|
-
return ms.plot_barplot(
|
65
|
-
adata=adata,
|
66
|
-
guide_rna_column=guide_rna_column,
|
67
|
-
mixscape_class_global=mixscape_class_global,
|
68
|
-
axis_text_x_size=axis_text_x_size,
|
69
|
-
axis_text_y_size=axis_text_y_size,
|
70
|
-
axis_title_size=axis_title_size,
|
71
|
-
legend_title_size=legend_title_size,
|
72
|
-
legend_text_size=legend_text_size,
|
73
|
-
show=show,
|
74
|
-
save=save,
|
75
|
-
)
|
76
|
-
|
77
|
-
@staticmethod
|
78
|
-
def heatmap( # pragma: no cover
|
79
|
-
adata: AnnData,
|
80
|
-
labels: str,
|
81
|
-
target_gene: str,
|
82
|
-
control: str,
|
83
|
-
layer: str | None = None,
|
84
|
-
method: str | None = "wilcoxon",
|
85
|
-
subsample_number: int | None = 900,
|
86
|
-
vmin: float | None = -2,
|
87
|
-
vmax: float | None = 2,
|
88
|
-
show: bool | None = None,
|
89
|
-
save: bool | str | None = None,
|
90
|
-
**kwargs,
|
91
|
-
):
|
92
|
-
"""Heatmap plot using mixscape results. Requires `pt.tl.mixscape()` to be run first.
|
93
|
-
|
94
|
-
Args:
|
95
|
-
adata: The annotated data object.
|
96
|
-
labels: The column of `.obs` with target gene labels.
|
97
|
-
target_gene: Target gene name to visualize heatmap for.
|
98
|
-
control: Control category from the `pert_key` column.
|
99
|
-
layer: Key from `adata.layers` whose value will be used to perform tests on.
|
100
|
-
method: The default method is 'wilcoxon', see `method` parameter in `scanpy.tl.rank_genes_groups` for more options.
|
101
|
-
subsample_number: Subsample to this number of observations.
|
102
|
-
vmin: The value representing the lower limit of the color scale. Values smaller than vmin are plotted with the same color as vmin.
|
103
|
-
vmax: The value representing the upper limit of the color scale. Values larger than vmax are plotted with the same color as vmax.
|
104
|
-
show: Show the plot, do not return axis.
|
105
|
-
save: If `True` or a `str`, save the figure. A string is appended to the default filename. Infer the filetype if ending on {`'.pdf'`, `'.png'`, `'.svg'`}.
|
106
|
-
**kwds: Additional arguments to `scanpy.pl.rank_genes_groups_heatmap`.
|
107
|
-
|
108
|
-
Examples:
|
109
|
-
>>> import pertpy as pt
|
110
|
-
>>> mdata = pt.dt.papalexi_2021()
|
111
|
-
>>> ms = pt.tl.Mixscape()
|
112
|
-
>>> ms.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate")
|
113
|
-
>>> ms.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
114
|
-
>>> ms.plot_heatmap(
|
115
|
-
... adata=mdata["rna"], labels="gene_target", target_gene="IFNGR2", layer="X_pert", control="NT"
|
116
|
-
... )
|
117
|
-
"""
|
118
|
-
warnings.warn(
|
119
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
120
|
-
" Please use the corresponding 'pt.tl' object",
|
121
|
-
FutureWarning,
|
122
|
-
stacklevel=2,
|
123
|
-
)
|
124
|
-
|
125
|
-
from pertpy.tools import Mixscape
|
126
|
-
|
127
|
-
ms = Mixscape()
|
128
|
-
return ms.plot_heatmap(
|
129
|
-
adata=adata,
|
130
|
-
labels=labels,
|
131
|
-
target_gene=target_gene,
|
132
|
-
control=control,
|
133
|
-
layer=layer,
|
134
|
-
method=method,
|
135
|
-
subsample_number=subsample_number,
|
136
|
-
vmin=vmin,
|
137
|
-
vmax=vmax,
|
138
|
-
show=show,
|
139
|
-
save=save,
|
140
|
-
**kwargs,
|
141
|
-
)
|
142
|
-
|
143
|
-
@staticmethod
|
144
|
-
def perturbscore( # pragma: no cover
|
145
|
-
adata: AnnData,
|
146
|
-
labels: str,
|
147
|
-
target_gene: str,
|
148
|
-
mixscape_class="mixscape_class",
|
149
|
-
color="orange",
|
150
|
-
split_by: str = None,
|
151
|
-
before_mixscape=False,
|
152
|
-
perturbation_type: str = "KO",
|
153
|
-
):
|
154
|
-
"""Density plots to visualize perturbation scores calculated by the `pt.tl.mixscape` function. Requires `pt.tl.mixscape` to be run first.
|
155
|
-
|
156
|
-
https://satijalab.org/seurat/reference/plotperturbscore
|
157
|
-
|
158
|
-
Args:
|
159
|
-
adata: The annotated data object.
|
160
|
-
labels: The column of `.obs` with target gene labels.
|
161
|
-
target_gene: Target gene name to visualize perturbation scores for.
|
162
|
-
mixscape_class: The column of `.obs` with mixscape classifications.
|
163
|
-
color: Specify color of target gene class or knockout cell class. For control non-targeting and non-perturbed cells, colors are set to different shades of grey.
|
164
|
-
split_by: Provide the column `.obs` if multiple biological replicates exist to calculate
|
165
|
-
the perturbation signature for every replicate separately.
|
166
|
-
before_mixscape: Option to split densities based on mixscape classification (default) or original target gene classification. Default is set to NULL and plots cells by original class ID.
|
167
|
-
perturbation_type: specify type of CRISPR perturbation expected for labeling mixscape classifications. Default is KO.
|
168
|
-
|
169
|
-
Returns:
|
170
|
-
The ggplot object used for drawn.
|
171
|
-
|
172
|
-
Examples:
|
173
|
-
Visualizing the perturbation scores for the cells in a dataset:
|
174
|
-
|
175
|
-
>>> import pertpy as pt
|
176
|
-
>>> mdata = pt.dt.papalexi_2021()
|
177
|
-
>>> mixscape_identifier = pt.tl.Mixscape()
|
178
|
-
>>> mixscape_identifier.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate")
|
179
|
-
>>> mixscape_identifier.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
180
|
-
>>> mixscape_identifier.perturbscore(
|
181
|
-
... adata=mdata["rna"], labels="gene_target", target_gene="IFNGR2", color="orange"
|
182
|
-
... )
|
183
|
-
"""
|
184
|
-
warnings.warn(
|
185
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
186
|
-
" Please use the corresponding 'pt.tl' object",
|
187
|
-
FutureWarning,
|
188
|
-
stacklevel=2,
|
189
|
-
)
|
190
|
-
|
191
|
-
from pertpy.tools import Mixscape
|
192
|
-
|
193
|
-
ms = Mixscape()
|
194
|
-
return ms.plot_perturbscore(
|
195
|
-
adata=adata,
|
196
|
-
labels=labels,
|
197
|
-
target_gene=target_gene,
|
198
|
-
mixscape_class=mixscape_class,
|
199
|
-
color=color,
|
200
|
-
split_by=split_by,
|
201
|
-
before_mixscape=before_mixscape,
|
202
|
-
perturbation_type=perturbation_type,
|
203
|
-
)
|
204
|
-
|
205
|
-
@staticmethod
|
206
|
-
def violin( # pragma: no cover
|
207
|
-
adata: AnnData,
|
208
|
-
target_gene_idents: str | list[str],
|
209
|
-
keys: str | Sequence[str] = "mixscape_class_p_ko",
|
210
|
-
groupby: str | None = "mixscape_class",
|
211
|
-
log: bool = False,
|
212
|
-
use_raw: bool | None = None,
|
213
|
-
stripplot: bool = True,
|
214
|
-
hue: str | None = None,
|
215
|
-
jitter: float | bool = True,
|
216
|
-
size: int = 1,
|
217
|
-
layer: str | None = None,
|
218
|
-
scale: Literal["area", "count", "width"] = "width",
|
219
|
-
order: Sequence[str] | None = None,
|
220
|
-
multi_panel: bool | None = None,
|
221
|
-
xlabel: str = "",
|
222
|
-
ylabel: str | Sequence[str] | None = None,
|
223
|
-
rotation: float | None = None,
|
224
|
-
show: bool | None = None,
|
225
|
-
save: bool | str | None = None,
|
226
|
-
ax: Axes | None = None,
|
227
|
-
**kwargs,
|
228
|
-
):
|
229
|
-
"""Violin plot using mixscape results. Requires `pt.tl.mixscape` to be run first.
|
230
|
-
|
231
|
-
Args:
|
232
|
-
adata: The annotated data object.
|
233
|
-
target_gene: Target gene name to plot.
|
234
|
-
keys: Keys for accessing variables of `.var_names` or fields of `.obs`. Default is 'mixscape_class_p_ko'.
|
235
|
-
groupby: The key of the observation grouping to consider. Default is 'mixscape_class'.
|
236
|
-
log: Plot on logarithmic axis.
|
237
|
-
use_raw: Whether to use `raw` attribute of `adata`. Defaults to `True` if `.raw` is present.
|
238
|
-
stripplot: Add a stripplot on top of the violin plot.
|
239
|
-
order: Order in which to show the categories.
|
240
|
-
xlabel: Label of the x axis. Defaults to `groupby` if `rotation` is `None`, otherwise, no label is shown.
|
241
|
-
ylabel: Label of the y axis. If `None` and `groupby` is `None`, defaults to `'value'`. If `None` and `groubpy` is not `None`, defaults to `keys`.
|
242
|
-
show: Show the plot, do not return axis.
|
243
|
-
save: If `True` or a `str`, save the figure. A string is appended to the default filename. Infer the filetype if ending on {`'.pdf'`, `'.png'`, `'.svg'`}.
|
244
|
-
ax: A matplotlib axes object. Only works if plotting a single component.
|
245
|
-
**kwargs: Additional arguments to `seaborn.violinplot`.
|
246
|
-
|
247
|
-
Returns:
|
248
|
-
A :class:`~matplotlib.axes.Axes` object if `ax` is `None` else `None`.
|
249
|
-
|
250
|
-
Examples:
|
251
|
-
>>> import pertpy as pt
|
252
|
-
>>> mdata = pt.dt.papalexi_2021()
|
253
|
-
>>> ms = pt.tl.Mixscape()
|
254
|
-
>>> ms.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate")
|
255
|
-
>>> ms.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
256
|
-
>>> ms.plot_violin(
|
257
|
-
... adata=mdata["rna"], target_gene_idents=["NT", "IFNGR2 NP", "IFNGR2 KO"], groupby="mixscape_class"
|
258
|
-
... )
|
259
|
-
"""
|
260
|
-
warnings.warn(
|
261
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
262
|
-
" Please use the corresponding 'pt.tl' object",
|
263
|
-
FutureWarning,
|
264
|
-
stacklevel=2,
|
265
|
-
)
|
266
|
-
|
267
|
-
from pertpy.tools import Mixscape
|
268
|
-
|
269
|
-
ms = Mixscape()
|
270
|
-
return ms.plot_violin(
|
271
|
-
adata=adata,
|
272
|
-
target_gene_idents=target_gene_idents,
|
273
|
-
keys=keys,
|
274
|
-
groupby=groupby,
|
275
|
-
log=log,
|
276
|
-
use_raw=use_raw,
|
277
|
-
stripplot=stripplot,
|
278
|
-
hue=hue,
|
279
|
-
jitter=jitter,
|
280
|
-
size=size,
|
281
|
-
layer=layer,
|
282
|
-
scale=scale,
|
283
|
-
order=order,
|
284
|
-
multi_panel=multi_panel,
|
285
|
-
xlabel=xlabel,
|
286
|
-
ylabel=ylabel,
|
287
|
-
rotation=rotation,
|
288
|
-
show=show,
|
289
|
-
save=save,
|
290
|
-
ax=ax,
|
291
|
-
**kwargs,
|
292
|
-
)
|
293
|
-
|
294
|
-
@staticmethod
|
295
|
-
def lda( # pragma: no cover
|
296
|
-
adata: AnnData,
|
297
|
-
control: str,
|
298
|
-
mixscape_class="mixscape_class",
|
299
|
-
mixscape_class_global="mixscape_class_global",
|
300
|
-
perturbation_type: str | None = "KO",
|
301
|
-
lda_key: str | None = "mixscape_lda",
|
302
|
-
n_components: int | None = None,
|
303
|
-
show: bool | None = None,
|
304
|
-
save: bool | str | None = None,
|
305
|
-
**kwargs,
|
306
|
-
):
|
307
|
-
"""Visualizing perturbation responses with Linear Discriminant Analysis. Requires `pt.tl.mixscape()` to be run first.
|
308
|
-
|
309
|
-
Args:
|
310
|
-
adata: The annotated data object.
|
311
|
-
control: Control category from the `pert_key` column.
|
312
|
-
labels: The column of `.obs` with target gene labels.
|
313
|
-
mixscape_class: The column of `.obs` with the mixscape classification result.
|
314
|
-
mixscape_class_global: The column of `.obs` with mixscape global classification result (perturbed, NP or NT).
|
315
|
-
perturbation_type: Specify type of CRISPR perturbation expected for labeling mixscape classifications.
|
316
|
-
Defaults to 'KO'.
|
317
|
-
lda_key: If not speficied, lda looks .uns["mixscape_lda"] for the LDA results.
|
318
|
-
n_components: The number of dimensions of the embedding.
|
319
|
-
show: Show the plot, do not return axis.
|
320
|
-
save: If `True` or a `str`, save the figure. A string is appended to the default filename.
|
321
|
-
Infer the filetype if ending on {`'.pdf'`, `'.png'`, `'.svg'`}.
|
322
|
-
**kwargs: Additional arguments to `scanpy.pl.umap`.
|
323
|
-
|
324
|
-
Examples:
|
325
|
-
>>> import pertpy as pt
|
326
|
-
>>> mdata = pt.dt.papalexi_2021()
|
327
|
-
>>> ms = pt.tl.Mixscape()
|
328
|
-
>>> ms.perturbation_signature(mdata["rna"], "perturbation", "NT", "replicate")
|
329
|
-
>>> ms.mixscape(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
330
|
-
>>> ms.lda(adata=mdata["rna"], control="NT", labels="gene_target", layer="X_pert")
|
331
|
-
>>> ms.plot_lda(adata=mdata["rna"], control="NT")
|
332
|
-
"""
|
333
|
-
warnings.warn(
|
334
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
335
|
-
" Please use the corresponding 'pt.tl' object",
|
336
|
-
FutureWarning,
|
337
|
-
stacklevel=2,
|
338
|
-
)
|
339
|
-
|
340
|
-
from pertpy.tools import Mixscape
|
341
|
-
|
342
|
-
ms = Mixscape()
|
343
|
-
|
344
|
-
return ms.plot_lda(
|
345
|
-
adata=adata,
|
346
|
-
control=control,
|
347
|
-
mixscape_class=mixscape_class,
|
348
|
-
mixscape_class_global=mixscape_class_global,
|
349
|
-
perturbation_type=perturbation_type,
|
350
|
-
lda_key=lda_key,
|
351
|
-
n_components=n_components,
|
352
|
-
show=show,
|
353
|
-
save=save,
|
354
|
-
**kwargs,
|
355
|
-
)
|