The Spatial Neighbor Distance extension can be used to compute Euclidean spatial distances from cells of a given cell type to their nearest neighbor of another cell type.

In the diagram to the right, *d* represents the distance from a cell of type A (the “from” cell type) to its nearest neighbor of type B (the “to” cell type).

Our algorithm will, for every cell of the “from” type:

- Find its nearest neighbor of the “to” type
- Compute the Euclidean distance between the “from” cell to this nearest neighbor cell

To configure a new run, specify:

- A run name.
- (optional) A description of the run.
- The regions to include in the computation.
- Annotation set in which the “from” cell type is defined (e.g. “Clustering 1”).
- The “from” cell type (e.g. “T cells”).
- Annotation set in which the “to” cell type is defined (e.g. “Clustering 1”).
- The “to” cell type (e.g. “Macrophages”).

Once you’ve completed the form, press `Launch Cell Distance Computation`

to kick off the run.

For each cell of the “from” cell type, the extension will first find its nearest neighbor of the “to” cell type and then compute the distance between the two cells in microns.

<aside> ⚠️ If the “from” and “to” annotations are derived from different annotation sets, it may be possible for some cells to have both “from” and “to” annotations. Any cells that have both labels will be excluded from the distance computation.

Also note that the “from” and “to” annotation sets must be derived from the same segmentation run, e.g. they must annotate the same set of cells.

</aside>

You should now see your new run in the `Cell Distance Run`

dropdown. You’ll receive a notification once the distances have been computed.

Once computation is complete, you’ll be able to view the distribution of distances for each cell of the “from” type to its nearest “to” cell within a given region in the kernel density estimate (KDE) plot to the right. Use the `Region`

dropdown to toggle between regions. The x-axis scale should remain constant between regions.

You can also download a CSV file containing statistics summarizing the distribution of cell distances within each region by clicking the `Download Summary`

button below the configuration card.

This includes:

- Mean
- Median
- Standard deviation
- Minimum distance
- Maximum distance

To edit the annotation name or description, click the `Edit`

button.

Each run will generate cell annotations where every cell of the “from” type will be annotated with the distance to its nearest neighbor of the “to” type. For all other cells that are not of the “from” type, the value will be `NULL`

. These annotations can be downloaded from the Analysis Version Metadata tab under your Study Details page.

<aside> ⚠️ If you plan to analyze these annotations using Workbench, note that SpatialMap does not support annotations that are generated from different biomarker expression versions (e.g. both “T cell” and “Macrophage” cell annotations must be derived from annotations done on “Biomarker Expression Version 1” to be ingested by SpatialMap)

</aside>

Return to **Home Directory**