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

adding a phy_tree to phyloseq object removes otu_table and tax_table info #1635

Open laura-brettell opened 1 year ago

laura-brettell commented 1 year ago

Hi, I was wondering if you could help me with an issue adding phylogenetic data to my phyloseq object?

I made a phyloseq object with TAX and OTU data like this

taxonomydata <- read_qza("taxonomy.qza")$data
tax_parsed <- parse_taxonomy(taxonomydata) 
taxmat <- as.matrix(tax_parsed)
TAX = tax_table(taxmat) 

ASVs <- read_qza("table-dada2.qza") 
ASV_df <- as.data.frame(ASVs$data) 
ASVmat <- as.matrix(ASV_df) 
OTU = otu_table(ASVmat, taxa_are_rows = TRUE) 

physeq = phyloseq(OTU, TAX)

image

All looks good so far. But then I import phylogenetic data:

library(ape)
TREE = read_tree("tree.nwk")
is.rooted(TREE)
# TRUE
any(TREE$tip.label == "389391d39bed456bc97f612b78e4a877")
# TRUE
TREE= root(TREE, 1, resolve.root = T)

phylob <- phyloseq(OTU, TAX, TREE)
phylob

But now tax_table is filled with NAs (on levels lower than Kingdom), and otu_table is filled with zeros image

I also tried importing the tree as a .qza file using read_qza, and tried merge_phyloseq to add the TREE to my original physeq object, but always get the same result. It seems like often this can be due to the taxa names/numbers being incorrect, but that doesn't seem to be the case here?

ntaxa(TREE)
#[1] 7611
ntaxa(OTU)
#[1] 7611
ntaxa(TAX)
#[1] 7611
#setequal(taxa_names(OTU), taxa_names(TREE))
#[1] TRUE
#setequal(taxa_names(TAX), taxa_names(TREE))
#[1] TRUE

I can't work out what's wrong?! Any help would be much appreciated!!