microeco icon indicating copy to clipboard operation
microeco copied to clipboard

Compute prevalence and abundance summary of each species/OTU for different variables

Open apoosakkannu opened this issue 1 year ago • 5 comments

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.

apoosakkannu avatar Mar 16 '23 08:03 apoosakkannu

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))

ChiLiubio avatar Mar 16 '23 11:03 ChiLiubio

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.

apoosakkannu avatar Mar 16 '23 12:03 apoosakkannu

It is ok to write a simple for cycle to do that if the group number is large.

ChiLiubio avatar Mar 16 '23 14:03 ChiLiubio

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!

apoosakkannu avatar Mar 24 '23 10:03 apoosakkannu

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)

ChiLiubio avatar Mar 25 '23 07:03 ChiLiubio