Skip to content
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
14 changes: 13 additions & 1 deletion R/import_mzroll.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#' Process mzRoll
#'
#' @param mzroll_db_path path to mzroll DB file
#' @param mzroll_db_path path to mzroll DB file,
#' or a pre-built romic triple_omic object with type tag 'mzroll'.
#' Callers of this function are responsible for passing in a valid input object
#' in that use case. However, the object will still be tested via
#' \code{test_mzroll_list()}.
#' @param only_identified TRUE/FALSE, filter to only features which were
#' identified.
#' @param validate TRUE/FALSE, use meta-data to only name the subset of
Expand Down Expand Up @@ -37,6 +41,14 @@ process_mzroll <- function(mzroll_db_path,
peakgroup_labels_to_keep = "*",
peakgroup_labels_to_exclude = "",
quant_col = "peakAreaTop") {
# Issue 12: Support import of pre-built 'mzroll' tomic (romic tiple omic) object.
# Callers are responsible to generate a valid 'mzroll' object.
# test_mzroll_list() will fail if object is invalid.
if ("mzroll" %in% class(mzroll_db_path)) {
test_mzroll_list(mzroll_db_path)
return(mzroll_db_path)
}

checkmate::assertFileExists(mzroll_db_path)
checkmate::assertLogical(only_identified, len = 1)
checkmate::assertLogical(validate, len = 1)
Expand Down
6 changes: 5 additions & 1 deletion man/process_mzroll.Rd

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

11 changes: 5 additions & 6 deletions tests/testthat/test_mutates.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,31 @@ test_that("Test reference samples and reference conditions", {
})

test_that("Flooring adds missing peaks", {

# discard random measurements representing peaks that weren't
# picked due to being below the limit of detection

nplug_with_missing_values <- nplug_mzroll_augmented
nplug_with_missing_values$measurements <- nplug_mzroll_augmented$measurements %>%
dplyr::anti_join(
nplug_mzroll_augmented$measurements %>%
dplyr::sample_n(100),
by = c("groupId", "sampleId")
)

floored_nplug <- floor_peaks(nplug_with_missing_values)

peakgroups_with_missing_vals <- floored_nplug$measurements %>%
dplyr::count(groupId) %>%
dplyr::filter(n != max(n))

expect_equal(nrow(peakgroups_with_missing_vals), 0)
})

test_that("Flooring works and is maintained", {
floored_peaks <- claman::floor_peaks(
nplug_mzroll_augmented,
log2_floor_value = 12
)
)

expect_equal(
floored_peaks$measurements$log2_abundance >= 12,
Expand Down
65 changes: 33 additions & 32 deletions vignettes/NPLUG.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mzroll_list_augmented <- merge_samples_tbl(
nplug_samples,
"sample_name",
exact = TRUE
)
)
```

```{r read_sample_metadata_tables, echo = FALSE}
Expand Down Expand Up @@ -105,7 +105,7 @@ romic::plot_heatmap(
sample_var = "name",
value_var = "centered_log2_abundance",
change_threshold = 5
) + facet_grid(~ exp_ref + limitation, scales = "free_x", space = "free_x") +
) + facet_grid(~ exp_ref + limitation, scales = "free_x", space = "free_x") +
ggtitle("Metabolites separated by limiting nutrients")
```

Expand All @@ -124,7 +124,7 @@ romic::plot_heatmap(
sample_var = "name",
value_var = "centered_log2_abundance",
change_threshold = 5
) + facet_grid(~ limitation + extraction, scales = "free_x", space = "free_x") +
) + facet_grid(~ limitation + extraction, scales = "free_x", space = "free_x") +
ggtitle("Metabolites separated by extraction") +
theme(strip.text = element_text(size = 10))
```
Expand All @@ -141,12 +141,12 @@ mzroll_list_augmented %>%
filter_table = "samples",
filter_variable = "exp_ref",
filter_value = "ref"
) %>%
) %>%
romic::plot_heatmap(
feature_var = "compoundName",
sample_var = "name",
value_var = "centered_log2_abundance",
change_threshold = 5
feature_var = "compoundName",
sample_var = "name",
value_var = "centered_log2_abundance",
change_threshold = 5
) + facet_grid(~ month + DR, scales = "free_x", space = "free_x") +
ggtitle("References separated by month and distinct cultures (by DR)") +
theme(strip.text = element_text(size = 10))
Expand All @@ -171,14 +171,14 @@ plot_compare_injection(
mzroll_list_augmented,
grouping_vars = "condition",
peak_quant_var = "centered_log2_abundance"
) + ggtitle("Comparison of injection technical replicates")
) + ggtitle("Comparison of injection technical replicates")

mzroll_list_distinct_conditions <- collapse_injections(
mzroll_list_augmented,
grouping_vars = "condition",
peak_quant_vars = c("log2_abundance", "centered_log2_abundance"),
collapse_fxn = "mean"
)
)
```

```{r technical_replicates_table, echo = FALSE}
Expand All @@ -201,7 +201,7 @@ mzroll_list_normalized <- normalize_peaks(
batch_varnames = c("month", "extraction"),
reference_varname = "exp_ref",
reference_values = "ref"
) %>%
) %>%
# having normalized by the common reference, we can re-center the data
# since slow-phosphate limited growth is not a biological reference.
romic::center_tomic(measurement_vars = "normalized_log2_abundance")
Expand All @@ -217,7 +217,7 @@ romic::plot_heatmap(
value_var = "normalized_log2_abundance",
change_threshold = 5,
cluster_dim = "rows"
) + facet_grid(~ exp_ref + limitation, scales = "free_x", space = "free_x") +
) + facet_grid(~ exp_ref + limitation, scales = "free_x", space = "free_x") +
ggtitle("Post-normalization metabolite abundances") +
theme(strip.text = element_text(size = 10))
```
Expand All @@ -236,15 +236,15 @@ final_processed_data <- mzroll_list_normalized %>%
filter_table = "samples",
filter_variable = "exp_ref",
filter_value = "exp"
) %>%
) %>%
# retain only filter extraction
romic::filter_tomic(
filter_type = "category",
filter_table = "samples",
filter_variable = "extraction",
filter_value = "filter"
)
)

# clean-up sample data
renamed_samples <- final_processed_data$samples %>%
select(sampleId, limitation, DR) %>%
Expand All @@ -254,14 +254,14 @@ renamed_samples <- final_processed_data$samples %>%
group_by(name) %>%
mutate(name = case_when(
n() == 1 ~ name,
TRUE ~ paste0(name, "-", 1:n()))
) %>%
TRUE ~ paste0(name, "-", 1:n())
)) %>%
ungroup()

final_processed_data <- romic::update_tomic(
final_processed_data,
renamed_samples
)
)

romic::plot_heatmap(
final_processed_data,
Expand All @@ -270,7 +270,7 @@ romic::plot_heatmap(
value_var = "normalized_log2_abundance",
change_threshold = 5,
cluster_dim = "rows"
) + facet_grid(~ limitation, scales = "free_x", space = "free_x") +
) + facet_grid(~limitation, scales = "free_x", space = "free_x") +
ggtitle("Final processed metabolite abundances across 25 growth conditions") +
theme(strip.text = element_text(size = 10))
```
Expand All @@ -294,7 +294,7 @@ romic::plot_bivariate(
"PC1",
"PC2",
color_var = "limitation"
) + ggtitle("Top principal components driving metabolomic variation")
) + ggtitle("Top principal components driving metabolomic variation")
```

One plot doesn't quite cut it here. Luckily, romic has some powerful methods for shiny-based interactive analysis that we can leverage here to quickly make plots like these.
Expand All @@ -320,7 +320,7 @@ regression_significance <- diffex_mzroll(
final_processed_data,
"normalized_log2_abundance",
"limitation + limitation:DR + 0"
)
)

plot_pvalues(regression_significance)
plot_volcano(regression_significance)
Expand All @@ -335,7 +335,8 @@ n_lim_signif <- regression_significance %>%
left_join(
final_processed_data$features %>%
select(groupId, peak_label),
by = "groupId")
by = "groupId"
)
```

```{r met_examples_table, echo = FALSE}
Expand All @@ -352,7 +353,7 @@ plot_barplot(
grouping_vars = c("limitation", "DR"),
value_var = "normalized_log2_abundance",
fill_var = "limitation"
) + scale_fill_brewer(palette = "Set2")
) + scale_fill_brewer(palette = "Set2")
```

## Pathway Analysis
Expand All @@ -364,18 +365,18 @@ pathway_nest <- final_processed_data$features %>%

pathway_list <- purrr::map(
pathway_nest$pathway_members,
function(x) {
as.character(x$groupId)
}
)
function(x) {
as.character(x$groupId)
}
)
names(pathway_list) <- pathway_nest$pathway

enrichments <- find_pathway_enrichments(
final_processed_data,
regression_significance,
pathway_list,
test_absolute_effects = FALSE
)
)
```

### Generate tables and plots of top enrichments
Expand All @@ -397,7 +398,7 @@ ranked_nitrogen_enrichments$enrichment_plot[[1]] +
ggtitle(
"Amino acids are depleted during nitrogen limitation",
"Note that the x-axis is ranks, and negative values have higher ranks"
)
)
```

# Export results
Expand All @@ -420,13 +421,13 @@ final_processed_data <- romic::update_tomic(
util_pretty_khead(
final_processed_data$features,
caption = "Peakgroups with differential abundance statistics added"
)
)
```

```{r export_results, eval = FALSE}
romic::export_tomic_as_tidy(
final_processed_data,
dir_path = "/tmp",
name_preamble = "nplug"
)
)
```
Loading