ChiLiubio / microeco

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

Convert module to microtable object (trans_comm) #321

Closed anabelvonjackowski closed 1 month ago

anabelvonjackowski commented 4 months ago

Dear microeco team,

What an incredible package you have built!

I am trying to construct a network with the end goal of running the plot_spe_func_perc. section Explainable-class of the tutorial (v1.4.0)

My code is as follows:

micro <- phyloseq2meco(all_data) otu_table_16S <- micro$otu_table taxonomy_table_16S <- micro$tax_table taxonomy_table_16S_tidy <- taxonomy_table_16S %>% tidy_taxonomy sample_info_16S <- micro$sample_table[,c(1:11)] env_data_16S <-micro$sample_table[,-c(1:11)]

dataset <- microtable$new(sample_table = sample_info_16S, otu_table = otu_table_16S, tax_table = taxonomy_table_16S) dataset$filter_pollution(taxa = c("mitochondria", "chloroplast"))

use tidy_dataset() to make OTUs and samples information consistent across files dataset$tidy_dataset()

create trans_network object t1 <- trans_network$new(dataset = dataset, cal_cor = "base", taxa_level = "OTU", filter_thres = 0.000001, cor_method = "spearman")

create correlation network t1$cal_network(p_thres = 0.01, COR_cut = 0.7) t1$res_network

add modules t1$cal_module() t1$res_network convert module info to microtable object meco_module <- t1$trans_comm(use_col = "module")

running the trans_comm, I get the following error "Run get_node_table function to get the node property table ... Error in get(as.character(FUN), mode = "function", envir = envir) : object 'FUN' of mode 'function' was not found"

but when I run get_node_table(node_roles = TRUE) I receive the same error: Error in get(as.character(FUN), mode = "function", envir = envir) : object 'FUN' of mode 'function' was not found

I have been searching through trans_network.R for the longest time and cant figure out what my mistake is. Would you happen to know?

Thanks and best regards, Anabel

ChiLiubio commented 4 months ago

Hi. Could you please attach your t1 so that I can reproduce your issue? To save it, please follow the steps in the tutorial (https://chiliubio.github.io/microeco_tutorial/notes.html#save-function) and attach the compressed object.

Best, Chi

anabelvonjackowski commented 4 months ago

Dear Chi, The t1 is attached- Thanks for your help :-) vonjackowski_t1_test.RData.zip

ChiLiubio commented 4 months ago

Hi. I run those steps and find it is ok. Could you please recreate an R project and try to run these steps again?

library(microeco)
load("vonjackowski_t1_test.RData")
t1$cal_module()
t1$get_node_table()
meco_module <- t1$trans_comm(use_col = "module")
anabelvonjackowski commented 4 months ago

Hi Chi,

I did. After the trans_comm(use_col = "module") function I get the following error: "No sample_table provided, automatically use colnames in otu_table to create one ...", which is weird cause I do have t1$sample_table, right?

vonjackowski_t1_test_v2.zip

ChiLiubio commented 4 months ago

Hi. This is a message, not an error. The message is inside the microtable class and invoked when no sample_table is provided. The sample_table in t1 is for samples, but the sample names in created microtable is each module name, not the sample names. So the following analysis will do not need metadata.

ChiLiubio commented 4 months ago

So you can view the automatically created sample_table in the result, i.e. View(meco_module$sample_table).