This function creates a clusters.csv file similar to the ones created by SpaceRanger at outs/analysis/clustering but with the key column that combines the barcode and the sample_id, which is needed when the spe object contains data from multiple samples given that the barcodes are duplicated.

cluster_export(
  spe,
  cluster_var,
  cluster_dir = file.path(tempdir(), "exported_clusters"),
  overwrite = TRUE
)

Arguments

spe

A SpatialExperiment-class object. See fetch_data() for how to download some example objects or read10xVisiumWrapper() to read in spaceranger --count output files and build your own spe object.

cluster_var

A character(1) with the name of the variable you wish to export.

cluster_dir

A character(1) specifying the output directory, similar to the outs/analysis/clustering produced by SpaceRanger.

overwrite

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

Value

The path to the exported clusters.csv file.

See also

Other cluster export/import utility functions: cluster_import()

Examples

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

    ## Export two cluster variables
    cluster_export(spe, "spatialLIBD")
    cluster_export(spe, "GraphBased")
}
#> 2024-10-31 20:25:30.508778 loading file /github/home/.cache/R/BiocFileCache/f6f1918e278_Human_DLPFC_Visium_processedData_sce_scran_spatialLIBD.Rdata%3Fdl%3D1
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.