amici.interpretation.AMICIExplainedVarianceModule#
- class amici.interpretation.AMICIExplainedVarianceModule(_adata=None, _explained_variance_df=None, _compute_kwargs=None, _n_permutations=None)[source]#
Bases:
objectMethods
__init__Creates a DataFrame with the explained variance scores.
Compute the head with the maximum explained variance for the given cell type.
Plots a barplot of the maximum explained variance score for each head and each cell type.
Plots a heatmap of the explained variance scores for each head for n_top_genes genes.
Save explained variance scores to file
- classmethod compute(model, adata=None, alpha=0.05, run_permutation_test=True, n_permutations=None)[source]#
Creates a DataFrame with the explained variance scores.
DataFrame contains the explained variance scores for each head across cells for all cell types or a subset of cell types.
- Parameters:
adata (AnnData, optional) – The AnnData object.
alpha (float, optional) – The desired significance level for the explained variance of each head-cell type pair via permutation testing. Defaults to 0.05.
run_permutation_test (bool, optional) – Whether to run the permutation test. Defaults to True.
n_permutations (int, optional) – The number of permutations to use for the permutation test. If not provided, the minimum number of permutations required to achieve a significance level of alpha will be used.
- Return type:
- Returns:
AMICIExplainedVarianceModule: The module instance with computed explained variance scores stored in _explained_variance_df with columns:
head: The index of the head.
ct_name: The name of the cell type.
gene: The name of the gene.
expl_var_head_gene: The explained variance score when all but head is ablated for the gene.
expl_var_head: The explained variance score when all but head aggregated across all genes.
- if run_permutation_test is True, the following columns are also added:
p_value_head: The p-value of the explained variance score when all but head is ablated.
p_value_adj_head: The adjusted p-value of the explained variance score when all but head is ablated.
- compute_max_explained_variance_head(cell_type)[source]#
Compute the head with the maximum explained variance for the given cell type.
- plot_explained_variance_barplot(palette=None, cell_type_sub=None, wandb_log=False, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#
Plots a barplot of the maximum explained variance score for each head and each cell type.
- Parameters:
expl_variance_df (pd.DataFrame) – A DataFrame containing the explained variance scores for each head and each cell type as returned by model.get_expl_variance_scores().
palette (str, optional) – The color palette to use for the barplot. Defaults to None.
cell_type_sub (list[str], optional) – A list of cell types to include in the barplot. Defaults to None.
wandb_log (bool, optional) – Whether to log the plot to Weights and Biases. Defaults to True.
show (bool, optional) – Whether to display the plot. Defaults to False.
save_png (bool, optional) – Whether to save the plot as a PNG file. Defaults to False.
save_svg (bool, optional) – Whether to save the plot as an SVG file. Defaults to False.
save_dir (str, optional) – The directory to save the plot files. Defaults to “./figures”.
- plot_featurewise_explained_variance_heatmap(cell_type_sub=None, n_top_genes=20, wandb_log=False, show=True, save_png=False, save_svg=False, save_dir='./figures')[source]#
Plots a heatmap of the explained variance scores for each head for n_top_genes genes.
- Parameters:
expl_variance_df (pd.DataFrame) – A DataFrame containing the explained variance scores for each head and each cell type as returned by `model.get_expl_variance_scores()”
cell_type_sub (list[str], optional) – A list of cell types for which to plot the heatmap.
n_top_genes (int, optional) – The number of top genes to include in the heatmap.
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. Defaults to “./figures”. Saves the filename as “expl_variance_heatmap_{cell_type}.png” or “expl_variance_heatmap_{cell_type}.svg”.