0

I need to calculate the top 6 taxa in each individual sample of my phyloseq object. It seems like it should be a simple request...but I have not been able to find a way to do this!

Thank you

MAlvarez
  • 31
  • 5
  • It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 20 '22 at 18:42

1 Answers1

0

Maybe something like:

library(phyloseq)
library(tidyverse)
library(speedyseq)
as_tibble(p) |> 
  rename(Sample=.sample, ASV=.otu, Abundance=.abundance) |> 
  select(Sample, Abundance, ASV, Phylum, Class, Order, Family, Genus) |> 
  group_by(Sample) |> 
  slice_max(Abundance, n=6) |> 
  ungroup()

Where p is your phyloseq object with OTU table and Taxonomy table.

For speedyseq, see https://github.com/mikemc/speedyseq

J Quensen
  • 21
  • 3