barcodesToImageAnnotation: Create image annotations from a list of barcodes

View source: R/b.R

barcodesToImageAnnotationR Documentation

Create image annotations from a list of barcodes

Description

Creates image annotations from a list of barcodes by identifying the spots that outline the area covered by them. See details for more information.

Usage

barcodesToImageAnnotation(
  object,
  barcodes,
  id,
  tags = NULL,
  force1 = FALSE,
  concavity = 2,
  eps = getCCD(object, unit = "px") * 1.25,
  minPts = 3,
  sep = "_",
  expand_outline = getCCD(object, unit = "px")/2,
  overwrite = FALSE,
  verbose = NULL
)

Arguments

object

A valid spata2 object.

barcodes

Character vector. A vector of barcode-spots that cover histological areas that are supposed to annotated as image annotations.

id

Name of the created image annotation. If multiple areas are identified (see details) this name is suffixed with a number.

tags

Character vector or NULL. If character, the tags for the image annotation selection. See section Selection of image annotation with tags for more information.

force1

Logical value. If TRUE, the function assumes that the barcodes cover one contiguous area and creates only one image annotation.

concavity

Given to concaveman::concaveman().

eps

Distance measure. Converted to pixel unit and given to eps of dbscan::dbscan(). Defaults to the center-to-center distance multiplied with 1.25.

minPts

Given to minPts of dbscan::dbscan(). Defaults to 3.

sep

Character value. The separator between image annotation id and suffix.

expand_outline

Distance measure. Defines how much the identified outline of each area is buffered. If 0, no buffering is performed and the outer barcode-spots of each area are representative of the outline.

overwrite

Logical. Set to TRUE in order to overwrite existing image annotations.

verbose

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

Details

The functions filters the coordinates data.frame obtained via getCoordsDf() based on the input of argument barcodes. If force1 is not TRUE, the Density-based Spatial Clustering of Applications with Noise (DBSCAN) is applied to identify multiple areas covered by the barcodes denoted in barcodes. concaveman::concaveman() creates a polygon for each area identified by dbscan that is required to outline the area. Each polygon is used to create an image annotation combining input for id with a numeric suffix.

Value

An updated spata2 object

Examples


library(SPATA2)
data(spatial_segmentations)

object <- downloadSpataObject("313_T")

# add 'histology' variable
object <-
 addFeatures(
  object = object,
  feature_df = spatial_segmentations[["313_T"]]
   )

plotImageGgplot(object) + plotSurface(object, color_by = "histology", pt_alpha = 0.5)

# obtain list of barcodes that cover necrotic areas
necrotic_barcodes <-
 getFeatureDf(object) %>%
 dplyr::filter(histology == "necrosis") %>%
 dplyr::pull("barcodes")

print(necrotic_barcodes)

# convert list of barcodes to image annotations with default setting
object_ex1 <-
 barcodesToImageAnnotation(
  object = object,
  barcodes = necrotic_barcodes,
  id = "necrosis",
  )

plotImageAnnotations(object_ex1, expand = "1mm")

# skip algorithm to detect multiple areas
object_ex2 <-
 barcodesToImageAnnotation(
  object = object,
  barcodes = necrotic_barcodes,
  id = "necrosis",
  force1 = TRUE
  )

plotImageAnnotations(object_ex2, expand = "1mm")

# manipulate the outline via `expand_outline`
object_ex3 <-
 barcodesToImageAnnotation(
  object = object,
  barcodes = necrotic_barcodes,
  id = "necrosis",
  expand_outline = getCCD(object)*4.5 # *4.5 is too high, defaults to *1.25
  )

plotImageAnnotations(object_ex3, expand = "1mm")


kueckelj/SPATA2 documentation built on March 16, 2024, 10:25 a.m.