microeco
microeco copied to clipboard
Compute prevalence and abundance summary of each species/OTU for different variables
Hi, i wonder could it be possible to get prevalence and abundance summary of all the otus in a object somthing like mentioned in https://rdrr.io/github/vmikk/metagMisc/src/R/prevalence.R, but prevalence and abundance for different variables taken into consideration. please let me know if it is possible.
Your help is very much appreciated so far shaping up my manuscript.
Hi. To temporarily get such result, please use file2meco package to convert your microtable data.
library(microeco)
library(file2meco)
library(phyloseq)
data("dataset")
# load https://rdrr.io/github/vmikk/metagMisc/src/R/prevalence.R
test <- prevalence(meco2phyloseq(dataset))
Thanks, I could do that. Just want to get extra than that to get prevalence based on a factor. I mean to get abundance and prevalence for each sample and/or a factor.
It is ok to write a simple for
cycle to do that if the group number is large.
I am not much familiar with for cycle. I tried and it did not work. Could you please give me some toy example? Thanks in advance!
Hi. This is a simple example.
library(microeco)
library(file2meco)
library(magrittr)
library(phyloseq)
data("dataset")
# load https://rdrr.io/github/vmikk/metagMisc/src/R/prevalence.R
allgroups <- unique(dataset$sample_table[, "Group"])
allresult <- data.frame()
for(i in allgroups){
tmp <- clone(dataset)
tmp$sample_table %<>% .[.$Group == i, ]
tmp$tidy_dataset()
tmp_res <- prevalence(meco2phyloseq(tmp))
tmp_res <- data.frame(Feature = rownames(tmp_res), tmp_res, Group = i)
allresult <- rbind(allresult, tmp_res)
}
View(allresult)