Skip to contents

Use k-means clustering to cluster local indicators of spatial association. For other clustering use lisa.

Usage

lisaClust(
  cells,
  k = 2,
  Rs = NULL,
  spatialCoords = c("x", "y"),
  cellType = "cellType",
  imageID = "imageID",
  regionName = "region",
  BPPARAM = BiocParallel::SerialParam(),
  window = "convex",
  window.length = NULL,
  whichParallel = "imageID",
  sigma = NULL,
  lisaFunc = "K",
  minLambda = 0.05,
  fast = TRUE
)

Arguments

cells

A SingleCellExperiment, SpatialExperiment or data frame that contains at least the variables x and y, giving the coordinates of each cell, imageID and cellType.

k

The number of regions to cluster.

Rs

A vector of the radii that the measures of association should be calculated.

spatialCoords

The columns which contain the x and y spatial coordinates.

cellType

The column which contains the cell types.

imageID

The column which contains image identifiers.

regionName

The output column for the lisaClust regions.

BPPARAM

A BiocParallelParam object.

window

Should the window around the regions be 'square', 'convex' or 'concave'.

window.length

A tuning parameter for controlling the level of concavity when estimating concave windows.

whichParallel

Should the function use parallization on the imageID or the cellType.

sigma

A numeric variable used for scaling when filting inhomogeneous L-curves.

lisaFunc

Either "K" or "L" curve.

minLambda

Minimum value for density for scaling when fitting inhomogeneous L-curves.

fast

A logical describing whether to use a fast approximation of the inhomogeneous local L-curves.

Value

A matrix of LISA curves

Examples

library(spicyR)
library(SingleCellExperiment)
# Read in data
isletFile <- system.file("extdata", "isletCells.txt.gz", package = "spicyR")
cells <- read.table(isletFile, header = TRUE)
cellExp <- SingleCellExperiment(
    assay = list(intensities = t(cells[, grepl(names(cells), pattern = "Intensity_")])),
    colData = cells[, !grepl(names(cells), pattern = "Intensity_")]
)

# Cluster cell types
markers <- t(assay(cellExp, "intensities"))
kM <- kmeans(markers, 8)
colData(cellExp)$cluster <- paste("cluster", kM$cluster, sep = "")

# Generate LISA
cellExp <- lisaClust(cellExp,
    k = 2,
    imageID = "ImageNumber",
    cellType = "cluster",
    spatialCoords = c("Location_Center_X", "Location_Center_Y")
)
#> Generating local L-curves.