Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for ggplot2 v3.4.0 & tidyselect v1.2.0 #44

Merged
merged 14 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
^_pkgdown\.yml$
^pkgdown$
^CRAN-SUBMISSION$
^conda-env
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-pandoc@master
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# schtools development version

- Preemptively fix test failure in advance of next ggplot2 release (#41, @kelly-sovacool).
- Fixes for API changes in ggplot2 v3.4.0 and tidyselect v1.2.0 (#42, #44, @kelly-sovacool).

# schtools 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ theme_lucas <- function() {
panel.background = ggplot2::element_blank(),
legend.position = "bottom",
legend.key = ggplot2::element_rect(
fill = "white", color = "white", size = 4
fill = "white", color = "white", linewidth = 4
),
legend.key.width = ggplot2::unit(2, "cm"),
legend.text = ggplot2::element_text(size = 12),
Expand Down
5 changes: 3 additions & 2 deletions R/read_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' dist_tbl <- read_dist(dist_filepath)
#' head(dist_tbl)
read_dist <- function(dist_filename) {
distances <- rows <- NULL
# TODO: input validation - make sure file has expected format & throw errors if it doesn't
# read in the first row to determine the matrix dimensions
matrix_dim <-
Expand All @@ -31,10 +32,10 @@ read_dist <- function(dist_filename) {
return(
distance_matrix %>%
tidyr::pivot_longer(
cols = -.data[["rows"]],
cols = -rows,
values_to = "distances",
names_to = "columns"
) %>%
dplyr::filter(!is.na(.data[["distances"]]))
dplyr::filter(!is.na(distances))
)
}
54 changes: 28 additions & 26 deletions R/read_tax.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,60 @@
#' head(taxonomy_tbl)
parse_tax <- function(dat) {
levels <- c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus")
dat <- dat %>%
dplyr::mutate(Taxonomy = gsub("_", " ", .data[["Taxonomy"]])) %>%
tidyr::separate(.data[["Taxonomy"]], levels, sep = "\\(\\d{2,3}\\);", extra = "drop") %>%
dplyr::select(-.data[["Size"]])
Classification <- Genus <- Level <- Lowest_classified <- OTU <- Size <- Taxonomy <- tax_otu_label <- NULL
dat_sep <- dat %>%
dplyr::mutate(Taxonomy = gsub("_", " ", Taxonomy)) %>%
tidyr::separate(Taxonomy, levels, sep = "\\(\\d{2,3}\\);", extra = "drop") %>%
dplyr::select(-Size)
# in older version of mothur unclassified are listed as unclassified
# without information from higher level classification
# for those cases, append with lowest identified classification
if (any(dat$Genus == "unclassified")) {
dat <- dat %>%
if ("unclassified" %in% (dat_sep %>% dplyr::pull("Genus"))) {
dat_sep <- dat_sep %>%
tidyr::pivot_longer(
cols = -.data[["OTU"]],
cols = -OTU,
names_to = "Level",
values_to = "Classification"
) %>%
# order classification level
dplyr::mutate(Level = factor(.data[["Level"]], levels)) %>%
dplyr::left_join(dplyr::group_by(., .data[["OTU"]]) %>%
dplyr::filter(.data[["Classification"]] != "unclassified") %>%
# select lowest level classification
dplyr::filter(.data[["Level"]] == levels[max(as.numeric(.data[["Level"]]))]) %>%
dplyr::select(.data[["OTU"]], Lowest_classified = .data[["Classification"]]),
by = "OTU"
dplyr::mutate(Level = factor(Level, levels)) %>%
dplyr::left_join(
dplyr::group_by(., OTU) %>%
dplyr::filter(Classification != "unclassified") %>%
# select lowest level classification
dplyr::filter(Level == levels[max(as.numeric(Level))]) %>%
dplyr::select(OTU, Lowest_classified = Classification),
by = "OTU"
) %>%
dplyr::mutate(Classification = ifelse(.data[["Classification"]] == "unclassified",
dplyr::mutate(Classification = ifelse(Classification == "unclassified",
# append unclassified with lowest classification
paste(.data[["Lowest_classified"]], .data[["Classification"]], sep = " "),
.data[["Classification"]]
paste(Lowest_classified, Classification, sep = " "),
Classification
)) %>%
dplyr::select(-.data[["Lowest_classified"]]) %>%
dplyr::select(-Lowest_classified) %>%
tidyr::pivot_wider(
names_from = "Level",
values_from = "Classification"
)
}
# create label options for OTU and lowest taxonomic classification with the OTU
dat <- dat %>%
dat_labs <- dat_sep %>%
dplyr::mutate(
tax_otu_label = paste0(.data[["Genus"]], " (", gsub("tu0*", "TU ", .data[["OTU"]]), ")"),
tax_otu_label = gsub(" unclassified", "", .data[["tax_otu_label"]]),
otu_label = paste0(gsub("tu0*", "TU ", .data[["OTU"]])),
tax_otu_label = paste0(Genus, " (", gsub("tu0*", "TU ", OTU), ")"),
tax_otu_label = gsub(" unclassified", "", tax_otu_label),
otu_label = paste0(gsub("tu0*", "TU ", OTU)),
label_html = stringr::str_replace(
.data[["tax_otu_label"]],
tax_otu_label,
"([a-zA-Z]+) (.*)",
glue::glue("<i>\\1</i> \\2")
)
)
colnames(dat) <- tolower(colnames(dat))
dat <- dat %>%
colnames(dat_labs) <- tolower(colnames(dat_labs))
dat_reordered <- dat_labs %>%
dplyr::relocate(c("otu_label", "tax_otu_label", "label_html"),
.after = "otu"
)
return(dat)
return(dat_reordered)
}

#' Read in a taxonomy file and parse it to a wide dataframe
Expand Down
26 changes: 26 additions & 0 deletions conda-env/schtools-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: schtools-dev
channels:
- conda-forge
- r
dependencies:
- r-base=4
- r-devtools
- r-dplyr
- r-formatR
- r-glue
- r-rlang
- r-stringr
- r-tidyr
- r-covr
- r-cowplot
- r-ggplot2=3.4.0
- r-ggtext
- r-here
#- r-hexSticker
- r-hrbrthemes
- r-knitr
- r-purrr
- r-readr
- r-rmarkdown
- r-showtext
- r-testthat
51 changes: 27 additions & 24 deletions docs/dev/articles/logo.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-10-11T16:57Z
last_built: 2022-11-08T20:44Z
urls:
reference: http://www.schlosslab.org/schtools/reference
article: http://www.schlosslab.org/schtools/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/search.json

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions tests/testthat/test-read_dist.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
test_that("read_dist works on example file", {
tbl_head <- structure(list(
rows = c("104_1_D1", "104_1_D10", "104_1_D10", "104_1_D2", "104_1_D2", "104_1_D2"),
columns = c("104_1_D0", "104_1_D0", "104_1_D1", "104_1_D0", "104_1_D1", "104_1_D10"),
distances = c(0.892663, 0.253927, 0.921823, 0.874497, 0.108682, 0.90357)
),
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame")
tbl_head <- structure(
list(
rows = c("104_1_D1", "104_1_D10", "104_1_D10", "104_1_D2", "104_1_D2", "104_1_D2"),
columns = c("104_1_D0", "104_1_D0", "104_1_D1", "104_1_D0", "104_1_D1", "104_1_D10"),
distances = c(0.892663, 0.253927, 0.921823, 0.874497, 0.108682, 0.90357)
),
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame")
)
tbl_tail <- structure(list(
rows = c(
"98_3_Dminus1", "98_3_Dminus1", "98_3_Dminus1",
"98_3_Dminus1", "98_3_Dminus1", "98_3_Dminus1"
tbl_tail <- structure(
list(
rows = c(
"98_3_Dminus1", "98_3_Dminus1", "98_3_Dminus1",
"98_3_Dminus1", "98_3_Dminus1", "98_3_Dminus1"
),
columns = c("98_3_D4", "98_3_D5", "98_3_D6", "98_3_D7", "98_3_D8", "98_3_D9"),
distances = c(0.659194, 0.697918, 0.717304, 0.621887, 0.645434, 0.638572)
),
columns = c("98_3_D4", "98_3_D5", "98_3_D6", "98_3_D7", "98_3_D8", "98_3_D9"),
distances = c(0.659194, 0.697918, 0.717304, 0.621887, 0.645434, 0.638572)
),
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame")
row.names = c(NA, -6L),
class = c("tbl_df", "tbl", "data.frame")
)
dist_out <- read_dist(system.file("extdata",
"sample.final.thetayc.0.03.lt.ave.dist",
Expand Down
19 changes: 14 additions & 5 deletions tests/testthat/test-read_tax.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
test_that("read_tax works on example file", {
taxonomy_out <- read_tax(system.file("extdata",
"test.taxonomy",
package = "schtools"
))
tax_infilename <- system.file("extdata",
"test.taxonomy",
package = "schtools"
)
tax_raw_tbl <- readr::read_tsv(tax_infilename)

test_that("parse_tax works on example file", {
taxonomy_out <- parse_tax(tax_raw_tbl)
expect_equal(
colnames(taxonomy_out),
c(
Expand Down Expand Up @@ -32,3 +35,9 @@ test_that("read_tax works on example file", {
)
)
})
test_that("read_tax works as well as `read_tsv %>% parse_tax`", {
expect_equal(
read_tax(tax_infilename),
parse_tax(tax_raw_tbl)
)
})
Loading