% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hexBinCells.R
\name{hexBinCells}
\alias{hexBinCells}
\title{Bin cells into hexagonal spatial bins}
\usage{
hexBinCells(
  coords_df,
  counts_matrix,
  bin_size = 50,
  min_cells = 1,
  group = NULL
)
}
\arguments{
\item{coords_df}{Data frame or matrix with columns \code{x_centroid} and
\code{y_centroid} (e.g. the output of \code{SpatialExperiment::spatialCoords()}).
Row names must be cell IDs matching the column names of \code{counts_matrix}.}

\item{counts_matrix}{Gene-by-cell count matrix (dense or sparse). Row names
must be gene symbols; column names must be cell IDs present in
\code{coords_df}.}

\item{bin_size}{Numeric. Approximate width of each hexagonal bin in
coordinate units (e.g. microns). Analogous to \code{grid.length.x} in
\code{sciderHex::gridDensity}. Default \code{50}.}

\item{min_cells}{Integer. Bins containing fewer than \code{min_cells} cells
are dropped from the output. Default \code{1}.}

\item{group}{Factor or character vector of length \code{ncol(counts_matrix)}
giving the cell-type label of each cell. When supplied, a named list of
per-cell-type gene-by-bin matrices is included in the output as
\code{counts_by_group}. Default \code{NULL} (not computed).}
}
\value{
A list with:
\describe{
\item{counts_matrix}{Gene-by-bin sparse count matrix (all cells combined).
Column \emph{i} corresponds to row \emph{i} of \code{bins}.}
\item{bins}{An \code{sf} object of hexagonal bin polygons with an
\code{n_cells} column recording how many cells fall in each bin. Row
order matches the columns of \code{counts_matrix}.}
\item{counts_by_group}{(Only when \code{group} is supplied.) A named list
of gene-by-bin sparse matrices, one per cell-type level, with the same
bin order as \code{counts_matrix}.}
}
}
\description{
Aggregates single-cell spatial data into hexagonal bins and returns a
bin-level count matrix together with a matching \code{sf} polygon object,
ready to pass directly to \code{\link{blisa.default}}.
}
