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

Phyloseq taxa don't match error, but TRUE when asked if values match? #1733

Open hank00000 opened 4 months ago

hank00000 commented 4 months ago

I originally pulled the OTU table from a phyloseq object and modified it with a normalization method not supported within the package. Now I want to re-create a phyloseq object but am running into issues.

I've created a normalized and relative abundance table and made the row names the OTU sequences, and the column names sampleIDs. I also have a taxa table with row names as OTU sequences, and the tax info as columns. My metadata has rownames as sampleID and the variables as columns.

I get the following affirmations :

rownames(Relative_Abundance) == rownames(tax_table) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [20] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [39] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [58] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [77] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [96] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [115] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [134] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [153] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [172] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [191] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [210] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [229] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [248] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [267] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [286] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [305] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [324] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

rownames(metadata_subset) == colnames (Relative_Abundance) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [20] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [39] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [58] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [77] TRUE TRUE TRUE TRUE TRUE

relnormps <- phyloseq(otu_table(Relative_Abundance), sample_data(metadata_subset), tax_table(tax_table))

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

Any suggestions? Much appreciated.

Screenshot 2024-02-28 at 10 56 52 AM Screenshot 2024-02-28 at 10 57 04 AM Screenshot 2024-02-28 at 10 58 00 AM
hank00000 commented 3 months ago

Note that I've also tried the as.matrix() trick offered in another post, but this didn't change the error. I'd really appreciate any insight.

ycl6 commented 3 months ago

Hi @hank00000

Can you try:

relnormps <- phyloseq(otu_table(Relative_Abundance),   # data.frame
                      sample_data(metadata_subset),    # data.frame
                      tax_table(as.matrix(tax_table))) # matrix
hank00000 commented 3 months ago

Hi @hank00000

Can you try:

relnormps <- phyloseq(otu_table(Relative_Abundance, taxa_are_rows = TRUE), # data.frame + sample_data(metadata_subset), # data.frame + tax_table(as.matrix(tax_df))) #matrix

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

Checked and the above TRUEs are still valid.

ycl6 commented 3 months ago

Hi @hank00000 Hmm, that's strange, How about:

# Check taxa names
identical(taxa_names(otu_table(Relative_Abundance, taxa_are_rows = TRUE)), 
          taxa_names(tax_table(as.matrix(tax_df))))

# Check sample names
identical(sample_names(otu_table(Relative_Abundance,, taxa_are_rows = TRUE)), 
          sample_names(sample_data(metadata_subset)))

Please use the code block markdown for better visualization out of your output.

For example:

``` r x <- sum(c(1, 2, 3, 4)) x ```