Error with slingshot slingPseudotime and slingCurveWeights after using fitGAM from tradeSeq
0
0
Entering edit mode
manduchi ▴ 10
@manduchi-9940
Last seen 9 months ago
United States

Hello, I've been using slingshot and tradeSeq. Great packages, thanks! After running slingshot, I can successfully call slingPseudotime and slingCurveWeights on my SCE object. However, after applying fitGAM to it, I get errors when calling these functions again. Below are the relevant code excerpts. It looks like the class of colData(secr.ko.sce)$slingshot gets somehow changed from PseudotimeOrdering to DataFrame, after running fitGAM. Am I calling fitGAM incorrectly? Thanks for any advice, Elisabetta

library(tidyverse)
library(Seurat)
library(slingshot)
library(scales)
library(RColorBrewer)
library(rgl)
library(tradeSeq)
library(bioc2020trajectories)
library(pheatmap)
library(msigdbr)
library(fgsea)
library(ggplot2);library(gridExtra)
library(condiments)
library(clusterProfiler)

epi <- readRDS("fromAvital/Epi_sub_clusters.rds")

secr.ko <- subset(epi, sub_cluster_5_17 %in% c('Stem', 'Goblet progenitor', 'Goblet progenitor KO', 'Enteroendocrine', 
                                                'Enteroendocrine KO', 'Enteroendocrine-goblet KO') & orig.ident %in% c("analysis07.97372","analysis07.97373"))
secr.ko.sce <- as.SingleCellExperiment(secr.ko, assay='RNA')
secr.ko.sce <- slingshot(secr.ko.sce, reducedDim='UMAP', clusterLabels=colData(secr.ko.sce)$ident, start.clus='Stem', approx_points=150)

rm(epi)

slingLineages(secr.ko.sce)


pto.secr.ko <- slingPseudotime(secr.ko.sce) # NO ERROR HERE
cw.secr.ko <- slingCurveWeights(SlingshotDataSet(secr.ko.sce))  # NO ERROR HERE

genes.use <- readRDS('genes.use.rds')
genes.use.index = which(rownames(secr.ko.sce) %in% genes.use)
length(genes.use)
# 3082

# Select the number of knots
set.seed(3)
icMat.secr.ko <- evaluateK(counts = as.matrix(assays(secr.ko.sce)$counts),
                           pseudotime = pto.secr.ko,
                           cellWeights = cw.secr.ko,
                           conditions = factor(colData(secr.ko.sce)$condition),
                           k = 3:7)

set.seed(3)
secr.ko.sce <- fitGAM(secr.ko.sce, genes=genes.use.index, nknots=6)
mean(rowData(secr.ko.sce)$tradeSeq$converged[genes.use.index])
# 0.9519636

# Now I get an error calling the two functions
slingPseudotime(secr.ko.sce)
# Error in (function (classes, fdef, mtable)  : 
 #  unable to find an inherited method for function ‘slingPseudotime’ for signature ‘"DFrame"’
slingCurveWeights(SlingshotDataSet(secr.ko.sce))
# Error in h(simpleError(msg, call)) : 
#  error in evaluating the argument 'x' in selecting a method for function 'slingCurveWeights': unable to find an inherited method for function ‘as.SlingshotDataSet’ for signature ‘"DFrame"’

traceback()
# 9: h(simpleError(msg, call))
# 8: .handleSimpleError(function (cond) 
#   .Internal(C_tryCatchHelper(addr, 1L, cond)), "unable to find an inherited method for function ‘as.SlingshotDataSet’ for signature ‘\"DFrame\"’", 
#       base::quote((function (classes, fdef, mtable) 
#      {
#           methods <- .findInheritedMethods(classes, fdef, mtable)
#           if (length(methods) == 1L) 
#               return(methods[[1L]])
#           else if (length(methods) == 0L) {
#               cnames <- paste0("\"", vapply(classes, as.character, 
#                   ""), "\"", collapse = ", ")
#               stop(gettextf("unable to find an inherited method for function %s for signature %s", 
#                   sQuote(fdef@generic), sQuote(cnames)), domain = NA)
#           }
#           else stop("Internal error in finding inherited methods; didn't return a unique method", 
#               domain = NA)
#       })(list(structure("DFrame", package = "S4Vectors")), new("standardGeneric", 
#           .Data = function (x, ...) 
#           standardGeneric("as.SlingshotDataSet"), generic = structure("as.SlingshotDataSet", package = "slingshot"), 
#           package = "slingshot", group = list(), valueClass = character(0), 
#           signature = "x", default = NULL, skeleton = (function (x, 
#    ...
# 7: stop(gettextf("unable to find an inherited method for function %s for signature %s", 
#       sQuote(fdef@generic), sQuote(cnames)), domain = NA)
# 6: (function (classes, fdef, mtable) 
#  {
#       methods <- .findInheritedMethods(classes, fdef, mtable)
#       if (length(methods) == 1L) 
#           return(methods[[1L]])
#       else if (length(methods) == 0L) {
#           cnames <- paste0("\"", vapply(classes, as.character, 
#               ""), "\"", collapse = ", ")
#           stop(gettextf("unable to find an inherited method for function %s for signature %s", 
#               sQuote(fdef@generic), sQuote(cnames)), domain = NA)
#       }
#       else stop("Internal error in finding inherited methods; didn't return a unique method", 
#           domain = NA)
#   })(list(structure("DFrame", package = "S4Vectors")), new("standardGeneric", 
#       .Data = function (x, ...) 
#       standardGeneric("as.SlingshotDataSet"), generic = structure("as.SlingshotDataSet", package = "slingshot"), 
#       package = "slingshot", group = list(), valueClass = character(0), 
#       signature = "x", default = NULL, skeleton = (function (x, 
#           ...) 
#       stop("invalid call in method dispatch to 'as.SlingshotDataSet' (no default method)", 
#    ...
# 5: as.SlingshotDataSet(colData(data)$slingshot)
# 4: .local(data, ...)
# 3: SlingshotDataSet(secr.ko.sce)
# 2: SlingshotDataSet(secr.ko.sce)
# 1: slingCurveWeights(SlingshotDataSet(secr.ko.sce))

sessionInfo( )
# R version 4.1.2 (2021-11-01)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19044)
# 
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
#
# attached base packages:
# [1] parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     
#
# other attached packages:
# [1] clusterProfiler_4.0.5         BiocManager_1.30.18           caret_6.0-92                 
#  [4] lattice_0.20-45               condiments_1.0.0              gridExtra_2.3                
# [7] fgsea_1.18.0                  msigdbr_7.5.1                 pheatmap_1.0.12              
# [10] UpSetR_1.4.0                  bioc2020trajectories_0.0.0.93 tradeSeq_1.6.0               
# [13] rgl_0.108.3.2                 RColorBrewer_1.1-3            scales_1.2.0                 
# [16] slingshot_2.0.0               TrajectoryUtils_1.0.0         SingleCellExperiment_1.14.1  
# [19] SummarizedExperiment_1.22.0   Biobase_2.52.0                GenomicRanges_1.44.0         
# [22] GenomeInfoDb_1.28.4           IRanges_2.26.0                S4Vectors_0.30.2             
# [25] BiocGenerics_0.38.0           MatrixGenerics_1.4.3          matrixStats_0.62.0           
# [28] princurve_2.1.6               sp_1.4-7                      SeuratObject_4.1.0           
# [31] Seurat_4.1.1                  forcats_0.5.1                 stringr_1.4.0                
# [34] dplyr_1.0.9                   purrr_0.3.4                   readr_2.1.2                  
# [37] tidyr_1.2.0                   tibble_3.1.7                  ggplot2_3.3.6                
# [40] tidyverse_1.3.1              
# 
# loaded via a namespace (and not attached):
#  [1] ica_1.0-2                 class_7.3-20              foreach_1.5.2             lmtest_0.9-40            
#  [5] crayon_1.5.1              spatstat.core_2.4-4       MASS_7.3-57               rhdf5filters_1.4.0       
#  [9] nlme_3.1-157              backports_1.4.1           qlcMatrix_0.9.7           reprex_2.0.1             
# [13] transport_0.12-2          GOSemSim_2.18.1           rlang_1.0.2               XVector_0.32.0           
# [17] ROCR_1.0-11               readxl_1.4.0              irlba_2.3.5               limma_3.48.3             
# [21] filelock_1.0.2            BiocParallel_1.26.2       bit64_4.0.5               glue_1.6.2               
# [25] sctransform_0.3.3         spatstat.sparse_2.1-1     AnnotationDbi_1.54.1      DOSE_3.18.3              
# [29] spatstat.geom_2.4-0       VGAM_1.1-6                haven_2.5.0               tidyselect_1.1.2         
# [33] fitdistrplus_1.1-8        XML_3.99-0.10             zoo_1.8-10                xtable_1.8-4             
# [37] magrittr_2.0.3            cli_3.3.0                 zlibbioc_1.38.0           rstudioapi_0.13          
# [41] miniUI_0.1.1.1            spatstat.linnet_2.3-2     rpart_4.1.16              fastmatch_1.1-3          
# [45] treeio_1.16.2             shiny_1.7.1               xfun_0.31                 cluster_2.1.3            
# [49] tidygraph_1.2.1           KEGGREST_1.32.0           ggrepel_0.9.1             ape_5.6-2                
# [53] listenv_0.8.0             Biostrings_2.60.2         png_0.1-7                 future_1.26.1            
# [57] ipred_0.9-13              withr_2.5.0               bitops_1.0-7              slam_0.1-50              
# [61] ggforce_0.3.3             plyr_1.8.7                cellranger_1.1.0          sparsesvd_0.2            
# [65] hardhat_1.1.0             e1071_1.7-11              pROC_1.18.0               pillar_1.7.0             
# [69] cachem_1.0.6              Ecume_0.9.1               fs_1.5.2                  kernlab_0.9-31           
# [73] DelayedMatrixStats_1.14.3 vctrs_0.4.1               ellipsis_0.3.2            generics_0.1.2           
# [77] lava_1.6.10               tools_4.1.2               munsell_0.5.0             tweenr_1.0.2             
# [81] proxy_0.4-27              DelayedArray_0.18.0       fastmap_1.1.0             HSMMSingleCell_1.12.0    
# [85] compiler_4.1.2            abind_1.4-5               httpuv_1.6.5              plotly_4.10.0            
# [89] rgeos_0.5-9               GenomeInfoDbData_1.2.6    prodlim_2019.11.13        edgeR_3.34.1             
# [93] deldir_1.0-6              snow_0.4-4                utf8_1.2.2                later_1.3.0              
# [97] BiocFileCache_2.0.0       recipes_0.2.0             jsonlite_1.8.0            docopt_0.7.1             \
# [101] tidytree_0.3.9            pbapply_1.5-0             sparseMatrixStats_1.4.2   genefilter_1.74.1        
# [105] lazyeval_0.2.2            promises_1.2.0.1          spatstat_2.3-4            goftest_1.2-3            
# [109] spatstat.utils_2.3-1      reticulate_1.25           cowplot_1.1.1             Rtsne_0.16               
# [113] downloader_0.4            uwot_0.1.11               igraph_1.3.1              HDF5Array_1.20.0         
# [117] survival_3.3-1            DDRTree_0.1.5             htmltools_0.5.2           memoise_2.0.1            
# [121] locfit_1.5-9.5            graphlayouts_0.8.0        viridisLite_0.4.0         digest_0.6.29            
# [125] assertthat_0.2.1          mime_0.12                 rappdirs_0.3.3            densityClust_0.3.2       
# [129] RSQLite_2.2.14            yulab.utils_0.0.4         future.apply_1.9.0        data.table_1.14.2        
# [133] blob_1.2.3                fastICA_1.2-3             splines_4.1.2             labeling_0.4.2           
# [137] Rhdf5lib_1.14.2           RCurl_1.98-1.6            broom_0.8.0               monocle_2.20.0           
# [141] hms_1.1.1                 modelr_0.1.8              rhdf5_2.36.0              colorspace_2.0-3         
# [145] aplot_0.1.6               nnet_7.3-17               Rcpp_1.0.8.3              RANN_2.6.1               
# [149] enrichplot_1.12.3         fansi_1.0.3               tzdb_0.3.0                parallelly_1.32.0        
# [153] ModelMetrics_1.2.2.2      R6_2.5.1                  grid_4.1.2                ggridges_0.5.3           
# [157] lifecycle_1.0.1           curl_4.3.2                leiden_0.4.2              DO.db_2.9                
# [161] Matrix_1.4-1              qvalue_2.24.0             RcppAnnoy_0.0.19          iterators_1.0.14         
# [165] gower_1.0.0               htmlwidgets_1.5.4         polyclip_1.10-0           shadowtext_0.1.2         
# [169] gridGraphics_0.5-1        rvest_1.0.2               mgcv_1.8-40               globals_0.15.0           
# [173] patchwork_1.1.1           spatstat.random_2.2-0     progressr_0.10.1          codetools_0.2-18         
# [177] lubridate_1.8.0           GO.db_3.13.0              FNN_1.1.3.1               randomForest_4.7-1.1     
# [181] dbplyr_2.2.0              gtable_0.3.0              DBI_1.1.2                 ggfun_0.0.6              
# [185] tensor_1.5                httr_1.4.3                highr_0.9                 KernSmooth_2.23-20       
# [189] stringi_1.7.6             reshape2_1.4.4            farver_2.1.0              annotate_1.70.0          
# [193] viridis_0.6.2             timeDate_3043.102         ggtree_3.0.4              xml2_1.3.3               
# [197] combinat_0.0-8            geneplotter_1.70.0        ggplotify_0.1.0           scattermore_0.8          
# [201] DESeq2_1.32.0             bit_4.0.4                 scatterpie_0.1.7          spatstat.data_2.2-0      
# [205] ggraph_2.0.5              pkgconfig_2.0.3           babelgene_22.3            knitr_1.39
tradeSeq slingshot • 2.7k views
ADD COMMENT
0
Entering edit mode

I tried with a random dataset and can't reproduce your issue, maybe you could try to share a small subset of your dataset ? Could you show us the output of secr.ko.sce ?

ADD REPLY
0
Entering edit mode

Thanks for your feedback. I just tried again with another slice of my original dataset and am getting the same issue. The SCE object is now called col.sce and, in the relevant code excerpt below, I indicate the output of col.sce after fitGAM. I also saved col.sce$slingshot (in col.slingshot) before running fitGAM (and show that its class is PseudotimeOrdering) and then show that the class of col.sce$slingshot after running fitGAM is DataFrame. I can share a subset of my dataset, not sure what would be the best way and what subset would be most useful though. Thanks

library(tidyverse)
library(Seurat)
library(slingshot)
library(scales)
library(RColorBrewer)
library(rgl)
library(tradeSeq)
library(bioc2020trajectories)
library(UpSetR)
library(pheatmap)
library(msigdbr)
library(fgsea)
library(ggplot2);library(gridExtra)
library(condiments)
library(clusterProfiler)

epi <- readRDS("fromAvital/Epi_sub_clusters.rds")
class(epi)
# [1] "Seurat"
# attr(,"package")
# [1] "SeuratObject"

`%notin%` <- Negate(`%in%`)
epi.red <- epi[, !colnames(epi) %in% c('A_AGTGCCGTCTCGTGAA', 'B_GTGCAGCAGGTAAGAG', 'C_TGCTGAAGTATACGGG')]

col <- subset(epi.red, sub_cluster_5_17 %in% c('Stem', 'Colonocyte progenitor 1', 'Colonocyte progenitor 2', 'Colonocyte 1', 'Colonocyte 2', 'Colonocyte KO'))
(col.sce <- as.SingleCellExperiment(col, assay='RNA'))

pto.col <- slingPseudotime(SlingshotDataSet(col.sce)) # WORKS WITH NO PROBLEM

genes.use <- readRDS('genes.use.rds')
genes.use.index = which(rownames(col.sce) %in% genes.use)
length(genes.use.index)
# 3285

# Save slingdhot component of col.sce before running fitGAM
col.slingshot <- col.sce$slingshot

set.seed(3)
col.sce <- fitGAM(col.sce, conditions = factor(colData(col.sce)$condition), genes=genes.use.index)

mean(rowData(col.sce)$tradeSeq$converged[genes.use.index])
# 0.9129376

class(col.slingshot) # REMEMBER THAT THIS STORES col.sce$slingshot BEFORE running fitGAM
# [1] "PseudotimeOrdering"
# attr(,"package")
# [1] "TrajectoryUtils"

# AFTER RUNNING fitGAM
col.sce
# class: SingleCellExperiment 
# dim: 31053 19200 
# metadata(1): tradeSeq
# assays(2): counts logcounts
# rownames(31053): Xkr4 Gm1992 ... Vmn2r122 CAAA01147332.1
# rowData names(1): tradeSeq
# colnames(19200): A_AAGTGAACACTTTATC A_AAGTGAACAGTGGCTC ... D_TTTGTTGTCGGCATTA D_TTTGTTGTCTCAATCT
# colData names(14): orig.ident nCount_RNA ... slingPseudotime_2 tradeSeq
# reducedDimNames(3): PCA UMAP TSNE
# mainExpName: RNA
# altExpNames(0):

class(col.sce$slingshot) # fitGAM has changed the class of col.sce$slingshot
# [1] "DFrame"
# attr(,"package")
# [1] "S4Vectors"

slingPseudotime(SlingshotDataSet(col.sce)) # NO LONGER WORKS
# Error in h(simpleError(msg, call)) : 
#  error in evaluating the argument 'x' in selecting a method for function 'slingPseudotime': unable to find an inherited method for function ‘as.SlingshotDataSet’ for signature ‘"DFrame"’

sessionInfo()
# R version 4.1.2 (2021-11-01)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19044)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
# [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
#
# attached base packages:
# [1] parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     
#
# other attached packages:
# [1] clusterProfiler_4.0.5         BiocManager_1.30.18           caret_6.0-92                 
# [4] lattice_0.20-45               condiments_1.0.0              gridExtra_2.3                
# [7] fgsea_1.18.0                  msigdbr_7.5.1                 pheatmap_1.0.12              
# [10] UpSetR_1.4.0                  bioc2020trajectories_0.0.0.93 tradeSeq_1.6.0               
# [13] rgl_0.108.3.2                 RColorBrewer_1.1-3            scales_1.2.0                 
# [16] slingshot_2.0.0               TrajectoryUtils_1.0.0         SingleCellExperiment_1.14.1  
# [19] SummarizedExperiment_1.22.0   Biobase_2.52.0                GenomicRanges_1.44.0         
# [22] GenomeInfoDb_1.28.4           IRanges_2.26.0                S4Vectors_0.30.2             
# [25] BiocGenerics_0.38.0           MatrixGenerics_1.4.3          matrixStats_0.62.0           
# [28] princurve_2.1.6               sp_1.4-7                      SeuratObject_4.1.0           
# [31] Seurat_4.1.1                  forcats_0.5.1                 stringr_1.4.0                
# [34] dplyr_1.0.9                   purrr_0.3.4                   readr_2.1.2                  
# [37] tidyr_1.2.0                   tibble_3.1.7                  ggplot2_3.3.6                
# [40] tidyverse_1.3.1              
#
# loaded via a namespace (and not attached):  png_0.1-7                 future_1.26.1            
# ...
ADD REPLY
0
Entering edit mode

Indeed, this behaviour does look strange. I think you should open a github issue here : https://github.com/statOmics/tradeSeq/issues. The creators of tradeSeq are very reactive and try to answer all questions. I hope you will solve your problem here !

ADD REPLY
0
Entering edit mode

Will do, thanks!

ADD REPLY
0
Entering edit mode

I was also unable to reproduce this, but this may be a result of the older package versions. The current version of slingshot is 2.4.0 and of tradeSeq is 1.10.0, whereas you seem to have versions 2.0.0 and 1.6.0, respectively. Can you try updating these packages and see if the issue persists?

ADD REPLY
0
Entering edit mode

Thanks for the suggestion, I've updated my packages and am trying again. However, it's now taking much much longer to fitGAM, so I don't know if it's working yet... BTW, I have 19200 cells, 2 conditions, 2 lineages, 6 knots and I'm providing 3285 genes to the gene argument of fitGAM.

ADD REPLY
1
Entering edit mode

Updating the package version resolved the issue, thanks!

ADD REPLY

Login before adding your answer.

Traffic: 654 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6