athena.plotting.visualization module¶
Summary¶
Functions:
Return the cmap and cmap labels for a given attribute if available, else a default |
|
Visualises a heatmap of the featuer intensity. |
|
Visualise results from |
|
Starts interactive Napari viewer to visualise raw images and explore samples. |
|
Visualise results from |
|
Various functionalities to visualise 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]¶ Various functionalities to visualise samples. Allows to visualise the samples and color observations according to features in either so.X or so.obs by setting the
attrparameter accordingly. Furthermore, observations (cells) within a sample can be quickly visualised using scatter plots (requires extraction of centroids withextract_centroids()) or by their actual segmentatio mask by settingmodeaccordingly. Finally, the graph representation of the sample can be overlayed by settingedges=Trueand specifing thegraph_keyas inso.G[spl][graph_key].For more examples on how to use this function have a look at the tutorial section.
- Parameters
so – SpatialOmics instance
spl (
str) – sample to visualiseattr (
str) – feature to visualisemode (
str) – {scatter, mask}. In scatter mode, observations are represented by their centroid, in mask mode by their actual segmentation masknode_size (
float) – size of the node when plotting the graph representationcoordinate_keys (
list) – column names in SpatialOmics.obs[spl] that indicates the x and y coordinatesmask_key (
str) – key for the segmentation masks when in mask modegraph_key (
str) – which graph representation to useedges (
bool) – whether to plot the graph or notedge_width (
float) – width of edgesedge_color (
str) – color of edges as stringedge_zorder (
int) – z-order of edgesbackground_color (
str) – background color of plotax (
Optional[Axes]) – axes object in which to plotnorm – normalisation instance to normalise the values of attr
set_title (
bool) – title of plotcmap – colormap to use
cmap_labels (
Optional[list]) – colormap labels to usecbar (
bool) – whether to plot a colorbar or notcbar_title (
bool) – whether to plot the attr name as title of the colorbarshow (
bool) – whether to show the plot or notsave (
Optional[str]) – path to the file in which the plot is savedtight_layout (
bool) – whether to apply tight_layout or not.
Examples
so = sh.dataset.imc() sh.pl.spatial(so, 'slide_7_Cy2x2', 'meta_id', mode='mask') sh.pl.spatial(so, 'slide_7_Cy2x2', 'meta_id', mode='scatter', edges=True)
-
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 and explore samples.
attrsare measured features in the high dimensional images inso.images[spl]. All specifiedattrsshould be inso.var[spl][attrs_key]along with the index in the high dimensional images. The column with the index in the high dimensional image where the measurement of an attribute is stored.- Parameters
so – SpatialOmics instance
spl (
str) – sample to visualiseattrs (
list) – list of attributes/features to add as channels to the viewercensor (
float) – percentil to use to censore pixle values in the raw imagesadd_masks – segmentation masks to add as channels to the viewer
attrs_key – key in
so.var[spl]that defines theattrsnamesindex_key (
str) – key inso.var[spl]that specifies the layer index in the high dimensional image inso.images[spl].
Examples:
so = sh.dataset.imc() spl = so.spl.index[0] # add all measured features to the napari viewer sh.pl.napari_viewer(so, spl, attrs=so.var[spl]['target'], add_masks=so.masks[spl].keys()) # specify the column containing the ``attrs`` names sh.pl.napari_viewer(so, spl, attrs=so.var[spl]['target'], attrs_key='target') # specify the column containing the ``attrs`` names and the columns that specifies the layer index sh.pl.napari_viewer(so, spl, attrs=so.var[spl]['target'], attrs_key='target', index_key='fullstack_index')
-
interactions(so, spl, attr, mode='proportion', prediction_type='diff', graph_key='knn', linewidths=0.5, cmap=None, norm=None, ax=None, show=True, cbar=True)[source]¶ Visualise results from
interactions()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
cbar – wheter to show the colorbar
Examples
# compute Ripley's K so = sh.dataset.imc() spl = so.spl.index[0] # build graph sh.graph.build_graph(so, spl, builder_type='knn', mask_key='cellmasks') # compute & plot interactions sh.neigh.interactions(so, spl, 'meta_id', mode='proportion', prediction_type='observation') sh.pl.interactions(so, spl, 'meta_id', mode='proportion', prediction_type='observation')
-
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]¶ Visualise results from
ripleysK()results.- Parameters
so – SpatialOmics instance
spl (
str) – Spl for which to compute the metricattr (
str) – Categorical feature in SpatialOmics.obs to use for the groupingids – 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
Examples
# compute Ripley's K so = sh.dataset.imc() sh.neigh.ripleysK(so, so.spl.index[0], 'meta_id', 1, mode='csr-deviation', radii=radii) sh.pl.ripleysK(so, so.spl.index[0], 'meta_id', [1], mode='csr-deviation')
-
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 metricattr (
str) – feature in SpatialOmics.obs to plotstep_size (
int) – grid step sizeinterpolation (
str) – interpolation method to use between grid values, see [1]cmap (
str) – colormap to usecollision_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.
Examples
so = sh.dataset.imc() spl = so.spl.index[0] # build graph sh.graph.build_graph(so, spl, builder_type='knn', mask_key='cellmasks') sh.neigh.infiltration(so, spl, 'meta_id', graph_key='knn') sh.pl.infiltration(so, spl, step_size=10)
Notes