Skip to content

Feature/DIMS_DrugDB - #128

Open
mraves2 wants to merge 16 commits into
developfrom
feature/DIMS_DrugDB
Open

Feature/DIMS_DrugDB#128
mraves2 wants to merge 16 commits into
developfrom
feature/DIMS_DrugDB

Conversation

@mraves2

@mraves2 mraves2 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Naast annotatie van piekgroepen op basis van metabolieten in de HMDB is nu ook de DrugDB ingebouwd. Drug metabolieten hebben een ID die begint met CHEMBL; op basis daarvan wordt een apart Excel bestand gemaakt en een extra tabel van drugs met de meest afwijkende Z-scores in de vioolplotjes PDF.
De stap GenerateExcel is gerefactored; er zijn twee nieuwe functies bijgekomen in export/generate_excel_functions.R waarvoor ook unit tests zijn geschreven. GenerateExcel.R is hierdoor overzichtelijker geworden, hoewel het waarschijnlijk nog verder geoptimaliseerd kan worden.

#' df_intensities: dataframe with the intensities of the controls
col_idx <- grep(label, colnames(outlist), fixed = TRUE)
# remove Z-score columns
col_idx <- col_idx[!grepl("_Zscore", colnames(outlist)[col_idx], fixed = TRUE)]

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.

Use grep(value = FALSE) instead of grepl(), so you don't have to retrieve the indices separately.

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.

grep(value = FALSE) gives an empty result if there are no column names with "_Zscore", grepl works both with and without columns containing "_Zscore".

#' @param stat_filter: Either percentage or outlier threshold used for excluding controls (integer)
#'
#' @returns: peakgroup_list_zscores: same dataframe as the input with added Z-score columns (matrix)
calculate_zscores <- function(peakgroup_list, zscore_type, stat_filter, control_label = "C", case_label = "P") {

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 function does more than just calculate Z-scores, maybe add a separate function that calculates the average and sd of the controls.

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.

Imho calculating the average and sd of the controls is the first step in calculating Z-scores. What makes this function long and complicated is the logic for different cases of Z-scores (with or without outlier removal); I could move this to a separate function.

Comment on lines +716 to +719
table_theme <- ttheme_default(
core = list(fg_params = list(hjust = 0, x = 0.05, fontsize = 6)),
colhead = list(fg_params = list(fontsize = 8, fontface = "bold"))
)

@ALuesink ALuesink Aug 13, 2026

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.

This is the same code as on lines 629-632, also change this on lines 667-670.

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.

Redundant code removed.

Comment on lines +711 to +731
max_rows_per_page <- 35
total_rows <- nrow(top_drugs_patient)
number_of_pages <- ceiling(total_rows / max_rows_per_page)

# get the names and numbers in the table aligned
table_theme <- ttheme_default(
core = list(fg_params = list(hjust = 0, x = 0.05, fontsize = 6)),
colhead = list(fg_params = list(fontsize = 8, fontface = "bold"))
)

for (page in seq(number_of_pages)) {
start_row <- (page - 1) * max_rows_per_page + 1
end_row <- min(page * max_rows_per_page, total_rows)
page_data <- top_drugs_patient[start_row:end_row, ]

table_grob <- tableGrob(page_data, theme = table_theme, rows = NULL)

grid.arrange(
table_grob,
top = paste0("Top deviating drug metabolites for patient: ", 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.

This code is the same as lines 662-683, maybe move this to a separate function.

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.

Function created for redundant code, including unit test.

Comment thread DIMS/export/generate_violin_plots_functions.R Outdated
Comment thread DIMS/GenerateExcel.R Outdated
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