ChiLiubio / microeco

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

About trans_diff$plot_diff_abund function: reorder taxa according to P.adj #273

Closed kestlermai closed 1 year ago

kestlermai commented 1 year ago

Hi,

The trans_diff$plot_diff_abund function by default sorts the species based on p-values in ascending order. Currently, I would like to change this sorting method, for example, to sort based on the total abundance.

I appreciate if you can help me solve this problem

ChiLiubio commented 1 year ago

Hi.

Good question! The parameter select_taxa can do that. Provided features by the param select_taxa will be used to select the taxa from the result and resort the result by the provided order. Here is an example.

library(microeco)
library(magrittr)
data(dataset)
t1 <- trans_diff$new(dataset = dataset, method = "KW", group = "Group", taxa_level = "Genus", filter_thres = 0.001)
# filter those non-significant
diff_table <- t1$res_diff %>% .[grepl("*", .$Significance, fixed = TRUE), ]
# select 20 to show
diff_taxa <- diff_table$Taxa[1:20] %>% gsub(".*\\|", "", .)
# the raw abundane table has been sorted by the mean abundance (similar to total abundance), so we can directly use them
raw_order <- rownames(dataset$taxa_abund$Genus) %>% gsub(".*\\|", "", .)
raw_order %<>% .[. %in% diff_taxa]
# use select_taxa
t1$plot_diff_abund(select_taxa = raw_order, add_sig = T)
kestlermai commented 1 year ago

It works very well, thank you very much for your assistance.