Skip to content

Commit ee9286c

Browse files
authored
feat(Metamorpheus): Remove decoys in converter for Metamorpheus; Add qvalue filtering when MBR is enabled (#108)
1 parent 6017c8b commit ee9286c

12 files changed

Lines changed: 119 additions & 358 deletions

R/clean_Metamorpheus.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
#' Clean raw Metamorpheus files
22
#' @param msstats_object an object of class `MSstatsMetamorpheusFiles`.
3+
#' @param MBR If TRUE, the function will include peaks detected by MBR
4+
#' @param qvalue_cutoff The q-value cutoff for filtering peaks detected by MBR
35
#' @return data.table
46
#' @keywords internal
5-
.cleanRawMetamorpheus = function(msstats_object) {
7+
.cleanRawMetamorpheus = function(msstats_object, MBR = TRUE, qvalue_cutoff = 0.05) {
68
metamorpheus_input = getInputFile(msstats_object, "input")
79
metamorpheus_input = data.table::as.data.table(metamorpheus_input)
10+
# Remove peptide decoys
11+
if ("DecoyPeptide" %in% colnames(metamorpheus_input)) {
12+
metamorpheus_input <- metamorpheus_input[!metamorpheus_input$DecoyPeptide, ]
13+
}
14+
# Remove peak decoys
15+
if ("RandomRT" %in% colnames(metamorpheus_input)) {
16+
metamorpheus_input <- metamorpheus_input[!metamorpheus_input$RandomRT, ]
17+
}
18+
if (MBR) {
19+
metamorpheus_input = metamorpheus_input[
20+
metamorpheus_input$PeakDetectionType == "MSMS" |
21+
metamorpheus_input$`PIPQ-Value` <= qvalue_cutoff , ]
22+
} else {
23+
metamorpheus_input = metamorpheus_input[
24+
metamorpheus_input$PeakDetectionType == "MSMS", ]
25+
}
826
req_cols = c('FileName', 'ProteinGroup', 'FullSequence',
927
'PrecursorCharge', 'Peakintensity')
1028
metamorpheus_input = metamorpheus_input[, req_cols, with = FALSE]

R/converters_MetamorpheusToMSstatsFormat.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#' Import Metamorpheus files
22
#'
33
#' @param input name of Metamorpheus output file, which is tabular format. Use the AllQuantifiedPeaks.tsv file from the Metamorpheus output.
4-
#' @param annotation name of 'annotation.txt' data which includes Condition, BioReplicate.
4+
#' @param annotation name of 'annotation.txt' data which includes Condition, BioReplicate.
5+
#' @param MBR If TRUE, the function will include peaks detected by MBR
6+
#' @param qvalue_cutoff The q-value cutoff for filtering peaks detected by MBR
57
#' @inheritParams .sharedParametersAmongConverters
68
#'
79
#' @return data.frame in the MSstats required format.
@@ -11,17 +13,18 @@
1113
#' @export
1214
#'
1315
#' @examples
14-
#' input = system.file("tinytest/raw_data/Metamorpheus/AllQuantifiedPeaks.tsv",
16+
#' input = system.file("tinytest/raw_data/Metamorpheus/QuantifiedPeaks.tsv",
1517
#' package = "MSstatsConvert")
1618
#' input = data.table::fread(input)
17-
#' annot = system.file("tinytest/raw_data/Metamorpheus/Annotation.tsv",
19+
#' annot = system.file("tinytest/raw_data/Metamorpheus/annotation.csv",
1820
#' package = "MSstatsConvert")
1921
#' annot = data.table::fread(annot)
2022
#' metamorpheus_imported = MSstatsConvert:::MetamorpheusToMSstatsFormat(input, annotation = annot)
2123
#' head(metamorpheus_imported)
2224
#'
2325
MetamorpheusToMSstatsFormat = function(
24-
input, annotation = NULL, useUniquePeptide = TRUE, removeFewMeasurements = TRUE,
26+
input, annotation = NULL, MBR = TRUE, qvalue_cutoff = 0.05,
27+
useUniquePeptide = TRUE, removeFewMeasurements = TRUE,
2528
removeProtein_with1Feature = FALSE, summaryforMultipleRows = max,
2629
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL,
2730
...
@@ -31,7 +34,7 @@ MetamorpheusToMSstatsFormat = function(
3134

3235
input = MSstatsConvert::MSstatsImport(list(input = input),
3336
"MSstats", "Metamorpheus", ...)
34-
input = MSstatsConvert::MSstatsClean(input)
37+
input = MSstatsConvert::MSstatsClean(input, MBR, qvalue_cutoff)
3538
annotation = MSstatsConvert::MSstatsMakeAnnotation(input, annotation)
3639

3740
feature_columns = c("PeptideSequence", "PrecursorCharge")
Binary file not shown.

inst/tinytest/raw_data/Metamorpheus/AllQuantifiedPeaks.tsv

Lines changed: 0 additions & 339 deletions
This file was deleted.

inst/tinytest/raw_data/Metamorpheus/Annotation.tsv

Lines changed: 0 additions & 5 deletions
This file was deleted.

inst/tinytest/raw_data/Metamorpheus/QuantifiedPeaks.tsv

Lines changed: 67 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Run","BioReplicate","Condition"
2+
"B03_05_150304_human_ecoli_E_3ul_3um_column_95_HCD_OT_2hrs_30B_9B-calib",5,"E"
3+
"B03_06_150304_human_ecoli_E_3ul_3um_column_95_HCD_OT_2hrs_30B_9B-calib",6,"E"
4+
"B03_10_150304_human_ecoli_A_3ul_3um_column_95_HCD_OT_2hrs_30B_9B-calib",10,"A"
5+
"B03_11_150304_human_ecoli_A_3ul_3um_column_95_HCD_OT_2hrs_30B_9B-calib",11,"A"

inst/tinytest/test_cleanRaw.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,6 @@ expect_true(nrow(sn_cleaned) > 0)
211211
expect_equal(sn_cleaned, sn_cleaned2)
212212

213213
# Metamorpheus
214-
metamorpheus_table = data.table::fread("./raw_data/Metamorpheus/AllQuantifiedPeaks.tsv")
214+
metamorpheus_table = data.table::fread("./raw_data/Metamorpheus/QuantifiedPeaks.tsv")
215215
input = MSstatsConvert::MSstatsImport(list(input = metamorpheus_table), "MSstats", "Metamorpheus")
216216
expect_identical(is(input), c("MSstatsMetamorpheusFiles", "MSstatsInputFiles"))

inst/tinytest/test_converters_MetamorpheusToMSstatsFormat.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Test MetamorpheusToMSstatsFormat ---------------------------
22

3-
input_file_path = system.file("tinytest/raw_data/Metamorpheus/AllQuantifiedPeaks.tsv", package="MSstatsConvert")
4-
annotation_file_path = system.file("tinytest/raw_data/Metamorpheus/Annotation.tsv", package = "MSstatsConvert")
3+
input_file_path = system.file("tinytest/raw_data/Metamorpheus/QuantifiedPeaks.tsv", package="MSstatsConvert")
4+
annotation_file_path = system.file("tinytest/raw_data/Metamorpheus/annotation.csv", package = "MSstatsConvert")
55
input = data.table::fread(input_file_path)
66
annotation = data.table::fread(annotation_file_path)
77
output = MSstatsConvert:::MetamorpheusToMSstatsFormat(input, annotation = annotation)
88
expect_equal(ncol(output), 11)
9-
expect_equal(nrow(output), 236)
9+
expect_equal(nrow(output), 20)
1010
expect_true("Run" %in% colnames(output))
1111
expect_true("ProteinName" %in% colnames(output))
1212
expect_true("PeptideSequence" %in% colnames(output))

man/MSstatsClean.Rd

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

0 commit comments

Comments
 (0)