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
15 changes: 10 additions & 5 deletions R/clean_Spectronaut.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' Clean raw Spectronaut output.
#' @param msstats_object an object of class `MSstatsSpectronautFiles`.
#' @param intensity chr, specifies which column will be used for Intensity.
#' @param calculateAnomalyScores logical, whether to calculate anomaly scores
#' @param anomalyModelFeatures character vector, specifies which columns will be used for anomaly detection model. Can be NULL if calculateAnomalyScores=FALSE.
#' @inheritParams SpectronauttoMSstatsFormat
#' @return `data.table`
#' @keywords internal
.cleanRawSpectronaut = function(msstats_object, intensity,
Expand All @@ -20,10 +18,17 @@
colnames(spec_input))
exclude_col = .findAvailable(c("FExcludedFromQuantification"),
colnames(spec_input))
intensity_column_mapping = c(
"PeakArea" = "FPeakArea",
"NormalizedPeakArea" = "FNormalizedPeakArea",
"MS1Quantity" = "FGMS1Quantity"
)
intensity = match.arg(intensity, names(intensity_column_mapping))
intensity_column = intensity_column_mapping[[intensity]]
cols = c("PGProteinGroups", "EGModifiedSequence", "FGCharge", "FFrgIon",
f_charge_col, "RFileName", "RCondition", "RReplicate",
"EGQvalue", pg_qval_col, interference_col, exclude_col,
paste0("F", intensity))
intensity_column)
if (calculateAnomalyScores){
cols = c(cols, anomalyModelFeatures)
}
Expand All @@ -32,7 +37,7 @@
data.table::setnames(
spec_input,
c("PGProteinGroups", "EGModifiedSequence", "FGCharge", "FFrgIon",
f_charge_col, "RFileName", paste0("F", intensity),
f_charge_col, "RFileName", intensity_column,
"RCondition", "RReplicate"),
c("ProteinName", "PeptideSequence", "PrecursorCharge", "FragmentIon",
"ProductCharge", "Run", "Intensity", "Condition", "BioReplicate"),
Expand Down
6 changes: 4 additions & 2 deletions R/converters_SpectronauttoMSstatsFormat.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#'
#' @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.
#' @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.
#' @param intensity 'PeakArea'(default) uses not normalized peak area. 'NormalizedPeakArea' uses peak area normalized by Spectronaut.
#' @param intensity 'PeakArea'(default) uses not normalized MS2 peak area. 'NormalizedPeakArea' uses MS2 peak area normalized by Spectronaut.
#' 'MS1Quantity' uses MS1 level quantification, which should be used if MS2 is unreliable.
#' @param excludedFromQuantificationFilter Remove rows with F.ExcludedFromQuantification=TRUE Default is TRUE.
#' @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.
#' @param qvalue_cutoff Cutoff for EG.Qvalue. default is 0.01.
Expand Down Expand Up @@ -32,7 +33,8 @@
#' head(spectronaut_imported)
#'
SpectronauttoMSstatsFormat = function(
input, annotation = NULL, intensity = 'PeakArea',
input, annotation = NULL,
intensity = c('PeakArea', 'NormalizedPeakArea', 'MS1Quantity'),
excludedFromQuantificationFilter = TRUE,
filter_with_Qvalue = FALSE, qvalue_cutoff = 0.01,
useUniquePeptide = TRUE, removeFewMeasurements=TRUE,
Expand Down
5 changes: 0 additions & 5 deletions R/utils_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@
}
}

# Intensity validation (if provided)
if (!is.null(config$intensity)) {
checkmate::assertString(config$intensity)
}

# Q-value filtering parameters
checkmate::assertLogical(config$filter_with_Qvalue, len = 1)
checkmate::assertNumber(config$qvalue_cutoff, lower = 0, upper = 1)
Expand Down
16 changes: 16 additions & 0 deletions inst/tinytest/test_clean_Spectronaut.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test intensity parameter
spectronaut_raw = system.file("tinytest/raw_data/Spectronaut/spectronaut_input.csv",
package = "MSstatsConvert")
spectronaut_raw = data.table::fread(spectronaut_raw)
spectronaut_raw$FG.MS1Quantity = 100000
msstats_input = MSstatsConvert::MSstatsImport(
list(input = spectronaut_raw), "MSstats", "Spectronaut")
output = MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'MS1Quantity',
calculateAnomalyScores = FALSE,
anomalyModelFeatures = c())
expect_true(all(output$Intensity == 100000))

expect_error(MSstatsConvert:::.cleanRawSpectronaut(msstats_input, intensity = 'invalid',
calculateAnomalyScores = FALSE,
anomalyModelFeatures = c()),
pattern = "'arg' should be one of .*PeakArea")
7 changes: 4 additions & 3 deletions man/MSstatsClean.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/SpectronauttoMSstatsFormat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/dot-cleanRawSpectronaut.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading