ChiLiubio / microeco

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

how to select a group as reference per run MaAsLin2 diferential abundance analysis #337

Open milyzhou opened 6 months ago

milyzhou commented 6 months ago

Hi Chi, Thank you for your nice answer. I want to select a group as reference per to do MaAsLin2 diferential abundance analysis like this fig. I wonder microeco can do that? 1 in this fig, it select CSab as reference per. Thank you again

ChiLiubio commented 6 months ago

Hi. Please use parameter passing. The parameters in Maaslin2 function of Maaslin2 package can be directly provided in the trans_diff. The reference is the parameter you need. Here is an example.

# use data in Maaslin2 package
library(Maaslin2)
input_data <- as.data.frame(t(read.delim(system.file('extdata','HMP2_taxonomy.tsv', package="Maaslin2"), row.names = 1)))
input_metadata <- read.delim(system.file('extdata','HMP2_metadata.tsv', package="Maaslin2"), row.names = 1)
library(microeco)
d1 <- microtable$new(input_data, sample_table = input_metadata)
d1$taxa_abund$Species <- d1$otu_table
t1 <- trans_diff$new(dataset = d1, method = "maaslin2", 
        fixed_effects = c('diagnosis', 'dysbiosisnonIBD','dysbiosisUC','dysbiosisCD', 'antibiotics', 'age'),
        random_effects = c('site', 'subject'),
        normalization = 'NONE',
        reference = 'diagnosis,nonIBD',
        standardize = FALSE,
        taxa_level = "Species", filter_thres = 0.001,
        tmp_input_maaslin2 = "maaslin2_tmp_input3", tmp_output_maaslin2 = "maaslin2_tmp_output3")
View(t1$res_diff)
# use name column as x axis; delete the Env column. it is a minor bug in v1.5.0. Fixed in the v1.6.0
t1$res_diff <- t1$res_diff[, -3]
t1$plot_diff_bar(heatmap_cell = "coef", heatmap_lab_fill = "Coef", heatmap_x = "name", heatmap_y = "Taxa", keep_prefix = TRUE)