ChiLiubio / microeco

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

add multiple taxa names to gexf file in trans_network, and also add relative abundance? #152

Open spencerlong1 opened 1 year ago

spencerlong1 commented 1 year ago

Hi,

I was wondering if there was a way to add multiple taxa names to the gephx file after using trans_network$cal_network. e.g if I wanted to colour nodes by phyla, but label them with family, would there be a way of doing this? At the moment it seems to be a case of manually adding the columns myself and labelling manually, but this is quite time consuming.

Additionally, is there a way of adding the relative abundance of the OTU in the dataset?, e.g. if I wanted to have node size correlated this.

Cheers! Spencer

ChiLiubio commented 1 year ago

Hi. Yes. Multiple taxonomic names are supported in the parameter add_taxa_name of cal_network function.

library(microeco)
data(dataset)
t1 <- trans_network$new(dataset = dataset, cor_method = "pearson", use_WGCNA_pearson_spearman = TRUE, filter_thres = 0.001)
t1$cal_network(COR_p_thres = 0.05, COR_cut = 0.6, add_taxa_name = c("Phylum", "Genus"))

Adding the relative abundance is a good idea. I will add this in the next release of the package. Thanks. Here is a temporary solution.

t1$cal_module()
nodes <- V(t1$res_network)$name
V(t1$res_network)$RelativeAbundance <- apply(t1$data_abund[, nodes], 2, sum) * 100/sum(dataset$otu_table)
t1$res_network
t1$save_network("network_test.gexf")

Best, Chi

spencerlong1 commented 1 year ago

Ah, makes sense! didn't think to concatenate. Thanks for all the help!

Spencer

ChiLiubio commented 1 year ago

Hi. Which network visualization way are you using? I am trying to map abundance to the node size and check the step.

spencerlong1 commented 1 year ago

Hi Chi, Had a go last night myself: I use Sparcc, with spieceasi (default settings currently) and then export on to gephi in same way as shown in your tutorial. Once in gephi, in the data I can see column with relative abundance (although this seems to add to >100) although can't currently map it to node size, which can still currently only correlated to the amount of connections.

I am not an expert at gephi so will keep playing around with it myself.

Cheers! Spencer

ChiLiubio commented 1 year ago

Yes. I also find that current Gephi can not map the abundance to node size and color as continuous variable. It only support the abundance as discrete variable (maybe all the foreign variables). I donot know why it is such designed.

Chi

spencerlong1 commented 1 year ago

Figured out how to map relative abundance to node size: in data laboratory, on your file for the graph, duplicate the relative abundance data column and class it as "float" when asked on the dropdown menu, then it can be found as a ranking for node size.

ChiLiubio commented 1 year ago

Wow! Fantastic! I got it as you said. The software make all the input data as strings. I will write a note in the tutorial to make readers know how to do it and direct them to the current webpage. Thanks for your solution.