-
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.
Merge pull request #38 from SchlossLab/calc-rel-abun
Create function to calculate relative abundances
- Loading branch information
Showing
15 changed files
with
435 additions
and
73 deletions.
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
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,30 @@ | ||
|
||
#' Calculate OTU relative abundances from a shared file | ||
#' | ||
#' @param abs_abun_dat a data frame from reading in a [shared file](https://mothur.org/wiki/shared_file). | ||
#' Should contain a `Group` column for sample names, | ||
#' `Otu` columns for absolute counts of each OTU, | ||
#' and rows as each sample. | ||
#' | ||
#' @return a new data frame with OTU relative abundances in long format. | ||
#' @export | ||
#' @author Kelly Sovacool \email{sovacool@@umich.edu} | ||
#' | ||
#' @examples | ||
#' shared_dat <- readr::read_tsv(system.file("extdata", "test.shared", | ||
#' package = "schtools" | ||
#' )) | ||
#' shared_dat %>% calc_relabun() | ||
calc_relabun <- function(abs_abun_dat) { | ||
count <- Group <- mutate <- otu <- rel_abun <- total_counts <- NULL | ||
abs_abun_dat$total_counts <- rowSums(abs_abun_dat %>% | ||
dplyr::select(dplyr::starts_with("Otu"))) | ||
rel_abun_dat <- abs_abun_dat %>% | ||
dplyr::rename(sample = Group) %>% | ||
tidyr::pivot_longer(dplyr::starts_with("Otu"), | ||
names_to = "otu", values_to = "count" | ||
) %>% | ||
dplyr::mutate(rel_abun = count / total_counts) %>% | ||
dplyr::select(sample, otu, rel_abun) | ||
return(rel_abun_dat) | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
+21.9 KB
(120%)
docs/dev/articles/introduction_files/figure-html/italic-genus-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.