Feature/DIMS_DrugDB - #128
Conversation
…ut in DIMS/export/generate_excel_functions.R
| #' 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)] |
There was a problem hiding this comment.
Use grep(value = FALSE) instead of grepl(), so you don't have to retrieve the indices separately.
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
The function does more than just calculate Z-scores, maybe add a separate function that calculates the average and sd of the controls.
There was a problem hiding this comment.
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.
| 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")) | ||
| ) |
There was a problem hiding this comment.
This is the same code as on lines 629-632, also change this on lines 667-670.
There was a problem hiding this comment.
Redundant code removed.
| 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) | ||
| ) |
There was a problem hiding this comment.
This code is the same as lines 662-683, maybe move this to a separate function.
There was a problem hiding this comment.
Function created for redundant code, including unit test.
…lin_plots_functions.R
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.