Visualization

coral.utils.visualization.plot_spatial(adata, res: float = 0.1, size: float = 15, use_rep_for_cluster: str | None = None, to_plot_var: str | None = None, need_lognormed: bool | None = None, color_list: list[str] | None = None, figsize: tuple[float, float] = (4, 4), legd: bool = False, invert_yaxis: bool = True, axis_: bool = False, file_name: str | None = None, bbox_to_anchor: tuple[float, float] = (1.01, 0.8), legend_fontsize: int = 10, legend_markerscale: float = 5, return_cluster: bool = False, n_neighbors: int = 100, dpi: int = 150)

Plot spatial clusters from a spatial transcriptomics AnnData object.

Parameters:
  • adata (AnnData) – The annotated data matrix with .obsm[‘spatial’] coordinates.

  • res (float, optional) – Resolution parameter for Leiden clustering (default: 0.1).

  • size (float, optional) – Marker size in the scatter plot (default: 15).

  • use_rep_for_cluster (str or None, optional) – Key in adata.obsm to use for neighbor graph computation (e.g. ‘X_pca’). If None, PCA will be computed automatically.

  • need_lognormed (bool or None, optional) – If True, applies Scanpy’s total count normalization and log1p. If None, assumes pre-normalized input.

  • color_list (list of str, optional) – List of colors for clusters. If None, a default color palette will be used.

  • figsize (tuple, optional) – Figure size in inches (default: (4, 4)).

  • legd (bool, optional) – Whether to display the legend (default: False).

  • return (bool, optional) – If True, returns (fig, ax, adata_) instead of displaying only.

  • invert_yaxis (bool, optional) – Whether to invert y-axis (default: True, consistent with spatial plots).

  • axis (bool, optional) – Whether to display axis ticks and frames (default: False).

  • file_name (str or None, optional) – Optional path to save the figure (e.g. “spatial_cluster.pdf”).

  • bbox_to_anchor (tuple, optional) – Anchor position of the legend (default: (1.01, 0.8)).

  • legend_fontsize (int, optional) – Font size of legend labels (default: 10).

  • legend_markerscale (float, optional) – Scale factor of legend markers (default: 5).

Returns:

fig, ax, adata_ – Returned only if return_ is True.

Return type:

tuple

coral.utils.visualization.plot_umap(adata, res: float = 0.1, size: float = 15, use_rep_for_cluster: str | None = None, to_plot_var: str | None = None, need_lognormed: bool | None = None, color_list: list[str] | None = None, figsize: tuple[float, float] = (4, 4), legd: bool = False, return_: bool = False, invert_yaxis: bool = True, axis_: bool = False, file_name: str | None = None, bbox_to_anchor: tuple[float, float] = (1.01, 0.8), legend_fontsize: int = 10, legend_markerscale: float = 5, dpi: int = 150)

Plot spatial clusters from a spatial transcriptomics AnnData object.

Parameters:
  • adata (AnnData) – The annotated data matrix with .obsm[‘spatial’] coordinates.

  • res (float, optional) – Resolution parameter for Leiden clustering (default: 0.1).

  • size (float, optional) – Marker size in the scatter plot (default: 15).

  • use_rep (str or None, optional) – Key in adata.obsm to use for neighbor graph computation (e.g. ‘X_pca’). If None, PCA will be computed automatically.

  • need_lognormed (bool or None, optional) – If True, applies Scanpy’s total count normalization and log1p. If None, assumes pre-normalized input.

  • color_list (list of str, optional) – List of colors for clusters. If None, a default color palette will be used.

  • figsize (tuple, optional) – Figure size in inches (default: (4, 4)).

  • legd (bool, optional) – Whether to display the legend (default: False).

  • return (bool, optional) – If True, returns (fig, ax, adata_) instead of displaying only.

  • invert_yaxis (bool, optional) – Whether to invert y-axis (default: True, consistent with spatial plots).

  • axis (bool, optional) – Whether to display axis ticks and frames (default: False).

  • file_name (str or None, optional) – Optional path to save the figure (e.g. “spatial_cluster.pdf”).

  • bbox_to_anchor (tuple, optional) – Anchor position of the legend (default: (1.01, 0.8)).

  • legend_fontsize (int, optional) – Font size of legend labels (default: 10).

  • legend_markerscale (float, optional) – Scale factor of legend markers (default: 5).

Returns:

fig, ax, adata_ – Returned only if return_ is True.

Return type:

tuple

coral.utils.visualization.plot_latent_umap(adata, rep='X', to_plot_var='cluster', custom_palette=['#f4f1de', '#81b29a', '#f2cc8f', '#e07a5f', '#3d405b'], dpi=150)
coral.utils.visualization.plot_umap_gene(adata, res: float = 0.1, size: float = 15, use_rep_for_cluster: str | None = None, to_plot_gene: str | None = None, need_lognormed: bool | None = None, color_list: list[str] | None = None, figsize: tuple[float, float] = (4, 4), legd: bool = False, return_: bool = False, invert_yaxis: bool = True, axis_: bool = False, file_name: str | None = None, bbox_to_anchor: tuple[float, float] = (1.01, 0.8), legend_fontsize: int = 10, legend_markerscale: float = 5, vmin: float = 0, vmax: float | None = None, dpi: int = 150)
coral.utils.visualization.display_reconst(df_true, df_pred, density=False, marker_genes=None, sample_rate=0.01, size=(4, 4), spot_size=1, title=None, x_label='', y_label='', min_val=None, max_val=None)

Scatter plot - raw gexp vs. reconstructed gexp

coral.utils.visualization.visualize_subgraph(data)
coral.utils.visualization.compare_gene_expression_all(original_data, generated_data, gene_indices, gene_names, mean_bool=False)
coral.utils.visualization.compare_gene_expression(original_data, generated_data, gene_indices, gene_names)