Error in validObject(.Object) : invalid class “otu_table” object: OTU abundance data must have non-zero dimensions
MonicaSteffi opened this issue · comments
Dear All,
I am trying to split the phyloseq after merged by genus.
I executed the following steps:
amgut_genus <- phyloseq::tax_glom(physeq, taxrank = "Genus")
taxtab <- amgut_genus@tax_table@.Data
# Find undefined taxa (in this data set, unknowns occur only up to Family)
miss_f <- which(taxtab[, "Family"] == "f__")
miss_g <- which(taxtab[, "Genus"] == "g__")
# Number unspecified genera
taxtab[miss_f, "Family"] <- paste0("f__", 1:length(miss_f))
taxtab[miss_g, "Genus"] <- paste0("g__", 1:length(miss_g))
# Find duplicate genera
dupl_g <- which(duplicated(taxtab[, "Genus"]) |
duplicated(taxtab[, "Genus"], fromLast = TRUE))
for(i in seq_along(taxtab)){
# The next higher non-missing rank is assigned to unspecified genera
if(i %in% miss_f && i %in% miss_g){
taxtab[i, "Genus"] <- paste0(taxtab[i, "Genus"], "(", taxtab[i, "Order"], ")")
} else if(i %in% miss_g){
taxtab[i, "Genus"] <- paste0(taxtab[i, "Genus"], "(", taxtab[i, "Family"], ")")
}
# Family names are added to duplicate genera
if(i %in% dupl_g){
taxtab[i, "Genus"] <- paste0(taxtab[i, "Genus"], "(", taxtab[i, "Family"], ")")
}
}
amgut_genus@tax_table@.Data <- taxtab
rownames(amgut_genus@otu_table@.Data) <- taxtab[, "Genus"]
Then I tried to split the phyloseq data as follows:
amgut_split_genus <- metagMisc::phyloseq_sep_variable(amgut_genus,
"Intervention")
But got the error as:
Error in validObject(.Object) : invalid class “otu_table” object:
OTU abundance data must have non-zero dimensions.
Kindly help me
Dear Monica,
I suspect that something happened with the object structure during your manipulations.
(in general, it's not recommended to make such 'hard' assignments to S4 classes - e.g. ...@tax_table@.Data <- ...
)
Could you please try to recreate your phyloseq
object with:
new_phyloseq <- phyloseq(otu_table(amgut_genus), tax_table(amgut_genus), sample_data(amgut_genus))
phyloseq_sep_variable(new_phyloseq, "Intervention")
if there are any inconsistencies (e.g., duplicated names), it should let you know.
With kind regards,
Vladimir
I hope you've solved the problem.
I'm closing the issue for now. Feel free to re-open it if the problem remains.