ChiLiubio / microeco

An R package for data analysis in microbial community ecology
GNU General Public License v3.0
194 stars 56 forks source link

Plotting the colors with the positive and negative correlations. #260

Closed Aristotle1992 closed 3 months ago

Aristotle1992 commented 1 year ago

for root samples

root_bac_sub_no_bad_Filtered_final_non_normalized <- readRDS(file = "C:/Microbiome/RDS/root_bac_sub_no_bad_Filtered_final_non_normalized.rds")

root_norm = transform_sample_counts(root_bac_sub_no_bad_Filtered_final_non_normalized, function(x) x / sum(x) ) root_network = filter_taxa(root_norm, function(x) mean(x) > 0.0001, TRUE) root_network

first convert to microtable

root_amp <- phyloseq2meco(root_network) root_amp

The parameter cor_method in trans_network is used to select correlation calculation method.

default pearson or spearman correlation invoke R base cor.test, a little slow

net_root <- trans_network$new(dataset = root_amp, cor_method = "spearman", filter_thres = 0.001)

return net_root$res_cor_p list, containing two tables: correlation coefficient table and p value table

require WGCNA package

if(!require("WGCNA")) install.packages("WGCNA", repos = BiocManager::repositories()) net_root <- trans_network$new(dataset = root_amp, cor_method = "spearman", use_WGCNA_pearson_spearman = TRUE, filter_thres = 0.0001)

write.csv(t1[["res_cor_p"]][["p"]], "C:/Microbiome/network files/root_cor.csv")

use arbitrary coefficient threshold to contruct network

net_root$cal_network(COR_p_thres = 0.05, COR_cut = 0.6, COR_p_adjust = "fdr")

return net_root$res_network

invoke igraph cluster_fast_greedy function for this undirected network

net_root$cal_module(method = "cluster_fast_greedy")

require rgexf package to be installed

net_root$save_network(filepath = "C:/Microbiome/network files/root_network.gexf")

My next goal is to plot the colors with the positive and negative correlations using gephi and my problem is how do I add the correlation matrix to the gephi file format as they are in matrix. In essence i want my network plot to show just the negative and positive correlations between the phylum. Thanks

ChiLiubio commented 1 year ago

Hi. The positive and negative labels (+ and -) have been added into the network. When you open the saved root_network.gexf, please try to find it following those steps: Click Overview -> Appearance (in top left cornor) -> Edges -> Partition -> Select label. That is it.

Aristotle1992 commented 1 year ago

Thanks so much for your reply but when i followed the step you stated i only found + and no -. What could be a likely cause?

ChiLiubio commented 1 year ago

The reason should be that there is no negative significant correlation after the filtering with your parameters. To test this, you can lower the correlation coefficient threshold and try again.

Aristotle1992 commented 1 year ago

oh ok thanks. I will try that out.