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

subset_taxa not removing chloroplast taxa #1394

Open bioinfonext opened 4 years ago

bioinfonext commented 4 years ago

Hi all,

I am using below code for phyloseq object and wanted to remove chloroplast taxa using subset_taxa but it is not working. First time I am facing this issue, could anyone please suggest why this is happening? Is there any other command to deal with this issue in phyloseq?


> #########################################################
> otu <- read.table("asv.table.txt", row.names=1,sep="\t", header=T, blank.lines.skip=F, check.names=F)
>
> otu <- as.matrix(otu)
> metadata <- read.table("metadata.txt", header=T, row.names=1, stringsAsFactors=F, na.strings="NA")
> taxa <- read.table("taxonomy.txt", row.names=1, sep="\t", header=F ,stringsAsFactors=F,quote="")
> colnames(taxa) <- c("Kingdom","Phylum","Class","Order", "Family", "Genus", "Species")
> ## Create phyloseq objects
> physeq <- phyloseq(otu_table(otu, taxa_are_rows=T),tax_table(as.matrix(taxa)),sample_data(metadata))
> rank_names(physeq)
[1] "Kingdom" "Phylum"  "Class"   "Order"   "Family"  "Genus"   "Species"
> nsamples(physeq)
[1] 218
> ntaxa(physeq)
[1] 24121
> physeqN <- subset_samples(physeq, Compartment != "NC")
> nsamples(physeqN)
[1] 216
> physeqN <- subset_taxa(physeqN, (Order!="Chloroplast") | is.na(Order))
> ntaxa(physeqN)
[1] 24121
> head(taxa)
                                  Kingdom             Phylum
d2ec9f3b77975c0f457e4b7413b217ff Bacteria      Cyanobacteria
3147790f0d5a78316fb9dd64f53b9473 Bacteria     Proteobacteria
83874d9a7492eec72bdef4b81f680016 Bacteria  Methylomirabilota
5fa2a987221a1d9ca416148570c18086 Bacteria     Proteobacteria
8e60d301122d7aa359eb6b0b00f37f62 Bacteria        Myxococcota
16c306238059e7942361b356cb1fe8e0 Bacteria   Desulfobacterota
                                                Class               Order
d2ec9f3b77975c0f457e4b7413b217ff       Cyanobacteriia         Chloroplast
3147790f0d5a78316fb9dd64f53b9473  Alphaproteobacteria       Rickettsiales
83874d9a7492eec72bdef4b81f680016     Methylomirabilia  Methylomirabilales
5fa2a987221a1d9ca416148570c18086  Alphaproteobacteria       Rickettsiales
8e60d301122d7aa359eb6b0b00f37f62           Myxococcia        Myxococcales
16c306238059e7942361b356cb1fe8e0     Desulfuromonadia       Geobacterales
                                                 Family             Genus
d2ec9f3b77975c0f457e4b7413b217ff            Chloroplast       Chloroplast
3147790f0d5a78316fb9dd64f53b9473           Mitochondria      Mitochondria
83874d9a7492eec72bdef4b81f680016    Methylomirabilaceae     Sh765B-TzT-35
5fa2a987221a1d9ca416148570c18086           Mitochondria      Mitochondria
8e60d301122d7aa359eb6b0b00f37f62  Anaeromyxobacteraceae  Anaeromyxobacter
16c306238059e7942361b356cb1fe8e0         Geobacteraceae        uncultured
                                               Species
d2ec9f3b77975c0f457e4b7413b217ff
3147790f0d5a78316fb9dd64f53b9473
83874d9a7492eec72bdef4b81f680016  uncultured_bacterium
5fa2a987221a1d9ca416148570c18086
8e60d301122d7aa359eb6b0b00f37f62  uncultured_bacterium
16c306238059e7942361b356cb1fe8e0  uncultured_bacterium
claxon-microbiome commented 4 years ago

Have you tried calling Order explicitly?

Try: physeqN <- subset_taxa(physeqN, (tax_table(physeqN)[,"Order"]!="Chloroplast") | is.na(tax_table(physeqN)[,"Order"]))