Error creating phyloseq

Good morning. I am trying to create a phyloseq object with the following code:

otu <- read.table("C:/Users/acer/Datos_tesis/Combinados/Phyloseq/OTUcombinado.tsv", header = TRUE, sep = "\t")
otu_mat <- as.matrix(otu[, -1]) # Exclude the first column
rownames(otu_mat) <- otu$OTU_ID # Assign identifiers as row names
OTU <- otu_table(otu_mat, taxa_are_rows = FALSE)
# Load sample data
samples <- read.table("C:/Users/acer/Datos_tesis/Combinados/Phyloseq/metadataBBCH.tsv", header = TRUE, sep = "\t")
SAM <- sample_data(samples)
# Read the .xlsx file
tax <- read_excel("C:/Users/acer/Tesis_Data/Combined/Phyloseq/taxonomy/xd.xlsx")
TAX <- tax_table(as.matrix(tax))

# Load the phylogenetic tree
tree <- read_qza("C:/Users/acer/Tesis_Data/Combined/Phyloseq/rooted-tree-BB.qza")$data
PHY <- phy_tree(tree)

# Load the reference sequences
refseqs <- readDNAStringSet("C:/Users/acer/Tesis_Data/Combined/Phyloseq/aligned-dna-sequences.fasta")
REF <- refseq(refseqs)

#Create phyloseq please work aaaaa)
physeq <- phyloseq(OTU, TAX, SAM, PHY, refseq=REF)

Now it turns out that when I go to create the phyloseq. It gives me the following error:

Error in validObject(.Object) : invalid class “phyloseq” object:
  Component taxa/OTU names do not match.
  Taxa indices are critical to analysis.
  Try taxa_names()

But I have already verified that the OTU_IDs that I have from the Tax file and from my OTU table are the same and are in the same order. And yet I still get the error. I have already looked at some solutions on the forum but none of them have helped me. I would appreciate your help :slight_smile:

Welcome to the forums! :qiime2:

I have already looked at some solutions on the forum

Nice! You are off to a good start.

How did you check that they match?

Phyloseq can change names during import, so they may not match anymore!

Try checking after they are loaded into R


You could also merge these one at a time to see which one is the issue:

physeq.1 <- phyloseq(OTU, TAX)
physeq.2 <- phyloseq(OTU, SAM)
physeq.3 <- phyloseq(SAM, TAX)
1 Like