Skip to content

Commit

Permalink
v0.17.3 increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkimbrel committed Oct 7, 2024
1 parent 9889cda commit eee3233
Show file tree
Hide file tree
Showing 14 changed files with 3,864 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qSIP2
Title: qSIP Analysis
Version: 0.17.2
Version: 0.17.3
Authors@R:
person("Jeff", "Kimbrel", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7213-9392"))
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# qSIP2 0.17.3

# qSIP2 0.17.2

# qSIP2 0.17.1
Expand Down
19 changes: 13 additions & 6 deletions R/get_resample_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
get_resample_data <- function(qsip_data_object,
type = "all",
pivot = FALSE) {
if (!"qsip_data" %in% class(qsip_data_object)) {
stop("qsip_data_object should be class <qsip_data>", call. = FALSE)
} else if (length(qsip_data_object@resamples) == 0) {
stop("this function requires a qsip object that has been run through run_resampling()", call. = FALSE)
if (isFALSE(is_qsip_resampled(qsip_data_object, error = FALSE))) {
stop("This function requires a qsip object that has been run through run_resampling()", call. = FALSE)
}

# error if type is not one of "all", "unlabeled", or "labeled"
if (!type %in% c("all", "unlabeled", "labeled")) {
stop("type must be one of 'all', 'unlabeled', or 'labeled'", call. = FALSE)
}

# error if pivot is not TRUE/FALSE
if (!isTRUE(pivot) && !isFALSE(pivot)) {
stop("pivot must be TRUE or FALSE", call. = FALSE)
}


# bind variables
feature_id <- resample <- NULL

Expand All @@ -32,8 +41,6 @@ get_resample_data <- function(qsip_data_object,
df <- dplyr::bind_rows(qsip_data_object@resamples$u) |> dplyr::select(-type)
} else if (type == "labeled") {
df <- dplyr::bind_rows(qsip_data_object@resamples$l) |> dplyr::select(-type)
} else {
stop("type must be one of 'all', 'unlabeled', or 'labeled'", call. = FALSE)
}


Expand Down
2 changes: 1 addition & 1 deletion R/plot_feature_resamplings.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plot_feature_resamplings <- function(qsip_data_object,
confidence = 0.9,
intervals = "") {

if (isFALSE(is_qsip_filtered(qsip_data_object, error = FALSE))) {
if (isFALSE(is_qsip_resampled(qsip_data_object, error = FALSE))) {
stop("This function requires a qsip object that has been run through run_resampling()", call. = FALSE)
}

Expand Down
20 changes: 13 additions & 7 deletions R/plot_sample_curves.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Plot qSIP sample data density curves
#'
#' @param qsip_data (*qsip_data*) qSIP object
#' @param qsip_data_object (*qsip_data*) qSIP object
#' @param colors (*character*) A named vector of colors for each isotope (optional)
#' @param title (*character*) An optional title for the plot
#'
Expand All @@ -10,23 +10,29 @@
#'
#' @family "visualizations"

plot_sample_curves <- function(qsip_data,
plot_sample_curves <- function(qsip_data_object,
colors = NULL,
title = NULL) {

stopifnot("sample_data should be class <qsip_data>" = "qsip_data" %in% class(qsip_data))
is_qsip_data(qsip_data_object, error = TRUE)

# error if title is not a string
if (!is.null(title) && !is.character(title)) {
stop("title must be a character string", call. = FALSE)
}


# bind variables
sample_id <- gradient_position <- source_mat_id <- isotope <- WAD <- gradient_pos_density <- gradient_pos_rel_amt <- NULL

df <- qsip_data@tube_rel_abundance |>
df <- qsip_data_object@tube_rel_abundance |>
dplyr::left_join(
qsip_data@sample_data@data |>
qsip_data_object@sample_data@data |>
dplyr::select(sample_id, gradient_position),
by = "sample_id"
) |>
dplyr::left_join(
qsip_data@source_data@data |>
qsip_data_object@source_data@data |>
dplyr::select(source_mat_id, isotope),
by = "source_mat_id"
)
Expand All @@ -38,7 +44,7 @@ plot_sample_curves <- function(qsip_data,
df <- df |>
dplyr::filter(gradient_position > 0)

source_wads <- qsip_data@source_wads |>
source_wads <- qsip_data_object@source_wads |>
dplyr::filter(!is.na(WAD))

if (is.null(colors)) {
Expand Down
6 changes: 3 additions & 3 deletions R/run_comparison_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ run_comparison_groups <- function(groups,
seed = NULL,
resamples = NULL) {

is_qsip_data(qsip_data_object)
is_qsip_data(qsip_data_object, error = TRUE)

# groups dataframe should contain group, unlabeled and labeled columns, and there can be others
required_cols <- c("group", "unlabeled", "labeled")
if (!all(required_cols %in% colnames(groups))) {
stop(glue::glue("Missing required column names in groups dataframe: {setdiff(required_cols, colnames(groups))}"))
stop(glue::glue("Missing required column names in groups dataframe: {setdiff(required_cols, colnames(groups))}"), call. = F)
}

# groups$group column should be unique
Expand Down Expand Up @@ -87,7 +87,7 @@ run_comparison_groups <- function(groups,
dplyr::pull(value)

if (length(setdiff(source_mat_ids_in_groups, get_source_mat_ids(qsip_data_object))) > 0) {
stop("Invalid source_mat_ids in group dataframe")
stop("Invalid source_mat_ids in group dataframe", call. = FALSE)
}

group_list <- split(groups, groups$group)
Expand Down
12 changes: 11 additions & 1 deletion R/run_growth_calculations.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ get_N_total_it <- function(qsip_data_object,
stop(glue::glue("no source_mat_ids with a 't = {t}' timepoint were found in <qsip_data>"), call. = FALSE)
}

N_total_i0 = N_total_i0|>
# group can be NULL, or should be a column in N_total_i0
if (!is.null(group)) {

if (!group %in% colnames(N_total_i0)) {
stop(glue::glue("grouping variable {group} not found in source_data"), call. = FALSE)
}
}



N_total_i0 = N_total_i0 |>
dplyr::filter(timepoint == t) |>
dplyr::mutate(N_total_i0 = REL * total_abundance)
# dplyr::select(feature_id, source_mat_id, timepoint, N_total_i0) |>
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ reference:
- calculate_di
- calculate_bi
- plot_resampling_convergence
- isotope_palette
- jgi_mixes

articles:
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/_snaps/get_N_total_it.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@
10 taxon_10 2793486. 0
# i 354 more rows

# works with grouping

Code
get_N_total_it(example_qsip_growth_object, t = 0, group = "isotopolog")
Condition
Warning:
1 feature_ids have zero abundance at time 0:
Warning:
taxon_194
Output
# A tibble: 364 x 4
feature_id isotopolog N_total_i0 timepoint1
<chr> <chr> <dbl> <dbl>
1 taxon_1 water 1595472105. 0
2 taxon_2 water 64576684. 0
3 taxon_3 water 4488930. 0
4 taxon_4 water 2494463. 0
5 taxon_5 water 9849881. 0
6 taxon_6 water 697760597. 0
7 taxon_7 water 4702904. 0
8 taxon_8 water 224366766. 0
9 taxon_9 water 1386539. 0
10 taxon_10 water 2793486. 0
# i 354 more rows

Loading

0 comments on commit eee3233

Please sign in to comment.