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

\item{border}{Optional data.frame of border spots. Can be output from either
[select_border_spots()] or [build_all_borders()].
Expected columns: spot_id, interface, mode.}

\item{core}{Optional data.frame of core spots. Can be output from either
[select_core_spots()] or [build_all_cores()].
Expected columns: spot_id, interface, mode.}

\item{erase}{Logical. If `TRUE`, erase pre-existing battlefield 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 spot selection results (either border or core spots)
and adds them as annotations in the colData of a SpatialExperiment object.
}
\details{
At least `border` must be provided. `core` is optional. If `core` is provided
without `border`, an error is raised.

The following unified columns are added:
- `is_border`: logical, TRUE if spot is a border spot, FALSE or NA otherwise
- `is_core`: logical, TRUE if spot is a core spot, FALSE or NA otherwise
- `interface`: the target interface cluster
- `border_mode`: character, "inner", "outer", or NA (from the `mode` column
in input data)
}
\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
)
# Using build_all_borders and build_all_cores
all_borders <- build_all_borders(df, k = 6)
all_cores <- build_all_cores(df, all_borders, mode = "inner")

# Or using individual select functions
border_3_to_4 <- select_border_spots(df, cluster = 3, interface = 4, k = 6)
core_3_to_4 <- select_core_spots(df, all_borders, cluster = 3, interface = 4)

}
