smorabit / hdWGCNA

High dimensional weighted gene co-expression network analysis
https://smorabit.github.io/hdWGCNA/
Other
316 stars 31 forks source link

Error during PlotDMEsLollipop #134

Closed kaizen89 closed 9 months ago

kaizen89 commented 9 months ago

Hi, Thanks a lot for this very useful package. I am facing a little issue when using PlotDMEsLollipop. The output of the plot seems odd

group1 <- seu_obj@meta.data %>% filter(group == "group1") %>% rownames
group2 <- seu_obj@meta.data %>% filter(group != 'group1') %>% rownames
DMEs <- FindDMEs(
  seu_obj,harmonized = F,pseudocount.use = 0,
  barcodes1 = group1,add_missing=F,
  barcodes2 = group2,
  test.use='wilcox'
)
PlotDMEsLollipop(
  seu_obj,
  DMEs,pvalue = "p_val",wgcna_name = 'fibro' # It doenst recongnize the default wgcna name
)
"Please be aware comparison group/groups are not provided, which may casue an ERROR. PlotDMEsLollipop function will automatically assume all values are within the same group."

MicrosoftTeams-image image

Any ideas? Thanks

rootze commented 9 months ago

@kaizen89 Hello Kaizen89, thanks for using hdWGCNA. Would you mind sharing how you run the SetupForWGCNA. It seems to me that your wgcna_name is not 'fibro' or maybe you changed the module name to M- something. And as far as I can tell, PlotDMEsLollipop cannot find your hdWGCNA modules size. And as you point out, the default wgcna names were not recognized.

chiwwong commented 9 months ago

I got the same issue that no color is shown for each cluster. The same issue also happened for plotting the volcano plot.

rootze commented 9 months ago

@chiwwong, If you could share your code starting with how you construct the hdWGCNA project till the PlotDMEsLollipop function as well as the figures that you generated, that would be helpful for me to understand what could potentially cause the problem. Thank you!

kaizen89 commented 9 months ago

@rootze, here's is how I did it, only showing the steps that could be related to the issue

seu_obj <- SetupForWGCNA(
  seu_obj, features= features,
  gene_select = "fraction", # the gene selection approach
  fraction = 0, # fraction of cells that a gene needs to be expressed in order to be included
  wgcna_name = "fibro" # the name of the hdWGCNA experiment
)
seu_obj <- ModuleEigengenes(
 seu_obj,
 group.by.vars=NULL,exclude_grey=F
)
seu_obj = ResetModuleNames(seu_obj, new_name= "M_",wgcna_name="fibro")
rootze commented 9 months ago

@kaizen89 Unfortunately, I've never seen this error before. Before calling for backup, out of curiosity, in SetupForWGCNA(), what features did you use for features= features,? Secondly, can you show me your output from this? I would like to see what your module looks like and how many genes are within which modules.

### get the module assignment table:
modules <- GetModules(seurat_obj)
modules

# genes per module
n_genes <- table(modules$module)
n_genes

Lastly,wgcna_name = "fibro", Is fibro a parameter that did not exist within the Seurat object before setting it as wgcna_name? @smorabit, I am not sure if setting a random wgcna_name that did not exist within the Seurat object would influence the plotting. Any ideas?

kaizen89 commented 9 months ago

@rootze,features are just variable genes from which I excluded junk genes and others with very low expression. fibro was not a parameter in the object. here's the output of table(modules$module). image

chiwwong commented 9 months ago

I was able to get the "colored" plot from tutorial data as I commented on https://github.com/smorabit/hdWGCNA/issues/130#issuecomment-1654473846

I also tried to get into the wrapper function and found there is color, until line 39 for PlotDMEsVolcano.

p <- p + scale_fill_manual(values = mod_colors) + scale_color_manual(values = mod_colors) +

Just a side topic, it would be great if you can also add for all function for consistency:

if (is.null(wgcna_name)) {
    wgcna_name <- seurat_obj@misc$active_wgcna
  }

e.g. the above lines were included in FindDMEs but not PlotDMEsVolcano and PlotDMEsLollipop

maithermbarros commented 9 months ago

Hi @rootze . I am also getting an error with PlotDMEsLollipop. The plot gets created, but no "x" is placed over each point that does not reach statistical significance. Also, how come almost half of my modules had a p value of absolute 0? Is that expected? Thank you!

`> DMEs
                    p_val avg_log2FC pct.1 pct.2     p_val_adj      module
Healthy-M12  0.000000e+00 -1.9064230 0.081 0.286  0.000000e+00 Healthy-M12
Healthy-M3   0.000000e+00 -2.0373291 0.260 0.509  0.000000e+00  Healthy-M3
Healthy-M8   0.000000e+00  1.2631941 0.541 0.460  0.000000e+00  Healthy-M8
Healthy-M13  0.000000e+00  0.8153260 0.683 0.420  0.000000e+00 Healthy-M13
Healthy-M2   0.000000e+00  1.7100469 0.476 0.262  0.000000e+00  Healthy-M2
Healthy-M6   0.000000e+00 -1.0338754 0.366 0.524  0.000000e+00  Healthy-M6
Healthy-M7  4.285894e-185  2.5882064 0.312 0.270 5.571662e-184  Healthy-M7
Healthy-M5  7.610967e-170  0.5883328 0.541 0.501 9.894258e-169  Healthy-M5
Healthy-M11 3.237868e-162 -0.4667147 0.370 0.479 4.209228e-161 Healthy-M11
Healthy-M1   6.054769e-85  2.3499849 0.275 0.249  7.871199e-84  Healthy-M1
Healthy-M9   6.497091e-65 -0.5387225 0.128 0.175  8.446218e-64  Healthy-M9
Healthy-M4   1.430422e-63  0.2535413 0.548 0.501  1.859549e-62  Healthy-M4
Healthy-M10  7.047625e-08  1.0537786 0.187 0.179  9.161913e-07 Healthy-M10`

capture

`> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

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

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

other attached packages:
 [1] ggforestplot_0.1.0    GeneOverlap_1.34.0    qlcMatrix_0.9.7       sparsesvd_0.2-2      
 [5] slam_0.1-50           Matrix_1.5-1          patchwork_1.1.2       hdWGCNA_0.2.19       
 [9] WGCNA_1.72-1          fastcluster_1.2.3     dynamicTreeCut_1.63-1 devtools_2.4.5       
[13] usethis_2.2.2         igraph_1.5.0          readxl_1.4.3          pheatmap_1.0.12      
[17] harmony_0.1.1         Rcpp_1.0.11           lubridate_1.9.2       forcats_1.0.0        
[21] stringr_1.5.0         dplyr_1.1.2           purrr_1.0.1           readr_2.1.4          
[25] tidyr_1.3.0           tibble_3.2.1          ggplot2_3.4.2         tidyverse_2.0.0      
[29] SeuratObject_4.1.3    Seurat_4.3.0          biomaRt_2.54.1       

loaded via a namespace (and not attached):
  [1] rappdirs_0.3.3         scattermore_1.2        bit64_4.0.5            knitr_1.43            
  [5] irlba_2.3.5.1          data.table_1.14.8      rpart_4.1.19           KEGGREST_1.38.0       
  [9] RCurl_1.98-1.12        doParallel_1.0.17      generics_0.1.3         BiocGenerics_0.44.0   
 [13] preprocessCore_1.60.2  callr_3.7.3            cowplot_1.1.1          RSQLite_2.3.1         
 [17] RANN_2.6.1             future_1.33.0          bit_4.0.5              tzdb_0.4.0            
 [21] spatstat.data_3.0-1    xml2_1.3.5             httpuv_1.6.11          xfun_0.39             
 [25] hms_1.1.3              evaluate_0.21          promises_1.2.0.1       fansi_1.0.4           
 [29] progress_1.2.2         caTools_1.18.2         dbplyr_2.3.3           DBI_1.1.3             
 [33] htmlwidgets_1.6.2      spatstat.geom_3.2-2    stats4_4.2.3           ellipsis_0.3.2        
 [37] tester_0.1.7           backports_1.4.1        deldir_1.0-9           vctrs_0.6.3           
 [41] Biobase_2.58.0         remotes_2.4.2.1        ROCR_1.0-11            abind_1.4-5           
 [45] cachem_1.0.8           withr_2.5.0            progressr_0.13.0       checkmate_2.2.0       
 [49] sctransform_0.3.5      prettyunits_1.1.1      goftest_1.2-3          cluster_2.1.4         
 [53] lazyeval_0.2.2         crayon_1.5.2           spatstat.explore_3.2-1 pkgconfig_2.0.3       
 [57] labeling_0.4.2         GenomeInfoDb_1.34.9    nlme_3.1-162           pkgload_1.3.2.1       
 [61] nnet_7.3-18            rlang_1.1.1            globals_0.16.2         lifecycle_1.0.3       
 [65] miniUI_0.1.1.1         filelock_1.0.2         BiocFileCache_2.6.1    enrichR_3.2           
 [69] cellranger_1.1.0       rprojroot_2.0.3        polyclip_1.10-4        matrixStats_1.0.0     
 [73] lmtest_0.9-40          zoo_1.8-12             base64enc_0.1-3        ggridges_0.5.4        
 [77] processx_3.8.2         png_0.1-8              viridisLite_0.4.2      rjson_0.2.21          
 [81] bitops_1.0-7           KernSmooth_2.23-20     Biostrings_2.66.0      blob_1.2.4            
 [85] parallelly_1.36.0      spatstat.random_3.1-5  S4Vectors_0.36.2       scales_1.2.1          
 [89] memoise_2.0.1          magrittr_2.0.3         plyr_1.8.8             ica_1.0-3             
 [93] gplots_3.1.3           zlibbioc_1.44.0        compiler_4.2.3         RColorBrewer_1.1-3    
 [97] fitdistrplus_1.1-11    cli_3.6.1              XVector_0.38.0         urlchecker_1.0.1      
[101] listenv_0.9.0          pbapply_1.7-2          ps_1.7.5               htmlTable_2.4.1       
[105] Formula_1.2-5          MASS_7.3-58.3          tidyselect_1.2.0       stringi_1.7.12        
[109] yaml_2.3.7             ggrepel_0.9.3          grid_4.2.3             tools_4.2.3           
[113] timechange_0.2.0       future.apply_1.11.0    parallel_4.2.3         rstudioapi_0.15.0     
[117] foreach_1.5.2          foreign_0.8-82         gridExtra_2.3          farver_2.1.1          
[121] Rtsne_0.16             digest_0.6.33          BiocManager_1.30.21.1  shiny_1.7.4.1         
[125] broom_1.0.5            later_1.3.1            RcppAnnoy_0.0.21       WriteXLS_6.4.0        
[129] httr_1.4.6             AnnotationDbi_1.60.2   colorspace_2.1-0       XML_3.99-0.14         
[133] fs_1.6.2               tensor_1.5             reticulate_1.30        IRanges_2.32.0        
[137] splines_4.2.3          uwot_0.1.16            spatstat.utils_3.0-3   sp_2.0-0              
[141] plotly_4.10.2          sessioninfo_1.2.2      xtable_1.8-4           jsonlite_1.8.7        
[145] R6_2.5.1               profvis_0.3.8          Hmisc_5.1-0            pillar_1.9.0          
[149] htmltools_0.5.5        mime_0.12              glue_1.6.2             fastmap_1.1.1         
[153] codetools_0.2-19       pkgbuild_1.4.2         utf8_1.2.3             lattice_0.20-45       
[157] spatstat.sparse_3.0-2  curl_5.0.1             leiden_0.4.3           gtools_3.9.4          
[161] GO.db_3.16.0           survival_3.5-5         limma_3.54.2           rmarkdown_2.23        
[165] docopt_0.7.1           desc_1.4.2             munsell_0.5.0          GenomeInfoDbData_1.2.9
[169] iterators_1.0.14       impute_1.72.3          reshape2_1.4.4         gtable_0.3.3  
smorabit commented 9 months ago

@maithermbarros what is your error message? Based on the information that you provided the plot is working as intended, it seems like all of your p values are smaller than 0.05.

Also, how come almost half of my modules had a p value of absolute 0? Is that expected?

I am not sure if this is expected because I don't know what data you are working on. The results will change based on what dataset you have, sample, species, cell type, modules, statistical test, etc. There is no ground truth available typically so is impossible to have an "expected" result in this case.

maithermbarros commented 9 months ago

@smorabit You are right, I had missed something re the graph, my bad! But thanks for getting back to me.

kaizen89 commented 9 months ago

Ok it turns out that the issue was caused by the underscore when I renamed the modules. Somehow FindDMEs transforms the underscore to a dash as you can see in the table and plot of my first comment. When removing the underscore the issue disappears.