scCrossTalk tutorial
Pre-processing
rev_gene()
Revise genes with rev_gene(). For scRNA-seq data, we
suggest to revise the gene symbols with rev_gene().
geneinfo is the system data.frame containing the
information of human and mouse from NCBI gene(updated in June. 19,
2022). To use your own geneinfo data.frame, please refer to
demo_geneinfo() to build a new one, e.g., rat, zebrafish,
Drosophila, C. elegans, etc.
library(scCrossTalk)
load(paste0(system.file(package = "scCrossTalk"), "/extdata/example.rda"))
# demo_geneinfo
demo_geneinfo()
#> symbol synonyms species
#> 1 A1BG A1B Human
#> 2 A1BG ABG Human
#> 3 A2MP1 A2MP Human
#> 4 Aco1 Aco Mouse
# demo_sc_data
demo_sc_data()
#> 6 x 6 sparse Matrix of class "dgCMatrix"
#> cell1 cell2 cell3 cell4 cell5 cell6
#> A1BG 41 . . 4 . 29
#> A2M . . 42 12 . .
#> A2MP 13 . . 50 . .
#> NAT1 . 21 . . 23 .
#> NAT2 45 . 48 . . .
#> NATP . 38 8 50 . 14
# revise gene symbols
sc_data <- rev_gene(data = sc_data,data_type = "count",species = "Human",geneinfo = geneinfo)Processing
create_scCrossTalk()
Create scCrossTalk object with create_scCrossTalk().
Users need to provide the raw count data and the cell type for
create_scCrossTalk(). scCrossTalk will use
NormalizeData() in Seurat to normalize data by
default. If your data has been normalized by other methods, you can set
the parameter if_normalize = FALSE
obj <- create_scCrossTalk(sc_data = sc_data, sc_celltype = sc_celltype, species = "Human", if_normalize = TRUE)
#> Warning: Feature names cannot have underscores ('_'), replacing with dashes
#> ('-')
# If your data has been normalized by other methods, you can set the parameter `if_normalize = FALSE`
# obj <- create_scCrossTalk(sc_data = sc_data, sc_celltype = sc_celltype,species = "Human", if_normalize = FALSE)find_lrpairs()
Find highly expressed LR pairs with find_lrpairs().
Users need to provided the speices and lr pairs database for
find_lrpairs(). lrpairs is the system
data.frame containing the known LR pairs of human and mouse from CellTalkDB. To use
your own lrpairs data.frame, please refer to demo_lrpairs()
to build a new one, e.g., rat, zebrafish, Drosophila, C. elegans,
etc.
# demo_lrpairs
demo_lrpairs()
#> ligand receptor species
#> 1 CX3CL1 CX3CR1 Human
#> 2 TGFB1 TGFBR2 Human
#> 3 CCL2 CCR2 Human
#> 4 Sst Sstr1 Mouse
# find highly expressed LR pairs
obj <- find_lrpairs(object = obj, lrpairs = lrpairs, min_cell_num = 10, cell_min_pct = 0.1, p_value = 0.05)
#> Finding highly expressed LR pairs
# results is stored in obj@cci
cci <- obj@cci
head(cci)
#> celltype_sender celltype_receiver ligand receptor ligand_pct ligand_exp_avg
#> 1 acinar_cell acinar_cell VIM CD44 0.6155718 0.8339240
#> 2 acinar_cell acinar_cell C3 CD46 0.5255474 0.8740566
#> 3 acinar_cell acinar_cell CXCL12 ITGB1 0.6496350 0.6158164
#> 4 acinar_cell acinar_cell LMAN1 MCFD2 0.8199513 0.7800645
#> 5 acinar_cell acinar_cell CXCL12 SDC4 0.6496350 0.6158164
#> 6 acinar_cell alpha_cell C3 CD46 0.5255474 0.8740566
#> ligand_z_score ligand_p_value receptor_pct receptor_exp_avg receptor_z_score
#> 1 2.611653 0.004505282 0.9075426 2.2410825 7.678032
#> 2 2.756148 0.002924328 0.8077859 0.8377001 2.625249
#> 3 1.826372 0.033897157 0.7883212 0.6926912 2.103154
#> 4 2.417736 0.007808710 0.8223844 0.9291400 2.954472
#> 5 1.826372 0.033897157 0.7737226 0.7283321 2.231477
#> 6 2.756148 0.002924328 0.9227683 1.6624160 5.250688
#> score
#> 1 1.8688924
#> 2 0.7321973
#> 3 0.4265706
#> 4 0.7247891
#> 5 0.4485189
#> 6 1.4530456Visualization
plot_cci_chord()
Parameters of plot_cci_chord() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot by order. Default is to plot all cell typescelltype_colorColors for the cell types, whose length must be equal tocelltypeligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorsedge_colorColors for the edges from the sender cell type, whose length must be equal to celltypeedge_typeTypes for the edges from the sender cell type. Default is “big.arrow”. “ellipse” for ellipse, “triangle” for triangle, “curved” for curved. Details seecirclize::chordDiagramshow_typewhich type to show, and for sum of inferred LR number and score, respectively. Default isif_show_autocrineWhether to show autocrine. Default istext_sizeSize of text labels. Default isy_scaley_scale to adjust the text. Default is...parameters pass tocirclize::chordDiagram, e.g.,link.arr.width,link.arr.length,link.arr.col
plot_cci_chord(object = obj)plot_cci_circle()
Parameters of plot_cci_circle() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot. Default is to plot all cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorscelltype_colorColors for the cell types, whose length must be equal tocelltypeedge_colorColors for the edges from the sender cell type, whose length must be equal tocelltypeedge_typeTypes for the edges. “fan” by default, “link”, “hive”show_typewhich type to show, “number” and “score” for sum of inferred LR number and score, respectively. Default is “number”if_show_autocrineWhether to show autocrine. Default isFALSEedge_alphaTransparency of edge. Default is 0.5node_sizeSize of node. Default is 10text_sizeSize of text. Default is 5
plot_cci_circle(object = obj)plot_cci_circle_simple()
To show one or more senders or receivers by retaining all cell
types, users can use plot_cci_circle_simple() for
plotting.
Parameters of plot_cci_circle_simple() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot. one or more cell typescelltype_dirwhich direction to plot, “sender” or “receiver”. Default is as “sender”ligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorscelltype_colorColors for the cell types, whose length must be equal tocelltypeedge_colorColors for the edges from the sender cell type, whose length must be equal tocelltypeedge_typeTypes for the edges. “fan” by default, “link”, “hive”show_typewhich type to show, “number” and “score” for sum of inferred LR number and score, respectively. Default is “number”if_show_autocrineWhether to show autocrine. Default isFALSEedge_alphaTransparency of edge. Default is 0.5node_sizeSize of node. Default is 10text_sizeSize of text. Default is 5
# as sender
plot_cci_circle_simple(object = obj, celltype = "ductal_cell", celltype_dir = "sender")
# as receiver
plot_cci_circle_simple(object = obj, celltype = "ductal_cell", celltype_dir = "reciver")plot_cci_heatmap()
Parameters of plot_cci_heatmap() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot. Default is to plot all cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorscelltype_colorColors for the cell types, whose length must be equal tocelltypeedge_colorColors for the edges from the sender cell type, whose length must be equal tocelltype, or use “NO” to cancel itshow_typewhich type to show, “number” and “score” for sum of inferred LR number and score, respectively. Default is “number”if_show_autocrineWhether to show autocrine. Default isFALSEedge_alphaTransparency of edge. Default is 0.5node_sizeSize of node. Default is 40text_sizeSize of text. Default is 15node_padSize of node padding. Numeric essentially influences the width height. Default is 20...parameters pass tonetworkD3::sankeyNetwork
plot_cci_heatmap(object = obj)plot_cci_sankey()
Parameters of plot_cci_sankey() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot by order. Default is to plot all cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorsshow_typewhich type to show, “number” and “score” for sum of inferred LR number and score, respectively. Default is “number”text_sizeSize of text labels. Default is 10viridis_optionoption inviridis::scale_color_viridis, can be “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”. Default is “D”....parameters pass toheatmaply::heatmaply, e.g., grid_color
plot_cci_sankey(object = obj)plot_cci_lrpairs_heatmap()
Parameters of plot_cci_lrpairs_heatmap()see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot. Default is to plot all cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorsif_show_autocrineWhether to show autocrine. Default isFALSEif_horizontalWhether to plot with the horizontal direction. Default isTRUEtext_sizeSize of text labels. Default is 10viridis_optionoption inviridis::scale_color_viridis, can be “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”. Default is “D”....parameters pass toheatmaply::heatmaply, e.g., grid_color
plot_cci_lrpairs_heatmap(object = obj)plot_cci_lrpairs_bubble()
Parameters of plot_cci_lrpairs_bubble() see below:
objectscCrossTalk object afterfind_lrpairscelltypewhich cell types to plot. Default is to plot all cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorsif_show_autocrineWhether to show autocrine. Default isFALSEif_horizontalWhether to plot with the horizontal direction. Default isTRUEsizeSize of the bubble. Default is 2viridis_optionoption inviridis::scale_color_viridis, can be “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”. Default is “D”.
plot_cci_lrpairs_bubble(object = obj)get_top_lrpairs()
Note: to filter the top LR interactions, users can use
get_top_lrpairs() for plotting
obj_filter <- obj
obj_filter@cci <- get_top_lrpairs(object = obj_filter, top_n = 5)
plot_cci_lrpairs_bubble(object = obj_filter, size = 2, if_horizontal = FALSE)plot_cci_lrpairs_heatmap(object = obj_filter, celltype = c("alpha_cell","beta_cell", "delta_cell", "ductal_cell"))plot_lrpairs_chord()
Parameters of plot_lrpairs_chord() see below:
objectscCrossTalk object afterfind_lrpairscelltype_senderName of celltype_sender. One or more cell typescelltype_receiverName of celltype_receiver. One or more cell typescelltype_colorColors for the celltype_sender nodes and celltype_receiver nodes, or use “NO” to make it simpleligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorsedge_colorColors for the edges from the sender cell typeedge_typeTypes for the edges from the sender cell type. Default is “circle”, “big.arrow” for big arrow, “triangle” for triangle, “ellipse” for ellipse, “curved” for curved. Details seecirclize::chordDiagramtext_sizeSize of text labels. Default is 0.5y_scaley_scale to adjust the text. Default is 1...parameters pass tocirclize::chordDiagram, e.g.,link.arr.width,link.arr.length,link.arr.col
plot_lrpairs_chord(obj,celltype_sender = "alpha_cell",celltype_receiver = "beta_cell",link.arr.width = 0.5, link.arr.length = 0.2, text_size = 0.8)plot_lrpairs_heatmap()
Parameters of plot_lrpairs_heatmap() see below:
objectscCrossTalk object afterfind_lrpairscelltype_senderName of celltype_sender. One or more cell typescelltype_receiverName of celltype_receiver. One or more cell typesligandwhich ligand to use. Default is to plot all inferred ligandsreceptorwhich receptor to use. Default is to plot all inferred receptorstext_sizeSize of text labels. Default is 3if_horizontalWhether to plot with the horizontal direction. Default isTRUEviridis_optionoption inviridis::scale_color_viridis, can be “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”. Default is “D”....parameters pass toheatmaply::heatmaply, e.g., grid_color
plot_lrpairs_heatmap(obj,celltype_sender = "alpha_cell",celltype_receiver = "beta_cell")sessionInfo()
#> R version 4.1.1 (2021-08-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.936
#> [2] LC_CTYPE=Chinese (Simplified)_China.936
#> [3] LC_MONETARY=Chinese (Simplified)_China.936
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=Chinese (Simplified)_China.936
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] scCrossTalk_1.0
#>
#> loaded via a namespace (and not attached):
#> [1] circlize_0.4.13 plyr_1.8.6 igraph_1.2.7
#> [4] lazyeval_0.2.2 sp_1.4-5 splines_4.1.1
#> [7] crosstalk_1.2.0 listenv_0.8.0 scattermore_0.7
#> [10] ggplot2_3.3.6 digest_0.6.28 foreach_1.5.1
#> [13] ca_0.71.1 htmltools_0.5.2 viridis_0.6.2
#> [16] fansi_0.5.0 magrittr_2.0.1 tensor_1.5
#> [19] cluster_2.1.2 ROCR_1.0-11 globals_0.14.0
#> [22] graphlayouts_0.7.1 matrixStats_0.61.0 spatstat.sparse_3.0-0
#> [25] rmdformats_1.0.3 prettyunits_1.1.1 colorspace_2.0-2
#> [28] ggrepel_0.9.1 xfun_0.30 dplyr_1.0.7
#> [31] crayon_1.4.2 jsonlite_1.7.2 progressr_0.9.0
#> [34] spatstat.data_3.0-0 survival_3.2-11 zoo_1.8-9
#> [37] iterators_1.0.13 glue_1.4.2 polyclip_1.10-0
#> [40] registry_0.5-1 gtable_0.3.0 webshot_0.5.4
#> [43] leiden_0.3.9 future.apply_1.8.1 shape_1.4.6
#> [46] abind_1.4-5 scales_1.1.1 DBI_1.1.1
#> [49] miniUI_0.1.1.1 Rcpp_1.0.7 viridisLite_0.4.0
#> [52] xtable_1.8-4 progress_1.2.2 reticulate_1.22
#> [55] spatstat.core_2.3-0 htmlwidgets_1.5.4 httr_1.4.2
#> [58] RColorBrewer_1.1-2 ellipsis_0.3.2 Seurat_4.1.1
#> [61] ica_1.0-2 pkgconfig_2.0.3 farver_2.1.0
#> [64] sass_0.4.0 uwot_0.1.10 deldir_1.0-6
#> [67] utf8_1.2.2 labeling_0.4.2 tidyselect_1.1.1
#> [70] rlang_0.4.12 reshape2_1.4.4 later_1.3.0
#> [73] munsell_0.5.0 tools_4.1.1 generics_0.1.1
#> [76] ggridges_0.5.3 evaluate_0.14 stringr_1.4.0
#> [79] fastmap_1.1.0 heatmaply_1.4.0 yaml_2.2.1
#> [82] goftest_1.2-3 knitr_1.36 fitdistrplus_1.1-6
#> [85] tidygraph_1.2.0 purrr_0.3.4 RANN_2.6.1
#> [88] dendextend_1.16.0 ggraph_2.0.5 pbapply_1.5-0
#> [91] future_1.23.0 nlme_3.1-152 mime_0.12
#> [94] compiler_4.1.1 plotly_4.10.0 png_0.1-7
#> [97] spatstat.utils_3.0-1 tibble_3.1.5 tweenr_1.0.2
#> [100] bslib_0.3.1 stringi_1.7.5 highr_0.9
#> [103] rgeos_0.5-9 lattice_0.20-44 Matrix_1.3-4
#> [106] vctrs_0.3.8 pillar_1.6.4 lifecycle_1.0.1
#> [109] networkD3_0.4 spatstat.geom_3.0-3 lmtest_0.9-38
#> [112] jquerylib_0.1.4 GlobalOptions_0.1.2 RcppAnnoy_0.0.19
#> [115] data.table_1.14.2 cowplot_1.1.1 irlba_2.3.3
#> [118] seriation_1.4.0 httpuv_1.6.3 patchwork_1.1.1
#> [121] R6_2.5.1 bookdown_0.25 promises_1.2.0.1
#> [124] TSP_1.2-1 KernSmooth_2.23-20 gridExtra_2.3
#> [127] parallelly_1.28.1 codetools_0.2-18 MASS_7.3-54
#> [130] assertthat_0.2.1 SeuratObject_4.1.0 sctransform_0.3.3
#> [133] mgcv_1.8-36 parallel_4.1.1 hms_1.1.1
#> [136] grid_4.1.1 rpart_4.1-15 tidyr_1.1.4
#> [139] rmarkdown_2.13 Rtsne_0.15 ggforce_0.3.3
#> [142] shiny_1.7.1About
Please refer to the scCrossTalk on GitHub or the document for more information.