-
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 all 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 |
|---|---|---|
|
|
@@ -401,7 +401,7 @@ MSstatsSummarizeSingleLinear = function(single_protein, | |
|
|
||
| if (impute & any(single_protein[["censored"]])) { | ||
| fit_data = if (is_labeled_reference) { | ||
| single_protein[is_labeled_ref == FALSE, cols, with = FALSE] | ||
| single_protein[(!is_labeled_ref), cols, with = FALSE] | ||
| } else { | ||
| single_protein[, cols, with = FALSE] | ||
| } | ||
|
|
@@ -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), predicted := NA] | ||
| single_protein[(censored) & !is_labeled_ref, | ||
| 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), | ||
|
|
@@ -547,7 +547,7 @@ MSstatsSummarizeSingleTMP = function(single_protein, impute, censored_symbol, | |
| converged = TRUE | ||
|
|
||
| fit_data = if (is_labeled_reference) { | ||
| single_protein[is_labeled_ref == FALSE, cols, with = FALSE] | ||
| single_protein[(!is_labeled_ref), cols, with = FALSE] | ||
| } else { | ||
| single_protein[, cols, with = FALSE] | ||
| } | ||
|
|
@@ -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), predicted := NA] | ||
| single_protein[(censored) & !is_labeled_ref, | ||
| 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 |
|---|---|---|
|
|
@@ -170,7 +170,7 @@ MSstatsPrepareForDataProcess = function(input, log_base, fix_missing) { | |
| input = data.table::as.data.table(unclass(input)) | ||
|
|
||
| if (!"AnomalyScores" %in% colnames(input)){ | ||
| input$AnomalyScores = NA | ||
| data.table::set(input, j = "AnomalyScores", value = NA) | ||
|
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. Use Using plain After column names are uppercased at line 198, the check at line 317 will find the column already exists and skip the Proposed fix- data.table::set(input, j = "AnomalyScores", value = NA)
+ data.table::set(input, j = "AnomalyScores", value = NA_real_)🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| cols = c("ProteinName", "PeptideSequence", "PeptideModifiedSequence", | ||
|
|
@@ -200,7 +200,8 @@ MSstatsPrepareForDataProcess = function(input, log_base, fix_missing) { | |
|
|
||
| if (!is.numeric(input$INTENSITY)) { | ||
| suppressWarnings({ | ||
| input$INTENSITY = as.numeric(as.character(input$INTENSITY)) | ||
| data.table::set(input, j = "INTENSITY", | ||
| value = as.numeric(as.character(input$INTENSITY))) | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -211,12 +212,15 @@ 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, | ||
| input$PRECURSORCHARGE, sep = "_") | ||
| input$TRANSITION = paste(input$FRAGMENTION, | ||
| input$PRODUCTCHARGE, sep = "_") | ||
| drop_cols = setdiff(colnames(input), cols) | ||
| for (col in drop_cols) data.table::set(input, j = col, value = NULL) | ||
|
|
||
| data.table::set(input, j = "PEPTIDE", | ||
| value = paste(input$PEPTIDESEQUENCE, | ||
| input$PRECURSORCHARGE, sep = "_")) | ||
| data.table::set(input, j = "TRANSITION", | ||
| value = paste(input$FRAGMENTION, | ||
| input$PRODUCTCHARGE, sep = "_")) | ||
|
|
||
| if (data.table::uniqueN(input$ISOTOPELABELTYPE) > 2) { | ||
| getOption("MSstatsLog")( | ||
|
|
@@ -226,7 +230,8 @@ MSstatsPrepareForDataProcess = function(input, log_base, fix_missing) { | |
| stop("Statistical tools in MSstats are only proper for label-free or with reference peptide experiments.") | ||
| } | ||
|
|
||
| input$ISOTOPELABELTYPE <- .mapIsotopeLabelType(input$ISOTOPELABELTYPE) | ||
| data.table::set(input, j = "ISOTOPELABELTYPE", | ||
| value = .mapIsotopeLabelType(input$ISOTOPELABELTYPE)) | ||
| input | ||
| } | ||
|
|
||
|
|
@@ -242,9 +247,14 @@ MSstatsPrepareForDataProcess = function(input, log_base, fix_missing) { | |
| data.table::setnames( | ||
| input, "PEPTIDEMODIFIEDSEQUENCE", "PEPTIDESEQUENCE") | ||
| } | ||
| input$PEPTIDE = paste(input$PEPTIDESEQUENCE, input$PRECURSORCHARGE, sep = "_") | ||
| input$TRANSITION = paste(input$FRAGMENTION, input$PRODUCTCHARGE, sep = "_") | ||
| input$ISOTOPELABELTYPE <- .mapIsotopeLabelType(input$ISOTOPELABELTYPE) | ||
| data.table::set(input, j = "PEPTIDE", | ||
| value = paste(input$PEPTIDESEQUENCE, | ||
| input$PRECURSORCHARGE, sep = "_")) | ||
| data.table::set(input, j = "TRANSITION", | ||
| value = paste(input$FRAGMENTION, | ||
| input$PRODUCTCHARGE, sep = "_")) | ||
| data.table::set(input, j = "ISOTOPELABELTYPE", | ||
| value = .mapIsotopeLabelType(input$ISOTOPELABELTYPE)) | ||
| input | ||
| } | ||
|
|
||
|
|
@@ -322,8 +332,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)] | ||
|
|
||
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