% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-border.R
\name{select_core_spots}
\alias{select_core_spots}
\title{Select core (non-interface) spots for a directed pair}
\usage{
select_core_spots(
  df,
  border_df,
  cluster,
  interface,
  mode = "both",
  coord_cols = c("x", "y"),
  cluster_col = "cluster"
)
}
\arguments{
\item{df}{A data.frame containing at least the coordinate columns and a
cluster label column.}

\item{border_df}{A data.frame of border spots from [build_all_borders()],
containing
  columns `spot_id`, `cluster`, `interface`, `directed_pair`, etc.}

\item{cluster}{Character. Label of the cluster from which to select inner
spots.}

\item{interface}{Character. Label of the target cluster for the directed
pair.}

\item{mode}{Character. One of "inner", "outer", or "both". Controls which
mode values
from border_df to use when counting border spots. When mode="both", both
"inner" and
  "outer" mode rows from border_df are used. Default is "both".}

\item{coord_cols}{Character vector of length 2 giving the coordinate column
names.
  Default is `c("x","y")`.}

\item{cluster_col}{Character. Name of the column containing cluster labels.
Default is `"cluster"`.}
}
\value{
A data.frame of sampled core spots from `cluster`, with all columns
from `df`  plus `interface` annotation.
}
\description{
This function selects core (non-interface) spots from a cluster that match
the count of border spots for a specific directed pair. The `mode` value is 
read from the `border_df` dataframe for this cluster/interface pair. If
multiple
mode values exist in border_df for the pair, a warning is printed and the
first value is used.
}
\details{
For example with `cluster="1"` and `interface="2"`:
- If mode in df is "inner": counts only border spots from 1→2
- If mode in df is "outer": counts only border spots from 2→1
- If mode in df is "both": counts border spots from both 1→2 AND 2→1

This returns N random inner spots from the cluster, where N equals the border
count.


Steps:
\enumerate{
  \item Counts directed border spots based on `mode` parameter.
  \item Gets all spots in `cluster` that are not at any border.
  \item Randomly samples the same number of core spots as the border count.
  \item Returns these sampled core spots with `interface` annotation.
}

If not enough core spots exist to match the border count, all available core
spots are returned with a warning.
}
\examples{
# Create synthetic spatial transcriptomics data with 3 clusters
df_ex <- data.frame(
  spot_id = paste0("spot_", seq_len(300)),
  x = rnorm(300),
  y = rnorm(300),
  cluster = sample(c("A", "B", "C"), 300, replace = TRUE)
)

# Step 1: Identify all border spots between clusters
all_borders <- build_all_borders(df_ex, k = 6)

# Step 2: Select core spots for the directed pair A→B
# matching the number of border spots found
cores_inner <- select_core_spots(
  df_ex,
  border_df = all_borders,
  cluster = "A",
  interface = "B",
  mode = "inner"
)
head(cores_inner)

# Step 3: Select core spots considering both directions (A→B AND B→A)
cores_both <- select_core_spots(
  df_ex,
  border_df = all_borders,
  cluster = "A",
  interface = "B",
  mode = "both"
)
head(cores_both)

}
