Skip to content

Commit 35fd8af

Browse files
authored
Add option to use MS1Quantity for quantifications for Spectronaut (#117)
1 parent 26b856e commit 35fd8af

7 files changed

Lines changed: 40 additions & 19 deletions

R/clean_Spectronaut.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#' Clean raw Spectronaut output.
22
#' @param msstats_object an object of class `MSstatsSpectronautFiles`.
3-
#' @param intensity chr, specifies which column will be used for Intensity.
4-
#' @param calculateAnomalyScores logical, whether to calculate anomaly scores
5-
#' @param anomalyModelFeatures character vector, specifies which columns will be used for anomaly detection model. Can be NULL if calculateAnomalyScores=FALSE.
3+
#' @inheritParams SpectronauttoMSstatsFormat
64
#' @return `data.table`
75
#' @keywords internal
86
.cleanRawSpectronaut = function(msstats_object, intensity,
@@ -20,10 +18,17 @@
2018
colnames(spec_input))
2119
exclude_col = .findAvailable(c("FExcludedFromQuantification"),
2220
colnames(spec_input))
21+
intensity_column_mapping = c(
22+
"PeakArea" = "FPeakArea",
23+
"NormalizedPeakArea" = "FNormalizedPeakArea",
24+
"MS1Quantity" = "FGMS1Quantity"
25+
)
26+
intensity = match.arg(intensity, names(intensity_column_mapping))
27+
intensity_column = intensity_column_mapping[[intensity]]
2328
cols = c("PGProteinGroups", "EGModifiedSequence", "FGCharge", "FFrgIon",
2429
f_charge_col, "RFileName", "RCondition", "RReplicate",
2530
"EGQvalue", pg_qval_col, interference_col, exclude_col,
26-
paste0("F", intensity))
31+
intensity_column)
2732
if (calculateAnomalyScores){
2833
cols = c(cols, anomalyModelFeatures)
2934
}
@@ -32,7 +37,7 @@
3237
data.table::setnames(
3338
spec_input,
3439
c("PGProteinGroups", "EGModifiedSequence", "FGCharge", "FFrgIon",
35-
f_charge_col, "RFileName", paste0("F", intensity),
40+
f_charge_col, "RFileName", intensity_column,
3641
"RCondition", "RReplicate"),
3742
c("ProteinName", "PeptideSequence", "PrecursorCharge", "FragmentIon",
3843
"ProductCharge", "Run", "Intensity", "Condition", "BioReplicate"),

R/converters_SpectronauttoMSstatsFormat.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#'
33
#' @param input name of Spectronaut output, which is long-format. ProteinName, PeptideSequence, PrecursorCharge, FragmentIon, ProductCharge, IsotopeLabelType, Condition, BioReplicate, Run, Intensity, F.ExcludedFromQuantification are required. Rows with F.ExcludedFromQuantification=True will be removed.
44
#' @param annotation name of 'annotation.txt' data which includes Condition, BioReplicate, Run. If annotation is already complete in Spectronaut, use annotation=NULL (default). It will use the annotation information from input.
5-
#' @param intensity 'PeakArea'(default) uses not normalized peak area. 'NormalizedPeakArea' uses peak area normalized by Spectronaut.
5+
#' @param intensity 'PeakArea'(default) uses not normalized MS2 peak area. 'NormalizedPeakArea' uses MS2 peak area normalized by Spectronaut.
6+
#' 'MS1Quantity' uses MS1 level quantification, which should be used if MS2 is unreliable.
67
#' @param excludedFromQuantificationFilter Remove rows with F.ExcludedFromQuantification=TRUE Default is TRUE.
78
#' @param filter_with_Qvalue FALSE(default) will not perform any filtering. TRUE will filter out the intensities that have greater than qvalue_cutoff in EG.Qvalue column. Those intensities will be replaced with zero and will be considered as censored missing values for imputation purpose.
89
#' @param qvalue_cutoff Cutoff for EG.Qvalue. default is 0.01.
@@ -32,7 +33,8 @@
3233
#' head(spectronaut_imported)
3334
#'
3435
SpectronauttoMSstatsFormat = function(
35-
input, annotation = NULL, intensity = 'PeakArea',
36+
input, annotation = NULL,
37+
intensity = c('PeakArea', 'NormalizedPeakArea', 'MS1Quantity'),
3638
excludedFromQuantificationFilter = TRUE,
3739
filter_with_Qvalue = FALSE, qvalue_cutoff = 0.01,
3840
useUniquePeptide = TRUE, removeFewMeasurements=TRUE,

R/utils_checks.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@
152152
}
153153
}
154154

155-
# Intensity validation (if provided)
156-
if (!is.null(config$intensity)) {
157-
checkmate::assertString(config$intensity)
158-
}
159-
160155
# Q-value filtering parameters
161156
checkmate::assertLogical(config$filter_with_Qvalue, len = 1)
162157
checkmate::assertNumber(config$qvalue_cutoff, lower = 0, upper = 1)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Test intensity parameter
2+
spectronaut_raw = system.file("tinytest/raw_data/Spectronaut/spectronaut_input.csv",
3+
package = "MSstatsConvert")
4+
spectronaut_raw = data.table::fread(spectronaut_raw)
5+
spectronaut_raw$FG.MS1Quantity = 100000
6+
msstats_input = MSstatsConvert::MSstatsImport(
7+
list(input = spectronaut_raw), "MSstats", "Spectronaut")
8+
output = MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'MS1Quantity',
9+
calculateAnomalyScores = FALSE,
10+
anomalyModelFeatures = c())
11+
expect_true(all(output$Intensity == 100000))
12+
13+
expect_error(MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'invalid',
14+
calculateAnomalyScores = FALSE,
15+
anomalyModelFeatures = c()),
16+
pattern = "'arg' should be one of .*PeakArea")

man/MSstatsClean.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/SpectronauttoMSstatsFormat.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dot-cleanRawSpectronaut.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)