Last updated: 2024-01-31

Checks: 6 1

Knit directory: SuperCellCyto-analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(42) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 264aa64. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    code/.DS_Store
    Ignored:    code/b_cell_identification/.DS_Store
    Ignored:    code/b_cell_identification/runtime_benchmark/.DS_Store
    Ignored:    code/batch_correction/.DS_Store
    Ignored:    code/batch_correction/runtime_benchmark/.DS_Store
    Ignored:    code/explore_supercell_purity_clustering/.DS_Store
    Ignored:    code/explore_supercell_purity_clustering/functions/.DS_Store
    Ignored:    code/explore_supercell_purity_clustering/louvain_all_cells/.DS_Store
    Ignored:    code/explore_supercell_purity_clustering/louvain_all_cells/levine_32dim/.DS_Store
    Ignored:    code/label_transfer/.Rhistory
    Ignored:    data/.DS_Store
    Ignored:    data/bodenmiller_cytof/
    Ignored:    data/explore_supercell_purity_clustering/
    Ignored:    data/haas_bm/
    Ignored:    data/oetjen_bm_dataset/
    Ignored:    data/trussart_cytofruv/
    Ignored:    output/.DS_Store
    Ignored:    output/bodenmiller_cytof/
    Ignored:    output/explore_supercell_purity_clustering/
    Ignored:    output/label_transfer/
    Ignored:    output/oetjen_b_cell_panel/
    Ignored:    output/trussart_cytofruv/

Untracked files:
    Untracked:  code/b_cell_identification/additional_code/
    Untracked:  code/batch_correction/additional_code/
    Untracked:  code/explore_supercell_purity_clustering/additional_code/
    Untracked:  code/label_transfer/additional_code/

Unstaged changes:
    Modified:   SuperCellCyto-analysis.Rproj
    Modified:   analysis/b_cells_identification.Rmd
    Modified:   analysis/batch_correction.Rmd
    Modified:   analysis/explore_supercell_purity_clustering.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/b_cells_identification.Rmd) and HTML (docs/b_cells_identification.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 98e46e0 Givanna Putri 2023-08-15 Build site.
Rmd 7baf7b7 Givanna Putri 2023-08-15 wflow_publish("analysis/*")
html a55c3ba Givanna Putri 2023-07-28 Build site.
html 366514e Givanna Putri 2023-07-28 Build site.
Rmd 402358b Givanna Putri 2023-07-28 wflow_publish(c("analysis/*Rmd"))

Introduction

In this analysis, we seek to verify whether we can faithfully replicate the traditional clustering and annotation process, and identify rare cell populations at the supercell level

The flow cytometry data set we employed were the large flow cytometry dataset profiling more than 8 million B cells in healthy human bone marrow samples (Oetjen et al. 2018).

The annotation for the dataset were not publicly available. However, the authors have provided the following gating strategy within the manuscript’s supplementary material (Oetjen et al. 2018), which can be employed to discern B cells within the data:

  • Pre-B cell (CD20-): CD45+ CD19+ CD20- CD10+
  • Immature B cells (CD20+): CD45+ CD19+ CD20+ CD10+
    • Transitional B cells: CD45+ CD19+ CD20+ CD10+ CD27-
  • Mature B cells: CD45+ CD19+ CD20+ CD10-
    • Naïve Mature B cells: CD45+ CD19+ CD20+ CD10- CD27- CD21hi
    • Exhausted/Tissue-like Memory: CD45+ CD19+ CD20+ CD10- CD27- CD21lo
    • Memory B cells: CD45+ CD19+ CD20+ CD10- CD27+
      • Activated Mature: CD45+ CD19+ CD20+ CD10- CD27+ CD21lo
      • Resting Memory: CD45+ CD19+ CD20+ CD10- CD27+ CD21hi
  • CD20- CD10-: CD45+ CD19+ CD20- CD10-
    • Plasmablast: CD45+ CD19+ CD20- CD10- CD27+ CD38+
      • Plasma Cell: CD45+ CD19+ CD20- CD10- CD27+ CD38+ CD138+

The B cell panel consists of 13 markers, namely:

  1. CD80
  2. Live/Dead
  3. CD27
  4. CD19
  5. CD45
  6. CD10
  7. CD138
  8. PD-1
  9. CD20
  10. CD38
  11. CD86
  12. CD21
  13. CD40

The process employed in this study comprises the following steps: FCS files were initially downloaded from the FlowRepository website FR-FCM-ZYQ9.

Single live cells were isolated through manual gating using CytoExplorer (Hammill 2021) (the relevant code can be found in code/b_cell_identification/gate_flow_data.R). The following single live cells were retained.

knitr::include_graphics("assets/oetjen_bcell_single_live_cells.png", error = FALSE)

Version Author Date
7f102a5 Givanna Putri 2023-07-28

Subsequently, the markers were transformed using the arcsinh transformation with a co-factor of 150. This was followed by the application of SuperCellCyto, which produced a set of supercells. These supercells were clustered using Louvain clustering with k parameter set to 3.

All code used to execute these procedures can be found in code/oetjen_bm_data/cluster_run_supercell.R.

Load libraries

library(scales)
library(SingleCellExperiment)
library(ggforce)
library(here)
library(data.table)
library(cowplot)
library(Spectre)
library(ggplot2)
library(viridis)
library(bluster)
library(pheatmap)
library(ggridges)

Load data

root_dir <- here("output", "oetjen_b_cell_panel", "20230511")
supercell_mat <- fread(here(root_dir, "supercellExpMat_clust_umap.csv"))

markers <- names(supercell_mat)[1:12]

cell_type_markers <- paste0(
  c("CD19", "CD45", "CD10", "CD20", "CD27", "CD21", "CD38", "CD138"),
  "_asinh_cf150"
)

Identify B cells

Use pheatmap annotate the clusters.

supercell_mat_forHeatmap <- supercell_mat[, c("louvain_k3", cell_type_markers), with = FALSE]
supercell_mat_forHeatmap <- supercell_mat_forHeatmap[order(louvain_k3)]
supercell_mat_forHeatmap[, cluster := paste0("cluster_", louvain_k3)]
supercell_mat_forHeatmap[, louvain_k3 := NULL]

median_exp <- supercell_mat_forHeatmap[, lapply(.SD, median), by = cluster, .SDcols = cell_type_markers]
median_exp_mat <- as.matrix(median_exp[, cell_type_markers, with = FALSE])
row.names(median_exp_mat) <- median_exp$cluster
colnames(median_exp_mat) <- gsub("_asinh_cf150", "", colnames(median_exp_mat))

pheatmap(
  median_exp_mat,
  cluster_cols = FALSE,
  cluster_rows = FALSE,
  display_numbers = TRUE,
  number_format = "%.2f",
  scale = "column",
  main = "Median Expression of Cell Type Markers Across Clusters"
)

Version Author Date
366514e Givanna Putri 2023-07-28

Using the heatmap, we derive the following cell type annotations.

annotation <- rep("CD45- and/or CD19-", 46)
annotation[41] <- "Pre B cells"
annotation[18] <- "Immature B cells"
annotation[26] <- "Transitional B cells"
annotation[c(27, 29, 32, 38, 39, 40)] <- "CD20- CD10-"
annotation[37] <- "Plasmablast"
annotation[46] <- "Plasma cells"
annotation[22] <- "Naive Mature B cells"
annotation[15] <- "Exhausted Tissue like Memory"
annotation[30] <- "Resting Memory"
annotation[c(28, 43)] <- "Activated Mature"

annotation_df <- data.table(cluster = paste0("cluster_", seq(1, 46)), cell_type = annotation)

Create the heatmap which show median expression and also the annotation for each cluster.

# The order is for ordering the heatmap so the same cell types are together
heatmap_annot_col <- annotation_df[order(cell_type)]
heatmap_annot_col <- heatmap_annot_col[cell_type != "CD45- and/or CD19-"]
heatmap_annot_col <- data.frame(heatmap_annot_col, row.names = "cluster")
annot_cell_types <- unique(heatmap_annot_col$cell_type)

annot_colours <- viridis(n = length(annot_cell_types), option = "turbo")
names(annot_colours) <- annot_cell_types

# Re-order heatmap to match annotation so the same cell types are together
median_exp_mat_noUnassigned <- median_exp_mat[rownames(heatmap_annot_col), ]

pheatmap(
  t(median_exp_mat_noUnassigned),
  cluster_cols = FALSE,
  cluster_rows = FALSE,
  annotation_col = heatmap_annot_col,
  # scale = "column",
  main = "Median Expression of Cell Type Markers Across Clusters",
  annotation_colors = list(cell_type = annot_colours),
  angle_col = 90
)

Version Author Date
366514e Givanna Putri 2023-07-28

We then embed them to the supercell matrix.

supercell_mat_annot <- supercell_mat
supercell_mat_annot[, cluster := paste0("cluster_", louvain_k3)]
supercell_mat_annot <- merge.data.table(
  x = supercell_mat,
  y = annotation_df,
  by = "cluster"
)

Following this, we generate the UMAP plot reflecting these annotations. The UMAP coordinates were generated using the Spectre package. The code to generate the UMAP coordinates is available on code/oetjen_bm_data/cluster_run_supercell.R.

cell_types <- sort(unique(supercell_mat_annot$cell_type))
cell_types <- cell_types[cell_types != "CD45- and/or CD19-"]
colour_scheme <- viridis(n = length(cell_types), option = "turbo")
names(colour_scheme) <- cell_types
colour_scheme["CD45- and/or CD19-"] <- "#D3D3D3"

# So unknown is at the bottom.
supercell_mat_annot[, cell_type := factor(cell_type, levels = names(colour_scheme))]

ggplot(supercell_mat_annot, aes(x = UMAP_X, y = UMAP_Y, colour = cell_type)) +
  geom_point(size = 0.2) +
  theme_classic() +
  guides(colour = guide_legend(override.aes = list(size = 5))) +
  scale_colour_manual(values = colour_scheme) +
  labs(colour = "Cell type")

Version Author Date
98e46e0 Givanna Putri 2023-08-15
366514e Givanna Putri 2023-07-28

To be more sure that our cell type annotation is reasonable, we shall expand our annotated supercells to the single cell level and visualise the distribution of their marker expression. We will exclude those we assigned “unknown” label.

Remove unassigned for heatmap.

supercell_mat_annot_noUnassigned <- supercell_mat_annot[cell_type != "CD45- and/or CD19-"]

Check the distribution of the marker expression of the single cells expanded from the annotated supercells.

cell_mat <- fread(here(
  "output", "oetjen_b_cell_panel", "20230404_cytoexplorer_gating",
  "cell_dat_asinh.csv"
))

cell_map_full <- fread(here(
  "output", "oetjen_b_cell_panel", "20230511",
  "supercellCellMap.csv"
))

cell_map <- merge.data.table(
  x = cell_map_full,
  y = supercell_mat_annot_noUnassigned[, c("SuperCellId", "cell_type")],
  by.x = "SuperCellID",
  by.y = "SuperCellId"
)
cell_map <- cell_map[cell_type != "CD45- and/or CD19-", ]

cell_mat <- merge.data.table(
  x = cell_mat,
  y = cell_map,
  by = "CellId"
)

cell_mat_long <- melt(
  data = cell_mat,
  id.vars = "cell_type",
  measure.vars = cell_type_markers,
  variable.name = "marker"
)

cell_mat_long$marker <- gsub("_asinh_cf150", "", cell_mat_long$marker)

# So we can order the y-axis of the plot so the order somewhat resembles the
# hierarchical structure of the gating strategy.
cell_mat_long$marker <- factor(cell_mat_long$marker,
  levels = c("CD45", "CD19", "CD20", "CD10", "CD27", "CD21", "CD38", "CD138")
)
cell_mat_long <- cell_mat_long[order(marker)]
ggplot(cell_mat_long, aes(x = value, y = marker, colour = marker, fill = marker)) +
  geom_density_ridges(alpha = 0.3) +
  scale_colour_viridis(option = "turbo", discrete = TRUE, guide = "none") +
  scale_fill_viridis(option = "turbo", discrete = TRUE, guide = "none") +
  theme_ridges() +
  facet_wrap(~cell_type) +
  scale_x_continuous(breaks = pretty_breaks(n = 10)) +
  labs(
    y = "Marker", x = "Marker Expression",
    title = "Distribution of Marker Expression of Single Cells"
  )

Version Author Date
366514e Givanna Putri 2023-07-28

How many supercells unannotated.

table(supercell_mat_annot$cell_type)["CD45- and/or CD19-"] / nrow(supercell_mat_annot)
CD45- and/or CD19- 
         0.6827868 

How many plasma cells we found?

plasma_cell_supercells <- supercell_mat_annot[cell_type == "Plasma cells"]
plasma_cells <- cell_map_full[SuperCellID %in% plasma_cell_supercells$SuperCellId]
nrow(plasma_cells)
[1] 162
100*nrow(plasma_cells) / nrow(cell_map_full)
[1] 0.00194846
nrow(plasma_cell_supercells)
[1] 14

Plot the proportion of each cell type as boxplot.

cell_map <- merge.data.table(
  x = cell_map_full,
  y = supercell_mat_annot[, c("SuperCellId", "cell_type", "louvain_k3")],
  by.x = "SuperCellID",
  by.y = "SuperCellId"
)

# Proportion for each cluster and cell type
cell_type_proportion <- cell_map[, .(cnt_per_clust = .N), by = c("cell_type", "Sample")]
cell_type_proportion[, proportion := cnt_per_clust / nrow(cell_map)]
cell_type_proportion_noUnassigned <- cell_type_proportion[cell_type != "CD45- and/or CD19-", ]

# Get the cell type name ordered alphabetically so we match the colour to the heatmap
ordered_cell_name <- sort(cell_type_proportion_noUnassigned$cell_type)
cell_name_color <- turbo(n = length(ordered_cell_name))
names(cell_name_color) <- ordered_cell_name


# Order from highest proportion to low
# cell_type_proportion_noUnassigned <- cell_type_proportion_noUnassigned[order(-proportion)]
# cell_type_proportion_noUnassigned[, cell_type := factor(cell_type, levels = cell_type_proportion_noUnassigned$cell_type)]
ggplot(cell_type_proportion_noUnassigned, aes(x = cell_type, y = proportion)) +
  geom_boxplot() +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none") +
  scale_y_continuous(breaks = pretty_breaks(n = 10)) +
  scale_color_manual(values = cell_name_color, breaks = names(cell_name_color)) +
  labs(
    y = "Proportion of single cells", x = "Cell type", color = "Cell type",
    title = "Proportion of B cell subsets across all samples"
  )

Version Author Date
98e46e0 Givanna Putri 2023-08-15
366514e Givanna Putri 2023-07-28

References

Hammill, Dillon. 2021. CytoExploreR: Interactive Analysis of Cytometry Data. https://github.com/DillonHammill/CytoExploreR.
Oetjen, Karolyn A, Katherine E Lindblad, Meghali Goswami, Gege Gui, Pradeep K Dagur, Catherine Lai, Laura W Dillon, J Philip McCoy, and Christopher S Hourigan. 2018. “Human Bone Marrow Assessment by Single-Cell RNA Sequencing, Mass Cytometry, and Flow Cytometry.” JCI Insight 3 (23).

sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 14.0

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ggridges_0.5.4              pheatmap_1.0.12            
 [3] bluster_1.8.0               viridis_0.6.2              
 [5] viridisLite_0.4.1           Spectre_1.0.0-0            
 [7] cowplot_1.1.1               data.table_1.14.10         
 [9] here_1.0.1                  ggforce_0.4.1              
[11] ggplot2_3.4.1               SingleCellExperiment_1.20.0
[13] SummarizedExperiment_1.28.0 Biobase_2.58.0             
[15] GenomicRanges_1.50.2        GenomeInfoDb_1.34.9        
[17] IRanges_2.32.0              S4Vectors_0.36.1           
[19] BiocGenerics_0.44.0         MatrixGenerics_1.10.0      
[21] matrixStats_0.63.0          scales_1.2.1               
[23] workflowr_1.7.0            

loaded via a namespace (and not attached):
  [1] spam_2.10-0            plyr_1.8.8             igraph_1.4.0          
  [4] lazyeval_0.2.2         sp_1.6-0               splines_4.2.3         
  [7] flowCore_2.10.0        RcppHNSW_0.4.1         BiocParallel_1.32.6   
 [10] listenv_0.9.0          scattermore_1.2        digest_0.6.31         
 [13] htmltools_0.5.4        fansi_1.0.4            magrittr_2.0.3        
 [16] tensor_1.5             cluster_2.1.4          ROCR_1.0-11           
 [19] limma_3.54.1           globals_0.16.2         cytolib_2.10.0        
 [22] spatstat.sparse_3.0-0  colorspace_2.1-0       ggrepel_0.9.3         
 [25] xfun_0.39              dplyr_1.1.0            callr_3.7.3           
 [28] RCurl_1.98-1.10        jsonlite_1.8.4         progressr_0.13.0      
 [31] spatstat.data_3.0-0    survival_3.5-3         zoo_1.8-11            
 [34] glue_1.6.2             polyclip_1.10-4        gtable_0.3.1          
 [37] zlibbioc_1.44.0        XVector_0.38.0         leiden_0.4.3          
 [40] DelayedArray_0.24.0    future.apply_1.10.0    abind_1.4-5           
 [43] spatstat.random_3.1-3  miniUI_0.1.1.1         Rcpp_1.0.10           
 [46] xtable_1.8-4           reticulate_1.28        rsvd_1.0.5            
 [49] dotCall64_1.1-1        htmlwidgets_1.6.1      httr_1.4.4            
 [52] RColorBrewer_1.1-3     ellipsis_0.3.2         Seurat_5.0.1          
 [55] ica_1.0-3              pkgconfig_2.0.3        farver_2.1.1          
 [58] uwot_0.1.14            deldir_1.0-6           sass_0.4.5            
 [61] utf8_1.2.3             labeling_0.4.2         tidyselect_1.2.0      
 [64] rlang_1.0.6            reshape2_1.4.4         later_1.3.0           
 [67] munsell_0.5.0          tools_4.2.3            cachem_1.0.6          
 [70] cli_3.6.1              generics_0.1.3         evaluate_0.20         
 [73] stringr_1.5.0          fastmap_1.1.0          goftest_1.2-3         
 [76] yaml_2.3.7             processx_3.8.0         knitr_1.42            
 [79] fs_1.6.1               fitdistrplus_1.1-8     purrr_1.0.1           
 [82] RANN_2.6.1             nlme_3.1-162           pbapply_1.7-0         
 [85] future_1.33.1          whisker_0.4.1          mime_0.12             
 [88] compiler_4.2.3         rstudioapi_0.14        plotly_4.10.1         
 [91] png_0.1-8              spatstat.utils_3.0-1   tibble_3.1.8          
 [94] tweenr_2.0.2           bslib_0.4.2            stringi_1.7.12        
 [97] highr_0.10             ps_1.7.2               RSpectra_0.16-1       
[100] lattice_0.20-45        Matrix_1.6-4           vctrs_0.5.2           
[103] pillar_1.8.1           lifecycle_1.0.3        spatstat.geom_3.0-6   
[106] lmtest_0.9-40          jquerylib_0.1.4        BiocNeighbors_1.16.0  
[109] RcppAnnoy_0.0.20       bitops_1.0-7           irlba_2.3.5.1         
[112] httpuv_1.6.9           patchwork_1.1.2        R6_2.5.1              
[115] promises_1.2.0.1       RProtoBufLib_2.10.0    KernSmooth_2.23-20    
[118] gridExtra_2.3          parallelly_1.34.0      codetools_0.2-19      
[121] fastDummies_1.7.3      MASS_7.3-58.2          rprojroot_2.0.3       
[124] withr_2.5.0            SeuratObject_5.0.1     sctransform_0.4.1     
[127] GenomeInfoDbData_1.2.9 parallel_4.2.3         grid_4.2.3            
[130] tidyr_1.3.0            rmarkdown_2.20         Rtsne_0.16            
[133] git2r_0.31.0           getPass_0.2-2          spatstat.explore_3.0-6
[136] shiny_1.7.4