Introduction

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.

Visualization of a trajectory

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)

3D visualization

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.

Visualization of gene expression along a trajectory

Visualizing gene expression along with the trajectory in reduced space

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")

Visualizing gene expression along pseudotime

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")

Feedback and suggestions

Any comment, question, or feedback is welcome and can be posted as an issue on the traviz repo.

Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-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.4.0                scater_1.26.0              
##  [3] scuttle_1.8.0               dplyr_1.0.10               
##  [5] ggplot2_3.3.6               slingshot_2.6.0            
##  [7] TrajectoryUtils_1.6.0       SingleCellExperiment_1.20.0
##  [9] SummarizedExperiment_1.28.0 Biobase_2.58.0             
## [11] GenomicRanges_1.50.0        GenomeInfoDb_1.34.0        
## [13] IRanges_2.32.0              S4Vectors_0.36.0           
## [15] BiocGenerics_0.44.0         MatrixGenerics_1.10.0      
## [17] matrixStats_0.62.0          princurve_2.1.6            
## [19] knitr_1.40                 
## 
## loaded via a namespace (and not attached):
##  [1] nlme_3.1-160              bitops_1.0-7             
##  [3] RColorBrewer_1.1-3        tools_4.2.1              
##  [5] bslib_0.4.0               utf8_1.2.2               
##  [7] R6_2.5.1                  irlba_2.3.5.1            
##  [9] vipor_0.4.5               DBI_1.1.3                
## [11] mgcv_1.8-41               colorspace_2.0-3         
## [13] withr_2.5.0               tidyselect_1.2.0         
## [15] gridExtra_2.3             extrafontdb_1.0          
## [17] compiler_4.2.1            cli_3.4.1                
## [19] BiocNeighbors_1.16.0      DelayedArray_0.24.0      
## [21] labeling_0.4.2            sass_0.4.2               
## [23] scales_1.2.1              stringr_1.4.1            
## [25] digest_0.6.30             rmarkdown_2.17           
## [27] XVector_0.38.0            base64enc_0.1-3          
## [29] pkgconfig_2.0.3           htmltools_0.5.3          
## [31] extrafont_0.18            sparseMatrixStats_1.10.0 
## [33] fastmap_1.1.0             highr_0.9                
## [35] htmlwidgets_1.5.4         rlang_1.0.6              
## [37] DelayedMatrixStats_1.20.0 jquerylib_0.1.4          
## [39] farver_2.1.1              generics_0.1.3           
## [41] jsonlite_1.8.3            BiocParallel_1.32.0      
## [43] RCurl_1.98-1.9            magrittr_2.0.3           
## [45] BiocSingular_1.14.0       GenomeInfoDbData_1.2.9   
## [47] Matrix_1.5-1              Rcpp_1.0.9               
## [49] ggbeeswarm_0.6.0          munsell_0.5.0            
## [51] fansi_1.0.3               viridis_0.6.2            
## [53] lifecycle_1.0.3           stringi_1.7.8            
## [55] yaml_2.3.6                zlibbioc_1.44.0          
## [57] grid_4.2.1                parallel_4.2.1           
## [59] ggrepel_0.9.1             lattice_0.20-45          
## [61] cowplot_1.1.1             beachmat_2.14.0          
## [63] splines_4.2.1             pillar_1.8.1             
## [65] igraph_1.3.5              codetools_0.2-18         
## [67] ScaledMatrix_1.6.0        glue_1.6.2               
## [69] evaluate_0.17             vctrs_0.5.0              
## [71] Rttf2pt1_1.3.11           gtable_0.3.1             
## [73] assertthat_0.2.1          cachem_1.0.6             
## [75] xfun_0.34                 rsvd_1.0.5               
## [77] viridisLite_0.4.1         tibble_3.1.8             
## [79] beeswarm_0.4.0            rgl_0.110.2

References

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.