Cell type classification in tumor microenvironment using HiTME
Source code: HiTME_CaseStudies/HiTME_GetStarted
Background
In this vignette we will use HiTME to
classify the cell types found in whole-tumor samples from Breast cancer.
This single-cell data set was processed from the original work from Bassez et
al. (2021) Nature Medicine.
Installation
Install HiTME package and its dependencies, if not already
Data loading
Demo dataset can be downloaded from (https://figshare.com/ndownloader/files/43848153). This includes 3 samples in a list.
# increase download timeout max if slow connection
options(timeout = max(2000, getOption("timeout")))
# donwload data
if (!file.exists(dest)) {
dir.create(ddir)
dataUrl <- "https://figshare.com/ndownloader/files/43848153"
download.file(dataUrl, destfile = dest)
}Load data
Load reference maps
HiTME layer 2 for finer cell type classification requires expert-curated single-cell reference maps. Download reference maps for human:
library(ProjecTILs)
# Retrieve human reference maps
ref.maps <- get.reference.maps(collection = "human", as.list = F)We can quickly explore the reference maps by visualizating their UMAPs with the cell subtypes they contain
library(ggplot2)
library(Seurat)
# Plot UMAP for each human reference map
refmap_umap <- lapply(names(ref.maps), function(x) {
DimPlot(ref.maps[[x]], cols = ref.maps[[x]]@misc$atlas.palette, label = T, repel = T) +
ggtitle(x) + NoLegend()
})
# Show all UMAPs
patchwork::wrap_plots(refmap_umap)Cell type classification
Classify cell types using HiTME, specifiy the species of origin of
the dataset. Default is human.
After cell type classification, the object metadata has been updated with different layers of cell type classification of granularity. We can explore the new metadata content:
# select the 3 layers or levels of granuality provided by HiTME
layers <- grep("layer[123]$", names(bassez@meta.data), value = T)
bassez@meta.data[1:20, layers]We can also visualize the cell type annotation in a UMAP
representation. Let’s do it for layer1, showing the broad
cell type classification.
# plot UMAP for layer1
DimPlot(bassez, group.by = "layer1", label = T, repel = T) + ggtitle("HiTME Layer1 annotation")Finally, we can also explore the cell type classification at the different levels using barplots showing the number of each cell subtype.
# Show barplot for each level of granularity
barplots_layers <- lapply(layers, function(l) {
ggplot(bassez@meta.data, aes(y = .data[[l]], fill = .data[[l]])) + geom_bar(show.legend = F) +
ggtitle(l) + theme_light()
})
barplots_layersSession Info
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/Zurich
tzcode source: internal
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] HiTME_2.0.0 Seurat_5.0.1 patchwork_1.1.3 ggplot2_3.4.4
[5] ProjecTILs_3.4.2 SeuratObject_5.0.1 sp_2.1-2 DT_0.28
[9] formatR_1.14 rmdformats_1.0.4 knitr_1.45
loaded via a namespace (and not attached):
[1] matrixStats_1.2.0 spatstat.sparse_3.0-3
[3] bitops_1.0-7 httr_1.4.7
[5] RColorBrewer_1.1-3 tools_4.3.1
[7] sctransform_0.4.1 backports_1.4.1
[9] utf8_1.2.4 R6_2.5.1
[11] lazyeval_0.2.2 uwot_0.1.16
[13] withr_2.5.2 prettyunits_1.2.0
[15] gridExtra_2.3 progressr_0.14.0
[17] cli_3.6.2 Biobase_2.62.0
[19] spatstat.explore_3.2-5 fastDummies_1.7.3
[21] labeling_0.4.3 sass_0.4.8
[23] spatstat.data_3.0-3 ggridges_0.5.5
[25] pbapply_1.7-2 askpass_1.2.0
[27] R.utils_2.12.2 parallelly_1.36.0
[29] RSQLite_2.3.4 generics_0.1.3
[31] crosstalk_1.2.1 ica_1.0-3
[33] spatstat.random_3.2-2 car_3.1-2
[35] dplyr_1.1.4 Matrix_1.6-3
[37] fansi_1.0.6 S4Vectors_0.40.2
[39] abind_1.4-5 R.methodsS3_1.8.2
[41] lifecycle_1.0.4 yaml_2.3.8
[43] carData_3.0-5 SummarizedExperiment_1.32.0
[45] SparseArray_1.2.3 BiocFileCache_2.10.1
[47] Rtsne_0.17 grid_4.3.1
[49] blob_1.2.4 promises_1.2.1
[51] crayon_1.5.2 miniUI_0.1.1.1
[53] lattice_0.21-8 cowplot_1.1.2
[55] KEGGREST_1.42.0 scGate_1.6.2
[57] pillar_1.9.0 GenomicRanges_1.54.1
[59] future.apply_1.11.1 codetools_0.2-19
[61] leiden_0.4.3.1 glue_1.6.2
[63] data.table_1.14.10 vctrs_0.6.5
[65] png_0.1-8 spam_2.10-0
[67] gtable_0.3.4 cachem_1.0.8
[69] xfun_0.41 S4Arrays_1.2.0
[71] mime_0.12 pracma_2.4.4
[73] survival_3.5-5 SingleCellExperiment_1.24.0
[75] pheatmap_1.0.12
[ reached getOption("max.print") -- omitted 104 entries ]