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.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-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] traviz_1.8.0                scater_1.30.0              
##  [3] scuttle_1.12.0              dplyr_1.1.3                
##  [5] ggplot2_3.4.4               slingshot_2.10.0           
##  [7] TrajectoryUtils_1.10.0      SingleCellExperiment_1.24.0
##  [9] SummarizedExperiment_1.32.0 Biobase_2.62.0             
## [11] GenomicRanges_1.54.0        GenomeInfoDb_1.38.0        
## [13] IRanges_2.36.0              S4Vectors_0.40.0           
## [15] BiocGenerics_0.48.0         MatrixGenerics_1.14.0      
## [17] matrixStats_1.0.0           princurve_2.1.6            
## [19] knitr_1.44                 
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_1.2.0          viridisLite_0.4.2        
##  [3] vipor_0.4.5               farver_2.1.1             
##  [5] viridis_0.6.4             bitops_1.0-7             
##  [7] fastmap_1.1.1             RCurl_1.98-1.12          
##  [9] digest_0.6.33             rsvd_1.0.5               
## [11] lifecycle_1.0.3           magrittr_2.0.3           
## [13] compiler_4.3.1            rlang_1.1.1              
## [15] sass_0.4.7                tools_4.3.1              
## [17] igraph_1.5.1              utf8_1.2.4               
## [19] yaml_2.3.7                htmlwidgets_1.6.2        
## [21] S4Arrays_1.2.0            labeling_0.4.3           
## [23] DelayedArray_0.28.0       RColorBrewer_1.1-3       
## [25] abind_1.4-5               BiocParallel_1.36.0      
## [27] withr_2.5.1               rgl_1.2.1                
## [29] grid_4.3.1                fansi_1.0.5              
## [31] beachmat_2.18.0           colorspace_2.1-0         
## [33] extrafontdb_1.0           scales_1.2.1             
## [35] cli_3.6.1                 rmarkdown_2.25           
## [37] crayon_1.5.2              generics_0.1.3           
## [39] DelayedMatrixStats_1.24.0 ggbeeswarm_0.7.2         
## [41] cachem_1.0.8              splines_4.3.1            
## [43] zlibbioc_1.48.0           parallel_4.3.1           
## [45] XVector_0.42.0            base64enc_0.1-3          
## [47] vctrs_0.6.4               Matrix_1.6-1.1           
## [49] jsonlite_1.8.7            BiocSingular_1.18.0      
## [51] BiocNeighbors_1.20.0      ggrepel_0.9.4            
## [53] irlba_2.3.5.1             beeswarm_0.4.0           
## [55] jquerylib_0.1.4           glue_1.6.2               
## [57] codetools_0.2-19          cowplot_1.1.1            
## [59] gtable_0.3.4              extrafont_0.19           
## [61] ScaledMatrix_1.10.0       munsell_0.5.0            
## [63] tibble_3.2.1              pillar_1.9.0             
## [65] htmltools_0.5.6.1         GenomeInfoDbData_1.2.11  
## [67] R6_2.5.1                  sparseMatrixStats_1.14.0 
## [69] evaluate_0.22             lattice_0.22-5           
## [71] bslib_0.5.1               Rcpp_1.0.11              
## [73] Rttf2pt1_1.3.12           nlme_3.1-163             
## [75] gridExtra_2.3             SparseArray_1.2.0        
## [77] mgcv_1.9-0                xfun_0.40                
## [79] pkgconfig_2.0.3

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.