joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
586 stars 186 forks source link

Subtracting taxa from a phyloseq object #1755

Open GinaGizzi opened 6 months ago

GinaGizzi commented 6 months ago

Hello everyone, I am new to R. I have two subset phyloseq objects (ps.V and ps.P) composed as follows.

arth_ps phyloseq-class experiment-level object otu_table() OTU Table: [ 2312 taxa and 25 samples ] sample_data() Sample Data: [ 25 samples by 7 sample variables ] tax_table() Taxonomy Table: [ 2312 taxa by 8 taxonomic ranks ] phy_tree() Phylogenetic Tree: [ 2312 tips and 2311 internal nodes ]

arth_ps_glom <- tax_glom(arth_ps, "Species") arth_ps_glom phyloseq-class experiment-level object otu_table() OTU Table: [ 834 taxa and 25 samples ] sample_data() Sample Data: [ 25 samples by 7 sample variables ] tax_table() Taxonomy Table: [ 834 taxa by 8 taxonomic ranks ] phy_tree() Phylogenetic Tree: [ 834 tips and 833 internal nodes ]

ps.V <- subset_samples(arth_ps_glom, SampleType == "V") ps.V<- prune_taxa(taxa_sums(ps.V) > 0, ps.V) ps.V phyloseq-class experiment-level object otu_table() OTU Table: [ 532 taxa and 15 samples ] sample_data() Sample Data: [ 15 samples by 7 sample variables ] tax_table() Taxonomy Table: [ 532 taxa by 8 taxonomic ranks ] phy_tree() Phylogenetic Tree: [ 532 tips and 531 internal nodes ]

ps.P <- subset_samples(arth_ps_glom, SampleType == "P") ps.P<- prune_taxa(taxa_sums(ps.P) > 0, ps.P) sample ps.P phyloseq-class experiment-level object otu_table() OTU Table: [ 341 taxa and 10 samples ] sample_data() Sample Data: [ 10 samples by 7 sample variables ] tax_table() Taxonomy Table: [ 341 taxa by 8 taxonomic ranks ] phy_tree() Phylogenetic Tree: [ 341 tips and 340 internal nodes ]

I have already calculated which species are common between the 2 phyloseq objects:

asv_list <- intersect(taxa_names(ps.V), taxa_names(ps.P)) taxa_sub <- arth_ps_glom@tax_table[rownames(arth_ps_glom@tax_table) %in% asv_list, ] length(taxa_names(taxa_sub)) [1] 198

I would now like to subtract the 198 species from the ps.V object (532-198=334) and the ps.P object (341-198=143). I would like a list of species that I only find in the ps.V object (334 taxa) and the ps.P object (143 taxa).

Can you give me some ideas? Is it possible to do this?