Harmony is an algorithm for performing integration of single cell genomics datasets. Please check out our latest manuscript on Nature Methods.
Install Harmony from CRAN with standard commands.
Once Harmony is installed, load it up!
The example below follows Figure 2 in the manuscript.
We downloaded 3 cell line datasets from the 10X website. The first two (jurkat and 293t) come from pure cell lines while the half dataset is a 50:50 mixture of Jurkat and HEK293T cells. We inferred cell type with the canonical marker XIST, since the two cell lines come from 1 male and 1 female donor.
We library normalized the cells, log transformed the counts, and scaled the genes. Then we performed PCA and kept the top 20 PCs. The PCA embeddings and meta data are available as part of this package.
Initially, the cells cluster by both dataset (left) and cell type (right).
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `group_by()` instead.
## ℹ See vignette('programming') for more help
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in geom_label(data = data_labels, label.size = NA, aes_string(label =
## label_name), : Ignoring unknown parameters: `segment.size`
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `group_by()` instead.
## ℹ See vignette('programming') for more help
## Ignoring unknown parameters: `segment.size`
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Let’s run Harmony to remove the influence of dataset-of-origin from the cell embeddings.
After Harmony, the datasets are now mixed (left) and the cell types are still separate (right).
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `group_by()` instead.
## ℹ See vignette('programming') for more help
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in geom_label(data = data_labels, label.size = NA, aes_string(label =
## label_name), : Ignoring unknown parameters: `segment.size`
## Warning: `group_by_()` was deprecated in dplyr 0.7.0.
## ℹ Please use `group_by()` instead.
## ℹ See vignette('programming') for more help
## Ignoring unknown parameters: `segment.size`
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
You can also run Harmony as part of an established pipeline in several packages, such as Seurat and SingleCellExperiment. For these vignettes, please visit our github page.
For more details on how each part of Harmony works, consult our more detailed vignette “Detailed Walkthrough of Harmony Algorithm”.
## R version 4.2.0 (2022-04-22)
## Platform: x86_64-conda-linux-gnu (64-bit)
## Running under: Arch Linux
##
## Matrix products: default
## BLAS/LAPACK: /home/main/miniconda3/envs/Renv/lib/libopenblasp-r0.3.21.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] patchwork_1.2.0 ggrepel_0.9.3 ggthemes_4.2.4 lubridate_1.9.2
## [5] forcats_1.0.0 stringr_1.5.0 purrr_1.0.2 readr_2.1.4
## [9] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.5.1 tidyverse_2.0.0
## [13] data.table_1.14.8 cowplot_1.1.3 dplyr_1.1.4 Seurat_5.0.1
## [17] SeuratObject_5.0.1 sp_1.6-1 harmony_1.2.1 Rcpp_1.0.12
##
## loaded via a namespace (and not attached):
## [1] Rtsne_0.16 colorspace_2.1-0 deldir_1.0-9
## [4] ellipsis_0.3.2 ggridges_0.5.4 RcppHNSW_0.5.0
## [7] spatstat.data_3.0-1 farver_2.1.2 leiden_0.4.3
## [10] listenv_0.9.0 RSpectra_0.16-1 fansi_1.0.6
## [13] codetools_0.2-19 splines_4.2.0 cachem_1.0.7
## [16] knitr_1.42 polyclip_1.10-4 spam_2.10-0
## [19] jsonlite_1.8.7 RhpcBLASctl_0.23-42 ica_1.0-3
## [22] cluster_2.1.4 png_0.1-8 uwot_0.1.16
## [25] spatstat.sparse_3.0-1 shiny_1.7.4 sctransform_0.4.1
## [28] compiler_4.2.0 httr_1.4.5 Matrix_1.6-5
## [31] fastmap_1.1.1 lazyeval_0.2.2 cli_3.6.2
## [34] later_1.3.0 htmltools_0.5.6.1 tools_4.2.0
## [37] igraph_1.6.0 dotCall64_1.1-1 gtable_0.3.5
## [40] glue_1.7.0 RANN_2.6.1 reshape2_1.4.4
## [43] scattermore_1.2 jquerylib_0.1.4 vctrs_0.6.5
## [46] nlme_3.1-162 spatstat.explore_3.2-1 progressr_0.13.0
## [49] lmtest_0.9-40 spatstat.random_3.1-5 xfun_0.40
## [52] globals_0.16.2 timechange_0.2.0 mime_0.12
## [55] miniUI_0.1.1.1 lifecycle_1.0.4 irlba_2.3.5.1
## [58] goftest_1.2-3 future_1.32.0 MASS_7.3-58.3
## [61] zoo_1.8-12 scales_1.3.0 hms_1.1.3
## [64] promises_1.2.0.1 spatstat.utils_3.0-5 parallel_4.2.0
## [67] RColorBrewer_1.1-3 yaml_2.3.7 reticulate_1.29
## [70] pbapply_1.7-0 gridExtra_2.3 sass_0.4.5
## [73] stringi_1.7.12 highr_0.10 fastDummies_1.7.3
## [76] rlang_1.1.3 pkgconfig_2.0.3 matrixStats_1.0.0
## [79] evaluate_0.22 lattice_0.20-45 tensor_1.5
## [82] ROCR_1.0-11 labeling_0.4.3 htmlwidgets_1.6.2
## [85] tidyselect_1.2.1 parallelly_1.36.0 RcppAnnoy_0.0.20
## [88] plyr_1.8.8 magrittr_2.0.3 R6_2.5.1
## [91] generics_0.1.3 withr_3.0.0 pillar_1.9.0
## [94] fitdistrplus_1.1-11 abind_1.4-5 survival_3.5-5
## [97] future.apply_1.11.0 crayon_1.5.2 KernSmooth_2.23-21
## [100] utf8_1.2.4 spatstat.geom_3.2-1 plotly_4.10.2
## [103] tzdb_0.4.0 rmarkdown_2.21 grid_4.2.0
## [106] digest_0.6.33 xtable_1.8-4 httpuv_1.6.9
## [109] munsell_0.5.1 viridisLite_0.4.2 bslib_0.4.2