Last active
June 17, 2016 22:11
-
-
Save jwaage/bd61defb79c694f761fac34632c64f95 to your computer and use it in GitHub Desktop.
Create "lowest" tax rank for phyloseq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lowest <- function(tax){ | |
returnPhyseq <- FALSE | |
if(class(tax) == "phyloseq"){ | |
physeq <- tax | |
tax <- tax_table(physeq) | |
returnPhyseq <- TRUE | |
} | |
tax <- tax[, colnames(tax) != "lowest"] | |
tax <- tax %>% as("matrix") | |
low <- tax[,ncol(tax)] %>% as.vector | |
for(i in (ncol(tax)-1):1){ | |
low[low == "unclassified"] <- tax[low == "unclassified",i] %>% as.vector | |
} | |
tax <- tax %>% cbind(lowest = as.vector(low)) %>% tax_table | |
if(returnPhyseq){ | |
tax_table(physeq) <- tax | |
return(physeq) | |
} | |
else | |
tax | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment