ktplotspy.plot.plot_cpdb

ktplotspy.plot.plot_cpdb(adata, cell_type1, cell_type2, means, pvals, celltype_key, interaction_scores=None, cellsign=None, degs_analysis=False, splitby_key=None, alpha=0.05, keep_significant_only=True, genes=None, gene_family=None, custom_gene_family=None, standard_scale=True, cluster_rows=True, cmap_name='viridis', max_size=8, max_highlight_size=3, default_style=True, highlight_col='#d62728', highlight_size=None, special_character_regex_pattern=None, exclude_interactions=None, title='', return_table=False, figsize=(6.4, 4.8), min_interaction_score=0, scale_alpha_by_interaction_scores=False, scale_alpha_by_cellsign=False, filter_by_cellsign=False, keep_id_cp_interaction=False)[source]

Plotting CellPhoneDB results as a dot plot.

Parameters:
  • adata (AnnData) – AnnData object with the .obs storing the celltype_key with or without splitby_key. The .obs_names must match the first column of the input meta.txt used for CellPhoneDB.

  • cell_type1 (str) – Name of cell type 1. Accepts regex pattern.

  • cell_type2 (str) – Name of cell type 1. Accepts regex pattern.

  • means (pd.DataFrame) – Data frame corresponding to means.txt from CellPhoneDB.

  • pvals (pd.DataFrame) – Data frame corresponding to pvalues.txt or relevant_interactions.txt from CellPhoneDB.

  • celltype_key (str) – Column name in adata.obs storing the celltype annotations. Values in this column should match the second column of the input meta.txt used for CellPhoneDB.

  • interaction_scores (Optional[pd.DataFrame], optional) – Data frame corresponding to interaction_scores.txt from CellPhoneDB version 5 onwards.

  • cellsign (Optional[pd.DataFrame], optional) – Data frame corresponding to CellSign.txt from CellPhoneDB version 5 onwards.

  • degs_analysis (bool, optional) – Whether CellPhoneDB was run in deg_analysis mode.

  • splitby_key (Optional[str], optional) – If provided, will attempt to split the output plot/table by groups. In order for this to work, the second column of the input meta.txt used for CellPhoneDB MUST be this format: {splitby}_{celltype}.

  • alpha (float, optional) – P value threshold value for significance.

  • keep_significant_only (bool, optional) – Whether or not to trim to significant (p<0.05) hits.

  • genes (Optional[str], optional) – If provided, will attempt to plot only interactions containing the specified gene(s).

  • gene_family (Optional[Literal[“chemokines”, “th1”, “th2”, “th17”, “treg”, “costimulatory”, “coinhibitory”]], optional) – If provided, will attempt to plot a predetermined set of chemokines or genes associated with Th1, Th2, Th17, Treg, costimulatory or coinhibitory molecules.

  • custom_gene_family (Optional[Dict[str, List[str]]], optional) – If provided, will update the gene_family dictionary with this custom dictionary. Both gene_family (name of the custom family) and custom_gene_family (dictionary holding this new family) must be specified for this to work.

  • standard_scale (bool, optional) – Whether or not to scale the mean interaction values from 0 to 1 per receptor-ligand variable.

  • cluster_rows (bool, optional) – Whether or not to cluster the rows (interactions).

  • cmap_name (str, optional) – Matplotlib built-in colormap names.

  • max_size (int, optional) – Maximum size of points in plot.

  • max_highlight_size (int, optional) – Maximum highlight size of points in plot.

  • default_style (bool, optional) – Whether or not to plot in default style or inspired from squidpy’s plotting style.

  • highlight_col (str, optional) – Colour of highlights marking significant hits.

  • highlight_size (Optional[int], optional) – Size of highlights marking significant hits.

  • special_character_regex_pattern (Optional[str], optional) – Regex string pattern to perform substitution. This option should not realy be used unless there is really REALLY special characters that you really REALLY want to keep. Rather than using this option, the easiest way is to not your celltypes with weird characters. Just use alpha numeric characters and underscores if necessary.

  • exclude_interactions (Optional[Union[List, str]], optional) – If provided, the interactions will be removed from the output.

  • title (str, optional) – Plot title.

  • return_table (bool, optional) – Whether or not to return the results as a dataframe.

  • figsize (Tuple[Union[int, float], Union[int, float]], optional) – Figure size.

  • min_interaction_score (int, optional) – Filtering the interactions shown by including only those above the given interaction score.

  • scale_alpha_by_interaction_scores (bool, optional) – Whether or not to filter values by the interaction score.

  • scale_alpha_by_cellsign (bool, optional) – Whether or not to filter the transparency of interactions by the cellsign.

  • filter_by_cellsign (bool, optional) – Filter out interactions with a 0 value cellsign.

  • keep_id_cp_interaction (bool, optional) – Whether to keep the original id_cp_interaction value when plotting.

Returns:

Either a plotnine ggplot plot or a pandas Data frame holding the results.

Return type:

Union[ggplot, pd.DataFrame]

Raises:

KeyError – If genes and gene_family are both provided, wrong key for gene family provided, or if interaction_score and cellsign are both provided the error will occur.