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/
582 stars 187 forks source link

subset_taxa doesn't extract the taxa of my interest #1648

Open mghotbi opened 1 year ago

mghotbi commented 1 year ago

Hi everyone, I am trying to subset specific taxa using the below commands. however, it seems none of them are working. I have made my phyloseq obj and rarified it, so physeqR refers to rarified phyloseq obj

transform to equal depth by rarifying

set.seed(28132) physeqR = rarefy_even_depth(physeq, rngseed=200, sample.size=0.9*min(sample_sums(physeq)), replace=F)

physeqR = rarefy_even_depth(physeq, sample.size = 5000)

physeqR <- subset_taxa(physeq, !is.na(Phylum) & !Phylum %in% c("", "uncharacterized"))

physeqR = transform_sample_counts(physeqR, standf)

Nitrifiers.tax = subset_taxa(physeqR, Phylum != "Nitrospirota" | Genus != "Nitrosomonas" | Order != "Burkholderiales" | Phylum != "Crenarchaeota" )

or

Nitrifiers.tax = subset_taxa(physeqR, Phylum != "Nitrospirota" & Genus != "Nitrosomonas" & Order != "Burkholderiales" & Phylum != "Crenarchaeota" )

or

Nitrifiers.tax = subset_taxa(physeqR, Phylum == "Nitrospirota" & Genus == "Nitrosomonas" & Order == "Burkholderiales" & Phylum == "Crenarchaeota" )

what I am trying to do is constructing a barplot of specific taxa (below is the script I am using)

ps.Family = tax_glom(Nitrifiers.tax, taxrank="Family", NArm=FALSE) ncol(tax_table(ps.Family)) colnames(tax_table(ps.Family))<- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species") myTaxa = names(sort(taxa_sums(ps.Family), decreasing = TRUE)[1:12]) fam= prune_taxa(myTaxa, ps.Family)

to re-introduce the flattened trt

sample_data(ps.Family)$Germplasm = factor( get_variable(ps.Family, "Germplasm") %in% c("Inbred:B73","Inbred:BNI_NIL_1 ","Inbred:BNI_NIL_2") )

plotting

phy<-plot_bar(fam, x="Germplasm", fill = "Phylum") + theme(text=element_text(family = "Calibri",size=14)) + mytheme + scale_fill_paletteer_d("LaCroixColoR::paired", direction = 1, dynamic = FALSE) + ylab("Relative Abundance (%)") +scale_x_discrete(limits=c("Inbred:B73", "Inbred:BNI_NIL_1", "Inbred:BNI_NIL_2")) + geom_bar(aes(fill=Family), stat="identity", position="stack")

I know I either miss a part of the script or I am using the wrong script though I couldn't figure it out myself. Could you help me with that? Thanks !! Mitra