smorabit / hdWGCNA

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

Supplying a named list to rename all modules doesn't work #132

Closed iamakhilverma closed 9 months ago

iamakhilverma commented 10 months ago

This doesn't work as described in the Module customization tutorial. Something seems to be broken with ResetModuleNames. I've tried it with multiple seurat objects from different hdWGCNA runs.

rename_list <- list(
  "Renamed-M1" = 'Charlie', # "old_module_name" = "new_module_name"
  "Renamed-M2" = "Mac",
  "Renamed-M3" = "Dennis"
)

seurat_obj <- ResetModuleNames(
  seurat_obj,
  new_name = rename_list
)

# print out the new module names
modules <- GetModules(seurat_obj)
print(levels(modules$module))

R session info

R version 4.2.2 (2022-10-31) Platform: x86_64-conda-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux Server 7.9 (Maipo)

Matrix products: default BLAS/LAPACK: /ahg/regevdata/projects/ICA_Lung/Nishant/conda/envs/scrna/lib/libopenblasp-r0.3.21.so

locale: [1] C

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

other attached packages: [1] hdWGCNA_0.2.11 hash_2.2.6.2
[3] paletteer_1.5.0 lubridate_1.9.2
[5] forcats_1.0.0 stringr_1.5.0
[7] purrr_1.0.1 readr_2.1.4
[9] tibble_3.2.0 tidyverse_2.0.0
[11] igraph_1.4.1 WGCNA_1.72-1
[13] fastcluster_1.2.3 dynamicTreeCut_1.63-1
[15] NMF_0.26 cluster_2.1.4
[17] rngtools_1.5.2 registry_0.5-1
[19] clusterProfiler_4.6.2 ggridges_0.5.4
[21] BiocParallel_1.32.6 viridis_0.6.3
[23] viridisLite_0.4.2 org.Hs.eg.db_3.16.0
[25] org.Mm.eg.db_3.16.0 GO.db_3.16.0
[27] AnnotationDbi_1.60.2 plotly_4.10.2
[29] destiny_3.12.0 scater_1.26.1
[31] scuttle_1.8.4 harmony_0.1.0
[33] Rcpp_1.0.10 DropletUtils_1.18.1
[35] SingleCellExperiment_1.20.1 SummarizedExperiment_1.28.0 [37] Biobase_2.58.0 GenomicRanges_1.50.2
[39] GenomeInfoDb_1.34.9 IRanges_2.32.0
[41] S4Vectors_0.36.2 BiocGenerics_0.44.0
[43] MatrixGenerics_1.10.0 matrixStats_0.63.0
[45] GSA_1.03.2 gdata_2.19.0
[47] tidyr_1.3.0 fgsea_1.24.0
[49] ggrepel_0.9.3 RColorBrewer_1.1-3
[51] ComplexHeatmap_2.15.1 patchwork_1.1.2
[53] gplots_3.1.3 biomaRt_2.54.1
[55] ggpubr_0.6.0 Matrix_1.5-4.1
[57] dplyr_1.1.0 SeuratObject_4.1.3
[59] Seurat_4.3.0 ggplot2_3.4.2
[61] jsonlite_1.8.4 formatR_1.14

loaded via a namespace (and not attached): [1] rsvd_1.0.5 vcd_1.4-11
[3] Hmisc_5.1-0 ica_1.0-3
[5] class_7.3-22 foreach_1.5.2
[7] lmtest_0.9-40 crayon_1.5.2
[9] laeken_0.5.2 MASS_7.3-58.3
[11] rhdf5filters_1.10.1 nlme_3.1-162
[13] backports_1.4.1 impute_1.72.3
[15] GOSemSim_2.24.0 rlang_1.1.1
[17] XVector_0.38.0 HDO.db_0.99.1
[19] ROCR_1.0-11 irlba_2.3.5.1
[21] limma_3.54.2 smoother_1.1
[23] filelock_1.0.2 rjson_0.2.21
[25] bit64_4.0.5 glue_1.6.2
[27] sctransform_0.3.5 parallel_4.2.2
[29] vipor_0.4.5 spatstat.sparse_3.0-1
[31] DOSE_3.24.2 spatstat.geom_3.2-1
[33] tidyselect_1.2.0 fitdistrplus_1.1-11
[35] XML_3.99-0.14 zoo_1.8-12
[37] xtable_1.8-4 RcppHNSW_0.4.1
[39] magrittr_2.0.3 evaluate_0.21
[41] cli_3.6.1 zlibbioc_1.44.0
[43] rstudioapi_0.14 miniUI_0.1.1.1
[45] sp_1.6-0 rpart_4.1.19
[47] fastmatch_1.1-3 treeio_1.22.0
[49] RcppEigen_0.3.3.9.3 shiny_1.7.4
[51] xfun_0.39 BiocSingular_1.14.0
[53] clue_0.3-64 gson_0.1.0
[55] caTools_1.18.2 tidygraph_1.2.3
[57] pcaMethods_1.90.0 pbdZMQ_0.3-9
[59] KEGGREST_1.38.0 ape_5.7-1
[61] listenv_0.9.0 Biostrings_2.66.0
[63] png_0.1-8 future_1.32.0
[65] withr_2.5.0 bitops_1.0-7
[67] ggforce_0.4.1 ranger_0.15.1
[69] plyr_1.8.8 e1071_1.7-13
[71] dqrng_0.3.0 pillar_1.9.0
[73] GlobalOptions_0.1.2 cachem_1.0.8
[75] scatterplot3d_0.3-44 TTR_0.24.3
[77] GetoptLong_1.0.5 DelayedMatrixStats_1.20.0 [79] xts_0.13.1 vctrs_0.5.2
[81] ellipsis_0.3.2 generics_0.1.3
[83] tools_4.2.2 foreign_0.8-84
[85] beeswarm_0.4.0 tweenr_2.0.2
[87] munsell_0.5.0 proxy_0.4-27
[89] DelayedArray_0.24.0 fastmap_1.1.1
[91] compiler_4.2.2 abind_1.4-5
[93] httpuv_1.6.11 GenomeInfoDbData_1.2.9
[95] gridExtra_2.3 edgeR_3.40.2
[97] lattice_0.21-8 deldir_1.0-9
[99] utf8_1.2.3 later_1.3.1
[101] prismatic_1.1.1 BiocFileCache_2.6.1
[103] ggplot.multistats_1.0.0 scales_1.2.1
[105] ScaledMatrix_1.6.0 tidytree_0.4.2
[107] pbapply_1.7-0 carData_3.0-5
[109] sparseMatrixStats_1.10.0 lazyeval_0.2.2
[111] promises_1.2.0.1 car_3.1-2
[113] doParallel_1.0.17 R.utils_2.12.2
[115] goftest_1.2-3 checkmate_2.2.0
[117] spatstat.utils_3.0-3 reticulate_1.28
[119] rmarkdown_2.22 cowplot_1.1.1
[121] Rtsne_0.16 downloader_0.4
[123] uwot_0.1.14 HDF5Array_1.26.0
[125] survival_3.5-3 htmltools_0.5.5
[127] memoise_2.0.1 locfit_1.5-9.8
[129] graphlayouts_1.0.0 digest_0.6.31
[131] mime_0.12 rappdirs_0.3.3
[133] repr_1.1.6 RSQLite_2.3.1
[135] yulab.utils_0.0.6 future.apply_1.11.0
[137] data.table_1.14.8 blob_1.2.4
[139] R.oo_1.25.0 preprocessCore_1.60.2
[141] labeling_0.4.2 Formula_1.2-5
[143] splines_4.2.2 rematch2_2.1.2
[145] Rhdf5lib_1.20.0 RCurl_1.98-1.10
[147] broom_1.0.5 hms_1.1.3
[149] rhdf5_2.42.1 colorspace_2.1-0
[151] base64enc_0.1-3 BiocManager_1.30.21
[153] ggbeeswarm_0.7.2 shape_1.4.6
[155] aplot_0.1.10 nnet_7.3-19
[157] RANN_2.6.1 circlize_0.4.15
[159] enrichplot_1.18.4 fansi_1.0.4
[161] tzdb_0.4.0 VIM_6.2.2
[163] parallelly_1.36.0 IRdisplay_1.1
[165] R6_2.5.1 lifecycle_1.0.3
[167] curl_5.0.0 ggsignif_0.6.4
[169] leiden_0.4.3 robustbase_0.99-0
[171] qvalue_2.30.0 RcppAnnoy_0.0.20
[173] iterators_1.0.14 spatstat.explore_3.2-1
[175] htmlwidgets_1.6.2 beachmat_2.14.2
[177] polyclip_1.10-4 shadowtext_0.1.2
[179] timechange_0.2.0 gridGraphics_0.5-1
[181] globals_0.16.2 htmlTable_2.4.1
[183] spatstat.random_3.1-5 progressr_0.13.0
[185] codetools_0.2-19 gtools_3.9.4
[187] prettyunits_1.1.1 dbplyr_2.3.2
[189] gridBase_0.4-7 RSpectra_0.16-1
[191] R.methodsS3_1.8.2 gtable_0.3.3
[193] DBI_1.1.3 ggfun_0.1.0
[195] tensor_1.5 httr_1.4.6
[197] KernSmooth_2.23-21 stringi_1.7.12
[199] progress_1.2.2 farver_2.1.1
[201] reshape2_1.4.4 uuid_1.1-0
[203] ggthemes_4.2.4 hexbin_1.28.3
[205] ggtree_3.6.2 xml2_1.3.4
[207] boot_1.3-28.1 IRkernel_1.3.2
[209] BiocNeighbors_1.16.0 ggplotify_0.1.0
[211] scattermore_1.1 DEoptimR_1.0-14
[213] bit_4.0.5 scatterpie_0.2.1
[215] spatstat.data_3.0-1 ggraph_2.1.0
[217] pkgconfig_2.0.3 rstatix_0.7.2
[219] knitr_1.43

smorabit commented 9 months ago

Can you please describe the deviation from expected behavior that you are observing? I just tried to do this with the tutorial dataset and it worked just fine.

iamakhilverma commented 9 months ago

Can you please describe the deviation from expected behavior that you are observing? I just tried to do this with the tutorial dataset and it worked just fine.

My code was:

seurat_obj <- ResetModuleNames(
    seurat_obj.wgcna,
    new_name = rename_list
)

# print out the new module names
modules <- GetModules(seurat_obj)
print(levels(modules$module))

I wanted it to not only rename the modules that we get using GetModules() function but also rename the module names present as column names in seurat object's metadata. I had to do that part manually which we can easily add to the source code.

smorabit commented 9 months ago

I am sorry but I still don't understand what you are expecting versus what you are observing. I am not sure what you mean by "WGCNA object"?

Could you please provide a reproducible example?

iamakhilverma commented 9 months ago

I am sorry but I still don't understand what you are expecting versus what you are observing. I am not sure what you mean by "WGCNA object"?

Could you please provide a reproducible example?

I meant Seurat object with hdWGCNA run information (I've modified my comment above).

For example, you identified four modules, say blue, cyan, red, and black using hdWGCNA. Now, you want to rename them to EMT, Cell_Cycle, OxPhos, and Hypoxia. You create a rename list as follows:

rename_list <- list(
    "blue" = "EMT",
    "cyan" = "Cell_Cycle",
    "red" = "OxPhos",
    "black" = "Hypoxia"
)

seurat_obj <- ResetModuleNames(
    seurat_obj.wgcna,
    new_name = rename_list
)

# print out the new module names
modules <- GetModules(seurat_obj)
print(levels(modules$module))

and get output:

[1] "EMT" "grey"
[3] "Cell_Cycle" "OxPhos"
[5] "Hypoxia"

This is as expected but when you ask for colnames(seurat_obj@meta.data), you don't see EMT, Cell_Cycle, OxPhos, and Hypoxia but it has blue, cyan, red, and black. Also, in the wgcna_modules_r_max column, you still see old module names which is the deviation from what we want, i.e., the new module names.

The following code fixes the issue that I mentioned:

data.table::setnames(
    seurat_obj@meta.data, 
    old = as.character(names(rename_list)), 
    new = as.character(rename_list)
)

df <- seurat_obj@meta.data[as.character(rename_list)]

seurat_obj <- AddMetaData(
  object = seurat_obj,
  metadata = colnames(df)[max.col(df, ties.method="first")],
  col.name = 'wgcna_renamedModules_r_max'
)
smorabit commented 9 months ago

Based on this code that you provide it looks like you are interested in changing the Seurat object meta data, and I think if you are having an issue or error regarding this then it's ultimately a problem with Seurat rather than with hdWGCNA. To clarify, hdWGCNA itself does not use the Seurat meta data to store any information about the modules.

iamakhilverma commented 9 months ago

Based on this code that you provide it looks like you are interested in changing the Seurat object meta data, and I think if you are having an issue or error regarding this then it's ultimately a problem with Seurat rather than with hdWGCNA. To clarify, hdWGCNA itself does not use the Seurat meta data to store any information about the modules.

Correct me if I'm wrong, but doesn't it run AddModuleScore for each identified module which in turn modifies the seurat object's metadata?

smorabit commented 9 months ago

I am not sure what code that you ran, so I am not sure? Typically with GitHub issues I need to know the relevant details in order to identify and resolve your issue, which is why a reproducible example would be very helpful.

iamakhilverma commented 9 months ago

Screenshot 2023-08-10 at 7 11 30 PM

One of the commands in hdWGCNA tutorial runs AddModuleScore (PFA the screenshot showing that part of output), not sure which one was it because I ran it a few months ago but when I noticed the same issue when my labmate ran hdWGCNA pipeline, I opened this issue. I understand a reproducible example is more helpful, if this doesn't help, let me know and I'll try to create one more like the one I created above.

smorabit commented 9 months ago

I think that this information about module scores or module eigengenes is optionally added to the Seurat object metadata by the user for some suggested plotting in the tutorial, but to be clear the hdWGCNA functions do not directly add this information to the Seurat object metadata. For this reason, the ResetModuleNames function does not change any of the information in the Seurat metadata.