amici.interpretation.AMICIAblationModule#

class amici.interpretation.AMICIAblationModule(_adata=None, _ablation_scores_df=None, _compute_kwargs=None, _cell_types=None, _z_computed=False, _labels_key=None)[source]#

Bases: object

Methods

__init__

compute

Difference in gene expression prediction error for cell type of interest when ablating neighbor cell types for a specific head of interest.

get_interaction_circos_plot

Plots a circos plot of the interactions between the cell types based on the ablation scores.

load_object

Load a previously saved AMICIAblationModule object from a pickle file

plot_featurewise_ablation_heatmap

Plots the heatmap of the top genes by ablation scores for a given cell type and head index.

plot_featurewise_contributions_dotplot

Plots a dotplot of the top genes by color_by and size_by for a given cell type and head index.

plot_featurewise_contributions_heatmap

Plots the heatmap of gene contributions for the top genes by ablation scores for a given cell type and head index.

plot_interaction_directed_graph

Plots a directed graph of the interactions between cell types based on the ablation scores.

plot_interaction_weight_heatmap

Plots a heatmap of the interactions between the cell types based on the ablation scores.

plot_neighbor_ablation_scores

Plots the ablation scores for each neighbor cell type provided the cell type and head index.

save_object

Save the entire AMICIAblationModule object to a pickle file

classmethod compute(model, cell_type, head_idx, adata=None, ablated_neighbor_ct_sub=None, ablated_neighbor_indices=None, compute_z_value=False)[source]#

Difference in gene expression prediction error for cell type of interest when ablating neighbor cell types for a specific head of interest.

Parameters:
  • cell_type (str) – The cell type to compute the residuals for. None indicates using all cell types.

  • head_idx (int, optional) – The index of the head to test. None indicates using all heads.

  • adata (AnnData, optional) – The AnnData object.

  • ablated_neighbor_ct_sub (list[str], optional) – The neighbor cell types to ablate.

  • ablated_neighbor_indices (list[int], optional) – The indices of the neighbor cells to ablate.

  • compute_z_value (bool, optional) – Whether to save the z-value using the correlation coefficient or not.

Return type:

AMICIAblationModule

Returns:

pd.DataFrame: A DataFrame with the difference in gene expression prediction error for cell type of interest when ablating neighbor cell types. The DataFrame has the columns:

  • [ablated_neighbor_ct]: The difference in gene expression prediction error when ablating the neighbor cell type ablated_neighbor_ct.

save_object(save_path)[source]#

Save the entire AMICIAblationModule object to a pickle file

Parameters:

save_path (str) – Path to save the object (should end with .pkl)

Returns:

AMICIAblationModule: Self for method chaining

classmethod load_object(save_path)[source]#

Load a previously saved AMICIAblationModule object from a pickle file

Parameters:

save_path (str) – Path to the saved object file

Return type:

AMICIAblationModule

Returns:

AMICIAblationModule: The loaded ablation module object

plot_neighbor_ablation_scores(cell_type=None, score_col='ablation', palette=None, threshold=0.02, wandb_log=False, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots the ablation scores for each neighbor cell type provided the cell type and head index.

Parameters:
  • cell_type (str, optional) – The cell type to plot the ablation scores for.

  • plot_z_value (bool, optional) – Whether to plot the z-value rather than ablation scores.

  • palette (dict, optional) – A dictionary mapping each cell type to a color.

  • threshold (float, optional) – The threshold for sparsifying the ablation scores.

  • wandb_log (bool, optional) – Whether to log the plot to Weights and Biases.

  • show (bool, optional) – Whether to display the plot.

  • save_png (bool, optional) – Whether to save the plot as a PNG file.

  • save_svg (bool, optional) – Whether to save the plot as an SVG file.

  • save_dir (str, optional) – The directory to save the plot files.

Returns:

None

plot_featurewise_ablation_heatmap(cell_type=None, score_col='ablation', n_top_genes=10, wandb_log=False, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots the heatmap of the top genes by ablation scores for a given cell type and head index.

Parameters:
  • cell_type (str, optional) – The cell type to plot the ablation scores for.

  • plot_z_value (bool, optional) – Whether to plot the z-value rather than ablation scores.

  • n_top_genes (int, optional) – The number of top genes to plot.

  • wandb_log (bool, optional) – Whether to log the plot to Weights and Biases.

  • show (bool, optional) – Whether to display the plot.

  • save_png (bool, optional) – Whether to save the plot as a PNG file.

  • save_svg (bool, optional) – Whether to save the plot as an SVG file.

  • save_dir (str, optional) – The directory to save the plot files.

Returns:

None

plot_featurewise_contributions_heatmap(cell_type=None, sort_by='ablation', n_top_genes=10, wandb_log=False, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots the heatmap of gene contributions for the top genes by ablation scores for a given cell type and head index.

Parameters:
  • cell_type (str, optional) – The cell type to plot the contributions for.

  • sort_by (str, optional) – The score column to sort the genes by.

  • n_top_genes (int, optional) – The number of top genes to plot.

  • wandb_log (bool, optional) – Whether to log the plot to Weights and Biases.

  • show (bool, optional) – Whether to display the plot.

  • save_png (bool, optional) – Whether to save the plot as a PNG file.

  • save_svg (bool, optional) – Whether to save the plot as an SVG file.

  • save_dir (str, optional) – The directory to save the plot files.

Returns:

None

plot_featurewise_contributions_dotplot(cell_type=None, color_by='diff', size_by='nl10_pval_adj', n_top_genes=10, dot_max=200, dot_min=0, step=5, min_size_by=0, vrange=0.5, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots a dotplot of the top genes by color_by and size_by for a given cell type and head index.

Parameters:
  • cell_type (str, optional) – The cell type to plot the dotplot for.

  • color_by (str, optional) – The column to color the dots by.

  • size_by (str, optional) – The column to size the dots by.

  • n_top_genes (int, optional) – The number of top genes to plot.

  • dot_max (int, optional) – The maximum size of the dots.

  • dot_min (int, optional) – The minimum size of the dots.

  • step (int, optional) – The step size of the dots.

  • min_size_by (int, optional) – The minimum size_by value to plot.

  • min_color_by (int, optional) – The minimum color_by value to plot.

  • vrange (float, optional) – The range for color scaling.

  • show (bool, optional) – Whether to show the plot.

  • save_png (bool, optional) – Whether to save the plot as a png.

  • save_svg (bool, optional) – Whether to save the plot as a svg.

  • save_dir (str, optional) – The directory to save the plot to.

get_interaction_circos_plot(cell_type_sub=None, significance_threshold=0.05, palette=None, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots a circos plot of the interactions between the cell types based on the ablation scores.

Parameters:
  • cell_type_sub (list) – The cell types to plot.

  • significance_threshold (float) – The significance threshold for the pvalues.

  • palette (dict) – The palette to use for the colors.

  • show (bool) – Whether to show the plot.

  • save_png (bool) – Whether to save the plot as a png.

  • save_svg (bool) – Whether to save the plot as a svg.

Returns:

fig (): The figure object for the plot.

plot_interaction_weight_heatmap(significance_threshold=0.05, vmin=0, vmax=80, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots a heatmap of the interactions between the cell types based on the ablation scores.

Parameters:
  • cell_type_sub (list) – The cell types to plot.

  • significance_threshold (float) – The significance threshold for the pvalues.

  • vmin (float) – The minimum value for the colorbar.

  • vmax (float) – The maximum value for the colorbar.

  • save_png (bool) – Whether to save the plot as a png.

  • save_svg (bool) – Whether to save the plot as a svg.

  • save_dir (str) – The directory to save the plot to.

plot_interaction_directed_graph(cell_type_sub=None, significance_threshold=0.05, weight_threshold=0, node_size=1500, palette=None, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#

Plots a directed graph of the interactions between cell types based on the ablation scores.

Parameters:
  • cell_type_sub (list) – The cell types to plot.

  • significance_threshold (float) – The significance threshold for the pvalues.

  • weight_threshold (float) – The threshold for the weight of the edges.

  • node_size (int) – The size of the nodes.

  • palette (dict) – The palette to use for the colors.

  • show (bool) – Whether to show the plot.

  • save_png (bool) – Whether to save the plot as a png.

  • save_svg (bool) – Whether to save the plot as a svg.

  • save_dir (str) – The directory to save the plot to.