almeidasilvaf / BioNERO

Easy and comprehensive biological network reconstruction and analysis
https://almeidasilvaf.github.io/BioNERO/
24 stars 5 forks source link

plot_gcn #17

Closed WWz33 closed 8 months ago

WWz33 commented 8 months ago

Hi! Thanks for so many elegant packages. plot_gcn is written based on ggplot2. Have you considered generating the r object directly instead of returning a plot?

Best !

almeidasilvaf commented 8 months ago

Hi, @WWz33

Thank you for your kind feedback.

Do you mean returning the data frame (to be used with custom ggplot2 code) instead of the ggplot object itself?

Best, Fabricio

WWz33 commented 8 months ago

Thanks for the reply, I would like to add some phenotypic node information . I ran the exp2gcn function with the default settings in the tutorial and it took up twice as much memory as wgcna. And I'm not sure why running the same data takes nearly 20 minutes to complete with WGCNA, but it's been close to an hour and exp2gcn hasn't finished running yet.

final_exp=filtered_exp_204

sft <- SFT_fit(final_exp, net_type = "signed hybrid", cor_method = "pearson")
power <- sft$power

net <- exp2gcn(
  final_exp, net_type = "signed hybrid", SFTpower = power, 
  cor_method = "pearson"
)
datExpr=t(filtered_exp_204)
powers = c(c(1:10), seq(from = 12, to=20, by=2))
sft = pickSoftThreshold(datExpr, powerVector = powers, verbose = 5)
net = blockwiseModules(datExpr, power = sft$powerEstimate,
                       TOMType = "unsigned", minModuleSize = 30,
                       reassignThreshold = 0, mergeCutHeight = 0.25,
                       numericLabels = TRUE, pamRespectsDendro = FALSE,
                       saveTOMs = TRUE, saveTOMFileBase = "TOM",
                       verbose = 3)
almeidasilvaf commented 8 months ago

Hi, @WWz33

I will add the option to return the data frame in plot_gcn().

Regarding the memory usage and runtime issue, this is because your WGCNA version of the code is using the blockwiseModules() function, which infers the GCN in blocks (to reduce memory usage). This is different from inferring the network with all data at once, and will lead to a similar, but still different network (see the documentation of WGCNA for more details on using the step-by-step vs the blockwise approach).

Under the hood, BioNERO imports WGCNA functions, so the same approach in BioNERO (network inference with all data, not blockwise) should be equivalent to doing it with WGCNA. If you want to make it faster with the all-data approach, you can increase the number of threads to use in computations with:

# Example: using 8 threads
WGCNA::allowWGCNAThreads(nThreads = 8)

This way, WGCNA functions used in BioNERO will automatically understand that they can parallelize computations using N threads.

Best, Fabricio

WWz33 commented 8 months ago

Hi! Fabricio Thank you for your patient reply, I learned a lot. Thank you again for the elegant packages and the detailed manual.

Best!