Skip to content

Commit d5cc850

Browse files
authored
Merge pull request #126 from UMCUGenetics/hotfix/v2.7.5
Hotfix/v2.7.5 to main
2 parents dcdd971 + a9bfa3e commit d5cc850

6 files changed

Lines changed: 54 additions & 34 deletions

File tree

DIMS/CollectFilled.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ for (scanmode in scanmodes) {
2828
# calculate Z-scores
2929
if (z_score == 1) {
3030
outlist_stats <- calculate_zscores_peakgrouplist(outlist_total)
31+
} else {
32+
outlist_stats <- outlist_total
3133
}
3234
# calculate ppm deviation
3335
outlist_withppm <- calculate_ppm_deviation(outlist_stats)

DIMS/GenerateQCOutput.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ dir.create(paste0(outdir, "/plots"), showWarnings = FALSE)
3737
control_label <- "C"
3838

3939
#### CHECK NUMBER OF CONTROLS ####
40-
file_name <- "Check_number_of_controls.txt"
41-
min_num_controls <- 25
42-
check_number_of_controls(outlist, min_num_controls, file_name)
40+
if (any(grepl("nr_ctrls", colnames(outlist)))) {
41+
file_name <- "Check_number_of_controls.txt"
42+
min_num_controls <- 25
43+
check_number_of_controls(outlist, min_num_controls, file_name)
44+
}
4345

4446
#### INTERNAL STANDARDS ####
4547
is_list <- outlist[grep("Internal standard", outlist[, "relevance"], fixed = TRUE), ]

DIMS/export/generate_violin_plots_functions.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ add_zscores_ratios_to_df <- function(outlist, metabolites_ratios_df, all_sample_
6767
#'
6868
#' @returns zscore_ratios_df: dataframe containing Z-scores for all ratios for all samples
6969
calculate_zscore_ratios <- function(metabolites_ratios_df, intensities_zscores_df, intensity_col_names) {
70+
# remove Z-score columns from intensity_col_names
71+
if (any(grepl("_Zscore", intensity_col_names))) {
72+
intensity_col_names <- intensity_col_names[-grep("_Zscore", intensity_col_names)]
73+
}
74+
75+
# create empty data frame for results
7076
zscore_ratios_df <- data.frame(matrix(
7177
ncol = ncol(intensities_zscores_df),
7278
nrow = nrow(metabolites_ratios_df)
@@ -665,14 +671,20 @@ create_pdf_violin_plots <- function(pdf_dir, patient_id, metab_perpage, top_meta
665671
for (metab_class in names(metab_perpage)) {
666672
# extract list of metabolites to plot on a page
667673
metab_zscores_df <- metab_perpage[[metab_class]]
668-
# extract original data for patient of interest (pt_name) before cut-offs
669-
patient_zscore_df <- metab_zscores_df %>% filter(Sample == patient_id)
670-
671-
# Remove patient column and change Z-score. If under -5 to -5 and if above 20 to 20.
674+
# copy Z-scores to Z_score_original for displaying values
675+
metab_zscores_df$Z_score_original <- metab_zscores_df$Z_score
676+
# Cap Z-scores under -5 to -5 and above 20 to 20
672677
metab_zscores_df <- metab_zscores_df %>%
673-
filter(Sample != patient_id) %>%
674678
mutate(Z_score = pmin(pmax(Z_score, -5), 20))
675679

680+
# extract original data for patient of interest (pt_name)
681+
patient_zscore_df <- metab_zscores_df %>%
682+
filter(Sample == patient_id)
683+
684+
# Remove patient of interest and retain only other patient data
685+
metab_zscores_df <- metab_zscores_df %>%
686+
filter(Sample != patient_id)
687+
676688
# subtitle per page
677689
sub_perpage <- gsub("_", " ", metab_class)
678690
# for IEM plots, put subtitle on two lines
@@ -733,7 +745,7 @@ create_violin_plot <- function(metab_zscores_df, patient_zscore_df, sub_perpage,
733745
# Add the Z-score at the right side of the plot
734746
geom_text(
735747
data = patient_zscore_df,
736-
aes(16, label = paste0("Z=", round(Z_score, 2))),
748+
aes(16, label = paste0("Z=", round(Z_score_original, 2))),
737749
hjust = "left", vjust = +0.2, size = 3, na.rm = TRUE
738750
) +
739751
# Set colour for the Z-score of the selected patient

DIMS/preprocessing/collect_filled_functions.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ order_columns_peakgrouplist <- function(peakgroup_list) {
129129

130130
original_colnames <- colnames(peakgroup_list)
131131
mass_columns <- c(grep("mzm", original_colnames), grep("nrsamples", original_colnames))
132-
descriptive_columns <- grep("assi_HMDB", original_colnames):grep("avg.int", original_colnames)
132+
if (any(grepl("avg.int", original_colnames))) {
133+
descriptive_columns <- grep("assi_HMDB", original_colnames):grep("avg.int", original_colnames)
134+
} else {
135+
descriptive_columns <- grep("assi_HMDB", original_colnames):grep("ppmdev", original_colnames)
136+
}
133137
intensity_columns <- c((grep("nrsamples", original_colnames) + 1):(grep("assi_HMDB", original_colnames) - 1))
134-
# if no Z-scores have been calculated, the following two variables will be empty without consequences for outlist_total
138+
# if no Z-scores have been calculated, the following two variables will be empty without consequences for peakgroup_list
135139
control_columns <- grep ("ctrls", original_colnames)
136140
zscore_columns <- grep("_Zscore", original_colnames)
137141
# create peak group list with columns in correct order

DIMS/preprocessing/sum_intensities_adducts.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ sum_intensities_adducts <- function(peakgroup_list, hmdb_part, adducts, z_score)
3232
int_cols_pats <- grep("P", colnames(peakgroup_list)[1:which(colnames(peakgroup_list) == "avg.ctrls")])
3333
int_cols <- c(int_cols_ctrls, int_cols_pats)
3434
} else {
35-
int_cols_start <- which(colnames(peakgroup_list) == "nrsamples") + 1
36-
int_cols_end <- which(colnames(peakgroup_list) == "assi_HMDB") - 1
35+
int_cols_start <- which(colnames(peakgroup_list) == "ppmdev") + 1
36+
int_cols_end <- ncol(peakgroup_list)
3737
int_cols <- c(int_cols_start:int_cols_end)
3838
}
3939

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
HMDB_name Sample Z_score
2-
metab1 P2025M1 0.31
3-
metab3 P2025M1 2.34
4-
metab1 P2025M2 2.45
5-
metab3 P2025M2 1.45
6-
metab1 P2025M3 2.14
7-
metab3 P2025M3 -1.44
8-
metab1 P2025M4 12.18
9-
metab3 P2025M4 -0.18
10-
metab1 P2025M5 3.22
11-
metab3 P2025M5 -3.18
12-
metab1 C101.1 0.45
13-
metab3 C101.1 -1.86
14-
metab1 C102.1 2.89
15-
metab3 C102.1 -1.88
16-
metab1 C103.1 0.54
17-
metab3 C103.1 1.58
18-
metab1 C104.1 0.53
19-
metab3 C104.1 0.35
20-
metab1 C105.1 3.46
21-
metab3 C105.1 0.14
1+
HMDB_name Sample Z_score Z_score_original
2+
metab1 P2025M1 0.31 0.31
3+
metab3 P2025M1 2.34 2.34
4+
metab1 P2025M2 2.45 2.45
5+
metab3 P2025M2 1.45 1.45
6+
metab1 P2025M3 2.14 2.14
7+
metab3 P2025M3 -1.44 -1.44
8+
metab1 P2025M4 12.18 12.18
9+
metab3 P2025M4 -0.18 -0.18
10+
metab1 P2025M5 3.22 3.22
11+
metab3 P2025M5 -3.18 -3.18
12+
metab1 C101.1 0.45 0.45
13+
metab3 C101.1 -1.86 -1.86
14+
metab1 C102.1 2.89 2.89
15+
metab3 C102.1 -1.88 -1.88
16+
metab1 C103.1 0.54 0.54
17+
metab3 C103.1 1.58 1.58
18+
metab1 C104.1 0.53 0.53
19+
metab3 C104.1 0.35 0.35
20+
metab1 C105.1 3.46 3.46
21+
metab3 C105.1 0.14 0.14

0 commit comments

Comments
 (0)