spicyR 1.8.0

```
if (!require("BiocManager"))
install.packages("BiocManager")
BiocManager::install("spicyR")
```

```
# load required packages
library(spicyR)
library(lisaClust)
library(ggplot2)
```

Clustering local indicators of spatial association (LISA) functions is a
methodology for identifying consistent spatial organisation of multiple
cell-types in an unsupervised way. This can be used to enable the
characterization of interactions between multiple cell-types simultaneously and
can complement traditional pairwise analysis. In our implementation our LISA
curves are a localised summary of an L-function from a Poisson point process
model. Our framework `lisaClust`

can be used to provide a high-level summary
of cell-type colocalization in high-parameter spatial cytometry data,
facilitating the identification of distinct tissue compartments or
identification of complex cellular microenvironments.

TO illustrate our `lisaClust`

framework, here we consider a very simple toy
example where two cell-types are completely separated spatially. We simulate
data for two different images.

```
set.seed(51773)
x <- round(c(runif(200),runif(200)+1,runif(200)+2,runif(200)+3,
runif(200)+3,runif(200)+2,runif(200)+1,runif(200)),4)*100
y <- round(c(runif(200),runif(200)+1,runif(200)+2,runif(200)+3,
runif(200),runif(200)+1,runif(200)+2,runif(200)+3),4)*100
cellType <- factor(paste('c',rep(rep(c(1:2),rep(200,2)),4),sep = ''))
imageID <- rep(c('s1', 's2'),c(800,800))
cells <- data.frame(x, y, cellType, imageID)
ggplot(cells, aes(x,y, colour = cellType)) + geom_point() + facet_wrap(~imageID)
```

First we store our data in a `SegmentedCells`

object.

```
cellExp <- SegmentedCells(cells, cellTypeString = 'cellType')
```

We can then calculate local indicators of spatial association (LISA) functions
using the `lisa`

function. Here the LISA curves are a
localised summary of an L-function from a Poisson point process model. The radii
that will be calculated over can be set with `Rs`

.

```
lisaCurves <- lisa(cellExp, Rs = c(20, 50, 100))
```

The LISA curves can then be used to cluster the cells. Here we use k-means
clustering, other clustering methods like SOM could be used. We can store these
cell clusters or cell “regions” in our `SegmentedCells`

object using the
`region() <-`

function.

```
kM <- kmeans(lisaCurves,2)
region(cellExp) <- paste('region',kM$cluster,sep = '_')
```

The `hatchingPlot`

function can be used to construct a `ggplot`

object where the
regions are marked by different hatching patterns. This allows us to plot both
regions and cell-types on the same visualization.

`hatchingPlot(cellExp, imageID = c('s1','s2'))`