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.4.0 Patched (2024-04-24 r86482)
## Platform: aarch64-apple-darwin20
## Running under: macOS Ventura 13.6.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] traviz_1.11.0 scater_1.33.0
## [3] scuttle_1.15.0 dplyr_1.1.4
## [5] ggplot2_3.5.1 slingshot_2.13.0
## [7] TrajectoryUtils_1.13.0 SingleCellExperiment_1.27.0
## [9] SummarizedExperiment_1.35.0 Biobase_2.65.0
## [11] GenomicRanges_1.57.0 GenomeInfoDb_1.41.0
## [13] IRanges_2.39.0 S4Vectors_0.43.0
## [15] BiocGenerics_0.51.0 MatrixGenerics_1.17.0
## [17] matrixStats_1.3.0 princurve_2.1.6
## [19] knitr_1.46
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 viridisLite_0.4.2
## [3] vipor_0.4.7 farver_2.1.1
## [5] viridis_0.6.5 fastmap_1.1.1
## [7] digest_0.6.35 rsvd_1.0.5
## [9] lifecycle_1.0.4 magrittr_2.0.3
## [11] compiler_4.4.0 rlang_1.1.3
## [13] sass_0.4.9 tools_4.4.0
## [15] igraph_2.0.3 utf8_1.2.4
## [17] yaml_2.3.8 htmlwidgets_1.6.4
## [19] S4Arrays_1.5.0 labeling_0.4.3
## [21] DelayedArray_0.31.0 RColorBrewer_1.1-3
## [23] abind_1.4-5 BiocParallel_1.39.0
## [25] withr_3.0.0 rgl_1.3.1
## [27] grid_4.4.0 fansi_1.0.6
## [29] beachmat_2.21.0 colorspace_2.1-0
## [31] scales_1.3.0 cli_3.6.2
## [33] rmarkdown_2.26 crayon_1.5.2
## [35] generics_0.1.3 httr_1.4.7
## [37] DelayedMatrixStats_1.27.0 ggbeeswarm_0.7.2
## [39] cachem_1.0.8 splines_4.4.0
## [41] zlibbioc_1.51.0 parallel_4.4.0
## [43] XVector_0.45.0 base64enc_0.1-3
## [45] vctrs_0.6.5 Matrix_1.7-0
## [47] jsonlite_1.8.8 BiocSingular_1.21.0
## [49] BiocNeighbors_1.23.0 ggrepel_0.9.5
## [51] irlba_2.3.5.1 beeswarm_0.4.0
## [53] jquerylib_0.1.4 glue_1.7.0
## [55] codetools_0.2-20 cowplot_1.1.3
## [57] gtable_0.3.5 UCSC.utils_1.1.0
## [59] ScaledMatrix_1.13.0 munsell_0.5.1
## [61] tibble_3.2.1 pillar_1.9.0
## [63] htmltools_0.5.8.1 GenomeInfoDbData_1.2.12
## [65] R6_2.5.1 sparseMatrixStats_1.17.0
## [67] evaluate_0.23 lattice_0.22-6
## [69] highr_0.10 bslib_0.7.0
## [71] Rcpp_1.0.12 nlme_3.1-164
## [73] gridExtra_2.3 SparseArray_1.5.0
## [75] mgcv_1.9-1 xfun_0.43
## [77] pkgconfig_2.0.3