squidpy.gr.spatial_neighbors
- squidpy.gr.spatial_neighbors(adata, spatial_key='spatial', library_key=None, coord_type=None, n_neighs=6, radius=None, delaunay=False, n_rings=1, transform=None, set_diag=False, key_added='spatial', copy=False)[source]
Create a graph from spatial coordinates.
- Parameters:
adata (
AnnData
) – Annotated data object.spatial_key (
str
) – Key inanndata.AnnData.obsm
where spatial coordinates are stored.library_key (
Optional
[str
]) – If multiple library_id, column inanndata.AnnData.obs
which stores mapping betweenlibrary_id
and obs.coord_type (
Union
[str
,CoordType
,None
]) –Type of coordinate system. Valid options are:
’grid’ - grid coordinates.
’generic’ - generic coordinates.
None - ‘grid’ if
spatial_key
is inanndata.AnnData.uns
withn_neighs = 6
(Visium), otherwise use ‘generic’.
n_neighs (
int
) –Depending on the
coord_type
:’grid’ - number of neighboring tiles.
’generic’ - number of neighborhoods for non-grid data. Only used when
delaunay = False
.
radius (
Union
[float
,tuple
[float
,float
],None
]) –Only available when
coord_type = 'generic'
. Depending on the type:delaunay (
bool
) – Whether to compute the graph from Delaunay triangulation. Only used whencoord_type = 'generic'
.n_rings (
int
) – Number of rings of neighbors for grid data. Only used whencoord_type = 'grid'
.transform (
Union
[str
,Transform
,None
]) –Type of adjacency matrix transform. Valid options are:
’spectral’ - spectral transformation of the adjacency matrix.
’cosine’ - cosine transformation of the adjacency matrix.
None - no transformation of the adjacency matrix.
set_diag (
bool
) – Whether to set the diagonal of the spatial connectivities to 1.0.key_added (
str
) – Key which controls where the results are saved ifcopy = False
.copy (
bool
) – IfTrue
, return the result, otherwise save it to theadata
object.
- Return type:
- Returns:
: If
copy = True
, returns atuple
with the spatial connectivities and distances matrices.Otherwise, modifies the
adata
with the following keys:anndata.AnnData.obsp
['{key_added}_connectivities']
- the spatial connectivities.anndata.AnnData.obsp
['{key_added}_distances']
- the spatial distances.anndata.AnnData.uns
['{key_added}']
-dict
containing parameters.