Creates spatial annotations from a list of barcodes from data points that cover the area to be outlined. See details for more information.

barcodesToSpatialAnnotation(
  object,
  barcodes,
  id,
  tags = NULL,
  tags_expand = TRUE,
  use_dbscan = TRUE,
  inner_borders = TRUE,
  eps = getCCD(object) * 1.25,
  minPts = 3,
  min_size = nBarcodes(object) * 0.005,
  fct_incr = 20,
  force1 = FALSE,
  concavity = 2,
  overwrite = FALSE,
  class = "SpatialAnnotation",
  verbose = NULL,
  ...
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

barcodes

Character vector. A vector of data points that cover histological areas that are supposed to annotated as spatial annotations.

id

Character value. The ID of the spatial annotation. If NULL, the ID of the annotation is created by combining the string 'spat_ann' with the index the new annotation has in the list of all annotations.

tags

A character vector of tags for the spatial annotation.

tags_expand

Logical value. If TRUE, the tags with which the image annotations are tagged are expanded by the unsuffixed id, the variable, the threshold and 'barcodesToSpatialAnnotation()'.

use_dbscan

Logical value. If TRUE, the DBSCAN algorithm is used to identify spatial clusters and outliers before the outline of the spatial annotation is drawn.

inner_borders

Logical value. If TRUE, the algorithm checks whether the annotation requires inner borders and sets them accordingly. If FALSE, only an outer border is created.

eps

Distance measure. Given to eps of dbscan::dbscan(). Determines the size (radius) of the epsilon neighborhood.

minPts

Numeric value. Given to dbscan::dbscan(). Determines the number of minimum points required in the eps neighborhood for core points (including the point itself)

min_size

Numeric value. The minimum number of data points a dbscan cluster must have in order not to be discarded as a spatial outlier.

force1

Logical value. If TRUE, spatial sub groups identified by DBSCAN are merged into one cluster. Note: If FALSE (the default), the input for ìd is suffixed with an index to label each spatial annotation created uniquely, regardless of how many are eventually created. E.g. if id = "my_ann" and the algorithm created two spatial annotations, they are named my_ann_1 and my_ann_2.

concavity

Numeric value. Given to argument concavity of concaveman::concaveman(). Determines the relative measure of concavity. 1 results in a relatively detailed shape, Infinity results in a convex hull. You can use values lower than 1, but they can produce pretty crazy shapes.

overwrite

Logical value. Must be TRUE to allow overwriting.

verbose

Logical. If TRUE, informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

...

Additional slot content given to methods::new() when constructing the SpatialAnnotation object.

Value

The updated input object, containing the added, removed or computed results.

Details

The functions filters the coordinates data.frame obtained via getCoordsDf() based on the input of argument barcodes.

Following filtering, if use_dbscan is TRUE, the DBSCAN algorithm identifies spatial outliers, which are then removed. Furthermore, if DBSCAN detects multiple dense clusters, they can be merged into a single group if force1 is also set to TRUE.

It is essential to note that bypassing the DBSCAN step may lead to the inclusion of individual data points dispersed across the sample. This results in an image annotation that essentially spans the entirety of the sample, lacking the segregation of specific variable expressions. Similarly, enabling force1 might unify multiple segregated areas, present on both sides of the sample, into one group and subsequently, one spatial annotation encompassing the whole sample. Consider to allow the creation of multiple spatial annotations (suffixed with an index) and merging them afterwards via mergeSpatialAnnotations() if they are too close together.

Lastly, the remaining data points are fed into the concaveman algorithm on a per-group basis. The algorithm calculates concave polygons outlining the groups of data points. If dbscan_use is FALSE, all data points that remained after the initial filtering are submitted to the algorithm. Subsequently, these polygons are integrated into addSpatialAnnotation() along with the unsuffixed id and tags input arguments. The ID is suffixed with an index for each group.

Distance measures

The vignette on distance measures in SPATA2 has been replaced. Click here to read it.

See also

See mergeSpatialAnnotations() to merge spatial annotations.

See SpatialAnnotation-class for details about the S4 architecture.

Examples


library(SPATA2)
library(tidyverse)

data("example_data")

object <- example_data$object_UKF275T_diet

barcodes <-
  getMetaDf(object) %>%
  filter(bayes_space == "1") %>%
  pull(barcodes)

object <-
 barcodesToSpatialAnnotation(
  object = object,
  barcodes = barcodes,
  id = "example",
  overwrite = TRUE
  )

plotSurface(object, color_by = "bayes_space") +
  ggpLayerSpatAnnOutline(object, ids = "example")