% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-spe.R
\name{add_layers_to_spe}
\alias{add_layers_to_spe}
\title{Add layer classifications to SpatialExperiment colData}
\usage{
add_layers_to_spe(spe, layer = NULL, erase = FALSE)
}
\arguments{
\item{spe}{A SpatialExperiment object from which the layer dataframes were
derived.}

\item{layer}{A data.frame of layer classifications. Can be output from either
[create_cluster_layers()] or [create_all_layers()].
Expected columns: spot_id, layer.}

\item{erase}{Logical. If `TRUE`, erase pre-existing layer columns
before adding new ones. If `FALSE` (default), issue a warning if columns
already exist and skip adding them.}
}
\value{
The SpatialExperiment object with updated colData.
}
\description{
This function takes layer classification results (border, intermediate, core)
and adds them as annotations in the colData of a SpatialExperiment object.
}
\details{
The `layer` parameter must be provided and contain at least one row.

The following column is added:
- `layer`: character, one of "border", "intermediate", "core", or NA
}
\examples{
data("visiumHD_16um_simulated_spe", package = "Battlefield")
spe <- visiumHD_16um_simulated_spe
df <- data.frame(
  spot_id = colnames(spe),
  x = SpatialExperiment::spatialCoords(spe)[, 1],
  y = SpatialExperiment::spatialCoords(spe)[, 2],
  cluster = SummarizedExperiment::colData(spe)$cluster
)
# Or for a single cluster
cluster_1_layers <- create_cluster_layers(df, target_cluster = 1, k = 6)
spe <- add_layers_to_spe(spe, layer = cluster_1_layers)

}
