This function imports previously exported clustering results with
cluster_export()
and adds them to the colData()
slot of your
SpatialExperiment-class
object.
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.
A character(1)
specifying the output directory, similar
to the outs/analysis/clustering
produced by SpaceRanger.
A character(1)
specifying the prefix to use when naming
these new cluster variables.
A logical(1)
indicating whether to overwrite the spe$key
.
A
SpatialExperiment-class object
with the imported clusters appended on the colData()
.
Other cluster export/import utility functions:
cluster_export()
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")
## Re-import them
colData(cluster_import(spe))
}
#> 2024-07-26 23:47:16.386406 loading file /github/home/.cache/R/BiocFileCache/e60656c8edd_Human_DLPFC_Visium_processedData_sce_scran_spatialLIBD.Rdata%3Fdl%3D1
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.
#> Warning: '/tmp/RtmpSKMtQe/exported_clusters/spatialLIBD' already exists
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.
#> Warning: '/tmp/RtmpSKMtQe/exported_clusters/GraphBased' already exists
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.
#> DataFrame with 47681 rows and 71 columns
#> key sample_id Cluster sum_umi
#> <character> <character> <integer> <numeric>
#> AAACAACGAATAGTTC-1 AAACAACGAATAGTTC-1_1.. 151507 6 948
#> AAACAAGTATCTCCCA-1 AAACAAGTATCTCCCA-1_1.. 151507 3 4261
#> AAACAATCTACTAGCA-1 AAACAATCTACTAGCA-1_1.. 151507 2 1969
#> AAACACCAATAACTGC-1 AAACACCAATAACTGC-1_1.. 151507 5 3368
#> AAACAGCTTTCAGAAG-1 AAACAGCTTTCAGAAG-1_1.. 151507 1 2981
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 TTGTTGTGTGTCAAGA-1_1.. 151676 5 2880
#> TTGTTTCACATCCAGG-1 TTGTTTCACATCCAGG-1_1.. 151676 2 2640
#> TTGTTTCATTAGTCTA-1 TTGTTTCATTAGTCTA-1_1.. 151676 2 2063
#> TTGTTTCCATACAACT-1 TTGTTTCCATACAACT-1_1.. 151676 7 1031
#> TTGTTTGTGTAAATTC-1 TTGTTTGTGTAAATTC-1_1.. 151676 1 2625
#> sum_gene subject position replicate
#> <integer> <character> <character> <character>
#> AAACAACGAATAGTTC-1 727 Br5292 0 1
#> AAACAAGTATCTCCCA-1 2170 Br5292 0 1
#> AAACAATCTACTAGCA-1 1093 Br5292 0 1
#> AAACACCAATAACTGC-1 1896 Br5292 0 1
#> AAACAGCTTTCAGAAG-1 1620 Br5292 0 1
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 1638 Br8100 300 2
#> TTGTTTCACATCCAGG-1 1526 Br8100 300 2
#> TTGTTTCATTAGTCTA-1 1279 Br8100 300 2
#> TTGTTTCCATACAACT-1 748 Br8100 300 2
#> TTGTTTGTGTAAATTC-1 1392 Br8100 300 2
#> subject_position discard cell_count SNN_k50_k4 SNN_k50_k5
#> <character> <logical> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 Br5292_pos0 FALSE 0 1 1
#> AAACAAGTATCTCCCA-1 Br5292_pos0 FALSE 3 1 1
#> AAACAATCTACTAGCA-1 Br5292_pos0 FALSE 2 3 2
#> AAACACCAATAACTGC-1 Br5292_pos0 FALSE 5 2 3
#> AAACAGCTTTCAGAAG-1 Br5292_pos0 FALSE 3 1 1
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 Br8100_pos300 FALSE 1 1 1
#> TTGTTTCACATCCAGG-1 Br8100_pos300 FALSE 6 2 3
#> TTGTTTCATTAGTCTA-1 Br8100_pos300 FALSE 9 2 3
#> TTGTTTCCATACAACT-1 Br8100_pos300 FALSE 2 1 1
#> TTGTTTGTGTAAATTC-1 Br8100_pos300 FALSE 0 1 1
#> SNN_k50_k6 SNN_k50_k7 SNN_k50_k8 SNN_k50_k9 SNN_k50_k10
#> <integer> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 1 3 3 4 4
#> AAACAAGTATCTCCCA-1 1 1 1 1 1
#> AAACAATCTACTAGCA-1 3 4 4 5 5
#> AAACACCAATAACTGC-1 4 5 8 9 10
#> AAACAGCTTTCAGAAG-1 1 1 1 3 3
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 1 1 1 1 1
#> TTGTTTCACATCCAGG-1 4 5 6 7 8
#> TTGTTTCATTAGTCTA-1 4 5 6 7 8
#> TTGTTTCCATACAACT-1 1 1 1 3 3
#> TTGTTTGTGTAAATTC-1 2 2 2 2 2
#> SNN_k50_k11 SNN_k50_k12 SNN_k50_k13 SNN_k50_k14 SNN_k50_k15
#> <integer> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 5 5 5 6 7
#> AAACAAGTATCTCCCA-1 4 4 4 4 3
#> AAACAATCTACTAGCA-1 6 6 6 7 8
#> AAACACCAATAACTGC-1 11 10 9 10 11
#> AAACAGCTTTCAGAAG-1 3 3 3 3 2
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 4 4 4 4 3
#> TTGTTTCACATCCAGG-1 9 8 8 9 10
#> TTGTTTCATTAGTCTA-1 9 8 8 9 10
#> TTGTTTCCATACAACT-1 3 3 3 3 2
#> TTGTTTGTGTAAATTC-1 1 1 1 1 5
#> SNN_k50_k16 SNN_k50_k17 SNN_k50_k18 SNN_k50_k19 SNN_k50_k20
#> <integer> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 7 9 10 10 10
#> AAACAAGTATCTCCCA-1 3 3 2 2 2
#> AAACAATCTACTAGCA-1 8 7 8 8 8
#> AAACACCAATAACTGC-1 11 12 13 12 11
#> AAACAGCTTTCAGAAG-1 2 2 1 1 1
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 3 3 2 2 2
#> TTGTTTCACATCCAGG-1 10 11 12 18 18
#> TTGTTTCATTAGTCTA-1 10 11 12 15 15
#> TTGTTTCCATACAACT-1 2 2 1 1 1
#> TTGTTTGTGTAAATTC-1 5 5 5 5 5
#> SNN_k50_k21 SNN_k50_k22 SNN_k50_k23 SNN_k50_k24 SNN_k50_k25
#> <integer> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 10 11 11 11 12
#> AAACAAGTATCTCCCA-1 2 1 1 1 6
#> AAACAATCTACTAGCA-1 8 9 9 9 9
#> AAACACCAATAACTGC-1 11 12 20 20 21
#> AAACAGCTTTCAGAAG-1 1 6 6 6 5
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 2 1 1 1 10
#> TTGTTTCACATCCAGG-1 17 18 17 17 18
#> TTGTTTCATTAGTCTA-1 14 15 14 13 14
#> TTGTTTCCATACAACT-1 1 6 6 6 5
#> TTGTTTGTGTAAATTC-1 5 4 4 4 3
#> SNN_k50_k26 SNN_k50_k27 SNN_k50_k28 GraphBased Maynard
#> <integer> <integer> <integer> <integer> <factor>
#> AAACAACGAATAGTTC-1 13 13 14 6 WM
#> AAACAAGTATCTCCCA-1 5 5 4 3 6
#> AAACAATCTACTAGCA-1 9 9 9 2 1
#> AAACACCAATAACTGC-1 22 21 22 5 5
#> AAACAGCTTTCAGAAG-1 4 4 3 1 4
#> ... ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 10 10 10 5 5
#> TTGTTTCACATCCAGG-1 19 18 19 2 WM
#> TTGTTTCATTAGTCTA-1 15 15 16 2 WM
#> TTGTTTCCATACAACT-1 4 4 3 7 6
#> TTGTTTGTGTAAATTC-1 3 3 2 1 1
#> Martinowich layer_guess layer_guess_reordered
#> <factor> <factor> <factor>
#> AAACAACGAATAGTTC-1 WM Layer1 Layer1
#> AAACAAGTATCTCCCA-1 6 Layer3 Layer3
#> AAACAATCTACTAGCA-1 1 Layer1 Layer1
#> AAACACCAATAACTGC-1 5 WM WM
#> AAACAGCTTTCAGAAG-1 4 Layer6 Layer6
#> ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 4 Layer6 Layer6
#> TTGTTTCACATCCAGG-1 WM WM WM
#> TTGTTTCATTAGTCTA-1 WM WM WM
#> TTGTTTCCATACAACT-1 6 Layer6 Layer6
#> TTGTTTGTGTAAATTC-1 1 Layer1 Layer1
#> layer_guess_reordered_short expr_chrM expr_chrM_ratio
#> <factor> <numeric> <numeric>
#> AAACAACGAATAGTTC-1 L1 88 0.0928270
#> AAACAAGTATCTCCCA-1 L3 657 0.1541892
#> AAACAATCTACTAGCA-1 L1 431 0.2188928
#> AAACACCAATAACTGC-1 WM 272 0.0807601
#> AAACAGCTTTCAGAAG-1 L6 502 0.1683999
#> ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 L6 475 0.164931
#> TTGTTTCACATCCAGG-1 WM 320 0.121212
#> TTGTTTCATTAGTCTA-1 WM 262 0.127000
#> TTGTTTCCATACAACT-1 L6 161 0.156159
#> TTGTTTGTGTAAATTC-1 L1 667 0.254095
#> SpatialDE_PCA SpatialDE_pool_PCA HVG_PCA pseudobulk_PCA
#> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 4 5 3 5
#> AAACAAGTATCTCCCA-1 2 3 1 2
#> AAACAATCTACTAGCA-1 4 4 4 4
#> AAACACCAATAACTGC-1 6 7 6 6
#> AAACAGCTTTCAGAAG-1 1 1 3 1
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 1 2 2 2
#> TTGTTTCACATCCAGG-1 5 5 4 5
#> TTGTTTCATTAGTCTA-1 5 5 4 4
#> TTGTTTCCATACAACT-1 4 8 6 2
#> TTGTTTGTGTAAATTC-1 1 1 2 7
#> markers_PCA SpatialDE_UMAP SpatialDE_pool_UMAP HVG_UMAP
#> <integer> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 4 1 2 1
#> AAACAAGTATCTCCCA-1 2 1 3 1
#> AAACAATCTACTAGCA-1 8 2 4 5
#> AAACACCAATAACTGC-1 8 5 7 7
#> AAACAGCTTTCAGAAG-1 1 2 3 6
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 1 1 3 2
#> TTGTTTCACATCCAGG-1 6 4 5 5
#> TTGTTTCATTAGTCTA-1 1 4 5 7
#> TTGTTTCCATACAACT-1 3 1 2 3
#> TTGTTTGTGTAAATTC-1 4 2 1 4
#> pseudobulk_UMAP markers_UMAP SpatialDE_PCA_spatial
#> <integer> <integer> <integer>
#> AAACAACGAATAGTTC-1 3 1 3
#> AAACAAGTATCTCCCA-1 2 1 4
#> AAACAATCTACTAGCA-1 3 6 3
#> AAACACCAATAACTGC-1 7 1 7
#> AAACAGCTTTCAGAAG-1 1 1 1
#> ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 2 3 1
#> TTGTTTCACATCCAGG-1 6 1 5
#> TTGTTTCATTAGTCTA-1 4 2 5
#> TTGTTTCCATACAACT-1 3 1 4
#> TTGTTTGTGTAAATTC-1 2 6 2
#> SpatialDE_pool_PCA_spatial HVG_PCA_spatial
#> <integer> <integer>
#> AAACAACGAATAGTTC-1 5 5
#> AAACAAGTATCTCCCA-1 1 2
#> AAACAATCTACTAGCA-1 4 3
#> AAACACCAATAACTGC-1 6 7
#> AAACAGCTTTCAGAAG-1 2 1
#> ... ... ...
#> TTGTTGTGTGTCAAGA-1 1 4
#> TTGTTTCACATCCAGG-1 5 5
#> TTGTTTCATTAGTCTA-1 5 5
#> TTGTTTCCATACAACT-1 8 2
#> TTGTTTGTGTAAATTC-1 2 1
#> pseudobulk_PCA_spatial markers_PCA_spatial
#> <integer> <integer>
#> AAACAACGAATAGTTC-1 4 3
#> AAACAAGTATCTCCCA-1 3 1
#> AAACAATCTACTAGCA-1 5 7
#> AAACACCAATAACTGC-1 7 7
#> AAACAGCTTTCAGAAG-1 1 2
#> ... ... ...
#> TTGTTGTGTGTCAAGA-1 2 6
#> TTGTTTCACATCCAGG-1 4 4
#> TTGTTTCATTAGTCTA-1 4 2
#> TTGTTTCCATACAACT-1 2 4
#> TTGTTTGTGTAAATTC-1 3 2
#> SpatialDE_UMAP_spatial SpatialDE_pool_UMAP_spatial
#> <integer> <integer>
#> AAACAACGAATAGTTC-1 1 1
#> AAACAAGTATCTCCCA-1 2 2
#> AAACAATCTACTAGCA-1 2 1
#> AAACACCAATAACTGC-1 7 8
#> AAACAGCTTTCAGAAG-1 8 2
#> ... ... ...
#> TTGTTGTGTGTCAAGA-1 6 1
#> TTGTTTCACATCCAGG-1 5 5
#> TTGTTTCATTAGTCTA-1 5 5
#> TTGTTTCCATACAACT-1 2 3
#> TTGTTTGTGTAAATTC-1 1 2
#> HVG_UMAP_spatial pseudobulk_UMAP_spatial
#> <integer> <integer>
#> AAACAACGAATAGTTC-1 1 1
#> AAACAAGTATCTCCCA-1 1 2
#> AAACAATCTACTAGCA-1 4 1
#> AAACACCAATAACTGC-1 7 8
#> AAACAGCTTTCAGAAG-1 8 1
#> ... ... ...
#> TTGTTGTGTGTCAAGA-1 4 1
#> TTGTTTCACATCCAGG-1 5 8
#> TTGTTTCATTAGTCTA-1 8 1
#> TTGTTTCCATACAACT-1 2 4
#> TTGTTTGTGTAAATTC-1 1 2
#> markers_UMAP_spatial spatialLIBD ManualAnnotation in_tissue
#> <integer> <factor> <character> <logical>
#> AAACAACGAATAGTTC-1 1 L1 NA TRUE
#> AAACAAGTATCTCCCA-1 1 L3 NA TRUE
#> AAACAATCTACTAGCA-1 6 L1 NA TRUE
#> AAACACCAATAACTGC-1 1 WM NA TRUE
#> AAACAGCTTTCAGAAG-1 1 L6 NA TRUE
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 1 L6 NA TRUE
#> TTGTTTCACATCCAGG-1 1 WM NA TRUE
#> TTGTTTCATTAGTCTA-1 1 WM NA TRUE
#> TTGTTTCCATACAACT-1 7 L6 NA TRUE
#> TTGTTTGTGTAAATTC-1 5 L1 NA TRUE
#> array_row array_col imported_GraphBased imported_spatialLIBD
#> <integer> <integer> <integer> <character>
#> AAACAACGAATAGTTC-1 0 16 6 L1
#> AAACAAGTATCTCCCA-1 50 102 3 L3
#> AAACAATCTACTAGCA-1 3 43 2 L1
#> AAACACCAATAACTGC-1 59 19 5 WM
#> AAACAGCTTTCAGAAG-1 43 9 1 L6
#> ... ... ... ... ...
#> TTGTTGTGTGTCAAGA-1 31 77 5 L6
#> TTGTTTCACATCCAGG-1 58 42 2 WM
#> TTGTTTCATTAGTCTA-1 60 30 2 WM
#> TTGTTTCCATACAACT-1 45 27 7 L6
#> TTGTTTGTGTAAATTC-1 7 51 1 L1