The traviz
package was created to collect visualization functions related to trajectory inference. Asides from general purpose functions useful to any user, it also contains visualizations that can be used in a slingshot
, tradeSeq
or condiments
workflow.
First, we will demonstrate functions to visualize a trajectory. Here, we’ll work with a trajectory as estimated by Slingshot (Street et al. 2018). An example trajectory is provided along with the traviz
package.
Below, we show how one can use the lines
and plot
functions for a SlingshotDataSet
object. We also show how the plotGeneCount
function can be used for a quick visualization of the trajectory.
library(slingshot)
library(traviz)
##
## Attaching package: 'traviz'
## The following object is masked from 'package:scater':
##
## plotExpression
data(crv, package = "traviz")
class(crv)
## [1] "SlingshotDataSet"
## attr(,"package")
## [1] "slingshot"
rd <- slingReducedDim(crv)
cl <- apply(slingClusterLabels(crv),1, function(x) which(x==1))
## Only visualize the trajectory
plot(crv)
## Visualize the trajectory on top of cells in reduced space
plot(rd, pch=16, col=cl+1, cex=2/3)
lines(crv, col="black", lwd=3)
## Visualizing trajectory and clusters using plotGeneCount
plotGeneCount(crv, clusters=cl)
The same functions (i.e., plot
and lines
) can also be used to visualize trajectories in 3D space using the rgl
package. This can be done using the plot3d
and lines3d
functions, in similar vein as the 2D visualizations above.
The plotGeneCount
also allows you to visualize the trajectory in reduced space, where each cell is colored according to its expression of the gene as defined by the gene
argument.
data(counts, package="traviz")
plotGeneCount(crv, counts, gene = "Mpo")
The plotExpression
function may be used to visualize gene expression along pseudotime along with a quick smooth estimate of average gene expression. It uses a loess smoother to smooth the raw gene expression values as a function of pseudotime. Note that no between-cell normalization occurs to do the smoothing.
plotExpression(counts=counts,
sds=crv,
gene="Car1")
If smoothers have been fitted using tradeSeq
, then one can use the plotSmoothers
function to plot the estimated smoothers. Note that here normalization does happen within tradeSeq
, and the smoothers are estimated using a negative binomial count model.
data(sce, package="traviz")
plotSmoothers(models = sce, counts = counts, gene = "Elane")
Any comment, question, or feedback is welcome and can be posted as an issue on the traviz repo.
sessionInfo()
## R version 4.1.1 (2021-08-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
##
## 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
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] traviz_1.0.0 scater_1.22.0
## [3] scuttle_1.4.0 dplyr_1.0.7
## [5] ggplot2_3.3.5 slingshot_2.2.0
## [7] TrajectoryUtils_1.2.0 SingleCellExperiment_1.16.0
## [9] SummarizedExperiment_1.24.0 Biobase_2.54.0
## [11] GenomicRanges_1.46.0 GenomeInfoDb_1.30.0
## [13] IRanges_2.28.0 S4Vectors_0.32.0
## [15] BiocGenerics_0.40.0 MatrixGenerics_1.6.0
## [17] matrixStats_0.61.0 princurve_2.1.6
## [19] knitr_1.36
##
## loaded via a namespace (and not attached):
## [1] nlme_3.1-153 fs_1.5.0
## [3] bitops_1.0-7 RColorBrewer_1.1-2
## [5] tools_4.1.1 bslib_0.3.1
## [7] utf8_1.2.2 R6_2.5.1
## [9] irlba_2.3.3 vipor_0.4.5
## [11] DBI_1.1.1 mgcv_1.8-38
## [13] colorspace_2.0-2 withr_2.4.2
## [15] tidyselect_1.1.1 gridExtra_2.3
## [17] extrafontdb_1.0 compiler_4.1.1
## [19] BiocNeighbors_1.12.0 DelayedArray_0.20.0
## [21] labeling_0.4.2 sass_0.4.0
## [23] scales_1.1.1 pkgdown_1.6.1
## [25] stringr_1.4.0 digest_0.6.28
## [27] rmarkdown_2.11 XVector_0.34.0
## [29] pkgconfig_2.0.3 htmltools_0.5.2
## [31] extrafont_0.17 sparseMatrixStats_1.6.0
## [33] fastmap_1.1.0 highr_0.9
## [35] htmlwidgets_1.5.4 rlang_0.4.12
## [37] DelayedMatrixStats_1.16.0 jquerylib_0.1.4
## [39] farver_2.1.0 generics_0.1.1
## [41] jsonlite_1.7.2 BiocParallel_1.28.0
## [43] RCurl_1.98-1.5 magrittr_2.0.1
## [45] BiocSingular_1.10.0 GenomeInfoDbData_1.2.7
## [47] Matrix_1.3-4 Rcpp_1.0.7
## [49] ggbeeswarm_0.6.0 munsell_0.5.0
## [51] fansi_0.5.0 viridis_0.6.2
## [53] lifecycle_1.0.1 stringi_1.7.5
## [55] yaml_2.2.1 zlibbioc_1.40.0
## [57] grid_4.1.1 parallel_4.1.1
## [59] ggrepel_0.9.1 crayon_1.4.1
## [61] lattice_0.20-45 cowplot_1.1.1
## [63] beachmat_2.10.0 splines_4.1.1
## [65] pillar_1.6.4 igraph_1.2.7
## [67] ScaledMatrix_1.2.0 glue_1.4.2
## [69] evaluate_0.14 vctrs_0.3.8
## [71] Rttf2pt1_1.3.9 gtable_0.3.0
## [73] purrr_0.3.4 assertthat_0.2.1
## [75] cachem_1.0.6 xfun_0.27
## [77] rsvd_1.0.5 viridisLite_0.4.0
## [79] tibble_3.1.5 memoise_2.0.0
## [81] beeswarm_0.4.0 rgl_0.107.14
## [83] ellipsis_0.3.2
Street, Kelly, Davide Risso, Russell B. Fletcher, Diya Das, John Ngai, Nir Yosef, Elizabeth Purdom, and Sandrine Dudoit. 2018. “Slingshot: cell lineage and pseudotime inference for single-cell transcriptomics.” BMC Genomics 19 (1): 477. https://doi.org/10.1186/s12864-018-4772-0.