Filtering taxa from phyloseq object

349 Views Asked by At

Edit: solution Below is how to subset specific taxa from a phyloseq object.

I make my phyloseq object, with the dput() posted below for recreation purposes.

TAX <- tax_table(as.matrix(tax.table.ex))
ASV <- otu_table(asv.table.ex, taxa_are_rows = TRUE)
physeq <- phyloseq(TAX,ASV,metadata)

And I use subset_taxa() to remove chloroplasts and mitochondria, but in the example data I've changed it to Pirellulales and Comamonadaceae.

physeq <- subset_taxa(physeq, Family!="f__Comamonadaceae")
physeq <- subset_taxa(physeq, Order!="o__Pirellulales")

But when I visualize physeq the dimensions of the asv table are the same. To make matters worse, I swear on my grandmother's grave this worked yesterday. I've checked the raw data that the mitochondria and chloroplasts are spelled correctly and identified at the correct taxonomic level. Thank you

> dput(tax.table.ex)
structure(list(Domain = c("d__Bacteria", "d__Bacteria", "d__Bacteria", 
"d__Bacteria", "d__Bacteria", "d__Bacteria"), Phylum = c(" p__Proteobacteria", 
" p__Bacteroidota", " p__Planctomycetota", " p__Proteobacteria", 
" p__Proteobacteria", " p__Planctomycetota"), Class = c(" c__Alphaproteobacteria", 
" c__Bacteroidia", " c__Planctomycetes", " c__Alphaproteobacteria", 
" c__Gammaproteobacteria", " c__Planctomycetes"), Order = c(" o__Rhodobacterales", 
" o__Cytophagales", " o__Pirellulales", " o__Rhizobiales", " o__Burkholderiales", 
" o__Planctomycetales"), Family = c(" f__Rhodobacteraceae", " f__Spirosomaceae", 
" f__Pirellulaceae", " f__Beijerinckiaceae", " f__Comamonadaceae", 
" f__uncultured"), Genus = c(" g__Pseudorhodobacter", " g__Rudanella", 
" g__Pirellula", " g__FukuN57", " g__Rhodoferax", " g__uncultured"
), Species = c("", " s__uncultured_bacterium", " s__uncultured_bacterium", 
" s__uncultured_bacterium", "", " s__uncultured_bacterium")), row.names = c("00000b57cef3e99cbb05ed9f100a8979", 
"000014668313f139cb99412fc6bebae4", "000038324192c781325f2fd7e790ab0f", 
"00003a23e84cfcf2db04c1207df21dd0", "00004018e8ac9cf222dc50e711c48eaf", 
"0000a1359cbec7d787f63cf50047786c"), class = "data.frame")

> dput(asv.table.ex)
structure(list(samp_1 = structure(c(3L, 5L, 1L, 4L, 1L, 2L), .Label = c("0", 
"2", "3", "5", "75"), class = "factor"), samp_2 = structure(c(3L, 
5L, 6L, 2L, 1L, 4L), .Label = c("1", "10", "101", "12", "32", 
"6"), class = "factor"), samp_3 = structure(c(4L, 3L, 1L, 1L, 
1L, 2L), .Label = c("0", "11", "3", "56"), class = "factor")), class = "data.frame", row.names = c("00000b57cef3e99cbb05ed9f100a8979", 
"000014668313f139cb99412fc6bebae4", "000038324192c781325f2fd7e790ab0f", 
"00003a23e84cfcf2db04c1207df21dd0", "00004018e8ac9cf222dc50e711c48eaf", 
"0000a1359cbec7d787f63cf50047786c"))
0

There are 0 best solutions below