-
Notifications
You must be signed in to change notification settings - Fork 10
feat(spectronaut): Add annotation and run order uploads for large spectronaut uploads #212
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
Merged
tonywu1999
merged 7 commits into
devel
from
MSstatsShiny/work/20260526_bigspectronaut_annotation_upload
May 26, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3f7ff4
feat(loadpage): Wire annotation upload + anomaly carry-through for bi…
tonywu1999 7656f9f
feat(loadpage): Add post-collect MSstatsAnomalyScores call to big-fil…
tonywu1999 fe8d2cf
feat(loadpage): Make Spectronaut intensity column a universal input
tonywu1999 5422a9e
fix(loadpage): Consolidate calculate_anomaly_scores namespace across …
tonywu1999 f1a6142
fix(loadpage): Fail-fast when run order is missing in big-file mode
tonywu1999 732350d
fix(loadpage): Fail-fast on missing run order in regular Spectronaut …
tonywu1999 e0aad58
fix(loadpage): Remove modal spinner before regular-path validation NU…
tonywu1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -639,11 +639,23 @@ getData <- function(input) { | |
| shinybusy::remove_modal_spinner() | ||
| return(NULL) | ||
| } | ||
|
|
||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores) && is.null(input$run_order_file)) { | ||
| showNotification( | ||
| "Error: Run Order CSV is required when Calculate Anomaly Scores is enabled. Please upload a CSV with Run and Order columns.", | ||
| type = "error", | ||
| duration = NULL) | ||
| shinybusy::remove_modal_spinner() | ||
| return(NULL) | ||
| } | ||
|
|
||
| shinybusy::update_modal_spinner(text = "Processing large Spectronaut file...") | ||
|
|
||
| # Call the big file conversion function from MSstatsConvert | ||
| converted_data <- MSstatsBig::bigSpectronauttoMSstatsFormat( | ||
|
|
||
| # Base arguments shared by every large-file Spectronaut run. | ||
| # Optional args (annotation override, anomaly-feature | ||
| # carry-through) are spliced in below so callers that don't | ||
| # supply them aren't forced to pass NULL / FALSE explicitly. | ||
| big_spec_args <- list( | ||
| input_file = local_big_file_path, | ||
| output_file_name = "output_file.csv", | ||
| backend = "arrow", | ||
|
|
@@ -656,6 +668,27 @@ getData <- function(input) { | |
| aggregate_psms = input$aggregate_psms, | ||
| filter_few_obs = input$filter_few_obs | ||
| ) | ||
|
|
||
| if (!is.null(input$spec_intensity_col) && | ||
| nchar(trimws(input$spec_intensity_col)) > 0) { | ||
| big_spec_args$intensity <- trimws(input$spec_intensity_col) | ||
| } | ||
|
|
||
| if (!is.null(input$big_spec_annotation)) { | ||
| big_spec_args$annotation <- data.table::fread( | ||
| input$big_spec_annotation$datapath) | ||
| } | ||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores)) { | ||
| big_spec_args$calculateAnomalyScores <- TRUE | ||
| big_spec_args$anomalyModelFeatures <- c( | ||
| "FG.ShapeQualityScore (MS2)", | ||
| "FG.ShapeQualityScore (MS1)", | ||
| "EG.DeltaRT") | ||
| } | ||
|
|
||
| converted_data <- do.call( | ||
| MSstatsBig::bigSpectronauttoMSstatsFormat, big_spec_args) | ||
|
|
||
| # Attempt to load the data into memory. | ||
| mydata <- tryCatch({ | ||
|
|
@@ -673,8 +706,37 @@ getData <- function(input) { | |
| shinybusy::remove_modal_spinner() | ||
| return(NULL) | ||
| } | ||
|
|
||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores) && | ||
| !is.null(input$run_order_file)) { | ||
| run_order <- data.table::fread(input$run_order_file$datapath) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| mydata <- MSstatsConvert::MSstatsAnomalyScores( | ||
| input = mydata, | ||
| quality_metrics = c("FGShapeQualityScore(MS2)", | ||
| "FGShapeQualityScore(MS1)", | ||
| "EGDeltaRT"), | ||
| temporal_direction = c("mean_decrease", | ||
| "mean_decrease", | ||
| "dispersion_increase"), | ||
| missing_run_count = 0.5, | ||
| n_feat = 100, | ||
| run_order = run_order, | ||
| n_trees = 100, | ||
| max_depth = "auto", | ||
| cores = 1) | ||
| } | ||
|
|
||
| } else { | ||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores) && is.null(input$run_order_file)) { | ||
|
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. Duplicate validations, only one is needed if possible. |
||
| showNotification( | ||
| "Error: Run Order CSV is required when Calculate Anomaly Scores is enabled. Please upload a CSV with Run and Order columns.", | ||
| type = "error", | ||
| duration = NULL) | ||
| remove_modal_spinner() | ||
| return(NULL) | ||
| } | ||
|
|
||
| data = data.table::fread(input$specdata$datapath) | ||
| # Base arguments for the Spectronaut converter | ||
| converter_args = list( | ||
|
|
@@ -958,14 +1020,87 @@ library(MSstatsPTM)\n", sep = "") | |
| } | ||
| else if(input$filetype == 'spec') { | ||
|
|
||
| if (isTRUE(input$big_file_spec)) { | ||
| codes = paste(codes, | ||
| "# Large-file (out-of-memory) Spectronaut path.\n", | ||
| "input_file = \"insert your raw Spectronaut export filepath\"\n", | ||
| sep = "") | ||
|
|
||
| big_spec_extra <- "" | ||
| if (!is.null(input$spec_intensity_col) && | ||
| nchar(trimws(input$spec_intensity_col)) > 0) { | ||
| big_spec_extra <- paste0(big_spec_extra, | ||
| ",\n intensity = \"", | ||
| trimws(input$spec_intensity_col), "\"") | ||
| } | ||
| if (!is.null(input$big_spec_annotation)) { | ||
| codes = paste(codes, | ||
| "annot_file = data.table::fread(\"insert your annotation filepath (Run, BioReplicate, Condition)\")\n", | ||
| sep = "") | ||
| big_spec_extra <- paste0(big_spec_extra, | ||
| ",\n annotation = annot_file") | ||
| } | ||
| if (isTRUE(input$calculate_anomaly_scores)) { | ||
| big_spec_extra <- paste0(big_spec_extra, | ||
| ",\n calculateAnomalyScores = TRUE", | ||
| ",\n anomalyModelFeatures = c(\"FG.ShapeQualityScore (MS2)\", \"FG.ShapeQualityScore (MS1)\", \"EG.DeltaRT\")") | ||
| } | ||
|
|
||
| codes = paste(codes, | ||
| "converted = MSstatsBig::bigSpectronauttoMSstatsFormat(input_file, | ||
| output_file_name = \"output_file.csv\", | ||
| backend = \"arrow\", | ||
| filter_by_excluded = ", input$filter_by_excluded, ", | ||
| filter_by_identified = ", input$filter_by_identified, ", | ||
| filter_by_qvalue = ", input$filter_by_qvalue, ", | ||
| qvalue_cutoff = ", input$qvalue_cutoff, ", | ||
| max_feature_count = ", input$max_feature_count, ", | ||
| filter_unique_peptides = ", input$filter_unique_peptides, ", | ||
| aggregate_psms = ", input$aggregate_psms, ", | ||
| filter_few_obs = ", input$filter_few_obs, | ||
| big_spec_extra, | ||
| ")\ndata = dplyr::collect(converted)\n", | ||
| sep = "") | ||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores)) { | ||
| codes = paste(codes, | ||
| "# Step 2 of the anomaly scoring pipeline: fit the\n", | ||
| "# isolation-forest model on the collected data and\n", | ||
| "# add an AnomalyScores column.\n", | ||
| "run_order = data.table::fread(\"insert your run order CSV filepath (Run, Order columns)\")\n", | ||
| "data = MSstatsConvert::MSstatsAnomalyScores(\n", | ||
| " input = data,\n", | ||
| " # Standardized column names (raw Spectronaut names\n", | ||
| " # had `.` and ` ` stripped during the converter step).\n", | ||
| " quality_metrics = c(\"FGShapeQualityScore(MS2)\", \"FGShapeQualityScore(MS1)\", \"EGDeltaRT\"),\n", | ||
| " temporal_direction = c(\"mean_decrease\", \"mean_decrease\", \"dispersion_increase\"),\n", | ||
| " missing_run_count = 0.5,\n", | ||
| " n_feat = 100,\n", | ||
| " run_order = run_order,\n", | ||
| " n_trees = 100,\n", | ||
| " max_depth = \"auto\",\n", | ||
| " cores = 1)\n", | ||
| sep = "") | ||
| } | ||
|
|
||
| } else { | ||
|
|
||
| codes = paste(codes, "data = data.table::fread(\"insert your MSstats scheme output from Spectronaut filepath\")\nannot_file = data.table::fread(\"insert your annotation filepath\")#Optional\n" | ||
| , sep = "") | ||
|
|
||
| reg_spec_intensity_arg <- if (!is.null(input$spec_intensity_col) && | ||
| nchar(trimws(input$spec_intensity_col)) > 0) { | ||
| paste0(" intensity = \"", | ||
| trimws(input$spec_intensity_col), "\",\n") | ||
| } else { | ||
| "" | ||
| } | ||
|
|
||
| if (isTRUE(input$calculate_anomaly_scores)) { | ||
| codes = paste(codes, "run_order = data.table::fread(\"insert your run order CSV filepath (Run, Order columns)\")\n", sep = "") | ||
| codes = paste(codes, "data = SpectronauttoMSstatsFormat(data, | ||
| annotation = annot_file, #Optional | ||
| filter_with_Qvalue = ", input$q_val, ", | ||
| ", reg_spec_intensity_arg, " filter_with_Qvalue = ", input$q_val, ", | ||
| qvalue_cutoff = ", input$q_cutoff, ", | ||
| removeProtein_with1Feature = ", input$remove, ", | ||
| use_log_file = FALSE, | ||
|
|
@@ -979,11 +1114,13 @@ library(MSstatsPTM)\n", sep = "") | |
| } else { | ||
| codes = paste(codes, "data = SpectronauttoMSstatsFormat(data, | ||
| annotation = annot_file, #Optional | ||
| filter_with_Qvalue = ", input$q_val, ", | ||
| ", reg_spec_intensity_arg, " filter_with_Qvalue = ", input$q_val, ", | ||
| qvalue_cutoff = ", input$q_cutoff, ", | ||
| removeProtein_with1Feature = ", input$remove, ", | ||
| use_log_file = FALSE)\n", sep = "") | ||
| } | ||
|
|
||
| } | ||
| } | ||
| else if(input$filetype == 'diann') { | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think this is necessary. i think one can just re-use the annotation file and run order upload panels for regular spectronaut