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

invalid archetype error for tax_glom #1697

Open hkittner opened 1 year ago

hkittner commented 1 year ago

I'm having an issue with using tax_glom to group all ASVs to the Phylum level. I constructed the phyloseq object and can't find anything wrong with the input files. My OTU table does not have NA values which has apparently been the issue for others in the past, and my taxa table looks fine. I've included the code I used to construct the object with the error at the end. Again, there are not NA values in the OTU table, so I'm not sure what the issue could be. I also tried using taxrank = rank_names(SPB_object)[2] in place of taxrank = "Phylum" to no avail. Thanks so much for the help with this!

# transform to phyloseq object

OTU = otu_table(otu_mat, taxa_are_rows = TRUE)
TAX = tax_table(tax_mat)
samples = sample_data(samples_df)

SPB_object <- phyloseq(OTU, TAX, samples)
SPB_object
rank_names(SPB_object)

[1] "Kingdom" "Phylum" "Class" "Order" "Family" "Genus" "Species"

sample_variables(SPB_object)

[1] "SampleID" "Station" "depth" "Replicate" "Station_Depth"

normalize number of reads in each samples using median sequencing depth

total = median(sample_sums(SPB_object))
standf = function(x, t=total) round(t * (x/sum(x)))
SPB_object = transform_sample_counts(SPB_object, standf)

Subset object to include the top 20 phyla

# agglomerate taxa at genus level
SPB_phylum <- tax_glom(SPB_object, taxrank = "Phylum", NArm = TRUE)
SPB_phylum

Error in merge_taxa.indices.internal(x, eqtaxa, archetype) : invalid archetype provided.