Extracts what DenMark needs from a Seurat object with imaging-based spatial
data, such as Xenium, MERSCOPE or CosMx data loaded with LoadXenium(),
LoadVizgen() or LoadNanostring(): the cell centroids, a cell-type label
and the raw counts, one row per cell. Compute the tissue boundary from all
rows with denmark_alpha_shape(), then analyze the cells of one type.
Arguments
- object
A Seurat object with a field of view holding cell centroids.
- celltype
Name of the column of the cell metadata that holds the cell types, for example the result of a clustering or an annotation.
- genes
Genes to include (default: all features of the assay). Each gene becomes a dense column, so select genes for whole-transcriptome panels.
- assay
Assay holding the raw counts (default: the default assay).
- fov
Field of view holding the cell centroids (default: the first).
Value
Data frame with the columns x, y (in the units of the field of
view, micrometers for Xenium), celltype and one count column per gene,
with the cell names as row names.
See also
denmark_annotate() to write the results of denmark_scan() back
into the object.
Examples
# a small Seurat object built from the toy data
toy <- denmark_toy_data()
counts <- Matrix::Matrix(t(as.matrix(toy[, c("geneA", "geneB", "geneC")])),
sparse = TRUE)
colnames(counts) <- paste0("cell", seq_len(nrow(toy)))
obj <- SeuratObject::CreateSeuratObject(counts = counts)
obj$celltype <- toy$celltype
obj[["fov"]] <- SeuratObject::CreateFOV(
SeuratObject::CreateCentroids(data.frame(x = toy$x, y = toy$y, cell = colnames(counts))),
type = "centroids", assay = "RNA")
cells <- denmark_from_seurat(obj, celltype = "celltype")
head(cells)
#> x y celltype geneA geneB geneC
#> cell1 4.958866 2.517796 Tumor 3 1 1
#> cell2 3.398667 1.109772 Tumor 2 1 4
#> cell3 2.060565 2.566543 Tumor 1 3 3
#> cell4 1.463342 2.365366 Tumor 3 0 4
#> cell5 5.085220 2.566559 Tumor 10 1 1
#> cell6 2.149059 1.976934 Tumor 0 8 1