dotools_py.pl.heatmap_foldchange

dotools_py.pl.heatmap_foldchange#

dotools_py.pl.heatmap_foldchange(adata, group_by, features, condition_key, reference, groups_order=None, conditions_order=None, layer=None, figsize=(5, 6), ax=None, swap_axes=True, title=None, title_fontproperties=None, palette='RdBu_r', palette_conditions='tab10', ticks_fontproperties=None, xticks_rotation=None, yticks_rotation=None, vmin=None, vcenter=None, vmax=None, colorbar_legend_title='Log2FC', groups_legend_title='Comparison', group_legend_ncols=1, path=None, filename='Heatmap.svg', show=True, add_stats=False, test='wilcoxon', correction_method='benjamini-hochberg', df_pvals=None, stats_x_size=None, square_x_size=None, pval_cutoff=0.05, log2fc_cutoff=0.0, linewidth=0.1, color_axis_ratio=0.15, **kargs)[source]#

Heatmap of the log2-foldchange of genes across a groups between two conditions.

Generate a heatmap of showing the log2-foldchange for a set of genes in different groups between different conditions. Differential gene expression analysis between the different conditions can be performed.

Parameters:
adata AnnData

Annotated data matrix.

group_by str | list

Name of a categorical column in adata.obs to groupby.

features str | list

A valid feature in adata.var_names or column in adata.obs with continuous values.

condition_key str

Name of a categorical column in adata.obs to compare to compute the log2foldchanges

reference str

Category in adata.obs[condition_key] to use as the reference to compute the log2foldchanges

groups_order list (default: None)

Order for the categories in adata.obs[group_by].

conditions_order list (default: None)

Order for the categories in adata.obs[condition_key]

path str | PathLike[str] | Path (default: None)

Path to the folder to save the figure.

filename str (default: 'Heatmap.svg')

Name of file to use when saving the figure.

layer str (default: None)

Name of the AnnData object layer that wants to be plotted. By default, adata.X is plotted. If layer is set to a valid layer name, then the layer is plotted.

swap_axes bool (default: True)

Whether to swap the axes or not.

palette str (default: 'RdBu_r')

String denoting matplotlib colormap.

palette_conditions str | dict (default: 'tab10')

String denoting matplotlib colormap for the comparisons.

title str (default: None)

Title for the figure.

title_fontproperties Dict[Literal['size', 'weight'], str | int] (default: None)

Dictionary which should contain ‘size’ and ‘weight’ to define the fontsize and fontweight of the title of the figure.

ax Axes | None (default: None)

Matplotlib axes to use for plotting. If not set, a new figure will be generated.

figsize tuple (default: (5, 6))

Figure size, the format is (width, height).

linewidth float (default: 0.1)

Linewidth for the border of cells.

ticks_fontproperties Dict[Literal['size', 'weight'], str | int] (default: None)

Dictionary which should contain ‘size’ and ‘weight’ to define the fontsize and fontweight of the font of the x/y-axis.

xticks_rotation int (default: None)

Rotation of the x-ticks.

yticks_rotation int (default: None)

Rotations of the y-ticks.

vmin float (default: None)

The value representing the lower limit of the color scale.

vcenter float (default: None)

The value representing the center of the color scale.

vmax float (default: None)

The value representing the upper limit of the color scale.

colorbar_legend_title str (default: 'Log2FC')

Title for the colorbar.

groups_legend_title str (default: 'Comparison')

Title for the comparison legend.

group_legend_ncols int (default: 1)

Number of columns for the comparison legend.

add_stats bool (default: False)

Add statistical annotation. Will add a square with an ‘*’ in the center if the expression is significantly different in a group with respect to the others.

df_pvals DataFrame (default: None)

Dataframe with the pvals. Should be gene x group or group x gene in case of swap_axes is False.

stats_x_size float (default: None)

Scaling factor to control the size of the asterisk.

square_x_size dict (default: None)

Size and thickness of the square.

test Literal['wilcoxon', 't-test'] (default: 'wilcoxon')

Name of the method to test for significance.

correction_method Literal['benjamini-hochberg', 'bonferroni'] (default: 'benjamini-hochberg')

Correction method for multiple testing.

pval_cutoff float (default: 0.05)

Cutoff for the p-value.

log2fc_cutoff float (default: 0.0)

Minimum cutoff for the log2FC.

show bool (default: True)

If set to False, returns a dictionary with the matplotlib axes.

color_axis_ratio default: 0.15

Ratio of the axis reserved for the colors denoting the comparisons.

kargs

Additional arguments pass to sns.heatmap.

Return type:

dict | None

Returns:

Depending on show, returns the plot if set to True or a dictionary with the axes.

Example

import dotools_py as do
adata = do.dt.example_10x_processed()
do.pl.heatmap_foldchange(adata, 'annotation', ['CD4', 'CD79A'], "condition", "healthy", add_stats=True, figsize=(5, 7))
../../_images/dotools_py-pl-heatmap_foldchange-1.png