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

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)
}
#> 2024-10-22 13:47:47.095717 loading file /github/home/.cache/R/BiocFileCache/1d065cbf634c_Human_DLPFC_Visium_processedData_sce_scran_spatialLIBD.Rdata%3Fdl%3D1
#> [1] "151507_AAACAACGAATAGTTC-1" "151507_AAACAAGTATCTCCCA-1"
#> [3] "151507_AAACAATCTACTAGCA-1" "151507_AAACACCAATAACTGC-1"
#> [5] "151507_AAACAGCTTTCAGAAG-1" "151507_AAACAGGGTCTATATT-1"