Skip to content

Feature/DIMS_v3.5_harmonize_Rscripts - #130

Open
mraves2 wants to merge 42 commits into
developfrom
feature/DIMS_v3.5_harmonize_Rscripts
Open

mraves2 wants to merge 42 commits into
developfrom
feature/DIMS_v3.5_harmonize_Rscripts

Conversation

@mraves2

@mraves2 mraves2 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

The R scripts for the DIMS pipeline (main scripts for every step of the pipeline and the function scripts in folders export and preprocessing) have been cleaned up:

  • variables have logical and self-explanatory names
  • obsolete or redundant variables have been removed
  • docstrings outside the function; variables in docstrings match those used
  • same order in main scripts: libraries, arguments, source functions, initialize, load objects
  • setting the number of digits has been added for every script in which calculations are performed.
    In addition, the variable outdir is no longer necessary and has been removed. The output files which start with outlist* have been renamed peakgroup_list*.
    The function seqToIntervals has been removed from peak_finding_functions.R since the package R.utils is incorporated in docker image v1.4 and an alternative function has been used for gaussfunc. All NF scripts now use the updated docker image.

Argument parsing is part of another feature branch and can be ignored in this PR. Also, GenerateExcel.R and generate_excel_functions.R have been refactored in feature DIMS_DrugDB. The log2 operation has been removed from generate_violin_plots_functions.R.

mraves2 added 30 commits July 14, 2026 17:36

@ALuesink ALuesink left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really a lot of work! It looks good, but I have a few specific comments and a few general comments.

General comments:

  • Check the comments, some start with capital letters and others with lowercase letters.
  • CollectSumAdducts.nf misses the change to de new Docker version.
  • Check the linting of all the files.

Comment on lines +15 to +16
df_intensities <- as.data.frame(peakgroup_list[, col_idx])
colnames(df_intensities) <- colnames(peakgroup_list)[col_idx]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could use the select() function of dplyr. This also works with indices and then there is no need to set the colnames.

#' @param row_index: Index of row (integer)
#'
#' @returns intensities_df_long: a dataframe with on each row a sample and their intensity
#' @returns intensities_df_long: Dataframe with on each row a sample and its intensity (matrix)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this variable a dataframe or a matrix?

Comment on lines +214 to +221
#' @param excel_workbook: An openxlsx Workbook object (workbook object)
#' @param sheetname: Name of the sheet where the plots are to be placed (string)
#' @param intensities_df: Dataframe containing intensities for controls and patients of a specific HMDB ID (matrix)
#' @param file_path: Filepath for the png (string)
#' @param hmdb_id: HMDB ID corresponding to intensities_df (string)
#' @param plot_width: Plot width for the png (integer)
#' @param col_width: Width of the column that has the plots (integer)
#' @param start_row_index: Index of the row where the plot has to be placed (integer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The @param section is not consistent in this R file. For this function the data type is at the end, but previous functions have the datatype within the text.

mz_range <- seq(70, 599, by = 1)
mz_missing <- setdiff(mz_range, mzmed_pgrp_ident)
# check if m/z are missing and make an .txt file with information
# check if m/z are missing and make a txt file with information

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this function make a txt file?

is_below_threshold <- is_selection_subset[below_threshold_index, ]
# add information on scan mode
is_below_threshold <- cbind(is_below_threshold, scanmode = rep(scanmode, nrow(is_below_threshold)))
if (nrow(is_below_threshold) > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The indentation is incorrect.

Comment on lines 316 to +317
#' @return df_zscores_to_helix: dataframe with patient data with only metabolites for Helix and violin plots
#' with Helix name, high/low Z-score cutoffs
#' with Helix name, high/low Z-score cutoffs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See previous comment on indentations for docstrings.

Comment on lines +545 to +546
#' @return top_metab_patient: Dataframe with metabolites that exceed the min and max Z-score cutoffs
#' for the selected patient (matrix)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See previous comment on indentations for docstrings.

patient_id_sub <- patient_id
suffix <- ""
if (grepl("Diagnostics", pdf_dir) && is_diagnostic_patients(patient_id)) {
if (grepl("Diagnost", pdf_dir) && is_diagnostic_patients(patient_id)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this changed to Diagnost?


# set new column names and calculate Z-scores
colnames_zscores <- NULL
peakgroup_list_zscores <-peakgroup_list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you create a new variable, peakgroup_list_zscores? Is it not possible to use 1 variable?

observed_mz <- peakgroup_list$mzmed.pgrp[row_index]
theor_mz <- peakgroup_list$theormz_HMDB[row_index]
peakgroup_list$ppmdev[row_index] <- 10^6 * (observed_mz - theor_mz) / theor_mz
peakgroup_list_ppm <- peakgroup_list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as the previous comment, why do you create a new variable without changing the original variable?

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