Skip to contents

Distance calculations for spatial coord

Usage

calc_distance(
  coord,
  metadata,
  cluster_col = "cluster",
  collapse_to_cluster = FALSE
)

Arguments

coord

dataframe or matrix of spatial coordinates, cell barcode as rownames

metadata

data.frame or vector containing cluster assignments per cell. Order must match column order in supplied matrix. If a data.frame provide the cluster_col parameters.

cluster_col

column in metadata with cluster number

collapse_to_cluster

instead of reporting min distance to cluster per cell, summarize to cluster level

Value

min distance matrix

Examples

cbs <- paste0("cb_", 1:100)

spatial_coords <- data.frame(
    row.names = cbs,
    X = runif(100),
    Y = runif(100)
)
group_ids <- sample(c("A", "B"), 100, replace = TRUE)
dist_res <- calc_distance(
    spatial_coords,
    group_ids
)
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’