spatialHeterogeneity.plotting.visualization module

Summary

Functions:

channel

Plot challnels.

get_cmap

Return the cmap and cmap labels for a given attribute if available, else a default

infiltration

Visualises a heatmap of the featuer intensity.

interactions

Visualise interaction results.

napari_viewer

Starts interactive Napari viewer to visualise raw images

ripleysK

Plot results

spatial

Visualisation of samples.

Reference

spatial(so, spl, attr, *, mode='scatter', node_size=4, coordinate_keys=['x', 'y'], mask_key='cellmasks', graph_key='knn', edges=False, edge_width=0.5, edge_color='black', edge_zorder=2, background_color='white', ax=None, norm=None, set_title=True, cmap=None, cmap_labels=None, cbar=True, cbar_title=True, show=True, save=None, tight_layout=True)[source]

Visualisation of samples.

Parameters
  • so – SpatialOmics instance

  • spl (str) – sample to visualise

  • attr (str) – feature to visualise

  • mode (str) – {scatter, mask}. In scatter mode, observations are represented by their centroid, in mask mode by their actual segmentation mask

  • node_size (float) – size of the node when plotting the graph representation

  • coordinate_keys (list) – column names in SpatialOmics.obs[spl] that indicates the x and y coordinates

  • mask_key (str) – key for the segmentation masks when in mask mode

  • graph_key (str) – which graph representation to use

  • edges (bool) – whether to plot the graph or not

  • edge_width (float) – width of edges

  • edge_color (str) – color of edges as string

  • edge_zorder (int) – z-order of edges

  • background_color (str) – background color of plot

  • ax (Optional[Axes]) – axes object in which to plot

  • norm – normalisation instance to normalise the values of attr

  • set_title (bool) – title of plot

  • cmap – colormap to use

  • cmap_labels (Optional[list]) – colormap labels to use

  • cbar (bool) – whether to plot a colorbar or not

  • cbar_title (bool) – whether to plot the attr name as title of the colorbar

  • show (bool) – whether to show the plot or not

  • save (Optional[str]) – path to the file in which the plot is saved

  • tight_layout (bool) – whether to apply tight_layout or not.

Returns:

napari_viewer(so, spl, attrs, censor=0.95, add_masks='cellmasks', attrs_key='target', index_key='fullstack_index')[source]

Starts interactive Napari viewer to visualise raw images

Parameters
  • so – SpatialOmics instance

  • spl (str) – sample to visualise

  • attrs (list) – list of attributes to add as channels to the viewer

  • censor (float) – percentil to use to censore pixle values in the raw images

  • add_masks – segmentation masks to add as channels to the viewer

Returns:

channel(so, spl, attrs, ax=None, colors=None, censor=None, show=True)[source]

Plot challnels. Decreapted, will be removed.

Parameters
  • so

  • spl (str) –

  • attrs (str) –

  • ax

  • colors

  • censor (Optional[float]) –

  • show

Returns:

interactions(so, spl, attr, mode='proportion', prediction_type='diff', graph_key='knn', linewidths=0.5, cmap=None, norm=None, ax=None, show=True)[source]

Visualise interaction results.

Parameters
  • so – SpatialOmics instance

  • spl – Spl for which to compute the metric

  • attr – Categorical feature in SpatialOmics.obs to use for the grouping

  • mode – One of {classic, histoCAT, proportion}, see notes

  • prediction_type – prediction_type: One of {observation, pvalue, diff}

  • graph_key – Specifies the graph representation to use in so.G[spl]

  • linewidths – Space between tiles

  • cmap – colormap to use

  • norm – normalisation to use

  • ax – axes object to use

  • show – whether to show the plot

Returns:

get_cmap(so, attr, data)[source]

Return the cmap and cmap labels for a given attribute if available, else a default

Parameters
  • so (IMCData) – so object form which to fetch the data

  • spl (str) – spl for which to get data

  • attr (str) – attribute for which to get the cmap and cmap labels if available

Returns

Return type

cmap and cmap labels for attribute

ripleysK(so, spl, attr, ids, *, mode='K', correction='ripley', key=None, ax=None, legend='auto')[source]

Plot results

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

  • attr (str) – Categorical feature in SpatialOmics.obs to use for the grouping

  • ids – The category in the categorical feature attr, for which Ripley’s K should be plotted

  • mode – {K, csr-deviation}. If K, Ripley’s K is estimated, with csr-deviation the deviation from a poission process is computed.

  • correction – Correction method to use to correct for boarder effects, see [1].

  • key – key to use in so.uns[‘ripleysK’] for the plot, if None it is constructed from spl,attr,ids,mode and correction

  • ax – axes to use for the plot

Returns

None

infiltration(so, spl, attr='infiltration', step_size=10, interpolation='gaussian', cmap='plasma', collision_strategy='mean', ax=None, show=True)[source]

Visualises a heatmap of the featuer intensity.

Approximates the sample with a grid representation and colors each grid square according to the value of the attribute. If multiple observations map to the same grid square a the aggregation specified in collision_strategy is employed (any value accepted by pandas aggregate function, i.e. ‘mean’, ‘max’, …)

Parameters
  • so – SpatialOmics instance

  • spl (str) – Spl for which to compute the metric

  • attr (str) – feature in SpatialOmics.obs to plot

  • step_size (int) – grid step size

  • interpolation (str) – interpolation method to use between grid values, see [1]

  • cmap (str) – colormap to use

  • collision_strategy – aggragation strategy to use if multiple obseravtion values map to the same grid value

  • ax – axes to use for the plot

  • show – whether to show the plot or not. Will be set to False if axes is provided.

Returns

None

Notes

1

https://matplotlib.org/stable/gallery/images_contours_and_fields/interpolation_methods.html