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/_coda.py
DELETED
@@ -1,601 +0,0 @@
|
|
1
|
-
import warnings
|
2
|
-
from typing import Literal, Optional, Union
|
3
|
-
|
4
|
-
import matplotlib.pyplot as plt
|
5
|
-
import numpy as np
|
6
|
-
import seaborn as sns
|
7
|
-
from anndata import AnnData
|
8
|
-
from matplotlib import cm, rcParams
|
9
|
-
from matplotlib.axes import Axes
|
10
|
-
from matplotlib.colors import ListedColormap
|
11
|
-
from mudata import MuData
|
12
|
-
|
13
|
-
from pertpy.tools._coda._base_coda import CompositionalModel2
|
14
|
-
|
15
|
-
sns.set_style("ticks")
|
16
|
-
|
17
|
-
|
18
|
-
class CodaPlot:
|
19
|
-
@staticmethod
|
20
|
-
def __stackbar( # pragma: no cover
|
21
|
-
y: np.ndarray,
|
22
|
-
type_names: list[str],
|
23
|
-
title: str,
|
24
|
-
level_names: list[str],
|
25
|
-
figsize: tuple[float, float] | None = None,
|
26
|
-
dpi: int | None = 100,
|
27
|
-
cmap: ListedColormap | None = cm.tab20,
|
28
|
-
show_legend: bool | None = True,
|
29
|
-
) -> plt.Axes:
|
30
|
-
"""Plots a stacked barplot for one (discrete) covariate.
|
31
|
-
|
32
|
-
Typical use (only inside stacked_barplot): plot_one_stackbar(data.X, data.var.index, "xyz", data.obs.index)
|
33
|
-
|
34
|
-
Args:
|
35
|
-
y: The count data, collapsed onto the level of interest. i.e. a binary covariate has two rows,
|
36
|
-
one for each group, containing the count mean of each cell type
|
37
|
-
type_names: The names of all cell types
|
38
|
-
title: Plot title, usually the covariate's name
|
39
|
-
level_names: Names of the covariate's levels
|
40
|
-
figsize: Figure size. Defaults to None.
|
41
|
-
dpi: Dpi setting. Defaults to 100.
|
42
|
-
cmap: The color map for the barplot. Defaults to cm.tab20.
|
43
|
-
show_legend: If True, adds a legend. Defaults to True.
|
44
|
-
|
45
|
-
Returns:
|
46
|
-
A :class:`~matplotlib.axes.Axes` object
|
47
|
-
"""
|
48
|
-
n_bars, n_types = y.shape
|
49
|
-
|
50
|
-
figsize = rcParams["figure.figsize"] if figsize is None else figsize
|
51
|
-
|
52
|
-
_, ax = plt.subplots(figsize=figsize, dpi=dpi)
|
53
|
-
r = np.array(range(n_bars))
|
54
|
-
sample_sums = np.sum(y, axis=1)
|
55
|
-
|
56
|
-
barwidth = 0.85
|
57
|
-
cum_bars = np.zeros(n_bars)
|
58
|
-
|
59
|
-
for n in range(n_types):
|
60
|
-
bars = [i / j * 100 for i, j in zip([y[k][n] for k in range(n_bars)], sample_sums, strict=False)]
|
61
|
-
plt.bar(
|
62
|
-
r,
|
63
|
-
bars,
|
64
|
-
bottom=cum_bars,
|
65
|
-
color=cmap(n % cmap.N),
|
66
|
-
width=barwidth,
|
67
|
-
label=type_names[n],
|
68
|
-
linewidth=0,
|
69
|
-
)
|
70
|
-
cum_bars += bars
|
71
|
-
|
72
|
-
ax.set_title(title)
|
73
|
-
if show_legend:
|
74
|
-
ax.legend(loc="upper left", bbox_to_anchor=(1, 1), ncol=1)
|
75
|
-
ax.set_xticks(r)
|
76
|
-
ax.set_xticklabels(level_names, rotation=45, ha="right")
|
77
|
-
ax.set_ylabel("Proportion")
|
78
|
-
|
79
|
-
return ax
|
80
|
-
|
81
|
-
@staticmethod
|
82
|
-
def stacked_barplot( # pragma: no cover
|
83
|
-
data: AnnData | MuData,
|
84
|
-
feature_name: str,
|
85
|
-
modality_key: str = "coda",
|
86
|
-
figsize: tuple[float, float] | None = None,
|
87
|
-
dpi: int | None = 100,
|
88
|
-
cmap: ListedColormap | None = cm.tab20,
|
89
|
-
show_legend: bool | None = True,
|
90
|
-
level_order: list[str] = None,
|
91
|
-
) -> plt.Axes:
|
92
|
-
"""Plots a stacked barplot for all levels of a covariate or all samples (if feature_name=="samples").
|
93
|
-
|
94
|
-
Args:
|
95
|
-
data: AnnData object or MuData object.
|
96
|
-
feature_name: The name of the covariate to plot. If feature_name=="samples", one bar for every sample will be plotted
|
97
|
-
modality_key: If data is a MuData object, specify which modality to use. Defaults to "coda".
|
98
|
-
figsize: Figure size. Defaults to None.
|
99
|
-
dpi: Dpi setting. Defaults to 100.
|
100
|
-
cmap: The matplotlib color map for the barplot. Defaults to cm.tab20.
|
101
|
-
show_legend: If True, adds a legend. Defaults to True.
|
102
|
-
level_order: Custom ordering of bars on the x-axis. Defaults to None.
|
103
|
-
|
104
|
-
Returns:
|
105
|
-
A :class:`~matplotlib.axes.Axes` object
|
106
|
-
|
107
|
-
Examples:
|
108
|
-
>>> import pertpy as pt
|
109
|
-
>>> haber_cells = pt.dt.haber_2017_regions()
|
110
|
-
>>> sccoda = pt.tl.Sccoda()
|
111
|
-
>>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
|
112
|
-
sample_identifier="batch", covariate_obs=["condition"])
|
113
|
-
>>> sccoda.plot_stacked_barplot(mdata, feature_name="samples")
|
114
|
-
"""
|
115
|
-
warnings.warn(
|
116
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
117
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
118
|
-
FutureWarning,
|
119
|
-
stacklevel=2,
|
120
|
-
)
|
121
|
-
|
122
|
-
from pertpy.tools import Sccoda
|
123
|
-
|
124
|
-
coda = Sccoda()
|
125
|
-
return coda.plot_stacked_barplot(
|
126
|
-
data=data,
|
127
|
-
feature_name=feature_name,
|
128
|
-
modality_key=modality_key,
|
129
|
-
figsize=figsize,
|
130
|
-
dpi=dpi,
|
131
|
-
palette=cmap,
|
132
|
-
show_legend=show_legend,
|
133
|
-
level_order=level_order,
|
134
|
-
)
|
135
|
-
|
136
|
-
@staticmethod
|
137
|
-
def effects_barplot( # pragma: no cover
|
138
|
-
data: AnnData | MuData,
|
139
|
-
modality_key: str = "coda",
|
140
|
-
covariates: str | list | None = None,
|
141
|
-
parameter: Literal["log2-fold change", "Final Parameter", "Expected Sample"] = "log2-fold change",
|
142
|
-
plot_facets: bool = True,
|
143
|
-
plot_zero_covariate: bool = True,
|
144
|
-
plot_zero_cell_type: bool = False,
|
145
|
-
figsize: tuple[float, float] | None = None,
|
146
|
-
dpi: int | None = 100,
|
147
|
-
cmap: str | ListedColormap | None = cm.tab20,
|
148
|
-
level_order: list[str] = None,
|
149
|
-
args_barplot: dict | None = None,
|
150
|
-
) -> plt.Axes | sns.axisgrid.FacetGrid | None:
|
151
|
-
"""Barplot visualization for effects.
|
152
|
-
|
153
|
-
The effect results for each covariate are shown as a group of barplots, with intra--group separation by cell types.
|
154
|
-
The covariates groups can either be ordered along the x-axis of a single plot (plot_facets=False) or as plot facets (plot_facets=True).
|
155
|
-
|
156
|
-
Args:
|
157
|
-
data: AnnData object or MuData object.
|
158
|
-
modality_key: If data is a MuData object, specify which modality to use. Defaults to "coda".
|
159
|
-
covariates: The name of the covariates in data.obs to plot. Defaults to None.
|
160
|
-
parameter: The parameter in effect summary to plot. Defaults to "log2-fold change".
|
161
|
-
plot_facets: If False, plot cell types on the x-axis. If True, plot as facets.
|
162
|
-
Defaults to True.
|
163
|
-
plot_zero_covariate: If True, plot covariate that have all zero effects. If False, do not plot.
|
164
|
-
Defaults to True.
|
165
|
-
plot_zero_cell_type: If True, plot cell type that have zero effect. If False, do not plot.
|
166
|
-
Defaults to False.
|
167
|
-
figsize: Figure size. Defaults to None.
|
168
|
-
dpi: Figure size. Defaults to 100.
|
169
|
-
cmap: The seaborn color map for the barplot. Defaults to cm.tab20.
|
170
|
-
level_order: Custom ordering of bars on the x-axis. Defaults to None.
|
171
|
-
args_barplot: Arguments passed to sns.barplot. Defaults to None.
|
172
|
-
|
173
|
-
Returns:
|
174
|
-
Depending on `plot_facets`, returns a :class:`~matplotlib.axes.Axes` (`plot_facets = False`)
|
175
|
-
or :class:`~sns.axisgrid.FacetGrid` (`plot_facets = True`) object
|
176
|
-
|
177
|
-
Examples:
|
178
|
-
>>> import pertpy as pt
|
179
|
-
>>> haber_cells = pt.dt.haber_2017_regions()
|
180
|
-
>>> sccoda = pt.tl.Sccoda()
|
181
|
-
>>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
|
182
|
-
sample_identifier="batch", covariate_obs=["condition"])
|
183
|
-
>>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
|
184
|
-
>>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
|
185
|
-
>>> sccoda.plot_effects_barplot(mdata)
|
186
|
-
"""
|
187
|
-
warnings.warn(
|
188
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
189
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
190
|
-
FutureWarning,
|
191
|
-
stacklevel=2,
|
192
|
-
)
|
193
|
-
|
194
|
-
from pertpy.tools import Sccoda
|
195
|
-
|
196
|
-
coda = Sccoda()
|
197
|
-
return coda.plot_effects_barplot(
|
198
|
-
data=data,
|
199
|
-
modality_key=modality_key,
|
200
|
-
covariates=covariates,
|
201
|
-
parameter=parameter,
|
202
|
-
plot_facets=plot_facets,
|
203
|
-
plot_zero_covariate=plot_zero_covariate,
|
204
|
-
plot_zero_cell_type=plot_zero_cell_type,
|
205
|
-
figsize=figsize,
|
206
|
-
dpi=dpi,
|
207
|
-
palette=cmap,
|
208
|
-
level_order=level_order,
|
209
|
-
args_barplot=args_barplot,
|
210
|
-
)
|
211
|
-
|
212
|
-
@staticmethod
|
213
|
-
def boxplots( # pragma: no cover
|
214
|
-
data: AnnData | MuData,
|
215
|
-
feature_name: str,
|
216
|
-
modality_key: str = "coda",
|
217
|
-
y_scale: Literal["relative", "log", "log10", "count"] = "relative",
|
218
|
-
plot_facets: bool = False,
|
219
|
-
add_dots: bool = False,
|
220
|
-
cell_types: list | None = None,
|
221
|
-
args_boxplot: dict | None = None,
|
222
|
-
args_swarmplot: dict | None = None,
|
223
|
-
figsize: tuple[float, float] | None = None,
|
224
|
-
dpi: int | None = 100,
|
225
|
-
cmap: str | None = "Blues",
|
226
|
-
show_legend: bool | None = True,
|
227
|
-
level_order: list[str] = None,
|
228
|
-
) -> plt.Axes | sns.axisgrid.FacetGrid | None:
|
229
|
-
"""Grouped boxplot visualization. The cell counts for each cell type are shown as a group of boxplots,
|
230
|
-
with intra--group separation by a covariate from data.obs.
|
231
|
-
|
232
|
-
Args:
|
233
|
-
data: AnnData object or MuData object
|
234
|
-
feature_name: The name of the feature in data.obs to plot
|
235
|
-
modality_key: If data is a MuData object, specify which modality to use. Defaults to "coda".
|
236
|
-
y_scale: Transformation to of cell counts. Options: "relative" - Relative abundance, "log" - log(count),
|
237
|
-
"log10" - log10(count), "count" - absolute abundance (cell counts).
|
238
|
-
Defaults to "relative".
|
239
|
-
plot_facets: If False, plot cell types on the x-axis. If True, plot as facets. Defaults to False.
|
240
|
-
add_dots: If True, overlay a scatterplot with one dot for each data point. Defaults to False.
|
241
|
-
model: When draw_effects, specify a tasCODA model
|
242
|
-
cell_types: Subset of cell types that should be plotted. Defaults to None.
|
243
|
-
args_boxplot: Arguments passed to sns.boxplot. Defaults to {}.
|
244
|
-
args_swarmplot: Arguments passed to sns.swarmplot. Defaults to {}.
|
245
|
-
figsize: Figure size. Defaults to None.
|
246
|
-
dpi: Dpi setting. Defaults to 100.
|
247
|
-
cmap: The seaborn color map for the barplot. Defaults to "Blues".
|
248
|
-
show_legend: If True, adds a legend. Defaults to True.
|
249
|
-
level_order: Custom ordering of bars on the x-axis. Defaults to None.
|
250
|
-
|
251
|
-
Returns:
|
252
|
-
Depending on `plot_facets`, returns a :class:`~matplotlib.axes.Axes` (`plot_facets = False`)
|
253
|
-
or :class:`~sns.axisgrid.FacetGrid` (`plot_facets = True`) object
|
254
|
-
|
255
|
-
Examples:
|
256
|
-
>>> import pertpy as pt
|
257
|
-
>>> haber_cells = pt.dt.haber_2017_regions()
|
258
|
-
>>> sccoda = pt.tl.Sccoda()
|
259
|
-
>>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
|
260
|
-
sample_identifier="batch", covariate_obs=["condition"])
|
261
|
-
>>> sccoda.plot_boxplots(mdata, feature_name="condition", add_dots=True)
|
262
|
-
"""
|
263
|
-
warnings.warn(
|
264
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
265
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
266
|
-
FutureWarning,
|
267
|
-
stacklevel=2,
|
268
|
-
)
|
269
|
-
|
270
|
-
from pertpy.tools import Sccoda
|
271
|
-
|
272
|
-
coda = Sccoda()
|
273
|
-
return coda.plot_boxplots(
|
274
|
-
data=data,
|
275
|
-
feature_name=feature_name,
|
276
|
-
modality_key=modality_key,
|
277
|
-
y_scale=y_scale,
|
278
|
-
plot_facets=plot_facets,
|
279
|
-
add_dots=add_dots,
|
280
|
-
cell_types=cell_types,
|
281
|
-
args_boxplot=args_boxplot,
|
282
|
-
args_swarmplot=args_swarmplot,
|
283
|
-
figsize=figsize,
|
284
|
-
dpi=dpi,
|
285
|
-
palette=cmap,
|
286
|
-
show_legend=show_legend,
|
287
|
-
level_order=level_order,
|
288
|
-
)
|
289
|
-
|
290
|
-
@staticmethod
|
291
|
-
def rel_abundance_dispersion_plot( # pragma: no cover
|
292
|
-
data: AnnData | MuData,
|
293
|
-
modality_key: str = "coda",
|
294
|
-
abundant_threshold: float | None = 0.9,
|
295
|
-
default_color: str | None = "Grey",
|
296
|
-
abundant_color: str | None = "Red",
|
297
|
-
label_cell_types: bool = True,
|
298
|
-
figsize: tuple[float, float] | None = None,
|
299
|
-
dpi: int | None = 100,
|
300
|
-
ax: Axes = None,
|
301
|
-
) -> plt.Axes:
|
302
|
-
"""Plots total variance of relative abundance versus minimum relative abundance of all cell types for determination of a reference cell type.
|
303
|
-
|
304
|
-
If the count of the cell type is larger than 0 in more than abundant_threshold percent of all samples, the cell type will be marked in a different color.
|
305
|
-
|
306
|
-
Args:
|
307
|
-
data: AnnData object or MuData object.
|
308
|
-
modality_key: If data is a MuData object, specify which modality to use. Defaults to "coda".
|
309
|
-
Defaults to "coda".
|
310
|
-
abundant_threshold: Presence threshold for abundant cell types. Defaults to 0.9.
|
311
|
-
default_color: Bar color for all non-minimal cell types. Defaults to "Grey".
|
312
|
-
abundant_color: Bar color for cell types with abundant percentage larger than abundant_threshold.
|
313
|
-
Defaults to "Red".
|
314
|
-
label_cell_types: Label dots with cell type names. Defaults to True.
|
315
|
-
figsize: Figure size. Defaults to None.
|
316
|
-
dpi: Dpi setting. Defaults to 100.
|
317
|
-
ax: A matplotlib axes object. Only works if plotting a single component. Defaults to None.
|
318
|
-
|
319
|
-
Returns:
|
320
|
-
A :class:`~matplotlib.axes.Axes` object
|
321
|
-
|
322
|
-
Examples:
|
323
|
-
>>> import pertpy as pt
|
324
|
-
>>> haber_cells = pt.dt.haber_2017_regions()
|
325
|
-
>>> sccoda = pt.tl.Sccoda()
|
326
|
-
>>> mdata = sccoda.load(haber_cells, type="cell_level", generate_sample_level=True, cell_type_identifier="cell_label", \
|
327
|
-
sample_identifier="batch", covariate_obs=["condition"])
|
328
|
-
>>> mdata = sccoda.prepare(mdata, formula="condition", reference_cell_type="Endocrine")
|
329
|
-
>>> sccoda.run_nuts(mdata, num_warmup=100, num_samples=1000, rng_key=42)
|
330
|
-
>>> sccoda.plot_rel_abundance_dispersion_plot(mdata)
|
331
|
-
"""
|
332
|
-
warnings.warn(
|
333
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
334
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
335
|
-
FutureWarning,
|
336
|
-
stacklevel=2,
|
337
|
-
)
|
338
|
-
|
339
|
-
from pertpy.tools import Sccoda
|
340
|
-
|
341
|
-
coda = Sccoda()
|
342
|
-
return coda.plot_rel_abundance_dispersion_plot(
|
343
|
-
data=data,
|
344
|
-
modality_key=modality_key,
|
345
|
-
abundant_threshold=abundant_threshold,
|
346
|
-
default_color=default_color,
|
347
|
-
abundant_color=abundant_color,
|
348
|
-
label_cell_types=label_cell_types,
|
349
|
-
figsize=figsize,
|
350
|
-
dpi=dpi,
|
351
|
-
ax=ax,
|
352
|
-
)
|
353
|
-
|
354
|
-
@staticmethod
|
355
|
-
def draw_tree( # pragma: no cover
|
356
|
-
data: AnnData | MuData,
|
357
|
-
modality_key: str = "coda",
|
358
|
-
tree: str = "tree", # Also type ete3.Tree. Omitted due to import errors
|
359
|
-
tight_text: bool | None = False,
|
360
|
-
show_scale: bool | None = False,
|
361
|
-
show: bool | None = True,
|
362
|
-
save: str | None = None,
|
363
|
-
units: Literal["px", "mm", "in"] | None = "px",
|
364
|
-
figsize: tuple[float, float] | None = (None, None),
|
365
|
-
dpi: int | None = 90,
|
366
|
-
):
|
367
|
-
"""Plot a tree using input ete3 tree object.
|
368
|
-
|
369
|
-
Args:
|
370
|
-
data: AnnData object or MuData object.
|
371
|
-
modality_key: If data is a MuData object, specify which modality to use.
|
372
|
-
Defaults to "coda".
|
373
|
-
tree: A ete3 tree object or a str to indicate the tree stored in `.uns`.
|
374
|
-
Defaults to "tree".
|
375
|
-
tight_text: When False, boundaries of the text are approximated according to general font metrics,
|
376
|
-
producing slightly worse aligned text faces but improving
|
377
|
-
the performance of tree visualization in scenes with a lot of text faces.
|
378
|
-
Default to False.
|
379
|
-
show_scale: Include the scale legend in the tree image or not.
|
380
|
-
Defaults to False.
|
381
|
-
show: If True, plot the tree inline. If false, return tree and tree_style objects.
|
382
|
-
Defaults to True.
|
383
|
-
file_name: Path to the output image file. Valid extensions are .SVG, .PDF, .PNG.
|
384
|
-
Output image can be saved whether show is True or not.
|
385
|
-
Defaults to None.
|
386
|
-
units: Unit of image sizes. “px”: pixels, “mm”: millimeters, “in”: inches.
|
387
|
-
Defaults to "px".
|
388
|
-
h: Height of the image in units. Defaults to None.
|
389
|
-
w: Width of the image in units. Defaults to None.
|
390
|
-
dpi: Dots per inches. Defaults to 90.
|
391
|
-
|
392
|
-
Returns:
|
393
|
-
Depending on `show`, returns :class:`ete3.TreeNode` and :class:`ete3.TreeStyle` (`show = False`) or plot the tree inline (`show = False`)
|
394
|
-
|
395
|
-
Examples:
|
396
|
-
>>> import pertpy as pt
|
397
|
-
>>> adata = pt.dt.tasccoda_example()
|
398
|
-
>>> tasccoda = pt.tl.Tasccoda()
|
399
|
-
>>> mdata = tasccoda.load(
|
400
|
-
>>> adata, type="sample_level",
|
401
|
-
>>> levels_agg=["Major_l1", "Major_l2", "Major_l3", "Major_l4", "Cluster"],
|
402
|
-
>>> key_added="lineage", add_level_name=True
|
403
|
-
>>> )
|
404
|
-
>>> mdata = tasccoda.prepare(
|
405
|
-
>>> mdata, formula="Health", reference_cell_type="automatic", tree_key="lineage", pen_args={"phi": 0}
|
406
|
-
>>> )
|
407
|
-
>>> tasccoda.run_nuts(mdata, num_samples=1000, num_warmup=100, rng_key=42)
|
408
|
-
>>> tasccoda.plot_draw_tree(mdata, tree="lineage")
|
409
|
-
|
410
|
-
Preview: #TODO: Add preview
|
411
|
-
"""
|
412
|
-
warnings.warn(
|
413
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
414
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
415
|
-
FutureWarning,
|
416
|
-
stacklevel=2,
|
417
|
-
)
|
418
|
-
|
419
|
-
from pertpy.tools import Tasccoda
|
420
|
-
|
421
|
-
coda = Tasccoda()
|
422
|
-
return coda.plot_draw_tree(
|
423
|
-
data=data,
|
424
|
-
modality_key=modality_key,
|
425
|
-
tree=tree,
|
426
|
-
tight_text=tight_text,
|
427
|
-
show_scale=show_scale,
|
428
|
-
show=show,
|
429
|
-
save=save,
|
430
|
-
units=units,
|
431
|
-
figsize=figsize,
|
432
|
-
dpi=dpi,
|
433
|
-
)
|
434
|
-
|
435
|
-
@staticmethod
|
436
|
-
def draw_effects( # pragma: no cover
|
437
|
-
data: AnnData | MuData,
|
438
|
-
covariate: str,
|
439
|
-
modality_key: str = "coda",
|
440
|
-
tree: str = "tree", # Also type ete3.Tree. Omitted due to import errors
|
441
|
-
show_legend: bool | None = None,
|
442
|
-
show_leaf_effects: bool | None = False,
|
443
|
-
tight_text: bool | None = False,
|
444
|
-
show_scale: bool | None = False,
|
445
|
-
show: bool | None = True,
|
446
|
-
save: str | None = None,
|
447
|
-
units: Literal["px", "mm", "in"] | None = "in",
|
448
|
-
figsize: tuple[float, float] | None = (None, None),
|
449
|
-
dpi: int | None = 90,
|
450
|
-
):
|
451
|
-
"""Plot a tree with colored circles on the nodes indicating significant effects with bar plots which indicate leave-level significant effects.
|
452
|
-
|
453
|
-
Args:
|
454
|
-
data: AnnData object or MuData object.
|
455
|
-
covariate: The covariate, whose effects should be plotted.
|
456
|
-
modality_key: If data is a MuData object, specify which modality to use.
|
457
|
-
Defaults to "coda".
|
458
|
-
tree: A ete3 tree object or a str to indicate the tree stored in `.uns`.
|
459
|
-
Defaults to "tree".
|
460
|
-
show_legend: If show legend of nodes significant effects or not.
|
461
|
-
Defaults to False if show_leaf_effects is True.
|
462
|
-
show_leaf_effects: If True, plot bar plots which indicate leave-level significant effects.
|
463
|
-
Defaults to False.
|
464
|
-
tight_text: When False, boundaries of the text are approximated according to general font metrics,
|
465
|
-
producing slightly worse aligned text faces but improving the performance of tree visualization in scenes with a lot of text faces.
|
466
|
-
Defaults to False.
|
467
|
-
show_scale: Include the scale legend in the tree image or not. Defaults to False.
|
468
|
-
show: If True, plot the tree inline. If false, return tree and tree_style objects. Defaults to True.
|
469
|
-
file_name: Path to the output image file. valid extensions are .SVG, .PDF, .PNG. Output image can be saved whether show is True or not.
|
470
|
-
Defaults to None.
|
471
|
-
units: Unit of image sizes. “px”: pixels, “mm”: millimeters, “in”: inches. Default is "in". Defaults to "in".
|
472
|
-
h: Height of the image in units. Defaults to None.
|
473
|
-
w: Width of the image in units. Defaults to None.
|
474
|
-
dpi: Dots per inches. Defaults to 90.
|
475
|
-
|
476
|
-
Returns:
|
477
|
-
Depending on `show`, returns :class:`ete3.TreeNode` and :class:`ete3.TreeStyle` (`show = False`)
|
478
|
-
or plot the tree inline (`show = False`)
|
479
|
-
|
480
|
-
Examples:
|
481
|
-
>>> import pertpy as pt
|
482
|
-
>>> adata = pt.dt.tasccoda_example()
|
483
|
-
>>> tasccoda = pt.tl.Tasccoda()
|
484
|
-
>>> mdata = tasccoda.load(
|
485
|
-
>>> adata, type="sample_level",
|
486
|
-
>>> levels_agg=["Major_l1", "Major_l2", "Major_l3", "Major_l4", "Cluster"],
|
487
|
-
>>> key_added="lineage", add_level_name=True
|
488
|
-
>>> )
|
489
|
-
>>> mdata = tasccoda.prepare(
|
490
|
-
>>> mdata, formula="Health", reference_cell_type="automatic", tree_key="lineage", pen_args={"phi": 0}
|
491
|
-
>>> )
|
492
|
-
>>> tasccoda.run_nuts(mdata, num_samples=1000, num_warmup=100, rng_key=42)
|
493
|
-
>>> tasccoda.plot_draw_effects(mdata, covariate="Health[T.Inflamed]", tree="lineage")
|
494
|
-
"""
|
495
|
-
warnings.warn(
|
496
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
497
|
-
" Please use the corresponding 'pt.tl' object",
|
498
|
-
FutureWarning,
|
499
|
-
stacklevel=2,
|
500
|
-
)
|
501
|
-
|
502
|
-
from pertpy.tools import Tasccoda
|
503
|
-
|
504
|
-
coda = Tasccoda()
|
505
|
-
return coda.plot_draw_effects(
|
506
|
-
data=data,
|
507
|
-
modality_key=modality_key,
|
508
|
-
covariate=covariate,
|
509
|
-
tree=tree,
|
510
|
-
show_legend=show_legend,
|
511
|
-
show_leaf_effects=show_leaf_effects,
|
512
|
-
tight_text=tight_text,
|
513
|
-
show_scale=show_scale,
|
514
|
-
show=show,
|
515
|
-
save=save,
|
516
|
-
units=units,
|
517
|
-
figsize=figsize,
|
518
|
-
dpi=dpi,
|
519
|
-
)
|
520
|
-
|
521
|
-
@staticmethod
|
522
|
-
def effects_umap( # pragma: no cover
|
523
|
-
data: MuData,
|
524
|
-
effect_name: str | list | None,
|
525
|
-
cluster_key: str,
|
526
|
-
modality_key_1: str = "rna",
|
527
|
-
modality_key_2: str = "coda",
|
528
|
-
show: bool = None,
|
529
|
-
ax: Axes = None,
|
530
|
-
**kwargs,
|
531
|
-
):
|
532
|
-
"""Plot a UMAP visualization colored by effect strength.
|
533
|
-
|
534
|
-
Effect results in .varm of aggregated sample-level AnnData (default is data['coda']) are assigned to cell-level AnnData
|
535
|
-
(default is data['rna']) depending on the cluster they were assigned to.
|
536
|
-
|
537
|
-
Args:
|
538
|
-
data: AnnData object or MuData object.
|
539
|
-
effect_name: The name of the effect results in .varm of aggregated sample-level AnnData to plot
|
540
|
-
cluster_key: The cluster information in .obs of cell-level AnnData (default is data['rna']).
|
541
|
-
To assign cell types' effects to original cells.
|
542
|
-
modality_key_1: Key to the cell-level AnnData in the MuData object. Defaults to "rna".
|
543
|
-
modality_key_2: Key to the aggregated sample-level AnnData object in the MuData object.
|
544
|
-
Defaults to "coda".
|
545
|
-
show: Whether to display the figure or return axis. Defaults to None.
|
546
|
-
ax: A matplotlib axes object. Only works if plotting a single component.
|
547
|
-
Defaults to None.
|
548
|
-
**kwargs: All other keyword arguments are passed to `scanpy.plot.umap()`
|
549
|
-
|
550
|
-
Returns:
|
551
|
-
If `show==False` a :class:`~matplotlib.axes.Axes` or a list of it.
|
552
|
-
|
553
|
-
Examples:
|
554
|
-
>>> import pertpy as pt
|
555
|
-
>>> import schist
|
556
|
-
>>> adata = pt.dt.haber_2017_regions()
|
557
|
-
>>> schist.inference.nested_model(adata, samples=100, random_seed=5678)
|
558
|
-
>>> tasccoda_model = pt.tl.Tasccoda()
|
559
|
-
>>> tasccoda_data = tasccoda_model.load(adata, type="cell_level",
|
560
|
-
>>> cell_type_identifier="nsbm_level_1",
|
561
|
-
>>> sample_identifier="batch", covariate_obs=["condition"],
|
562
|
-
>>> levels_orig=["nsbm_level_4", "nsbm_level_3", "nsbm_level_2", "nsbm_level_1"],
|
563
|
-
>>> add_level_name=True)sccoda = pt.tl.Sccoda()
|
564
|
-
>>> tasccoda_model.prepare(
|
565
|
-
>>> tasccoda_data,
|
566
|
-
>>> modality_key="coda",
|
567
|
-
>>> reference_cell_type="18",
|
568
|
-
>>> formula="condition",
|
569
|
-
>>> pen_args={"phi": 0, "lambda_1": 3.5},
|
570
|
-
>>> tree_key="tree"
|
571
|
-
>>> )
|
572
|
-
>>> tasccoda_model.run_nuts(
|
573
|
-
... tasccoda_data, modality_key="coda", rng_key=1234, num_samples=10000, num_warmup=1000
|
574
|
-
... )
|
575
|
-
>>> tasccoda_model.plot_effects_umap(tasccoda_data,
|
576
|
-
>>> effect_name=["effect_df_condition[T.Salmonella]",
|
577
|
-
>>> "effect_df_condition[T.Hpoly.Day3]",
|
578
|
-
>>> "effect_df_condition[T.Hpoly.Day10]"],
|
579
|
-
>>> cluster_key="nsbm_level_1",
|
580
|
-
>>> )
|
581
|
-
"""
|
582
|
-
warnings.warn(
|
583
|
-
"This function is deprecated and will be removed in pertpy 0.8.0!"
|
584
|
-
" Please use the corresponding 'pt.tl' object for plotting function directly.",
|
585
|
-
FutureWarning,
|
586
|
-
stacklevel=2,
|
587
|
-
)
|
588
|
-
|
589
|
-
from pertpy.tools import Tasccoda
|
590
|
-
|
591
|
-
coda = Tasccoda()
|
592
|
-
coda.plot_effects_umap(
|
593
|
-
data=data,
|
594
|
-
effect_name=effect_name,
|
595
|
-
cluster_key=cluster_key,
|
596
|
-
modality_key_1=modality_key_1,
|
597
|
-
modality_key_2=modality_key_2,
|
598
|
-
show=show,
|
599
|
-
ax=ax,
|
600
|
-
**kwargs,
|
601
|
-
)
|
pertpy/plot/_guide_rna.py
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
import warnings
|
4
|
-
from typing import TYPE_CHECKING
|
5
|
-
|
6
|
-
if TYPE_CHECKING:
|
7
|
-
import numpy as np
|
8
|
-
from anndata import AnnData
|
9
|
-
|
10
|
-
|
11
|
-
class GuideRnaPlot:
|
12
|
-
@staticmethod
|
13
|
-
def heatmap(
|
14
|
-
adata: AnnData,
|
15
|
-
layer: str | None = None,
|
16
|
-
order_by: np.ndarray | str | None = None,
|
17
|
-
key_to_save_order: str = None,
|
18
|
-
**kwargs,
|
19
|
-
):
|
20
|
-
"""Heatmap plotting of guide RNA expression matrix.
|
21
|
-
|
22
|
-
Assuming guides have sparse expression, this function reorders cells
|
23
|
-
and plots guide RNA expression so that a nice sparse representation is achieved.
|
24
|
-
The cell ordering can be stored and reused in future plots to obtain consistent
|
25
|
-
plots before and after analysis of the guide RNA expression.
|
26
|
-
Note: This function expects a log-normalized or binary data.
|
27
|
-
|
28
|
-
Args:
|
29
|
-
adata: Annotated data matrix containing gRNA values
|
30
|
-
layer: Key to the layer containing log normalized count values of the gRNAs.
|
31
|
-
adata.X is used if layer is None.
|
32
|
-
order_by: The order of cells in y axis. Defaults to None.
|
33
|
-
If None, cells will be reordered to have a nice sparse representation.
|
34
|
-
If a string is provided, adata.obs[order_by] will be used as the order.
|
35
|
-
If a numpy array is provided, the array will be used for ordering.
|
36
|
-
key_to_save_order: The obs key to save cell orders in the current plot. Only saves if not None.
|
37
|
-
kwargs: Are passed to sc.pl.heatmap.
|
38
|
-
|
39
|
-
Returns:
|
40
|
-
List of Axes. Alternatively you can pass save or show parameters as they will be passed to sc.pl.heatmap.
|
41
|
-
Order of cells in the y axis will be saved on adata.obs[key_to_save_order] if provided.
|
42
|
-
|
43
|
-
Examples:
|
44
|
-
Each cell is assigned to gRNA that occurs at least 5 times in the respective cell, which is then
|
45
|
-
visualized using a heatmap.
|
46
|
-
|
47
|
-
>>> import pertpy as pt
|
48
|
-
>>> mdata = pt.dt.papalexi_2021()
|
49
|
-
>>> gdo = mdata.mod["gdo"]
|
50
|
-
>>> ga = pt.pp.GuideAssignment()
|
51
|
-
>>> ga.assign_by_threshold(gdo, assignment_threshold=5)
|
52
|
-
>>> ga.plot_heatmap(gdo)
|
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.preprocessing import GuideAssignment
|
62
|
-
|
63
|
-
ga = GuideAssignment()
|
64
|
-
ga.plot_heatmap(adata=adata, layer=layer, order_by=order_by, key_to_save_order=key_to_save_order, kwargs=kwargs)
|