You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel like there should be an easy answer to this question, but I can't seem to find it. All I would like to do is to drop samples from a phyloseq object where there are less than n number of taxa. Anybody know how to do this? ntaxa() yields total number of OTUs. I know that samples can be dropped with the prune_samples() function requiring a list of TRUE/FALSE, but not sure how to generate that list.
The text was updated successfully, but these errors were encountered:
Hello Jon!
You can try to use estimate_richness to count the number of OTUs per sample.
library(phyloseq)
data("esophagus")
phyloseq_richness_filter <- function(physeq, mintaxa = 10){
sp <- estimate_richness(physeq, measures = "Observed")
samples_to_keep <- rownames(sp)[ which(sp$Observed >= mintaxa) ]
if(length(samples_to_keep) == 0){
stop("All samples will be removed.\n")
}
if(length(samples_to_keep) == nsamples(physeq)){
cat("All samples will be preserved\n")
res <- physeq
}
if(length(samples_to_keep) < nsamples(physeq)){
res <- prune_samples(samples = samples_to_keep, x = physeq)
}
return(res)
}
phyloseq_richness_filter(esophagus, mintaxa = 30)
phyloseq_richness_filter(esophagus, mintaxa = 10)
phyloseq_richness_filter(esophagus, mintaxa = 100)
But keep in mind that estimate_richness will work only with count data (not proportions).
I made the pull-request to fix this behaviour (#891), but it was not merged yet.
I feel like there should be an easy answer to this question, but I can't seem to find it. All I would like to do is to drop samples from a phyloseq object where there are less than n number of taxa. Anybody know how to do this?
ntaxa()
yields total number of OTUs. I know that samples can be dropped with theprune_samples()
function requiring a list of TRUE/FALSE, but not sure how to generate that list.The text was updated successfully, but these errors were encountered: