-
Notifications
You must be signed in to change notification settings - Fork 52
Removed deep-copy data.table ops from the dataProcess pipeline #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from 3 commits
16edbd5
b64b004
e2bd771
65df2b5
0764b34
27d5f7c
50a30da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -414,19 +414,19 @@ MSstatsSummarizeSingleLinear = function(single_protein, | |
| }] | ||
|
|
||
| if (is_labeled_reference) { | ||
| single_protein[, predicted := ifelse(censored & is_labeled_ref == FALSE, predicted, NA)] | ||
| single_protein[, newABUNDANCE := ifelse(censored & is_labeled_ref == FALSE, predicted, newABUNDANCE)] | ||
| single_protein[!(censored & is_labeled_ref == FALSE), predicted := NA] | ||
| single_protein[(censored) & is_labeled_ref == FALSE, | ||
| newABUNDANCE := predicted] | ||
| } else { | ||
| single_protein[, predicted := ifelse(censored, predicted, NA)] | ||
| single_protein[, newABUNDANCE := ifelse(censored, predicted, newABUNDANCE)] | ||
| single_protein[!(censored), predicted := NA] | ||
| single_protein[(censored), newABUNDANCE := predicted] | ||
| } | ||
|
|
||
| survival = single_protein[, intersect(c(cols, "LABEL", "predicted"), colnames(single_protein)), with = FALSE] | ||
| } else { | ||
| survival = single_protein[, intersect(c(cols, "LABEL"), colnames(single_protein)), with = FALSE] | ||
| survival[, predicted := NA] | ||
| } | ||
|
|
||
| if (all(!is.na(single_protein$ANOMALYSCORES))) { | ||
| single_protein[, weights := | ||
| anomaly_weights_z_vec(ANOMALYSCORES), | ||
|
|
@@ -569,11 +569,13 @@ MSstatsSummarizeSingleTMP = function(single_protein, impute, censored_symbol, | |
| } | ||
|
|
||
| if (is_labeled_reference) { | ||
| single_protein[, predicted := ifelse(censored & is_labeled_ref == FALSE, predicted, NA)] | ||
| single_protein[, newABUNDANCE := ifelse(censored & is_labeled_ref == FALSE, predicted, newABUNDANCE)] | ||
| single_protein[!(censored & is_labeled_ref == FALSE), predicted := NA] | ||
| single_protein[(censored) & is_labeled_ref == FALSE, | ||
| newABUNDANCE := predicted] | ||
| } else { | ||
| single_protein[, predicted := ifelse(censored, predicted, NA)] | ||
| single_protein[, newABUNDANCE := ifelse(censored, predicted, newABUNDANCE)] | ||
| single_protein[!(censored), predicted := NA] | ||
| single_protein[(censored), | ||
| newABUNDANCE := predicted] | ||
| } | ||
| survival = single_protein[, intersect(c(cols, "LABEL", "predicted"), colnames(single_protein)), with = FALSE] | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save as above
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,9 +211,10 @@ MSstatsPrepareForDataProcess = function(input, log_base, fix_missing) { | |
| cols = toupper(cols) | ||
| cols = intersect(c(cols, "FRACTION", "TECHREPLICATE"), | ||
| colnames(input)) | ||
| input = input[, cols, with = FALSE] | ||
|
|
||
| input$PEPTIDE = paste(input$PEPTIDESEQUENCE, | ||
| drop_cols = setdiff(colnames(input), cols) | ||
| for (col in drop_cols) data.table::set(input, j = col, value = NULL) | ||
|
|
||
| input$PEPTIDE = paste(input$PEPTIDESEQUENCE, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "$" assignments should go. Line 215 is the way to go |
||
| input$PRECURSORCHARGE, sep = "_") | ||
| input$TRANSITION = paste(input$FRAGMENTION, | ||
| input$PRODUCTCHARGE, sep = "_") | ||
|
|
@@ -322,8 +323,8 @@ setMethod(".checkDataValidity", "MSstatsValidated", .prepareForDataProcess) | |
| input[, PROTEIN := factor(PROTEIN)] | ||
| input[, PEPTIDE := factor(PEPTIDE)] | ||
| input[, TRANSITION := factor(TRANSITION)] | ||
| input = input[order(LABEL, GROUP_ORIGINAL, SUBJECT_ORIGINAL, | ||
| RUN, PROTEIN, PEPTIDE, TRANSITION), ] | ||
| data.table::setorder(input, LABEL, GROUP_ORIGINAL, SUBJECT_ORIGINAL, | ||
| RUN, PROTEIN, PEPTIDE, TRANSITION) | ||
| input[, GROUP := factor(GROUP)] | ||
| input[, SUBJECT := factor(SUBJECT)] | ||
| input[, FEATURE := factor(FEATURE)] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,13 +34,20 @@ | |
| #' output = output = MSstatsSummarizationOutput(input, summarized, processed, | ||
| #' method, impute, cens) | ||
| #' | ||
| MSstatsSummarizationOutput = function(input, summarized, processed, | ||
| MSstatsSummarizationOutput = function(input, summarized, processed, | ||
| method, impute, censored_symbol) { | ||
| LABEL = TotalGroupMeasurements = GROUP = Protein = RUN = NULL | ||
|
|
||
| input = .finalizeInput(input, summarized, method, impute, censored_symbol) | ||
| summarized = lapply(summarized, function(x) x[[1]]) | ||
| summarized = data.table::rbindlist(summarized, fill = TRUE) | ||
|
|
||
| predicted_survival = data.table::rbindlist(lapply(summarized, function(x) x[[2]]), | ||
| fill = TRUE) | ||
| for (i in seq_along(summarized)) summarized[[i]][[2]] = NULL | ||
| input = .finalizeInput(input, predicted_survival, method, impute, censored_symbol) | ||
| rm(predicted_survival) | ||
| protein_summaries = lapply(summarized, function(x) x[[1]]) | ||
| rm(summarized) | ||
| summarized = data.table::rbindlist(protein_summaries, fill = TRUE) | ||
| rm(protein_summaries) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (inherits(summarized, "try-error")) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does summarized inherit try-error here if there's no try-catch block for line 48?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I don't see a try-catch clause in the summarization code. Is there even a useful place for it there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it with: if (is.null(summarized)) |
||
| msg = paste("*** error : can't summarize per subplot with ", | ||
| method, ".") | ||
|
|
@@ -82,18 +89,21 @@ MSstatsSummarizationOutput = function(input, summarized, processed, | |
| "originalRUN", "censored", "INTENSITY", "ABUNDANCE", | ||
| "newABUNDANCE", "predicted", "feature_quality", | ||
| "is_outlier", "remove", "is_labeled_ref"), colnames(input)) | ||
| input = input[, output_cols, with = FALSE] | ||
|
|
||
| drop_cols = setdiff(colnames(input), output_cols) | ||
| for (col in drop_cols) data.table::set(input, j = col, value = NULL) | ||
|
|
||
| if (is.element("remove", colnames(processed))) { | ||
| processed = processed[(remove), | ||
| intersect(output_cols, | ||
| processed = processed[(remove), | ||
| intersect(output_cols, | ||
| colnames(processed)), with = FALSE] | ||
| input = rbind(input, processed, fill = TRUE) | ||
| } | ||
| list(FeatureLevelData = as.data.frame(input), | ||
| ProteinLevelData = as.data.frame(rqall), | ||
| data.table::setDF(input) | ||
| data.table::setDF(rqall) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| list(FeatureLevelData = input, | ||
| ProteinLevelData = rqall, | ||
| SummaryMethod = method) | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
@@ -104,9 +114,9 @@ MSstatsSummarizationOutput = function(input, summarized, processed, | |
| #' @param impute if TRUE, censored missing values were imputed | ||
| #' @param censored_symbol censored missing value indicator | ||
| #' @keywords internal | ||
| .finalizeInput = function(input, summarized, method, impute, censored_symbol) { | ||
| .finalizeInput = function(input, predicted_survival, method, impute, censored_symbol) { | ||
| # if (method == "TMP") { | ||
| input = .finalizeTMP(input, censored_symbol, impute, summarized) | ||
| input = .finalizeTMP(input, censored_symbol, impute, predicted_survival) | ||
| # } else { | ||
| # input = .finalizeLinear(input, censored_symbol) | ||
| # } | ||
|
|
@@ -117,21 +127,23 @@ MSstatsSummarizationOutput = function(input, summarized, processed, | |
| #' Summary statistics for output of TMP-based summarization | ||
| #' @inheritParams .finalizeInput | ||
| #' @keywords internal | ||
| .finalizeTMP = function(input, censored_symbol, impute, summarized) { | ||
| .finalizeTMP = function(input, censored_symbol, impute, predicted_survival) { | ||
| NonMissingStats = NumMeasuredFeature = MissingPercentage = LABEL = NULL | ||
| total_features = more50missing = nonmissing_orig = censored = NULL | ||
| INTENSITY = newABUNDANCE = NumImputedFeature = NULL | ||
|
|
||
| survival_predictions = lapply(summarized, function(x) x[[2]]) | ||
| predicted_survival = data.table::rbindlist(survival_predictions, fill = TRUE) | ||
|
|
||
| if (impute) { | ||
| cols = intersect(colnames(input), c("newABUNDANCE", | ||
| "cen", "RUN", | ||
| "FEATURE", "ref_covariate", "LABEL")) | ||
| input = merge(input[, colnames(input) != "newABUNDANCE", with = FALSE], | ||
| predicted_survival, | ||
| by = setdiff(cols, "newABUNDANCE"), | ||
| all.x = TRUE) | ||
| join_cols = intersect(intersect(colnames(input), | ||
| colnames(predicted_survival)), | ||
| c("cen", "RUN", "FEATURE", "ref_covariate", | ||
| "LABEL")) | ||
| data.table::set(input, j = "newABUNDANCE", value = NULL) | ||
| idx = predicted_survival[input, on = join_cols, which = TRUE, | ||
| mult = "first"] | ||
| data.table::set(input, j = "newABUNDANCE", | ||
| value = predicted_survival$newABUNDANCE[idx]) | ||
| data.table::set(input, j = "predicted", | ||
| value = predicted_survival$predicted[idx]) | ||
| } | ||
| input[, NonMissingStats := .getNonMissingFilterStats(.SD, censored_symbol)] | ||
| input[, NumMeasuredFeature := sum(NonMissingStats), | ||
|
|
@@ -144,7 +156,7 @@ MSstatsSummarizationOutput = function(input, summarized, processed, | |
| } else { | ||
| input[, nonmissing_orig := !is.na(INTENSITY)] | ||
| } | ||
| input[, nonmissing_orig := ifelse(is.na(newABUNDANCE), TRUE, nonmissing_orig)] | ||
| input[is.na(newABUNDANCE), nonmissing_orig := TRUE] | ||
| if (impute) { | ||
| input[, NumImputedFeature := sum(!nonmissing_orig), | ||
| by = c("PROTEIN", "RUN", "LABEL")] | ||
|
|
@@ -175,7 +187,7 @@ MSstatsSummarizationOutput = function(input, summarized, processed, | |
| } else { | ||
| input[, nonmissing_orig := !is.na(INTENSITY)] | ||
| } | ||
| input[, nonmissing_orig := ifelse(is.na(newABUNDANCE), TRUE, nonmissing_orig)] | ||
| input[is.na(newABUNDANCE), nonmissing_orig := TRUE] | ||
| input[, NumImputedFeature := 0] | ||
| } | ||
| input | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done — replaced all six is_labeled_ref == FALSE comparisons with !is_labeled_ref (in both MSstatsSummarizeSingleLinear and MSstatsSummarizeSingleTMP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked with address() — single_protein[, keep, with = FALSE] does materialize a copy of the selected columns (they get new addresses, not shared). But it's a per-protein slice (a handful of columns × one protein's rows), not a whole-dataset copy, so the size is negligible relative to the copies this PR targets. It's also a necessary copy: survival is returned separately and, in the no-impute branch, gets survival[, predicted := NA] — sharing storage with single_protein would corrupt it. So I'd leave it as-is, but happy to revisit