Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions R/clean_Spectronaut.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
anomalyModelFeatures,
peptideSequenceColumn = "EG.ModifiedSequence",
heavyLabels = NULL) {
FFrgLossType = FExcludedFromQuantification = NULL
FFrgLossType = FExcludedFromQuantification = Fraction = NULL

spec_input = getInputFile(msstats_object, "input")
.validateSpectronautInput(spec_input, peptideSequenceColumn)
Expand All @@ -29,8 +29,8 @@

cols = c(protein_col, peptide_col, "FGCharge", "FFrgIon",
f_charge_col, "RFileName", "RCondition", "RReplicate",
"EGQvalue", pg_qval_col, interference_col, exclude_col,
intensity_col)
"RFraction", "EGQvalue", pg_qval_col, interference_col,
exclude_col, intensity_col)
if (calculateAnomalyScores){
cols = c(cols, anomalyModelFeatures)
}
Expand All @@ -41,11 +41,24 @@
spec_input,
c(protein_col, peptide_col, "FGCharge", "FFrgIon",
f_charge_col, "RFileName", intensity_col,
"RCondition", "RReplicate"),
"RCondition", "RReplicate", "RFraction"),
c("ProteinName", "PeptideSequence", "PrecursorCharge", "FragmentIon",
"ProductCharge", "Run", "Intensity", "Condition", "BioReplicate"),
"ProductCharge", "Run", "Intensity", "Condition", "BioReplicate",
"Fraction"),
skip_absent = TRUE)

if ("Fraction" %in% colnames(spec_input)) {
n_missing_fraction = sum(is.na(spec_input$Fraction))
if (n_missing_fraction > 0) {
msg = paste("**", n_missing_fraction,
"row(s) have missing (NA) values in the Fraction column.",
"These will be assigned to Fraction 1.")
getOption("MSstatsLog")("WARN", msg)
getOption("MSstatsMsg")("WARN", msg)
spec_input[is.na(Fraction), Fraction := 1]
}
}

spec_input = .assignSpectronautIsotopeLabelType(
spec_input, heavyLabels)

Expand Down
23 changes: 23 additions & 0 deletions inst/tinytest/test_clean_Spectronaut.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ output = MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'FG.MS
calculateAnomalyScores = FALSE,
anomalyModelFeatures = c())
expect_true(all(output$Intensity == 100000))
expect_false("Fraction" %in% colnames(output))

spectronaut_frac = data.table::copy(spectronaut_raw)
spectronaut_frac$R.Fraction = 2L
msstats_frac = MSstatsConvert::MSstatsImport(
list(input = spectronaut_frac), "MSstats", "Spectronaut")
output_frac = MSstatsConvert:::.cleanRawSpectronaut(msstats_frac, intensity = 'FG.MS1Quantity',
calculateAnomalyScores = FALSE,
anomalyModelFeatures = c())
expect_true("Fraction" %in% colnames(output_frac))
expect_false("RFraction" %in% colnames(output_frac))
expect_true(all(output_frac$Fraction == 2L))

spectronaut_frac_na = data.table::copy(spectronaut_raw)
spectronaut_frac_na$R.Fraction = NA_integer_
msstats_frac_na = MSstatsConvert::MSstatsImport(
list(input = spectronaut_frac_na), "MSstats", "Spectronaut")
output_frac_na = MSstatsConvert:::.cleanRawSpectronaut(msstats_frac_na, intensity = 'FG.MS1Quantity',
calculateAnomalyScores = FALSE,
anomalyModelFeatures = c())
expect_true("Fraction" %in% colnames(output_frac_na))
expect_false(any(is.na(output_frac_na$Fraction)))
expect_true(all(output_frac_na$Fraction == 1))

expect_error(MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'invalid',
calculateAnomalyScores = FALSE,
Expand Down
Loading