spateo.plotting.static.interactions
#
Plots to visualize results from cell-cell colocalization based analyses, as well as cell-cell communication inference-based analyses. Makes use of dotplot-generating functions
Module Contents#
Functions#
|
Plot spatial_connections between labels- visualization of how closely labels are colocalized |
|
Dotplot for visualizing results of ligand-receptor interaction analysis |
- spateo.plotting.static.interactions.plot_connections(adata: anndata.AnnData, cat_key: str, spatial_key: str = 'spatial', n_spatial_neighbors: Union[None, int] = 6, spatial_weights_matrix: Union[None, scipy.sparse.csr_matrix, numpy.ndarray] = None, expr_weights_matrix: Union[None, scipy.sparse.csr_matrix, numpy.ndarray] = None, reverse_expr_plot_orientation: bool = False, ax: Union[None, matplotlib.axes.Axes] = None, figsize: tuple = (3, 3), zero_self_connections: bool = True, normalize_by_self_connections: bool = False, shapes_style: bool = True, label_outline: bool = False, max_scale: float = 0.46, colormap: Union[str, dict, matplotlib.colormap] = 'Spectral', title_str: Union[None, str] = None, title_fontsize: Union[None, float] = None, label_fontsize: Union[None, float] = None, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[dict] = {})[source]#
Plot spatial_connections between labels- visualization of how closely labels are colocalized
- Parameters
- adata
AnnData object
- cat_key
Key in .obs containing categorical grouping labels. Colocalization will be assessed for pairwise combinations of these labels.
- spatial_key
Key in .obsm containing coordinates in the physical space. Not used unless ‘spatial_weights_matrix’ is None, in which case this is required. Defaults to “spatial”.
- n_spatial_neighbors
Optional, number of neighbors in the physical space for each cell. Not used unless ‘spatial_weights_matrix’ is None.
- spatial_weights_matrix
Spatial distance matrix, weighted by distance between spots. If not given, will compute at runtime.
- expr_weights_matrix
Gene expression distance matrix, weighted by distance in transcriptomic or PCA space. If not given, only the spatial distance matrix will be plotted. If given, will plot the spatial distance matrix in the left plot and the gene expression distance matrix in the right plot.
- reverse_expr_plot_orientation
If True, plot the gene expression connections in the form of a lower right triangle. If False, gene expression connections will be an upper left triangle just like the spatial connections.
- ax
Existing axes object, if applicable
- figsize
Width x height of desired figure window in inches
- zero_self_connections
If True, ignores intra-label interactions
- normalize_by_self_connections
Only used if ‘zero_self_connections’ is False. If True, normalize intra-label connections by the number of spots of that label
- shapes_style
If True plots squares, if False plots heatmap
- label_outline
If True, gives dark outline to axis tick label text
- max_scale
Only used for the case that ‘shape_style’ is True, gives maximum size of square
- colormap
Specifies colors to use for plotting. If dictionary, keys should be numerical labels corresponding to those of the Label object.
- title_str
Optionally used to give plot a title
- title_fontsize
Size of plot title- only used if ‘title_str’ is given.
- label_fontsize
Size of labels along the axes of the graph
- save_show_or_return
Whether to save, show or return the figure. If “both”, it will save and plot the figure at the same time. If “all”, the figure will be saved, displayed and the associated axis and other object will be return.
- save_kwargs
A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise you can provide a dictionary that properly modifies those keys according to your needs.
- Returns
Returns plot and axis object if ‘save_show_or_return’ is “all”
- Return type
(fig, ax)
- spateo.plotting.static.interactions.ligrec(adata: anndata.AnnData, dict_key: str, source_groups: Union[None, str, List[str]] = None, target_groups: Union[None, str, List[str]] = None, means_range: Tuple[float, float] = (-np.inf, np.inf), pvalue_threshold: float = 1.0, remove_empty_interactions: bool = True, remove_nonsig_interactions: bool = False, dendrogram: Union[None, str] = None, alpha: float = 0.001, swap_axes: bool = False, title: Union[None, str] = None, figsize: Union[None, Tuple[float, float]] = None, save_show_or_return: Literal[save, show, return, both, all] = 'show', save_kwargs: Optional[ligrec.dict] = {}, **kwargs)[source]#
Dotplot for visualizing results of ligand-receptor interaction analysis
For each L:R pair on the dotplot, molecule 1 is sent from the cluster(s) labeled on the top of the plot (or on the right, if ‘swap_axes’ is True), whereas molecule 2 is the receptor on the cluster(s) labeled on the bottom.
- Parameters
- adata
Object of :class anndata.AnnData
- dict_key
Key in .uns to dictionary containing cell-cell communication information. Should contain keys labeled “means” and “pvalues”, with values being dataframes for the mean cell type-cell type L:R product and significance values.
- source_groups
Source interaction clusters. If None, select all clusters.
- target_groups
Target interaction clusters. If None, select all clusters.
- means_range
Only show interactions whose means are within this closed interval
- pvalue_threshold
Only show interactions with p-value <= pvalue_threshold
- remove_empty_interactions
Remove rows and columns that contain NaN values
- remove_nonsig_interactions
Remove rows and columns that only contain interactions that are larger than alpha
- dendrogram
How to cluster based on the p-values. Valid options are: - None (no input) - do not perform clustering. - ‘interacting_molecules’ - cluster the interacting molecules. - ‘interacting_clusters’ - cluster the interacting clusters. - ‘both’ - cluster both rows and columns. Note that in this case, the dendrogram is not shown.
- alpha
Significance threshold. All elements with p-values <= alpha will be marked by tori instead of dots.
- swap_axes
Whether to show the cluster combinations as rows and the interacting pairs as columns
- title
Title of the plot
- figsize
The width and height of a figure
- save_show_or_return
Options: “save”, “show”, “return”, “both”, “all” - “both” for save and show
- save_kwargs
A dictionary that will passed to the save_fig function. By default it is an empty dictionary and the save_fig function will use the {“path”: None, “prefix”: ‘scatter’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. But to change any of these parameters, this dictionary can be used to do so.
- kwargs
Keyword arguments for :func style or :func legend of :class Dotplot