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

Issue 66 - expanded test coverage and GHA updates #67

Merged
merged 3 commits into from
Sep 19, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

- name: Query dependencies
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

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

- name: Query dependencies
run: |
Expand Down
8 changes: 4 additions & 4 deletions R/app_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
observe({
# need double parenthesis since its a reactive of a reactive
print(glue::glue(
"Filtering results: tidy_filtered_samples is {nrow(tidy_filtered_samples()()$data)} rows"

Check warning on line 108 in R/app_heatmap.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_heatmap.R,line=108,col=81,[line_length_linter] Lines should not be more than 80 characters.
))
})

Expand Down Expand Up @@ -302,7 +302,7 @@
#' )
#' @export
plot_heatmap <- function(
tomic,

Check warning on line 305 in R/app_heatmap.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_heatmap.R,line=305,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces.
feature_var = NULL,
sample_var = NULL,
value_var = NULL,
Expand All @@ -315,7 +315,7 @@
x_label = NULL,
y_label = NULL,
colorbar_label = NULL
) {

Check warning on line 318 in R/app_heatmap.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_heatmap.R,line=318,col=4,[indentation_linter] Indentation should be 0 spaces but is 4 spaces.
checkmate::assertClass(tomic, "tomic")

if ("NULL" %in% class(feature_var)) {
Expand Down Expand Up @@ -410,7 +410,7 @@
nrow()

heatmap_theme <- theme_minimal() +
theme(

Check warning on line 413 in R/app_heatmap.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_heatmap.R,line=413,col=5,[indentation_linter] Indentation should be 4 spaces but is 5 spaces.
text = element_text(size = 16, color = "black"),
title = element_text(size = 20, color = "black"),
strip.text = element_text(size = 18),
Expand All @@ -423,7 +423,7 @@
theme(axis.text.y = element_blank())
} else {
heatmap_theme <- heatmap_theme +
theme(axis.text.y = element_text(size = pmin(20, 60 * sqrt(1 / n_features))))

Check warning on line 426 in R/app_heatmap.R

View workflow job for this annotation

GitHub Actions / lint

file=R/app_heatmap.R,line=426,col=81,[line_length_linter] Lines should not be more than 80 characters.
}

if (n_samples > 200) {
Expand All @@ -438,10 +438,10 @@

heatmap_plot <- ggplot(
augmented_tidy_omic_data,
aes_string(
x = "ordered_sampleId",
y = "ordered_featureId",
fill = value_var
aes(
x = !!rlang::sym("ordered_sampleId"),
y = !!rlang::sym("ordered_featureId"),
fill = !!rlang::sym(value_var)
)
) +
geom_raster() +
Expand Down
21 changes: 14 additions & 7 deletions R/data_classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
#' )
#' @export
create_tidy_omic <- function(
df,

Check warning on line 62 in R/data_classes.R

View workflow job for this annotation

GitHub Actions / lint

file=R/data_classes.R,line=62,col=4,[indentation_linter] Indentation should be 2 spaces but is 4 spaces.
feature_pk,
feature_vars = NULL,
sample_pk,
sample_vars = NULL,
omic_type_tag = "general",
verbose = TRUE
) {

Check warning on line 69 in R/data_classes.R

View workflow job for this annotation

GitHub Actions / lint

file=R/data_classes.R,line=69,col=4,[indentation_linter] Indentation should be 0 spaces but is 4 spaces.

checkmate::assertDataFrame(df)
checkmate::assertString(omic_type_tag)
Expand All @@ -86,7 +86,7 @@

n_var_uses <- table(c(feature_pk, feature_vars, sample_pk, sample_vars))
if (any(n_var_uses > 1)) {
invalid_vars <- names(n_var_uses)[n_var_uses > 1]

Check warning on line 89 in R/data_classes.R

View workflow job for this annotation

GitHub Actions / lint

file=R/data_classes.R,line=89,col=5,[object_usage_linter] local variable 'invalid_vars' assigned but may not be used

cli::cli_abort(
"{paste(invalid_vars, collapse = ', ')} were assigned to multiple
Expand Down Expand Up @@ -134,7 +134,7 @@
measurement_vars <- setdiff(
output$design$measurements$variable,
c(feature_pk, sample_pk)
)

Check warning on line 137 in R/data_classes.R

View workflow job for this annotation

GitHub Actions / lint

file=R/data_classes.R,line=137,col=6,[indentation_linter] Indentation should be 4 spaces but is 6 spaces.

message(glue::glue(
"{length(measurement_vars)} measurement variables were defined as the
Expand Down Expand Up @@ -706,6 +706,7 @@
#' @inheritParams create_tidy_omic
#' @param sample_var variable name to use for samples
#' @param measurement_var variable name to use for measurements
#' @inheritParams create_tidy_omic
#'
#' @returns A \code{tidy_omic} object as produced by \code{create_tidy_omic}.
#'
Expand All @@ -724,12 +725,16 @@
#' feature_vars = c("BP", "MF", "systematic_name")
#' )
#' @export
convert_wide_to_tidy_omic <- function(wide_df,
feature_pk,
feature_vars = NULL,
sample_var = "sample",
measurement_var = "abundance",
omic_type_tag = "general") {
convert_wide_to_tidy_omic <- function(
wide_df,
feature_pk,
feature_vars = NULL,
sample_var = "sample",
measurement_var = "abundance",
omic_type_tag = "general",
verbose = TRUE
) {

checkmate::assertDataFrame(wide_df)
checkmate::assertChoice(feature_pk, colnames(wide_df))
stopifnot(class(feature_vars) %in% c("character", "NULL"))
Expand All @@ -740,6 +745,7 @@
checkmate::assertString(sample_var)
checkmate::assertString(measurement_var)
checkmate::assertString(omic_type_tag)
checkmate::assertLogical(verbose, len = 1)

# test other provided variables
reserved_variable_names <- c(
Expand Down Expand Up @@ -835,7 +841,8 @@
feature_pk = feature_pk,
feature_vars = feature_vars,
sample_pk = sample_var,
omic_type_tag = omic_type_tag
omic_type_tag = omic_type_tag,
verbose = verbose
)

return(tidy_omic)
Expand Down
35 changes: 25 additions & 10 deletions R/dim_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @inheritParams remove_missing_values
#' @param label_percent_varex If true then PCs will be labelled by the percent
#' of variability they explain.
#' @inheritParams create_tidy_omic
#'
#' @returns A \code{tomic} object with principal components added to samples.
#'
Expand All @@ -24,13 +25,15 @@ add_pcs <- function(
center_rows = TRUE,
npcs = NULL,
missing_val_method = "drop_samples",
label_percent_varex = TRUE
label_percent_varex = TRUE,
verbose = TRUE
) {

checkmate::assertClass(tomic, "tomic")
checkmate::assertLogical(center_rows, len = 1)
stopifnot(length(npcs) <= 1, class(npcs) %in% c("NULL", "numeric", "integer"))
checkmate::assertLogical(label_percent_varex, len = 1)
checkmate::assertLogical(verbose, len = 1)

design <- tomic$design
feature_pk <- design$feature_pk
Expand All @@ -41,7 +44,8 @@ add_pcs <- function(
triple_omic <- tomic_to(tomic, "triple_omic") %>%
remove_missing_values(
value_var = value_var,
missing_val_method = missing_val_method
missing_val_method = missing_val_method,
verbose = verbose
)

cast_formula <- stats::as.formula(paste0(feature_pk, " ~ ", sample_pk))
Expand Down Expand Up @@ -129,6 +133,7 @@ add_pcs <- function(
#' then drop features}
#' \item{impute}{Impute missing values}
#' }
#' @inheritParams create_tidy_omic
#'
#' @returns A \code{tomic} object where missing values have been accounted
#' for.
Expand All @@ -140,12 +145,15 @@ add_pcs <- function(
remove_missing_values <- function(
tomic,
value_var = NULL,
missing_val_method = "drop_samples") {
missing_val_method = "drop_samples",
verbose = TRUE
) {
checkmate::assertClass(tomic, "tomic")
checkmate::assertChoice(
missing_val_method,
c("drop_features", "drop_samples")
)
checkmate::assertLogical(verbose, len = 1)

triple_omic <- tomic_to(tomic, "triple_omic")

Expand Down Expand Up @@ -183,7 +191,10 @@ remove_missing_values <- function(
stop(missing_val_method, " is not an implemented missing value method")
}
} else {
message("No missing values found; returning input tomic")
if (verbose) {
message("No missing values found; returning input tomic")
}

return(tomic)
}

Expand All @@ -198,9 +209,11 @@ remove_missing_values <- function(
n_dropped_samples <- n_initial_samples - nrow(triple_omic$samples)

if (n_dropped_samples != 0) {
print(
glue::glue("{n_dropped_samples} samples dropped due to missing values")
)
if (verbose) {
print(
glue::glue("{n_dropped_samples} samples dropped due to missing values")
)
}
}

n_dropped_features <- observed_measurements %>%
Expand All @@ -209,9 +222,11 @@ remove_missing_values <- function(
nrow()

if (n_dropped_features != 0) {
print(
glue::glue("{n_dropped_features} features dropped due to missing values")
)
if (verbose) {
print(
glue::glue("{n_dropped_features} features dropped due to missing values")
)
}
}

return(tomic_to(triple_omic, class(tomic)[1]))
Expand Down
35 changes: 27 additions & 8 deletions R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @inheritParams tomic_to
#' @param dir_path path to save outputs
#' @param name_preamble start of output file name
#' @inheritParams create_tidy_omic
#'
#' @returns Export three tables:
#' \itemize{
Expand All @@ -19,16 +20,24 @@
#' export_tomic_as_triple(brauer_2008_triple, "/tmp", "brauer")
#' }
#' @export
export_tomic_as_triple <- function(tomic, dir_path, name_preamble) {
export_tomic_as_triple <- function(
tomic,
dir_path,
name_preamble,
verbose = TRUE
) {
checkmate::assertDirectory(dir_path)
checkmate::assertString(name_preamble)
checkmate::assertLogical(verbose, len = 1)

triple_omic <- tomic_to(tomic, "triple_omic")

message(glue::glue(
"Saving {name_preamble}_features.tsv, {name_preamble}_samples.tsv, and
if (verbose) {
message(glue::glue(
"Saving {name_preamble}_features.tsv, {name_preamble}_samples.tsv, and
{name_preamble}_measurements.tsv to {dir_path}"
))
))
}

for (k in c("features", "samples", "measurements")) {
readr::write_tsv(
Expand All @@ -46,6 +55,7 @@ export_tomic_as_triple <- function(tomic, dir_path, name_preamble) {
#' measurements.
#'
#' @inheritParams export_tomic_as_triple
#' @inheritParams create_tidy_omic
#'
#' @returns Export one table which is one row per peak, which includes
#' all feature and sample attributes.
Expand All @@ -56,14 +66,17 @@ export_tomic_as_triple <- function(tomic, dir_path, name_preamble) {
#' export_tomic_as_tidy(brauer_2008_triple, "/tmp", "brauer")
#' }
#' @export
export_tomic_as_tidy <- function(tomic, dir_path, name_preamble) {
export_tomic_as_tidy <- function(tomic, dir_path, name_preamble, verbose = TRUE) {
checkmate::assertDirectory(dir_path)
checkmate::assertString(name_preamble)
checkmate::assertLogical(verbose, len = 1)

tidy_omic <- tomic_to(tomic, "tidy_omic")

filename <- paste0(name_preamble, "_tidy.tsv")
message(glue::glue("Saving {filename} to {dir_path}"))
if (verbose) {
message(glue::glue("Saving {filename} to {dir_path}"))
}

readr::write_tsv(
tidy_omic$data,
Expand All @@ -81,6 +94,7 @@ export_tomic_as_tidy <- function(tomic, dir_path, name_preamble) {
#' @inheritParams export_tomic_as_triple
#' @param value_var measurement variable to use for the matrix
#' @param transpose if TRUE then samples will be stored as rows
#' @inheritParams create_tidy_omic
#'
#' @returns Export one table which contains metabolites as rows and samples
#' as columns.
Expand All @@ -96,10 +110,13 @@ export_tomic_as_wide <- function(
dir_path,
name_preamble,
value_var = NULL,
transpose = FALSE) {
transpose = FALSE,
verbose = TRUE
) {
checkmate::assertDirectory(dir_path)
checkmate::assertString(name_preamble)
checkmate::assertLogical(transpose, len = 1)
checkmate::assertLogical(verbose, len = 1)

triple_omic <- tomic_to(tomic, "triple_omic")
design <- triple_omic$design
Expand Down Expand Up @@ -245,7 +262,9 @@ export_tomic_as_wide <- function(
}

filename <- paste0(name_preamble, "_", "wide.tsv")
message(glue::glue("Saving {filename} to {dir_path}"))
if (verbose) {
message(glue::glue("Saving {filename} to {dir_path}"))
}

output %>%
as.data.frame() %>%
Expand Down
14 changes: 10 additions & 4 deletions R/hclust.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ apply_hclust <- function(quant_matrix, distance_measure, hclust_method) {
#' @param design a list summarizing the design of the tidy dataset
#' @param max_display_features aggregate and downsample distinct feature to
#' this number to speed to up heatmap rendering.
#' @inheritParams create_tidy_omic
#'
#' @returns tidy_data with rows collapsed if the number of distinct features is
#' greater than \code{max_display_features}
Expand All @@ -330,10 +331,13 @@ downsample_heatmap <- function(
tidy_data,
value_var,
design,
max_display_features = 1000) {
max_display_features = 1000,
verbose = TRUE
) {
checkmate::assertDataFrame(tidy_data)
checkmate::assertChoice(value_var, colnames(tidy_data))
checkmate::assertNumber(max_display_features)
checkmate::assertLogical(verbose, len = 1)

if (!("ordered_featureId" %in% colnames(tidy_data))) {
stop("ordered_featureId is a requred variable in tidy_data")
Expand All @@ -358,9 +362,11 @@ downsample_heatmap <- function(
realized_max_display_features <- ceiling(
n_features / ceiling(n_features / max_display_features)
)
message(glue::glue(
"Downsampling {n_features} features to {realized_max_display_features}, targeting {max_display_features}"
))
if (verbose) {
message(glue::glue(
"Downsampling {n_features} features to {realized_max_display_features}, targeting {max_display_features}"
))
}

collapsed_rows_merges <- tibble::tibble(ordered_featureId_int = 1:n_features) %>%
dplyr::mutate(collapsed_row_number = rep(
Expand Down
Empty file removed R/romic.R
Empty file.
5 changes: 4 additions & 1 deletion man/add_pcs.Rd

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

5 changes: 4 additions & 1 deletion man/convert_wide_to_tidy_omic.Rd

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

10 changes: 9 additions & 1 deletion man/downsample_heatmap.Rd

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

Loading
Loading