cellrank.pl.heatmap#
- cellrank.pl.heatmap(adata, model, genes, lineages=None, backward=False, mode=HeatmapMode.LINEAGES, time_key='latent_time', time_range=None, callback=None, cluster_key=None, show_absorption_probabilities=False, cluster_genes=False, keep_gene_order=False, scale=True, n_convolve=5, show_all_genes=False, cbar=True, lineage_height=0.33, fontsize=None, xlabel=None, cmap=<matplotlib.colors.ListedColormap object>, dendrogram=True, return_genes=False, return_models=False, return_figure=False, n_jobs=1, backend='loky', show_progress_bar=True, figsize=None, dpi=None, save=None, **kwargs)[source]#
Plot a heatmap of smoothed gene expression along specified lineages.
This requires a pseudotemporal ordering of cellular dynamics, computed using a method like DPT [Haghverdi et al., 2016] or Palantir [Setty et al., 2019]. The function combines the pseudotemporal ordering with CellRank’s fate probabilities to visualize each gene’s expression along specific trajectories. In the heatmap, genes are ordered according to their peak in pseudotime, which emphasizes expression cascades of sequential activation.
- Parameters:
adata (
anndata.AnnData
) – Annotated data object.model (
Union
[BaseModel
,Mapping
[str
,Mapping
[str
,BaseModel
]]]) –Model based on
cellrank.models.BaseModel
to fit.If a
dict
, gene and lineage specific models can be specified. Use'*'
to indicate all genes or lineages, for example{'gene_1': {'*': ...}, 'gene_2': {'lineage_1': ..., '*': ...}}
.genes (
Sequence
[str
]) – Genes inanndata.AnnData.var_names
or inanndata.AnnData.raw.var_names
, ifuse_raw = True
.lineages (
Union
[str
,Sequence
[str
],None
]) – Names of the lineages for which to plot. If None, plot all lineages.backward (
bool
) – Direction of the process.mode (
Literal
['genes'
,'lineages'
]) –Valid options are:
’lineages’ - group by
genes
for each lineage inlineages
.’genes’ - group by
lineages
for each gene ingenes
.
time_key (
str
) – Key in attr:anndata.AnnData.obs where the pseudotime is stored.time_range (
Union
[float
,Tuple
[Optional
[float
],Optional
[float
]],None
,List
[Union
[float
,Tuple
[Optional
[float
],Optional
[float
]],None
]]]) –Specify start and end times:
This can also be specified on per-lineage basis.
gene_symbols – Key in
anndata.AnnData.var
to use instead ofanndata.AnnData.var_names
.callback (
Union
[Callable
,Mapping
[str
,Mapping
[str
,Callable
]],None
]) – Function which takes acellrank.models.BaseModel
and some keyword arguments forcellrank.models.BaseModel.prepare()
and returns the prepared model. Can be specified in gene- and lineage-specific manner, similarly tomodel
.cluster_key (
Union
[str
,Sequence
[str
],None
]) – Key(s) inanndata.AnnData.obs
containing categorical observations to be plotted on the top of heatmap. Only available whenmode = 'lineages'
.show_absorption_probabilities (
bool
) – Whether to also plot absorption probabilities alongside the smoothed expression. Only available whenmode = 'lineages'
.cluster_genes (
bool
) – Whether to cluster genes usingseaborn.clustermap()
whenmode = 'lineages'
.keep_gene_order (
bool
) – Whether to keep the gene order for later lineages after the first was sorted. Only available whencluster_genes = False
andmode = 'lineages'
.scale (
bool
) – Whether to normalize the gene expression [0, 1] range.n_convolve (
Optional
[int
]) – Size of the convolution window when smoothing absorption probabilities.show_all_genes (
bool
) – Whether to show all genes on y-axis.cbar (
bool
) – Whether to show the colorbar.lineage_height (
float
) – Height of a bar whenmode = 'genes'
.xlabel (
Optional
[str
]) – Label on the x-axis. If None, it is determined based ontime_key
.cmap (
ListedColormap
) – Colormap to use when visualizing the smoothed expression.dendrogram (
bool
) – Whether to show dendrogram whencluster_genes = True
.return_genes (
bool
) – Whether to return the sorted or clustered genes. Only available whenmode = 'lineages'
.return_models (
bool
) – If True, return the fitted models for each gene ingenes
and lineage inlineages
.return_figure (
bool
) – Whether to return the figure object. Setsreturn_genes = True
show_progress_bar (
bool
) – Whether to show a progress bar. Disabling it may slightly improve performance.n_jobs (
Optional
[int
]) – Number of parallel jobs. If -1, use all available cores. If None or 1, the execution is sequential.backend (
Literal
['loky'
,'multiprocessing'
,'threading'
]) – Which backend to use for parallelization. Seejoblib.Parallel
for valid options.figsize (
Optional
[Tuple
[float
,float
]]) – Size of the figure.save (
Union
[str
,Path
,None
]) – Filename where to save the plot.kwargs (
Any
) – Keyword arguments forcellrank.models.BaseModel.prepare()
.
- Return type:
Union
[Dict
[str
,DataFrame
],Tuple
[Mapping
[str
,Mapping
[str
,BaseModel
]],Dict
[str
,DataFrame
]],None
]- Returns:
: None
If
return_models = False
, just plots the figure and optionally saves it based onsave
.- Dict[str, Dict[str,
cellrank.models.BaseModel
]] Otherwise returns the fitted models as
{'gene_1': {'lineage_1': <model_11>, ...}, ...}
. Models which have failed will be instances ofcellrank.models.FailedModel
.
If
return_genes = True
andmode = 'lineages'
, returnspandas.DataFrame
containing the clustered or sorted genes.If
return_figure = True
, returns a tuple containing the figure and genes.- Dict[str, Dict[str,