scTGIF
scTGIF 1.14.0
Here, we explain the concept of scTGIF. The analysis of single-cell RNA-Seq (scRNA-Seq) has a potential difficult problem; which data corresponds to what kind of cell type is not known a priori.
Therefore, at the start point of the data analysis of the scRNA-Seq dataset, each cell is “not colored” (unannotated) (Figure 1). There some approaches to support users to infer the cell types such as (1) Known marker gene expression, (2) BLAST-like gene expression comparison with reference DB, (3) differentially expressed genes (DEGs) and over-representative analysis (ORA) (scRNA-tools).
The first approach might be the most popular method, but this task is based on the expert knowledge about the cell types, and not always general-purpose. The second approach is easy and scalable, but still limited when the cell type is not known or still not measured by the other research organization. The third approach can perhaps be used in any situation but ambiguous and time-consuming task; this task is based on the cluster label and the true cluster structure, which is not known and some DEG methods have to be performed in each cluster, but recent scRNA-Seq dataset has tens to hundreds of cell types. Besides, a scRNA-Seq dataset can have low-quality cells and artifacts (e.g. doublet) but it is hard to distinguish from real cell data. Therefore, in actual data analytical situation, laborious trial-and-error cycle along with the change of cellular label cannot be evitable (Figure 1).
scTGIF is developed to reduce this trial-and-error cycle; This tool directly connects the unannotated cells and related gene function. Since this tool does not use reference DB, marker gene list, and cluster label can be used in any situation without expert knowledge and is not influenced by the change of cellular label.
In scTGIF, three data is required; the gene expression matrix, 2D coordinates of the cells (e.g. t-SNE, UMAP), and geneset of MSigDB. Firstly, the 2D coordinates are segmented as 50-by-50 grids, and gene expression is summarized in each grid level (X1). Next, the correspondence between genes and the related gene functions are summarized as gene-by-function matrix (X2). Here, we support only common genes are used in X1 and X2. Performing joint non-negative matrix factorization (jNMF) algorithm, which is implemented in nnTensor, the shared latent variables (W) with the two matrices are estimated.
By this algorithm, a grid set and corresponding gene functions are paired. Lower-dimension (D)-by-Grid matrix H1 works as attention maps to help users to pay attention the grids, and D-by-Function matrix H2 shows the gene function enriched in the grids.
scTGIF also supports some QC metrics to distinguish low-quality cells and artifacts from real cellular data.
To demonstrate the usage of scTGIF, we prepared a testdata of distal lung epithelium.
library("scTGIF")
## Warning: replacing previous import 'utils::findMatches' by
## 'S4Vectors::findMatches' when loading 'AnnotationDbi'
library("SingleCellExperiment")
library("GSEABase")
library("msigdbr")
data("DistalLungEpithelium")
data("pca.DistalLungEpithelium")
data("label.DistalLungEpithelium")
Although this data is still annotated and the cell type label is provided, scTGIF does not rely on this information.
par(ask=FALSE)
plot(pca.DistalLungEpithelium, col=label.DistalLungEpithelium, pch=16,
main="Distal lung epithelium dataset", xlab="PCA1", ylab="PCA2", bty="n")
text(0.1, 0.05, "AT1", col="#FF7F00", cex=2)
text(0.07, -0.15, "AT2", col="#E41A1C", cex=2)
text(0.13, -0.04, "BP", col="#A65628", cex=2)
text(0.125, -0.15, "Clara", col="#377EB8", cex=2)
text(0.09, -0.2, "Cilliated", col="#4DAF4A", cex=2)
To combine with the gene expression and the related gene function, we suppose the gene function data is summarized as the object of GSEABase. This data is directly downloadable from MSigDB and can be imported like gmt <- GSEABase::getGmt(“/YOURPATH/h.all.v6.0.entrez.gmt”)
Note that scTGIF only supports NCBI Gene IDs (Entrez IDs) for now. When the scRNA-Seq is not about human, the situation is more complicated. Here, we use msigdbr package to retrieve the mouse MSigDB genesets like below.
m_df = msigdbr(species = "Mus musculus",
category = "H")[, c("gs_name", "entrez_gene")]
hallmark = unique(m_df$gs_name)
gsc <- lapply(hallmark, function(h){
target = which(m_df$gs_name == h)
geneIds = unique(as.character(m_df$entrez_gene[target]))
GeneSet(setName=h, geneIds)
})
gmt = GeneSetCollection(gsc)
gmt = gmt[1:10] # Reduced for this demo
Next, the data matrix is converted to the object of SingleCellExperiment package, and the 2D coordinates are registered as the reducedDims slot.
sce <- SingleCellExperiment(assays = list(counts = DistalLungEpithelium))
reducedDims(sce) <- SimpleList(PCA=pca.DistalLungEpithelium)
Although the default mode of scTGIF use count
slot as
the input matrix,
the normalized gene expression data can also be specified.
In such a case, we recommend using normcounts
slot to register the data.
CPMED <- function(input){
libsize <- colSums(input)
median(libsize) * t(t(input) / libsize)
}
normcounts(sce) <- log10(CPMED(counts(sce)) + 1)
After the registration of the data in sce
,
settingTGIF
will work like below.
settingTGIF(sce, gmt, reducedDimNames="PCA", assayNames="normcounts")
Finally, reportTGIF
generates the HTML report to summarize
the result of jNMF.
reportTGIF(sce,
html.open=FALSE,
title="scTGIF Report for DistalLungEpithelium dataset",
author="Koki Tsuyuzaki")
## index.Rmd is created...
## index.Rmd is compiled to index.html...
## ################################################
## Data files are saved in
## /tmp/RtmpIEV3LE
## ################################################
Since this function takes some time,
please type example("reportTGIF")
by your own environment.
## R version 4.3.0 RC (2023-04-13 r84269)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.2 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.17-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB 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
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] plotly_4.10.1 ggplot2_3.4.2
## [3] msigdbr_7.5.1 GSEABase_1.62.0
## [5] graph_1.78.0 annotate_1.78.0
## [7] XML_3.99-0.14 AnnotationDbi_1.62.0
## [9] SingleCellExperiment_1.22.0 SummarizedExperiment_1.30.0
## [11] Biobase_2.60.0 GenomicRanges_1.52.0
## [13] GenomeInfoDb_1.36.0 IRanges_2.34.0
## [15] S4Vectors_0.38.0 BiocGenerics_0.46.0
## [17] MatrixGenerics_1.12.0 matrixStats_0.63.0
## [19] scTGIF_1.14.0 BiocStyle_2.28.0
##
## loaded via a namespace (and not attached):
## [1] RcppAnnoy_0.0.20 rTensor_1.4.8 splines_4.3.0
## [4] later_1.3.0 bitops_1.0-7 fields_14.1
## [7] tibble_3.2.1 polyclip_1.10-4 lifecycle_1.0.3
## [10] tcltk_4.3.0 globals_0.16.2 lattice_0.21-8
## [13] MASS_7.3-59 crosstalk_1.2.0 magrittr_2.0.3
## [16] sass_0.4.5 rmarkdown_2.21 plot3D_1.4
## [19] jquerylib_0.1.4 yaml_2.3.7 httpuv_1.6.9
## [22] Seurat_4.3.0 sctransform_0.3.5 spam_2.9-1
## [25] sp_1.6-0 spatstat.sparse_3.0-1 reticulate_1.28
## [28] cowplot_1.1.1 pbapply_1.7-0 DBI_1.1.3
## [31] RColorBrewer_1.1-3 maps_3.4.1 abind_1.4-5
## [34] zlibbioc_1.46.0 Rtsne_0.16 purrr_1.0.1
## [37] RCurl_1.98-1.12 tweenr_2.0.2 misc3d_0.9-1
## [40] GenomeInfoDbData_1.2.10 ggrepel_0.9.3 irlba_2.3.5.1
## [43] listenv_0.9.0 spatstat.utils_3.0-2 schex_1.14.0
## [46] goftest_1.2-3 spatstat.random_3.1-4 fitdistrplus_1.1-11
## [49] parallelly_1.35.0 leiden_0.4.3 codetools_0.2-19
## [52] DelayedArray_0.26.0 ggforce_0.4.1 tidyselect_1.2.0
## [55] farver_2.1.1 viridis_0.6.2 spatstat.explore_3.1-0
## [58] jsonlite_1.8.4 ellipsis_0.3.2 progressr_0.13.0
## [61] ggridges_0.5.4 survival_3.5-5 systemfonts_1.0.4
## [64] tools_4.3.0 ragg_1.2.5 tagcloud_0.6
## [67] ica_1.0-3 Rcpp_1.0.10 glue_1.6.2
## [70] gridExtra_2.3 xfun_0.39 dplyr_1.1.2
## [73] withr_2.5.0 BiocManager_1.30.20 fastmap_1.1.1
## [76] fansi_1.0.4 entropy_1.3.1 digest_0.6.31
## [79] R6_2.5.1 mime_0.12 textshaping_0.3.6
## [82] colorspace_2.1-0 scattermore_0.8 tensor_1.5
## [85] spatstat.data_3.0-1 RSQLite_2.3.1 hexbin_1.28.3
## [88] utf8_1.2.3 tidyr_1.3.0 generics_0.1.3
## [91] data.table_1.14.8 httr_1.4.5 htmlwidgets_1.6.2
## [94] uwot_0.1.14 pkgconfig_2.0.3 gtable_0.3.3
## [97] blob_1.2.4 lmtest_0.9-40 XVector_0.40.0
## [100] htmltools_0.5.5 dotCall64_1.0-2 bookdown_0.33
## [103] SeuratObject_4.1.3 scales_1.2.1 png_0.1-8
## [106] knitr_1.42 reshape2_1.4.4 nlme_3.1-162
## [109] cachem_1.0.7 zoo_1.8-12 stringr_1.5.0
## [112] KernSmooth_2.23-20 concaveman_1.1.0 parallel_4.3.0
## [115] miniUI_0.1.1.1 pillar_1.9.0 grid_4.3.0
## [118] vctrs_0.6.2 RANN_2.6.1 promises_1.2.0.1
## [121] xtable_1.8-4 cluster_2.1.4 evaluate_0.20
## [124] magick_2.7.4 cli_3.6.1 compiler_4.3.0
## [127] rlang_1.1.0 crayon_1.5.2 future.apply_1.10.0
## [130] labeling_0.4.2 plyr_1.8.8 stringi_1.7.12
## [133] deldir_1.0-6 viridisLite_0.4.1 babelgene_22.9
## [136] munsell_0.5.0 Biostrings_2.68.0 lazyeval_0.2.2
## [139] spatstat.geom_3.1-0 Matrix_1.5-4 patchwork_1.1.2
## [142] nnTensor_1.1.13 bit64_4.0.5 future_1.32.0
## [145] KEGGREST_1.40.0 shiny_1.7.4 highr_0.10
## [148] ROCR_1.0-11 igraph_1.4.2 memoise_2.0.1
## [151] bslib_0.4.2 bit_4.0.5