Skip to content

Instantly share code, notes, and snippets.

@jwaage
Last active June 17, 2016 22:11
Show Gist options
  • Save jwaage/bd61defb79c694f761fac34632c64f95 to your computer and use it in GitHub Desktop.
Save jwaage/bd61defb79c694f761fac34632c64f95 to your computer and use it in GitHub Desktop.
Create "lowest" tax rank for phyloseq
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