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 <- NULL

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

    ## Note that the original 'key' order was 'sample_id'_'barcode' and we'
    ## have since changed it to 'barcode'_'sample_id'.
}
#> 2024-04-19 19:41:41.648978 loading file /github/home/.cache/R/BiocFileCache/c9922e59250_Human_DLPFC_Visium_processedData_sce_scran_spatialLIBD.Rdata%3Fdl%3D1
#> [1] "AAACAACGAATAGTTC-1_151507" "AAACAAGTATCTCCCA-1_151507"
#> [3] "AAACAATCTACTAGCA-1_151507" "AAACACCAATAACTGC-1_151507"
#> [5] "AAACAGCTTTCAGAAG-1_151507" "AAACAGGGTCTATATT-1_151507"