Title: | Cluster analysis of Spatial Transcriptomics data |
---|---|
Description: | SpatialCPie is an R package designed to facilitate cluster evaluation for spatial transcriptomics data by providing intuitive visualizations that display the relationships between clusters in order to guide the user during cluster identification and other downstream applications. The package is built around a shiny "gadget" to allow the exploration of the data with multiple plots in parallel and an interactive UI. The user can easily toggle between different cluster resolutions in order to choose the most appropriate visual cues. |
Authors: | Joseph Bergenstraahle [aut, cre] |
Maintainer: | Joseph Bergenstraahle <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.23.0 |
Built: | 2024-11-18 04:25:43 UTC |
Source: | https://github.com/bioc/SpatialCPie |
SpatialCPie is an R package designed to facilitate cluster evaluation for spatial transcriptomics data by providing intuitive visualizations that display the relationships between clusters in order to guide the user during cluster identification and other downstream applications. The package is built around a shiny "gadget" to allow the exploration of the data with multiple plots in parallel and an interactive UI. The user can easily toggle between different cluster resolutions in order to choose the most appropriate visual cues.
Maintainer: Joseph Bergenstraahle [email protected]
Parses the output from the ST spot detector tool for use with SpatialCPie.
parseSpotFile(file)
parseSpotFile(file)
file |
spot file |
data.frame
with columns "x" and "y" specifying
the pixel coordinates of each spot
## Create spot file data <- rbind( c(7, 18, 7.00, 18.07, 563.2, 947.0), c(8, 11, 8.00, 11.04, 612.5, 627.7) ) filename <- tempfile() write.table( data, file = filename, sep = "\t", quote = FALSE, col.names = c("x", "y", "new_x", "new_y", "pixel_x", "pixel_y") ) ## Parse spot file parseSpotFile(filename) ## Delete spot file unlink(filename)
## Create spot file data <- rbind( c(7, 18, 7.00, 18.07, 563.2, 947.0), c(8, 11, 8.00, 11.04, 612.5, 627.7) ) filename <- tempfile() write.table( data, file = filename, sep = "\t", quote = FALSE, col.names = c("x", "y", "new_x", "new_y", "pixel_x", "pixel_y") ) ## Parse spot file parseSpotFile(filename) ## Delete spot file unlink(filename)
Runs the SpatialCPie gadget.
runCPie(counts, image = NULL, spotCoordinates = NULL, margin = "spot", resolutions = 2:4, assignmentFunction = function(k, x) kmeans(x, centers = k)$cluster, view = NULL)
runCPie(counts, image = NULL, spotCoordinates = NULL, margin = "spot", resolutions = 2:4, assignmentFunction = function(k, x) kmeans(x, centers = k)$cluster, view = NULL)
counts |
gene count matrix or a
|
image |
image to be used as background to the plot. |
spotCoordinates |
|
margin |
which margin to cluster. |
resolutions |
|
assignmentFunction |
function to compute cluster assignments. |
view |
|
a list with the following items:
"clusters"
: Cluster assignments (may differ from assignments
)
"clusterGraph"
: The cluster tree ggplot object
"arrayPlot"
: The pie plot ggplot objects
if (interactive()) { options(device.ask.default = FALSE) ## Set up coordinate system coordinates <- as.matrix(expand.grid(1:10, 1:10)) ## Generate data set with three distinct genes generated by three ## distinct cell types profiles <- diag(rep(1, 3)) + runif(9) centers <- cbind(c(5, 2), c(2, 8), c(8, 2)) mixes <- apply(coordinates, 1, function(x) { x <- exp(-colSums((centers - x) ^ 2) / 50) x / sum(x) }) means <- 100 * profiles %*% mixes counts <- matrix(rpois(prod(dim(means)), means), nrow = nrow(profiles)) colnames(counts) <- apply( coordinates, 1, function(x) do.call(paste, c(as.list(x), list(sep = "x"))) ) rownames(counts) <- paste("gene", 1:nrow(counts)) ## Run SpatialCPie runCPie(counts) }
if (interactive()) { options(device.ask.default = FALSE) ## Set up coordinate system coordinates <- as.matrix(expand.grid(1:10, 1:10)) ## Generate data set with three distinct genes generated by three ## distinct cell types profiles <- diag(rep(1, 3)) + runif(9) centers <- cbind(c(5, 2), c(2, 8), c(8, 2)) mixes <- apply(coordinates, 1, function(x) { x <- exp(-colSums((centers - x) ^ 2) / 50) x / sum(x) }) means <- 100 * profiles %*% mixes counts <- matrix(rpois(prod(dim(means)), means), nrow = nrow(profiles)) colnames(counts) <- apply( coordinates, 1, function(x) do.call(paste, c(as.list(x), list(sep = "x"))) ) rownames(counts) <- paste("gene", 1:nrow(counts)) ## Run SpatialCPie runCPie(counts) }