- spac.spatial_analysis.spatial_interaction(adata, annotation, analysis_method, stratify_by=None, ax=None, return_matrix=False, seed=None, coord_type=None, n_rings=1, n_neighs=6, radius=None, cmap='seismic', **kwargs)[source]
Perform spatial analysis on the selected annotation in the dataset. Current analysis methods are provided in squidpy:
Neighborhood Enrichment, Cluster Interaction Matrix
- Parameters:
adata (anndata.AnnData) – The AnnData object.
annotation (str) – The column name of the annotation (e.g., phenotypes) to analyze in the provided dataset.
analysis_method (str) – The analysis method to use, currently available: “Neighborhood Enrichment” and “Cluster Interaction Matrix”.
stratify_by (str or list of strs) – The annotation[s] to stratify the dataset when generating interaction plots. If single annotation is passed, the dataset will be stratified by the unique labels in the annotation column. If n (n>=2) annotations are passed, the function will be stratified based on existing combination of labels in the passed annotations.
ax (matplotlib.axes.Axes, default None) – The matplotlib Axes to display the image. This option is only available when stratify is None.
return_matrix (boolean, default False) – If true, the fucntion will return a list of two dictionaries, the first contains axes and the second containing computed matrix. Note that for Neighborhood Encrichment, the matrix will be a tuple with the z-score and the enrichment count. For Cluster Interaction Matrix, it will returns the interaction matrix. If False, the function will return only the axes dictionary.
seed (int, default None) – Random seed for reproducibility, used in Neighborhood Enrichment Analysis.
coord_type (str, optional) – Type of coordinate system used in sq.gr.spatial_neighbors. Should be either ‘grid’ (Visium Data) or ‘generic’ (Others). Default is None, decided by the squidy pacakge. If spatial_key is in anndata.uns the coord_type would be ‘grid’, otherwise general.
n_rings (int, default 1) – Number of rings of neighbors for grid data. Only used when coord_type = ‘grid’ (Visium)
n_neights (int, optional) – Default is 6. Depending on the
coord_type
: - ‘grid’ (Visium) - number of neighboring tiles. - ‘generic’ - number of neighborhoods for non-grid data.radius (float, optional) –
Default is None. Only available when coord_type = ‘generic’. Depending on the type: -
float
- compute the graph based on neighborhood radius. -tuple
- prune the final graph to only containedges in interval [min(radius), max(radius)].
cmap (str, default 'seismic') – The colormap to use for the plot. The ‘seismic’ color map consist of three color regions: red for positive, blue for negative, and the white at the center. This color map effectively represents the nature of the spatial interaction analysis results, where positive values indicate clustering and negative values indicate seperation. For more color maps, please visit https://matplotlib.org/stable/tutorials/colors/colormaps.html
**kwargs – Keyword arguments for matplotlib.pyplot.text()
- Returns:
A dictionary containing the results of the spatial interaction analysis. The keys of the dictionary depend on the parameters passed to the function:
- Axdict or matplotlib.axes.Axes
If stratify_by is not used, returns a single matplotlib.axes.Axes object. If stratify_by is used, returns a dictionary of Axes objects, with keys representing the stratification groups.
- Matrixdict, optional
Contains processed DataFrames of computed matrices with row and column labels applied. If stratify_by is used, the keys represent the stratification groups. For example: - results[‘Matrix’][‘GroupA’] for a specific stratification group. - If stratify_by is not used, the table is accessible via results[‘Matrix’][‘annotation’].
- Return type:
dict