| hexBinCells | R Documentation |
Aggregates single-cell spatial data into hexagonal bins and returns a
bin-level count matrix together with a matching sf polygon object,
ready to pass directly to blisa.default.
hexBinCells(
coords_df,
counts_matrix,
bin_size = 50,
min_cells = 1,
min_total_counts = 10,
group = NULL,
verbose = FALSE
)
coords_df |
Data frame or matrix with columns |
counts_matrix |
Gene-by-cell count matrix (dense or sparse). Row names
must be gene symbols; column names must be cell IDs present in
|
bin_size |
Numeric. Approximate width of each hexagonal bin in
coordinate units (e.g. microns). Analogous to |
min_cells |
Integer. Bins containing fewer than |
min_total_counts |
Numeric. Bins whose total counts (summed over all
genes) fall below this threshold are dropped from the output, alongside
the |
group |
Factor or character vector of length |
verbose |
Logical. If |
A list with:
Gene-by-bin sparse count matrix (all cells combined).
Column i corresponds to row i of bins.
An sf object of hexagonal bin polygons with an
n_cells column recording how many cells fall in each bin and a
total_counts column recording the summed counts per bin. Row
order matches the columns of counts_matrix.
(Only when group is supplied.) A named list
of gene-by-bin sparse matrices, one per cell-type level, with the same
bin order as counts_matrix.
## Not run:
set.seed(42)
n <- 500
coords <- data.frame(
x_centroid = runif(n, 0, 1000),
y_centroid = runif(n, 0, 1000),
row.names = paste0("cell_", seq_len(n))
)
counts <- Matrix::Matrix(
matrix(rpois(20L * n, lambda = 5), nrow = 20L, ncol = n,
dimnames = list(paste0("gene_", 1:20), paste0("cell_", seq_len(n)))),
sparse = TRUE
)
group <- sample(c("TypeA", "TypeB"), n, replace = TRUE)
binned <- hexBinCells(coords, counts, bin_size = 100, group = group)
str(binned, max.level = 1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.