Skip to content

Commit

Permalink
Merge pull request #38 from SchlossLab/calc-rel-abun
Browse files Browse the repository at this point in the history
Create function to calculate relative abundances
  • Loading branch information
kelly-sovacool committed Sep 29, 2022
2 parents 0ea4fd1 + 090e5ba commit 63ac563
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 73 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(.data)
export(calc_relabun)
export(close_enough)
export(format_number)
export(inline_hook)
Expand Down
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
level (e.g. genus, phylum, etc.) to enable comparing analyses at different
taxonomic resolutions, as seen in <https://doi.org/10.1128/mbio.03161-21>
(#37, @kelly-sovacool).
- New function `calc_relabun()` calculates OTU relative abundances (#38, @kelly-sovacool).

# schtools 0.2.1

- Improvements to `parse_tax()` (#32, @kelly-sovacool)
- Improvements to `parse_tax()` (#32, @kelly-sovacool).
- New column `label_html` provides HTML to correctly italicize genus names but not OTU labels.
- Added an example to the intro vignette to demonstrate using this feature with `ggtext`.
- Changed taxonomy data frame column names to lowercase and reordered them.
- Minor documentation improvements (#33, @kelly-sovacool)
- Minor documentation improvements (#33, @kelly-sovacool).

# schtools 0.1.1

- Refactored `read_tax()` (#30, @kelly-sovacool)
- Refactored `read_tax()` (#30, @kelly-sovacool).
- New function `parse_tax()` to separate the logic of reading and parsing taxonomy files.
- `read_tax()` now accepts a `sep` parameter to handle different delim file types (e.g. csv or tsv).
- schtools now has a logo! (#31, @kelly-sovacool)
Expand Down
30 changes: 30 additions & 0 deletions R/calculate.R
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)
}
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ reference:
- schtools
- title: Microbiome
desc: >
Read files & handle microbiome-related data.
Handle microbiome-related data.
contents:
- starts_with('read_')
- starts_with('parse_')
- calc_relabun
- pool_taxon_counts
- title: R Markdown helpers
desc: >
Expand Down
120 changes: 83 additions & 37 deletions docs/dev/articles/introduction.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/dev/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/dev/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pkgdown_sha: ~
articles:
logo: logo.html
introduction: introduction.html
last_built: 2022-09-22T16:31Z
last_built: 2022-09-26T21:08Z
urls:
reference: http://www.schlosslab.org/schtools/reference
article: http://www.schlosslab.org/schtools/articles
Expand Down
133 changes: 133 additions & 0 deletions docs/dev/reference/calc_relabun.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion docs/dev/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/dev/search.json

Large diffs are not rendered by default.

Loading

0 comments on commit 63ac563

Please sign in to comment.