Skip to contents

# Pseudotime analysis

Source: `vignettes/Pseudotime_analysis.Rmd`
`Pseudotime_analysis.Rmd`

    library(cyCONDOR)
    library(pheatmap)
    library(ggplot2)
    library(dplyr)

With `cyCONDOR` we implemented `slingshot` for pseudotome analysis, following a workflow to calculate trajectories and pseudotime.

This workflow can be applied to any type of HDFC data, nevertheless the interpretation of trajectories and preudotime should always be validated by other experiment of domain knowledge. We exemplified here with a subset of the cyTOF dataset from Bendall et al. 2011

If you use this workflow in your work please consider citing cyCONDOR and Street et al. (2018).

cyCONDOR implementation of `slingshot` follows the tutorial from the NBIS tutorial

### Load an example dataset

We start here by loading an example `condor` object already annotated.

    condor <- readRDS("../.test_files/condor_pseudotime_016.rds")

    plot_dim_red(fcd= condor,
                 expr_slot = NULL,
                 reduction_method = "umap",
                 reduction_slot = "pca_orig",
                 cluster_slot = "phenograph_filter_pca_orig_k_10",
                 param = "metaclusters",
                 title = "UMAP colored by Phenograph",
                 alpha= 1, dot_size = 1)

    plot_marker_HM(fcd = condor,
                   expr_slot = "orig",
                   cluster_slot = "phenograph_filter_pca_orig_k_10",
                   cluster_var = "metaclusters",
                   cluster_rows = TRUE,
                   cluster_cols = TRUE,
                   title= "Marker expression Phenograph clustering")

## Pseudotime analysis

We can now calculate the pseudotime with different settings:

### With no constrains on the start of the trajectory

    condor <- runPseudotime(fcd = condor,
                            reduction_method = "umap",
                            reduction_slot = "pca_orig",
                            cluster_slot= "phenograph_filter_pca_orig_k_10",
                            cluster_var = "metaclusters",
                            approx_points = NULL)

    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"

The output of is saved in `condor$pseudotime$slingshot_umap_pca_orig`.

    condor$pseudotime$slingshot_umap_pca_orig[1:5,]

    ##                                               Lineage1 Lineage2      mean
    ## export_Marrow1_00_SurfaceOnly_singlets.fcs_2  8.907685       NA  8.907685
    ## export_Marrow1_00_SurfaceOnly_singlets.fcs_9        NA 11.40754 11.407538
    ## export_Marrow1_00_SurfaceOnly_singlets.fcs_18       NA 12.15903 12.159027
    ## export_Marrow1_00_SurfaceOnly_singlets.fcs_27       NA 11.36649 11.366492
    ## export_Marrow1_00_SurfaceOnly_singlets.fcs_49       NA 11.36649 11.366492

### With a specific starting cluster

    condor <- runPseudotime(fcd = condor,
                            reduction_method = "umap",
                            reduction_slot = "pca_orig",
                            cluster_slot= "phenograph_filter_pca_orig_k_10",
                            cluster_var = "metaclusters",
                            approx_points = NULL,
                            start.clus =  "CMPs",)

    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"

The output of is saved in `condor$pseudotime$slingshot_umap_pca_orig_CMPs`.

    condor$pseudotime$slingshot_umap_pca_orig_CMPs[1:5,]

    ## NULL

### Testing all clusters as starting point

    for (i in unique(condor$clustering$phenograph_filter_pca_orig_k_10$metaclusters)[1:5]) {

      condor <- runPseudotime(fcd = condor,
                              reduction_method = "umap",
                              reduction_slot = "pca_orig",
                              cluster_slot= "phenograph_filter_pca_orig_k_10",
                              cluster_var = "metaclusters",
                              approx_points = NULL,
                              start.clus =  i)

    }

    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"
    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"
    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"
    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"
    ## [1] "Slingshot - getLineages"
    ## [1] "Slingshot - getCurves"

### Visualize the result of `slingshot` analysis

It is possible to use the `plot_dim_red` function to plot the result of pseudotime analysis overlayed on the UMAP coordinates.

    plot_dim_red(fcd = condor,
                 expr_slot = "orig",
                 reduction_method = "umap",
                 reduction_slot = "pca_orig",
                 cluster_slot = "phenograph_filter_pca_orig_k_10",
                 add_pseudotime = TRUE,
                 pseudotime_slot = "slingshot_umap_pca_orig",
                 param = "mean",
                 order = T,
                 title = "UMAP colored by pseudotime",
                 facet_by_variable = FALSE,
                 raster = TRUE,
                 alpha = 1,
                 dot_size = 1) +
      geom_path(data = condor$extras$slingshot_umap_pca_orig$lineages %>% arrange(Order), aes(group = Lineage), size = 0.5)

    ## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    ## ℹ Please use `linewidth` instead.
    ## This warning is displayed once every 8 hours.
    ## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    ## generated.

## Heatmap visualization of monocytes trajectory

We provide here some custom code to visualize the pseudotime, nevertheless many visualization can be performed on this data depending on the biological question.

    selections <- rownames(condor$clustering$phenograph_filter_pca_orig_k_10[condor$clustering$phenograph_filter_pca_orig_k_10$metaclusters %in% c("HSCs", "CMPs", "Myeloblast", "Monocytes"), ])

    condor_mono <- filter_fcd(fcd = condor,
                                cell_ids = selections)

    expression <- condor_mono$expr$orig

    anno <- cbind(condor_mono$clustering$phenograph_filter_pca_orig_k_10[, c("Phenograph", "metaclusters")], condor_mono$pseudotime$slingshot_umap_pca_orig)

    anno <- anno[order(anno$Lineage2, decreasing = FALSE),]

    expression <- expression[rownames(anno), c("148-CD34", "160-CD14", "144-CD11b")]

    my_colour = list(metaclusters = c(Monocytes = "#CBD588", HSCs = "#689030", Myeloblast = "#DA5724", CMPs = "#F7941D"))

    pheatmap(mat = expression,
             scale = "column",
             show_rownames = FALSE,
             cluster_rows = F,
             cluster_cols = F,
             annotation_row = anno[, c("metaclusters", "Lineage2")],
             annotation_colors = my_colour,
             breaks = scaleColors(expression, maxvalue = 2)[["breaks"]],
             color = scaleColors(expression, maxvalue = 2)[["color"]], main = "Heatmap Monocytes pseudotime")

## Session Info

    info <- sessionInfo()

    info

    ## R version 4.4.2 (2024-10-31)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.1 LTS
    ##
    ## Matrix products: default
    ## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    ##
    ## locale:
    ##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    ##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    ##  [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: Etc/UTC
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] dplyr_1.1.4     ggplot2_3.5.2   pheatmap_1.0.13 cyCONDOR_0.3.1
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] IRanges_2.40.1              Rmisc_1.5.1
    ##   [3] urlchecker_1.0.1            nnet_7.3-20
    ##   [5] CytoNorm_2.0.1              TH.data_1.1-3
    ##   [7] vctrs_0.6.5                 digest_0.6.37
    ##   [9] png_0.1-8                   shape_1.4.6.1
    ##  [11] proxy_0.4-27                slingshot_2.14.0
    ##  [13] ggrepel_0.9.6               corrplot_0.95
    ##  [15] parallelly_1.45.0           MASS_7.3-65
    ##  [17] pkgdown_2.1.3               reshape2_1.4.4
    ##  [19] httpuv_1.6.16               foreach_1.5.2
    ##  [21] BiocGenerics_0.52.0         withr_3.0.2
    ##  [23] ggrastr_1.0.2               xfun_0.52
    ##  [25] ggpubr_0.6.1                ellipsis_0.3.2
    ##  [27] survival_3.8-3              memoise_2.0.1
    ##  [29] hexbin_1.28.5               ggbeeswarm_0.7.2
    ##  [31] RProtoBufLib_2.18.0         princurve_2.1.6
    ##  [33] profvis_0.4.0               ggsci_3.2.0
    ##  [35] systemfonts_1.2.3           ragg_1.4.0
    ##  [37] zoo_1.8-14                  GlobalOptions_0.1.2
    ##  [39] DEoptimR_1.1-3-1            Formula_1.2-5
    ##  [41] promises_1.3.3              scatterplot3d_0.3-44
    ##  [43] httr_1.4.7                  rstatix_0.7.2
    ##  [45] globals_0.18.0              rstudioapi_0.17.1
    ##  [47] UCSC.utils_1.2.0            miniUI_0.1.2
    ##  [49] generics_0.1.4              ggcyto_1.34.0
    ##  [51] base64enc_0.1-3             curl_6.4.0
    ##  [53] S4Vectors_0.44.0            zlibbioc_1.52.0
    ##  [55] flowWorkspace_4.18.1        polyclip_1.10-7
    ##  [57] randomForest_4.7-1.2        GenomeInfoDbData_1.2.13
    ##  [59] SparseArray_1.6.2           RBGL_1.82.0
    ##  [61] ncdfFlow_2.52.1             RcppEigen_0.3.4.0.2
    ##  [63] xtable_1.8-4                stringr_1.5.1
    ##  [65] desc_1.4.3                  doParallel_1.0.17
    ##  [67] evaluate_1.0.4              S4Arrays_1.6.0
    ##  [69] hms_1.1.3                   glmnet_4.1-9
    ##  [71] GenomicRanges_1.58.0        irlba_2.3.5.1
    ##  [73] colorspace_2.1-1            harmony_1.2.3
    ##  [75] reticulate_1.42.0           readxl_1.4.5
    ##  [77] magrittr_2.0.3              lmtest_0.9-40
    ##  [79] readr_2.1.5                 Rgraphviz_2.50.0
    ##  [81] later_1.4.2                 lattice_0.22-7
    ##  [83] future.apply_1.20.0         robustbase_0.99-4-1
    ##  [85] XML_3.99-0.18               cowplot_1.2.0
    ##  [87] matrixStats_1.5.0           xts_0.14.1
    ##  [89] class_7.3-23                Hmisc_5.2-3
    ##  [91] pillar_1.11.0               nlme_3.1-168
    ##  [93] iterators_1.0.14            compiler_4.4.2
    ##  [95] RSpectra_0.16-2             stringi_1.8.7
    ##  [97] gower_1.0.2                 minqa_1.2.8
    ##  [99] SummarizedExperiment_1.36.0 lubridate_1.9.4
    ## [101] devtools_2.4.5              CytoML_2.18.3
    ## [103] plyr_1.8.9                  crayon_1.5.3
    ## [105] abind_1.4-8                 locfit_1.5-9.12
    ## [107] sp_2.2-0                    sandwich_3.1-1
    ## [109] pcaMethods_1.98.0           codetools_0.2-20
    ## [111] multcomp_1.4-28             textshaping_1.0.1
    ## [113] recipes_1.3.1               openssl_2.3.3
    ## [115] Rphenograph_0.99.1          TTR_0.24.4
    ## [117] bslib_0.9.0                 e1071_1.7-16
    ## [119] destiny_3.20.0              GetoptLong_1.0.5
    ## [121] ggplot.multistats_1.0.1     mime_0.13
    ## [123] splines_4.4.2               circlize_0.4.16
    ## [125] Rcpp_1.1.0                  sparseMatrixStats_1.18.0
    ## [127] cellranger_1.1.0            knitr_1.50
    ## [129] clue_0.3-66                 lme4_1.1-37
    ## [131] fs_1.6.6                    listenv_0.9.1
    ## [133] checkmate_2.3.2             DelayedMatrixStats_1.28.1
    ## [135] Rdpack_2.6.4                pkgbuild_1.4.8
    ## [137] ggsignif_0.6.4              tibble_3.3.0
    ## [139] Matrix_1.7-3                rpart.plot_3.1.2
    ## [141] statmod_1.5.0               tzdb_0.5.0
    ## [143] tweenr_2.0.3                pkgconfig_2.0.3
    ## [145] tools_4.4.2                 cachem_1.1.0
    ## [147] rbibutils_2.3               smoother_1.3
    ## [149] fastmap_1.2.0               rmarkdown_2.29
    ## [151] scales_1.4.0                grid_4.4.2
    ## [153] usethis_3.1.0               broom_1.0.8
    ## [155] sass_0.4.10                 graph_1.84.1
    ## [157] carData_3.0-5               RANN_2.6.2
    ## [159] rpart_4.1.24                farver_2.1.2
    ## [161] reformulas_0.4.1            yaml_2.3.10
    ## [163] MatrixGenerics_1.18.1       foreign_0.8-90
    ## [165] ggthemes_5.1.0              cli_3.6.5
    ## [167] purrr_1.1.0                 stats4_4.4.2
    ## [169] lifecycle_1.0.4             uwot_0.2.3
    ## [171] askpass_1.2.1               caret_7.0-1
    ## [173] Biobase_2.66.0              mvtnorm_1.3-3
    ## [175] lava_1.8.1                  sessioninfo_1.2.3
    ## [177] backports_1.5.0             cytolib_2.18.2
    ## [179] timechange_0.3.0            gtable_0.3.6
    ## [181] rjson_0.2.23                umap_0.2.10.0
    ## [183] ggridges_0.5.6              parallel_4.4.2
    ## [185] pROC_1.18.5                 limma_3.62.2
    ## [187] jsonlite_2.0.0              edgeR_4.4.2
    ## [189] RcppHNSW_0.6.0              Rtsne_0.17
    ## [191] FlowSOM_2.14.0              ranger_0.17.0
    ## [193] flowCore_2.18.0             jquerylib_0.1.4
    ## [195] timeDate_4041.110           shiny_1.11.1
    ## [197] ConsensusClusterPlus_1.70.0 htmltools_0.5.8.1
    ## [199] diffcyt_1.26.1              glue_1.8.0
    ## [201] XVector_0.46.0              VIM_6.2.2
    ## [203] gridExtra_2.3               boot_1.3-31
    ## [205] TrajectoryUtils_1.14.0      igraph_2.1.4
    ## [207] R6_2.6.1                    tidyr_1.3.1
    ## [209] SingleCellExperiment_1.28.1 labeling_0.4.3
    ## [211] vcd_1.4-13                  cluster_2.1.8.1
    ## [213] pkgload_1.4.0               GenomeInfoDb_1.42.3
    ## [215] ipred_0.9-15                nloptr_2.2.1
    ## [217] DelayedArray_0.32.0         tidyselect_1.2.1
    ## [219] vipor_0.4.7                 htmlTable_2.4.3
    ## [221] ggforce_0.5.0               CytoDx_1.26.0
    ## [223] car_3.1-3                   future_1.58.0
    ## [225] ModelMetrics_1.2.2.2        laeken_0.5.3
    ## [227] data.table_1.17.8           htmlwidgets_1.6.4
    ## [229] ComplexHeatmap_2.22.0       RColorBrewer_1.1-3
    ## [231] rlang_1.1.6                 remotes_2.5.0
    ## [233] colorRamps_2.3.4            Cairo_1.6-2
    ## [235] ggnewscale_0.5.2            hardhat_1.4.1
    ## [237] beeswarm_0.4.0              prodlim_2025.04.28