-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakob Russel
committed
Feb 11, 2021
1 parent
62e8c55
commit 901f63e
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: MicEco | ||
Title: Various functions for microbial community data | ||
Version: 0.9.11 | ||
Version: 0.9.12 | ||
Authors@R: person("Jakob", "Russel", email = "[email protected]", role = c("aut", "cre")) | ||
Description: Collection of functions for microbiome analyses. E.g. fitting neutral models and standardized effect sizes of phylogenetic beta diversities, and much more. | ||
Depends: R (>= 3.2.5) | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#' Clean tax_table such that NAs are replaced with names of the most specific known taxonomy prefixed with the rank. | ||
#' | ||
#' Example: An OTU is annotated as Proteobacteria in the Phylum rank, but NAs in the more specific ranks. | ||
#' All annotations below Phylum for this OTU will be replaced with Phylum_Proteobacteria. | ||
#' @param data \code{phyloseq} or \code{tax_table} object. | ||
#' @return Similar to input, but with NAs replaced in the tax_table | ||
#' @export | ||
|
||
ps_tax_clean <- function(data){ | ||
|
||
# Extract | ||
if(is(data, "phyloseq")){ | ||
tax <- tax_table(data) | ||
} else if(is(data, "taxonomyTable")) { | ||
tax <- data | ||
} else { | ||
stop("Input should be a phyloseq or tax_table object") | ||
} | ||
|
||
rankn <- rank_names(data) | ||
|
||
# Replace NAs | ||
tax <- t(apply(tax, 1, function(x) | ||
if(sum(is.na(x))>0){ | ||
c(x[!is.na(x)], | ||
paste(rankn[max(which(!is.na(x)))], rep(x[max(which(!is.na(x)))], sum(is.na(x))), sep="_"))} | ||
else{x})) | ||
|
||
# Return | ||
colnames(tax) <- rankn | ||
|
||
if(is(data, "phyloseq")){ | ||
tax_table(data) <- tax_table(tax) | ||
return(data) | ||
} else if(is(data, "taxonomyTable")) { | ||
return(tax_table(tax)) | ||
} | ||
|
||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.