Skip to content

Feature/DIMS_previous_runs - #131

Open
mraves2 wants to merge 9 commits into
developfrom
feature/DIMS_previous_runs
Open

Feature/DIMS_previous_runs#131
mraves2 wants to merge 9 commits into
developfrom
feature/DIMS_previous_runs

Conversation

@mraves2

@mraves2 mraves2 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Added rectangles in the violin plots to indicate the 5-95% range of results for patients for each metabolite in previous runs.
image

Extra file is imported in GenerateViolinPlots and generate_violin_plots_functions has new function add_previous_runs. Unit test for new function has been added.

add_previous_runs <- function(patient_zscore_df, data_previous_runs) {
data_previous_runs <- as.data.frame(data_previous_runs)
for (row_nr in 1:nrow(patient_zscore_df)) {
# match data from previous run to data from current run based on common name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start with capital letter in comments.
https://style.tidyverse.org/documentation.html#capitalization-and-full-stops

In case you used lowercase all the time, consider this remark out-of-scope for this PR. In that case it is better to be consistent. However, you might want to consider changing this across whole project later on. :)

Just out of curiosity, any linter/styleguide/formatter check used by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a separate feature branch for harmonizing all R scripts, see #130
in which many things have been standardized. I didn't check all comments in all R files though, but I intend to do linting and style checks after all feature branches for DIMS v3.5 have been properly merged.

patient_zscore_df$max[row_nr] <- data_previous_runs$max[find_rownr]
patient_zscore_df$min95[row_nr] <- data_previous_runs$min95[find_rownr]
patient_zscore_df$max95[row_nr] <- data_previous_runs$max95[find_rownr]
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you need 5 separate lines, or whether the assignments can be combined;

patient_zscore_df[row_nr, c("mean", "min", "max", "min95", "max95")] <-
  data_previous_runs[find_rownr, c("average_patients", "min", "max", "min95", "max95")]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 5 lines can be replaced by 2 lines; modified.

common_name <- trimws(patient_zscore_df$HMDB_name[row_nr])
find_rownr <- which(data_previous_runs$common_name == common_name)
# add mean, min, max and 5-95% interval of data from previous runs
if (length(find_rownr) == 1) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong. I assume this conditional is to only add data if common_name is found (not 0). Theoretically, it is possible to have a find_rownr > 1. Do you need to check for this as well, and maybe add multiple values (or average or ...)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataframe data_previous_runs doesn't contain any double entries, so find_rownr is either 0 or 1. In case this situation does occur in the future, the current code will not give a rectangle in the violin plot which will be detectable.

Comment thread DIMS/export/generate_violin_plots_functions.R Outdated
#' @param explanation: text that explains the violin plots and the pipeline version (string)
create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_metab_pt, explanation) {
#' @param data_previous_runs: data from previous DIMS runs, not used for dIEM plots (matrix)
create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_metab_pt, explanation, data_previous_runs = NULL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, create_pdf_violin_plots is quite long (large number of lines). Adding additional code to it, makes me wonder if it could be split into multiple methods.

For example:

  • A method that determines the PDF filename.
  • Any edits to the data itself. (filter/select, mutates etc)
  • Create a list (or something similar) with all plots.
  • Create the page layout with tableGrob + gridarrange etc using the plot list.
  • Write to PDF. (Or, combine with determining the PDF filename)

Would like to hear your opinion. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part that determines the pdf file name could easily be made into a separate function. Creating a list of plots would not be my preference, I would prefer to keep each type of plot as a separate unit.
This code has been refactored previously and will remain as is for v3.5.

Comment thread DIMS/tests/testthat/test_generate_violin_plots.R
file.remove("missing_probability_scores.txt")
})

testthat::test_that("add_previous_runs: Information for metabolites from previous runs is correctly added", {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a 'negative' test also relevant? Aka In case no match with common_name, or no data present.
Are there any other edge cases to cover? If an input file could have metadata from multiple runs, you could test a scenario with single and once with multiple runs.

file_ratios_metabolites <- cmd_args[4]
file_expected_biomarkers_iem <- cmd_args[5]
file_explanation <- cmd_args[6]
file_previous_runs <- cmd_args[7]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there multiple runs in a single file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file_previous_runs contains summarized data (min, max, mean) from runs from the past half a year in one dataframe.

#' @param explanation: text that explains the violin plots and the pipeline version (string)
create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_metab_pt, explanation) {
#' @param data_previous_runs: data from previous DIMS runs, not used for dIEM plots (matrix)
create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_metab_pt, explanation, data_previous_runs = NULL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this PR. When I read the full function, I noticed table_theme is declared twice, line 641 and 679. I don't see any differences between the two lines. Is it possible that 679 could reuse the declared theme?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed in feature/DIMS_DrugDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants