Title: | Schloss Lab Tools for Reproducible Microbiome Research |
---|---|
Description: | A collection of useful functions and example code created and used by the Schloss Lab for reproducible microbiome research. Perform common tasks like read files created by mothur <https://mothur.org/>, tidy up your microbiome data, and format R Markdown documents for publication. See the website <http://www.schlosslab.org/schtools/> for more information, documentation, and examples. |
Authors: | Kelly Sovacool [aut, cre] |
Maintainer: | Kelly Sovacool <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.1.9000 |
Built: | 2025-03-12 04:47:56 UTC |
Source: | https://github.com/schlosslab/schtools |
Calculate OTU relative abundances from a shared file
calc_relabun(abs_abun_dat)
calc_relabun(abs_abun_dat)
abs_abun_dat |
a data frame from reading in a shared file.
Should contain a |
a new data frame with OTU relative abundances in long format.
Kelly Sovacool [email protected]
shared_dat <- readr::read_tsv(system.file("extdata", "test.shared", package = "schtools" )) shared_dat %>% calc_relabun()
shared_dat <- readr::read_tsv(system.file("extdata", "test.shared", package = "schtools" )) shared_dat %>% calc_relabun()
This is like dplyr::near()
except with much less precision.
close_enough(x, y, tol = 10^-3)
close_enough(x, y, tol = 10^-3)
x |
a numeric vector |
y |
another numeric vector |
tol |
tolerance (default: |
TRUE
if all numbers are near enough within the tolerance, otherwise FALSE
Kelly Sovacool [email protected]
close_enough(0.0004, 0) close_enough(0.8887, 0.8884) close_enough(1, 2)
close_enough(0.0004, 0) close_enough(0.8887, 0.8884) close_enough(1, 2)
Pastes formatted x
if numeric, otherwise x
unmodified.
Circumvents R's automatic scientific notation.
If a number is nearly whole (see is_nearly_whole()
), it is rounded to have
zero decimal places. Otherwise, numbers >= 1 are rounded to 1 decimal place;
numbers < 1 are rounded to have 2 significant digits.
format_number(x, nsmall = 1, signif_precise = 2)
format_number(x, nsmall = 1, signif_precise = 2)
x |
inline code |
nsmall |
number of digits after the decimal point to round to when |
signif_precise |
number of significant digits to use when |
formatted x
if numeric, otherwise x
unmodified.
Pat Schloss [email protected]
Kelly Sovacool [email protected]
format_number(0.0256) format_number(.Machine$double.eps^0.5) format_number(100000.08) format_number(1.00000000000000000001) format_number("this is a string")
format_number(0.0256) format_number(.Machine$double.eps^0.5) format_number(100000.08) format_number(1.00000000000000000001) format_number("this is a string")
Get the Snakemake wildcards as a tibble
get_wildcards_tbl()
get_wildcards_tbl()
a tibble of wildcards, with columns as names and rows as values
Kelly Sovacool [email protected]
Inline hook for knitr to paste human-readable numbers and nice lists.
inline_hook(x)
inline_hook(x)
x |
just about anything |
a string where each element in x
is separated by a comma and numbers
are in a human-readable format.
Kelly Sovacool [email protected]
Pat Schloss [email protected]
inline_hook(c(1.2993992, 0.03, 1000)) inline_hook(c("cats", "dogs"))
inline_hook(c(1.2993992, 0.03, 1000)) inline_hook(c("cats", "dogs"))
Checks whether a number is near to a whole number
is_nearly_whole(x)
is_nearly_whole(x)
x |
a numeric |
TRUE
or FALSE
Kelly Sovacool [email protected]
is_nearly_whole(.Machine$double.eps^0.5) is_nearly_whole(.Machine$double.eps^0.6) is_nearly_whole(1)
is_nearly_whole(.Machine$double.eps^0.5) is_nearly_whole(.Machine$double.eps^0.6) is_nearly_whole(1)
Check whether all elements given are sorted in non-descending order
is_nondesc(...)
is_nondesc(...)
... |
anything! |
TRUE
if the elements are sorted in non-descending order, otherwise FALSE
Kelly Sovacool [email protected]
is_nondesc(1, 2, 3) is_nondesc(c(1, 2), 3) is_nondesc(6, 4, 1) is_nondesc("a", "b", "c") is_nondesc(c("z", "y"))
is_nondesc(1, 2, 3) is_nondesc(c(1, 2), 3) is_nondesc(6, 4, 1) is_nondesc("a", "b", "c") is_nondesc(c("z", "y"))
Install & load packages
load_deps(...)
load_deps(...)
... |
package names to install & load |
Kelly Sovacool [email protected]
This function checks whether a log file was specified in the Snakemake rule. If so, it directs any output, messages, warnings, or errors to the rule-specific log file. See the Snakemake documentation on log files and R scripts for more details.
log_snakemake(quiet = TRUE)
log_snakemake(quiet = TRUE)
quiet |
Silence messages about the status of the snakemake object and
log file (default: |
Kelly Sovacool [email protected]
# The Snakemake object doesn't exist, so nothing happens log_snakemake(quiet = FALSE)
# The Snakemake object doesn't exist, so nothing happens log_snakemake(quiet = FALSE)
Convert taxonomy strings into dataframe of labels based on taxonomic classification
parse_tax(dat)
parse_tax(dat)
dat |
dataframe from mothur taxonomy file with columns |
a wide dataframe with taxonomic labels
Nick Lesniak, [email protected]
taxonomy_filepath <- system.file("extdata", "test.taxonomy", package = "schtools" ) taxonomy_tbl <- read_tax(taxonomy_filepath) head(taxonomy_tbl)
taxonomy_filepath <- system.file("extdata", "test.taxonomy", package = "schtools" ) taxonomy_tbl <- read_tax(taxonomy_filepath) head(taxonomy_tbl)
The word 'and' is inserted before the last element and an Oxford comma is used.
paste_oxford_list(x)
paste_oxford_list(x)
x |
a list or vector |
a string where each element in x
is separated by a comma
Pat Schloss [email protected]
Kelly Sovacool [email protected]
paste_oxford_list(1:3) paste_oxford_list(c("cats", "dogs", "turtles"))
paste_oxford_list(1:3) paste_oxford_list(c("cats", "dogs", "turtles"))
Enables comparing analyses at different taxonomic resolutions, as seen in doi:10.1128/mbio.03161-21. Implementation adapted from here.
pool_taxon_counts(otu_shared_dat, otu_tax_dat, taxon_level)
pool_taxon_counts(otu_shared_dat, otu_tax_dat, taxon_level)
otu_shared_dat |
data frame created from a shared file at the OTU level. |
otu_tax_dat |
data frame created from a taxonomy file at the OTU level. Must be from the same dataset as the shared file. |
taxon_level |
taxonomic level to pool OTUs into.
Options: "kingdom", "phylum", "class", "order", "family", "genus".
This should be the name of a column in |
a shared data frame with the OTUs at the specified taxon_level
and
a corresponding taxonomy dataframe with new OTU numbers.
Kelly Sovacool, [email protected]
Pat Schloss [email protected]
tax_dat <- read_tax(system.file("extdata", "test.taxonomy", package = "schtools" )) shared_dat <- readr::read_tsv(system.file("extdata", "test.shared", package = "schtools" )) pool_taxon_counts(shared_dat, tax_dat, "genus") pool_taxon_counts(shared_dat, tax_dat, "family") pool_taxon_counts(shared_dat, tax_dat, "phylum")
tax_dat <- read_tax(system.file("extdata", "test.taxonomy", package = "schtools" )) shared_dat <- readr::read_tsv(system.file("extdata", "test.shared", package = "schtools" )) pool_taxon_counts(shared_dat, tax_dat, "genus") pool_taxon_counts(shared_dat, tax_dat, "family") pool_taxon_counts(shared_dat, tax_dat, "phylum")
Read in lower left triangular matrix from file
read_dist(dist_filename)
read_dist(dist_filename)
dist_filename |
filename of lower left triangular matrix (.dist) |
distance matrix as a tibble
Nick Lesniak, [email protected]
dist_filepath <- system.file("extdata", "sample.final.thetayc.0.03.lt.ave.dist", package = "schtools" ) dist_tbl <- read_dist(dist_filepath) head(dist_tbl)
dist_filepath <- system.file("extdata", "sample.final.thetayc.0.03.lt.ave.dist", package = "schtools" ) dist_tbl <- read_dist(dist_filepath) head(dist_tbl)
Read in a taxonomy file and parse it to a wide dataframe
read_tax(taxonomy_filename, sep = "\t")
read_tax(taxonomy_filename, sep = "\t")
taxonomy_filename |
filename of taxonomy file |
sep |
Character that separates fields of the taxonomy file. (Default: |
dataframe of taxonomic labels, formatted by parse_tax()
Nick Lesniak, [email protected]
Kelly Sovacool, [email protected]
taxonomy_filepath <- system.file("extdata", "test.taxonomy", package = "schtools" ) taxonomy_tbl <- read_tax(taxonomy_filepath) head(taxonomy_tbl)
taxonomy_filepath <- system.file("extdata", "test.taxonomy", package = "schtools" ) taxonomy_tbl <- read_tax(taxonomy_filepath) head(taxonomy_tbl)
Call this function in the setup chunk of your R Markdown files.
set_knitr_opts()
set_knitr_opts()
Pat Schloss [email protected]
Kelly Sovacool [email protected]
Requires the hrbrthemes
package and the PT Sans
and PT Sans Narrow
fonts from Google Fonts.
theme_lucas()
theme_lucas()
list of ggproto objects
Sarah Lucas [email protected]
library(ggplot2) library(showtext) # run once to download the PT Sans fonts font_add_google(name = "PT Sans", family = "PT Sans") font_add_google(name = "PT Sans Narrow", family = "PT Sans Narrow") showtext_auto() # make a plot with theme_lucas() ggplot(mtcars) + aes(x = mpg, y = wt, color = cyl) + geom_point() + theme_lucas()
library(ggplot2) library(showtext) # run once to download the PT Sans fonts font_add_google(name = "PT Sans", family = "PT Sans") font_add_google(name = "PT Sans Narrow", family = "PT Sans Narrow") showtext_auto() # make a plot with theme_lucas() ggplot(mtcars) + aes(x = mpg, y = wt, color = cyl) + geom_point() + theme_lucas()
Uses ggplot2::theme_bw()
and removes margins.
theme_sovacool()
theme_sovacool()
list of ggproto objects
Kelly Sovacool [email protected]
library(ggplot2) ggplot(mtcars) + aes(x = mpg, y = wt, color = cyl) + geom_point() + theme_sovacool()
library(ggplot2) ggplot(mtcars) + aes(x = mpg, y = wt, color = cyl) + geom_point() + theme_sovacool()