diff --git a/R/dataProcessPlots.R b/R/dataProcessPlots.R index dd3e1f66..cd2e1567 100644 --- a/R/dataProcessPlots.R +++ b/R/dataProcessPlots.R @@ -261,15 +261,10 @@ dataProcessPlots = function( labels = seq(1, length(unique(RUN))))] summarized[, RUN := as.numeric(RUN)] - ## Meena :due to GROUP=0 for labeled.. extra care required. tempGroupName = unique(processed[, c("GROUP", "RUN")]) - if (length(unique(processed$LABEL)) == 2) { - tempGroupName = tempGroupName[GROUP != '0'] - } - tempGroupName = tempGroupName[order(RUN), ] ## Meena : should we order by GROUP or RUN? I guess by RUn, because x-axis is by RUN + tempGroupName = tempGroupName[order(RUN), ] level.group = as.character(unique(tempGroupName$GROUP)) - tempGroupName$GROUP = factor(tempGroupName$GROUP, - levels = level.group) ## Meena : factor GROUP again, due to 1, 10, 2, ... if you have better way, please change + tempGroupName$GROUP = factor(tempGroupName$GROUP, levels = level.group) groupAxis = as.numeric(xtabs(~GROUP, tempGroupName)) cumGroupAxis = cumsum(groupAxis) @@ -291,16 +286,22 @@ dataProcessPlots = function( Name = levels(tempGroupName$GROUP)) - if (length(unique(processed$LABEL)) == 2) { - processed[, LABEL := factor(LABEL, labels = c("Reference", "Endogenous"))] + if ("is_labeled_ref" %in% colnames(processed)) { + processed[, LABEL := factor( + ifelse(is_labeled_ref, "Reference", "Endogenous"), + levels = c("Reference", "Endogenous") + )] } else { - if (unique(processed$LABEL) == "L") { + label_levels = levels(factor(processed$LABEL)) + if (length(label_levels) == 2) { + processed[, LABEL := factor(LABEL, labels = c("Heavy", "Light"))] + } else if ("L" %in% label_levels) { processed[, LABEL := factor(LABEL, labels = c("Endogenous"))] } else { - processed[, LABEL := factor(LABEL, labels = c("Reference"))] + processed[, LABEL := factor(LABEL, labels = c("Heavy"))] } } - + if ("feature_quality" %in% colnames(processed)) { processed[, feature_quality := NULL] } @@ -357,10 +358,11 @@ dataProcessPlots = function( } if (summaryPlot) { - protein_by_run = expand.grid(Protein = unique(summarized$Protein), + protein_by_run = expand.grid(Protein = unique(summarized$Protein), RUN = unique(summarized$RUN)) summarized = merge(summarized, protein_by_run, by = c("Protein", "RUN"), all.x = TRUE, all.y = TRUE) + summary_label = if ("Light" %in% levels(processed$LABEL)) "Light" else "Endogenous" if(!isPlotly) { savePlot(address, "ProfilePlot_wSummarization", width, height) } @@ -384,7 +386,7 @@ dataProcessPlots = function( Protein == all_proteins[i], list(PROTEIN = unique(Protein), PEPTIDE = "Run summary", TRANSITION = "Run summary", FEATURE = "Run summary", - LABEL = "Endogenous", RUN = RUN, + LABEL = summary_label, RUN = RUN, ABUNDANCE = LogIntensities, FRACTION = 1, UPPERBOUND = if("Variance" %in% names(.SD)) LogIntensities + 1.96 * sqrt(Variance) else NA_real_, # 95% confidence interval LOWERBOUND = if("Variance" %in% names(.SD)) LogIntensities - 1.96 * sqrt(Variance) else NA_real_ @@ -442,30 +444,32 @@ dataProcessPlots = function( processed[, RUN := factor(RUN, levels = unique(processed$RUN), labels = seq(1, data.table::uniqueN(processed$RUN)))] - if (length(unique(processed$LABEL)) == 2) { - processed[, LABEL := factor(LABEL, labels = c("Reference", "Endogenous"))] + if ("is_labeled_ref" %in% colnames(processed)) { + processed[, LABEL := factor( + ifelse(is_labeled_ref, "Reference", "Endogenous"), + levels = c("Reference", "Endogenous") + )] label.color = c("darkseagreen1", "lightblue") } else { - if (unique(processed$LABEL) == "L") { + label_levels = levels(factor(processed$LABEL)) + if (length(label_levels) == 2) { + processed[, LABEL := factor(LABEL, labels = c("Heavy", "Light"))] + label.color = c("darkseagreen1", "lightblue") + } else if ("L" %in% label_levels) { processed[, LABEL := factor(LABEL, labels = c("Endogenous"))] label.color = c("lightblue") } else { - processed[, LABEL := factor(LABEL, labels = c("Reference"))] + processed[, LABEL := factor(LABEL, labels = c("Heavy"))] label.color = c("darkseagreen1") } } processed = processed[order(LABEL, GROUP, SUBJECT)] - ## Meena :due to GROUP=0 for labeled.. extra care required. tempGroupName = unique(processed[, list(GROUP, RUN)]) - if (length(unique(processed$LABEL)) == 2) { - tempGroupName = tempGroupName[GROUP != '0'] - } - tempGroupName = tempGroupName[order(RUN), ] ## Meena : should we order by GROUP or RUN? I guess by RUn, because x-axis is by RUN + tempGroupName = tempGroupName[order(RUN), ] level.group = as.character(unique(tempGroupName$GROUP)) - tempGroupName$GROUP = factor(tempGroupName$GROUP, - levels = level.group) ## Meena : factor GROUP again, due to 1, 10, 2, ... if you have better way, please change + tempGroupName$GROUP = factor(tempGroupName$GROUP, levels = level.group) groupAxis = as.numeric(xtabs(~GROUP, tempGroupName)) cumGroupAxis = cumsum(groupAxis) diff --git a/R/utils_checks.R b/R/utils_checks.R index 601f1685..3596e74d 100644 --- a/R/utils_checks.R +++ b/R/utils_checks.R @@ -295,8 +295,8 @@ setMethod(".checkDataValidity", "MSstatsValidated", .prepareForDataProcess) skip_absent = TRUE) input[, FEATURE := paste(PEPTIDE, TRANSITION, sep = "_")] - input[, GROUP := ifelse(LABEL == "L", GROUP_ORIGINAL, "0")] - input[, SUBJECT := ifelse(LABEL == "L", SUBJECT_ORIGINAL, "0")] + input[, GROUP := GROUP_ORIGINAL] + input[, SUBJECT := SUBJECT_ORIGINAL] cols = c("PROTEIN", "PEPTIDE", "TRANSITION", "FEATURE", "LABEL", "GROUP_ORIGINAL", "SUBJECT_ORIGINAL", "RUN", "GROUP", diff --git a/inst/tinytest/processed_data/quant_data_srm.rds b/inst/tinytest/processed_data/quant_data_srm.rds index 9505b359..3edcd6d6 100644 Binary files a/inst/tinytest/processed_data/quant_data_srm.rds and b/inst/tinytest/processed_data/quant_data_srm.rds differ