microbiome / mia

Microbiome analysis
https://microbiome.github.io/mia/
Artistic License 2.0
50 stars 27 forks source link

getTaxonomyLabels issue #398

Closed antagomir closed 1 year ago

antagomir commented 1 year ago

Received the following user feedback.

GetTaxonomyLabels does not seem to work when TreeSE-object is created from phyloseq object with makeTreeSummarizedExperimentFromPhyloseq.

When TreeSE-object is formed straight from original data it does work as expected.

This may indicate some issue to fix in the phyloseq->TreeSE conversion function

TuomasBorman commented 1 year ago
data("GlobalPatterns", package="phyloseq")
pseq <- GlobalPatterns
tse2 <- makeTreeSEFromPhyloseq(pseq)
getTaxonomyLabels(tse2)

This works. Without further information it is hard to say where is the problem.

The phyloseq object might be incorrect (without taxonomy information for instance.) For example, our BIOM-TreeSE importer gets the taxonomy ranks from prefixes. --> BIOM-phyloseq importer might not have that functionality which can cause this behavior

TuomasBorman commented 1 year ago

Coming back to this issue...

Regarding the email that you sent: the issue seems to be that the phyloseq object is not constructed correctly.

These "NA" values that are in rowData/tax_table are character values not NA values. That is why they are handled as a character values --> makeTreeSEFromPhyloseq is working correctly

# Import the object
phyloseq <- readRDS("phyloseq.rds")

# There are character values that are named as "NA"
head(tax_table(phyloseq)[, "Species"])
# No "real" NA values
any(is.na(tax_table(phyloseq)[, "Species"]))

# We can change those "NA" values to "real" NA values
mat <- matrix(tax_table(phyloseq), ncol = ncol(tax_table(phyloseq)))
mat[ mat == "NA" ] <- NA
mat <- tax_table(mat)
colnames(mat) <- colnames(tax_table(phyloseq))
rownames(mat) <- rownames(tax_table(phyloseq))
tax_table(phyloseq) <- mat

# Now the labels are correct
tse_p <- makeTreeSummarizedExperimentFromPhyloseq(phyloseq)
head(rowData(tse_p))
head(getTaxonomyLabels(tse_p))
antagomir commented 1 year ago

Interesting.

Should we consider throwing warning in such cases?

Feels a bit overkill, though. Might help some users as this problem source can be a bit tricky to identify.

TuomasBorman commented 1 year ago

Yes, it sounds little bit overkill. We have an examples on importing from external files, and those methods that we use in tutorials don't have this kind of issue