I'm trying to make a function to obtain a table in a relative abundance of any given taxrank with PHYLOSEQ, something like:
Relative_Table <- function (PhyloObj, TRank) {
GROUP <- tax_glom(PhyloObj, taxrank="TRank")
Percent <- transform_sample_counts(GROUP, function(x)100* x / sum(x))
OTUglom <- otu_table(Percent)
TAXglom <- tax_table(Percent)[,"TRank"]
GroupTable <- merge(TAXglom, OTUglom, by=0, all=TRUE)
GroupTable$Row.names = NULL
return(GroupTable)
}
so when I use it like: TABLE <- Relative_Table(PHYLO_Obj, Phylum) it give me an error:
Error in tax_glom(PhyloObj, taxrank = "TaxonRank") : Bad taxrank argument. Must be among the values of rank_names(physeq)
nevertheless when I use the the taxrank inside of the function, it works well:
Relative_Table <- function (PhyloObj) {
GROUP <- tax_glom(PhyloObj, taxrank="Phylum")
Percent <- transform_sample_counts(GROUP, function(x)100* x / sum(x))
OTUglom <- otu_table(Percent)
TAXglom <- tax_table(Percent)[,"Phylum"]
GroupTable <- merge(TAXglom, OTUglom, by=0, all=TRUE)
GroupTable$Row.names = NULL
return(GroupTable)
}
What its wrong with the first option ??, I just Want to use any given taxrank (Phylum, Class....... Genus) in the function and generate a Table !!!!
Thanks