add_key: Create a unique spot identifier

View source: R/add_key.R

add_keyR Documentation

Create a unique spot identifier

Description

This function adds spe$key to a SpatialExperiment-class object which is unique across all spots.

Usage

add_key(spe, overwrite = TRUE)

Arguments

spe

A SpatialExperiment-class object.

overwrite

A logical(1) indicating whether to overwrite the spe$key.

Value

A SpatialExperiment-class object with key added to the colData(spe) that is unique across all spots.

Examples

if (enough_ram()) {
    ## Obtain the necessary data
    if (!exists("spe")) spe <- fetch_data("spe")

    ## This object already has a 'key'
    head(spe$key)

    ## We can clean it
    spe$key_original <- spe$key
    spe$key <- NULL

    ## and then add it back
    spe <- add_key(spe)
    head(spe$key)

    ## Note that the original 'key' order was 'sample_id'_'barcode' and we'
    ## have since changed it to 'barcode'_'sample_id'.

    ## Below we restore the original 'key'
    spe$key <- spe$key_original
    spe$key_original <- NULL
    head(spe$key)
}

LieberInstitute/spatialLIBD documentation built on Dec. 19, 2024, 7:12 p.m.