cole-trapnell-lab / monocle-release

279 stars 116 forks source link

orderCells(cds) : Error in as.igraph.vs(graph, v) : Invalid vertex names #280

Closed fentouxungui closed 4 years ago

fentouxungui commented 5 years ago

I got the same error #19 , but I can not mange it! any help?

> cds <- orderCells(cds,root_pr_nodes = "Y_26")
Error in as.igraph.vs(graph, v) : Invalid vertex names
gnar5tar commented 5 years ago

I'm getting a similar issue except when trying to subset a specific cell population (using monocle3).

Example: cell_type1 <- row.names(subset(pData(monocle_obj), cell_type == "cell_type1")) type1_subset <- subsetCDS(monocle_obj, cells = cell_type1)

Error is: "Error in as.igraph.vs(graph, vids) : Invalid vertex names"

Any help? Thanks!

FloWuenne commented 5 years ago

Hi there,

I am also getting a similar error when trying to subset a dataset:

Error in as.igraph.vs(graph, vids) : Invalid vertex names

when trying to subset a monocle3 cds object based cell names using:

subset_monocle <- subsetCDS(monocle_cds, cells = rownames(subset(pData(monocle_cds), louvain_component == 2)))

I am using monocle_2.99.3.

Any suggestions?

brianpenghe commented 5 years ago

Hi there,

I am also getting a similar error when trying to subset a dataset:

Error in as.igraph.vs(graph, vids) : Invalid vertex names

when trying to subset a monocle3 cds object based cell names using:

subset_monocle <- subsetCDS(monocle_cds, cells = rownames(subset(pData(monocle_cds), louvain_component == 2)))

I am using monocle_2.99.3.

Any suggestions?

Same issue with you

stephanieRedmond commented 5 years ago

Hi, I'm having the same issue -

I found the bug report for Issue #19 and I'm having the same problem as described there. As long as I pick a vertex in order_cells() that is a leaf node, it seems to be fine.

But I get the error if I choose a node anywhere else in the graph. The tutorial for Monocle 3 suggests any node can be a root node, so I'm not sure what the issue is...? Anyone have success with picking a non-leaf node?

stephanieRedmond commented 5 years ago

I found what I think is the bug, and a work around:

error comes from when learn_graph(cds, use_partition = F) and you have more than one partition:

#Works:
cds_subset = reduce_dimension(cds_subset, max_components = 2)
cds_subset = cluster_cells(cds_subset)
cds_subset = learn_graph(cds_subset)
plot_cells(cds_subset, 
           color_cells_by = "partition")

A

cds_subset = order_cells(cds_subset)
plot_cells(cds_subset, 
           color_cells_by = "pseudotime")

#you can choose any number of vertices in any of the partitions and things go as they should

B


#Break it:
cds_subset_break = cds_subset
cds_subset_break = learn_graph(cds_subset_break, use_partition = F)
plot_cells(cds_subset_break, 
           color_cells_by = "partition")

D

cds_subset_break = order_cells(cds_subset_break)
plot_cells(cds_subset_break, 
           color_cells_by = "pseudotime")

#I have two partitions in my subset:
#selecting a node in partition 2 (any partition other than partition 1) breaks it
#selecting two nodes- one in partition 1 and one in partition 2 breaks it
#selecting two nodes - both in partition 2 breaks it

Error & Traceback:

Error in as.igraph.vs(graph, v) : Invalid vertex names

  1. stop("Invalid vertex names")
  2. as.igraph.vs(graph, v)
  3. igraph::distances(cell_wise_graph, v = closest_vertex_id)
  4. extract_general_graph_ordering(cds, root_pr_nodes, verbose, reduction_method)
  5. order_cells(cds_subset_break)
    
    #selecting two nodes - both in partition 1, works but partition 2 is black
![C](https://user-images.githubusercontent.com/37670221/59955490-4bf97180-943f-11e9-81c4-c431384fe0b7.png)

Here's the workaround that fixed it for me:

Want to have all the cells in the same trajectory without the bug of invalid vertex names:

check how many partitions there are (I had two partitions):

levels(cds_subset@clusters$UMAP$partitions)

set them all to "1"

cds_subset@clusters$UMAP$partitions[cds_subset@clusters$UMAP$partitions == "2"] <- "1"

checking again still says there are two types of partitions, "1" and "2"

levels(cds_subset@clusters$UMAP$partitions)

but there are no cells in partition "2":

length(cds_subset@clusters$UMAP$partitions[cds_subset@clusters$UMAP$partitions == "2"])

they are all in partition 1:

length(cds_subset@clusters$UMAP$partitions[cds_subset@clusters$UMAP$partitions == "1"])

check plot:

plot_cells(cds_subset, color_cells_by = "partition")

![H](https://user-images.githubusercontent.com/37670221/59955526-8a8f2c00-943f-11e9-909f-5bb026af10bc.png)

After this, you can call learn_graph(cds_subset) (default is use_partition=T) and get one trajectory and choose any vertex or several vertices. 

cds_subset = learn_graph(cds_subset) plot_cells(cds_subset, color_cells_by = "partition")

![E](https://user-images.githubusercontent.com/37670221/59955536-9549c100-943f-11e9-8b9d-9b1d09b16a25.png)

cds_subset = order_cells(cds_subset) plot_cells(cds_subset, color_cells_by = "pseudotime")

choose two roots on the lower-right side, the pseudo time extends to the cells on the far left:

![F](https://user-images.githubusercontent.com/37670221/59955555-b5798000-943f-11e9-8d05-9ee2f5444177.png)

choose a root in the center of the graph, pseudo time proceeds to the left and the right, as in the Monocle 3 tutorial:

![G](https://user-images.githubusercontent.com/37670221/59955574-d2ae4e80-943f-11e9-8c8b-4041cdc593b8.png)

Hope this helps!
Cheers!

sessionInfo() R version 3.6.0 (2019-04-26) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.2 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] grid stats4 parallel stats graphics grDevices utils datasets methods base

other attached packages: [1] igraph_1.2.4.1 shiny_1.3.2 mcclust_1.0 lpSolve_5.6.13.1 flexclust_1.4-0 modeltools_0.2-22 lattice_0.20-38
[8] usethis_1.5.0 devtools_2.0.2 monocle3_0.1.1 SingleCellExperiment_1.6.0 SummarizedExperiment_1.14.0 DelayedArray_0.10.0 BiocParallel_1.18.0
[15] matrixStats_0.54.0 GenomicRanges_1.36.0 GenomeInfoDb_1.20.0 BiocManager_1.30.4 IRanges_2.18.1 S4Vectors_0.22.0 Biobase_2.44.0
[22] BiocGenerics_0.30.0 reticulate_1.12 sctransform_0.2.0 ggplot2_3.2.0 Seurat_3.0.2

loaded via a namespace (and not attached): [1] backports_1.1.4 plyr_1.8.4 lazyeval_0.2.2 splines_3.6.0 crosstalk_1.0.0 listenv_0.7.0 digest_0.6.19 htmltools_0.3.6
[9] viridis_0.5.1 gdata_2.18.0 magrittr_1.5 memoise_1.1.0 cluster_2.0.9 ROCR_1.0-7 remotes_2.0.4 globals_0.12.4
[17] RcppParallel_4.4.3 R.utils_2.9.0 prettyunits_1.0.2 colorspace_1.4-1 ggrepel_0.8.1 xfun_0.7 dplyr_0.8.1 callr_3.2.0
[25] crayon_1.3.4 RCurl_1.95-4.12 jsonlite_1.6 survival_2.44-1.1 zoo_1.8-6 ape_5.3 glue_1.3.1 gtable_0.3.0
[33] zlibbioc_1.30.0 XVector_0.24.0 pkgbuild_1.0.3 future.apply_1.3.0 scales_1.0.0 bibtex_0.4.2 Rcpp_1.0.1 metap_1.1
[41] xtable_1.8-4 viridisLite_0.3.0 rsvd_1.0.1 proxy_0.4-23 SDMTools_1.1-221.1 tsne_0.1-3 htmlwidgets_1.3 httr_1.4.0
[49] gplots_3.0.1.1 RColorBrewer_1.1-2 ica_1.0-2 pkgconfig_2.0.2 R.methodsS3_1.7.1 uwot_0.1.3 later_0.8.0 tidyselect_0.2.5
[57] labeling_0.3 rlang_0.3.4 reshape2_1.4.3 munsell_0.5.0 tools_3.6.0 cli_1.1.0 ggridges_0.5.1 stringr_1.4.0
[65] yaml_2.2.0 npsurv_0.4-0 processx_3.3.1 knitr_1.23 fs_1.3.1 fitdistrplus_1.0-14 caTools_1.17.1.2 purrr_0.3.2
[73] RANN_2.6.1 pbapply_1.4-0 future_1.13.0 nlme_3.1-140 mime_0.7 R.oo_1.22.0 compiler_3.6.0 rstudioapi_0.10
[81] plotly_4.9.0 png_0.1-7 testthat_2.1.1 lsei_1.2-0 tibble_2.1.3 stringi_1.4.3 ps_1.3.0 desc_1.2.0
[89] RSpectra_0.15-0 Matrix_1.2-17 pillar_1.4.1 Rdpack_0.11-0 lmtest_0.9-37 RcppAnnoy_0.0.12 data.table_1.12.2 cowplot_0.9.4
[97] bitops_1.0-6 irlba_2.3.3 gbRd_0.4-11 httpuv_1.5.1 R6_2.4.0 promises_1.0.1 KernSmooth_2.23-15 gridExtra_2.3
[105] sessioninfo_1.1.1 codetools_0.2-16 MASS_7.3-51.1 gtools_3.8.1 assertthat_0.2.1 pkgload_1.0.2 rprojroot_1.3-2 withr_2.1.2
[113] GenomeInfoDbData_1.2.1 tidyr_0.8.3 class_7.3-15 DelayedMatrixStats_1.6.0 Rtsne_0.15

stephanieRedmond commented 5 years ago

I realize now that I added the wrong images for images #3 and #4 above (a different data object is plotted), but the outcome is the same.

brianpenghe commented 5 years ago

cluster_cells

It seems that your workaround is for Monocle3-beta but not Monocle3alpha?

stephanieRedmond commented 5 years ago

I have only used Monocle3-beta, so I don't know if this issue exists in Monocle3alpha, or if this workaround also works in alpha.

brianpenghe commented 5 years ago

I have only used Monocle3-beta, so I don't know if this issue exists in Monocle3alpha, or if this workaround also works in alpha.

OK. Monocle3alpha seems to have a very different structure. I can't find where it stores the partition information. But Monocle3Beta is inferior in the way that the trajectory backbone can be really messy.