Skip to content

Commit 077b51f

Browse files
authored
refactor(TMT): Add TMT converters to MSstatsConvert (#127)
1 parent 87acf56 commit 077b51f

38 files changed

Lines changed: 1508 additions & 34 deletions

DESCRIPTION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ Collate:
5454
'converters_DIAUmpiretoMSstatsFormat.R'
5555
'converters_FragPipetoMSstatsFormat.R'
5656
'converters_MaxQtoMSstatsFormat.R'
57+
'converters_MaxQtoMSstatsTMTFormat.R'
5758
'converters_MetamorpheusToMSstatsFormat.R'
5859
'converters_OpenMStoMSstatsFormat.R'
60+
'converters_OpenMStoMSstatsTMTFormat.R'
5961
'converters_OpenSWATHtoMSstatsFormat.R'
6062
'converters_PDtoMSstatsFormat.R'
63+
'converters_PDtoMSstatsTMTFormat.R'
64+
'converters_PhilosophertoMSstatsTMTFormat.R'
6165
'converters_ProgenesistoMSstatsFormat.R'
6266
'converters_ProteinProspectortoMSstatsTMTFormat.R'
6367
'converters_SkylinetoMSstatsFormat.R'
68+
'converters_SpectroMinetoMSstatsTMTFormat.R'
6469
'converters_SpectronauttoMSstatsFormat.R'
6570
'utils_MSstatsConvert.R'
6671
'utils_annotation.R'

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ export(MSstatsMakeAnnotation)
1515
export(MSstatsPreprocess)
1616
export(MSstatsSaveSessionInfo)
1717
export(MaxQtoMSstatsFormat)
18+
export(MaxQtoMSstatsTMTFormat)
1819
export(MetamorpheusToMSstatsFormat)
1920
export(OpenMStoMSstatsFormat)
21+
export(OpenMStoMSstatsTMTFormat)
2022
export(OpenSWATHtoMSstatsFormat)
2123
export(PDtoMSstatsFormat)
24+
export(PDtoMSstatsTMTFormat)
25+
export(PhilosophertoMSstatsTMTFormat)
2226
export(ProgenesistoMSstatsFormat)
2327
export(ProteinProspectortoMSstatsTMTFormat)
2428
export(SkylinetoMSstatsFormat)
29+
export(SpectroMinetoMSstatsTMTFormat)
2530
export(SpectronauttoMSstatsFormat)
2631
export(getDataType)
2732
export(getInputFile)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#' Generate MSstatsTMT required input format from MaxQuant output
2+
#'
3+
#' @param evidence name of 'evidence.txt' data, which includes feature-level data.
4+
#' @param proteinGroups name of 'proteinGroups.txt' data.
5+
#' @param annotation data frame which contains column Run, Fraction, TechRepMixture, Mixture, Channel, BioReplicate, Condition. Refer to the example 'annotation.mq' for the meaning of each column.
6+
#' @param which.proteinid Use 'Proteins' (default) column for protein name. 'Leading.proteins' or 'Leading.razor.proteins' or 'Gene.names' can be used instead to get the protein ID with single protein. However, those can potentially have the shared peptides.
7+
#' @param rmProt_Only.identified.by.site TRUE will remove proteins with '+' in 'Only.identified.by.site' column from proteinGroups.txt, which was identified only by a modification site. FALSE is the default.
8+
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
9+
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
10+
#' @param ... additional parameters to `data.table::fread`.
11+
#' @inheritParams .sharedParametersAmongConverters
12+
#'
13+
#' @return data.frame of class "MSstatsTMT"
14+
#'
15+
#' @export
16+
#'
17+
#' @examples
18+
#' evidence = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_ev.csv",
19+
#' package = "MSstatsConvert"))
20+
#' proteinGroups = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_pg.csv",
21+
#' package = "MSstatsConvert"))
22+
#' annotation.mq = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_annotation.csv",
23+
#' package = "MSstatsConvert"))
24+
#' input.mq <- MaxQtoMSstatsTMTFormat(evidence, proteinGroups, annotation.mq)
25+
#' head(input.mq)
26+
#'
27+
MaxQtoMSstatsTMTFormat = function(
28+
evidence, proteinGroups, annotation, which.proteinid = 'Proteins',
29+
rmProt_Only.identified.by.site = FALSE, useUniquePeptide = TRUE,
30+
rmPSM_withfewMea_withinRun = TRUE, rmProtein_with1Feature = FALSE,
31+
summaryforMultipleRows = sum,
32+
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL,
33+
...
34+
) {
35+
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
36+
log_file_path,
37+
base = "MSstatsTMT_converter_log_")
38+
39+
input = MSstatsConvert::MSstatsImport(list(evidence = evidence,
40+
protein_groups = proteinGroups),
41+
"MSstatsTMT", "MaxQuant", ...)
42+
input = MSstatsConvert::MSstatsClean(
43+
input,
44+
protein_id_col = which.proteinid,
45+
remove_by_site = rmProt_Only.identified.by.site,
46+
channel_columns = "Reporterintensitycorrected")
47+
annotation = MSstatsConvert::MSstatsMakeAnnotation(input, annotation)
48+
49+
feature_columns = c("PeptideSequence", "PrecursorCharge")
50+
input = MSstatsConvert::MSstatsPreprocess(
51+
input,
52+
annotation,
53+
feature_columns,
54+
remove_shared_peptides = useUniquePeptide,
55+
remove_single_feature_proteins = rmProtein_with1Feature,
56+
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
57+
summarize_multiple_psms = summaryforMultipleRows))
58+
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
59+
fix_missing = "zero_to_na")
60+
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)
61+
62+
msg_final = paste("** Finished preprocessing. The dataset is ready",
63+
"to be processed by the proteinSummarization function.")
64+
getOption("MSstatsLog")("INFO", msg_final)
65+
getOption("MSstatsMsg")("INFO", msg_final)
66+
getOption("MSstatsLog")("INFO", "\n")
67+
input
68+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#' Generate MSstatsTMT required input format for OpenMS output
2+
#' @param input MSstatsTMT report from OpenMS
3+
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
4+
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
5+
#' @param summaryforMultiplePSMs sum(default) or max - when there are multiple measurements for certain feature in certain run, select the feature with the largest summation or maximal value.
6+
#' @param ... additional parameters to `data.table::fread`.
7+
#' @inheritParams .sharedParametersAmongConverters
8+
#'
9+
#' @return `data.frame` of class `MSstatsTMT`.
10+
#'
11+
#' @export
12+
#'
13+
#' @examples
14+
#' raw.om = data.table::fread(system.file("tinytest/raw_data/OpenMSTMT/openmstmt_input.csv",
15+
#' package = "MSstatsConvert"))
16+
#' input.om <- OpenMStoMSstatsTMTFormat(raw.om)
17+
#' head(input.om)
18+
#'
19+
OpenMStoMSstatsTMTFormat = function(
20+
input, useUniquePeptide = TRUE, rmPSM_withfewMea_withinRun = TRUE,
21+
rmProtein_with1Feature = FALSE, summaryforMultiplePSMs = sum,
22+
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
23+
) {
24+
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
25+
log_file_path,
26+
base = "MSstatsTMT_converter_log_")
27+
28+
input = MSstatsConvert::MSstatsImport(list(input = input),
29+
"MSstatsTMT", "OpenMS", ...)
30+
input = MSstatsConvert::MSstatsClean(input)
31+
32+
feature_columns = c("PeptideSequence", "PrecursorCharge")
33+
input = MSstatsConvert::MSstatsPreprocess(
34+
input,
35+
NULL,
36+
feature_columns,
37+
remove_shared_peptides = useUniquePeptide,
38+
remove_single_feature_proteins = rmProtein_with1Feature,
39+
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
40+
summarize_multiple_psms = summaryforMultiplePSMs)
41+
)
42+
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
43+
fix_missing = "zero_to_na")
44+
45+
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)
46+
47+
msg_final = paste("** Finished preprocessing. The dataset is ready",
48+
"to be processed by the proteinSummarization function.")
49+
getOption("MSstatsLog")("INFO", msg_final)
50+
getOption("MSstatsMsg")("INFO", msg_final)
51+
getOption("MSstatsLog")("INFO", "\n")
52+
input
53+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#' Convert Proteome Discoverer output to MSstatsTMT format.
2+
#'
3+
#' @param input PD report or a path to it.
4+
#' @param annotation annotation with Run, Fraction, TechRepMixture, Mixture, Channel,
5+
#' BioReplicate, Condition columns or a path to file. Refer to the example 'annotation' for the meaning of each column.
6+
#' @param which.proteinid Use 'Protein.Accessions'(default) column for protein name. 'Master.Protein.Accessions' can be used instead to get the protein name with single protein.
7+
#' @param useNumProteinsColumn logical, TRUE (default) removes shared peptides by information of # Proteins column in PSM sheet.
8+
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
9+
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
10+
#' @param ... additional parameters to `data.table::fread`.
11+
#' @inheritParams .sharedParametersAmongConverters
12+
#'
13+
#' @return `data.frame` of class `MSstatsTMT`
14+
#'
15+
#' @export
16+
#'
17+
#' @examples
18+
#' raw.pd = data.table::fread(system.file("tinytest/raw_data/PDTMT/pdtmt_input.csv",
19+
#' package = "MSstatsConvert"))
20+
#' annotation.pd = data.table::fread(system.file("tinytest/raw_data/PDTMT/pd_annotation.csv",
21+
#' package = "MSstatsConvert"))
22+
#' head(raw.pd)
23+
#' head(annotation.pd)
24+
#' input.pd <- PDtoMSstatsTMTFormat(raw.pd, annotation.pd)
25+
#' head(input.pd)
26+
#'
27+
PDtoMSstatsTMTFormat <- function(
28+
input, annotation, which.proteinid = 'Protein.Accessions',
29+
useNumProteinsColumn = TRUE, useUniquePeptide = TRUE,
30+
rmPSM_withfewMea_withinRun = TRUE, rmProtein_with1Feature = FALSE,
31+
summaryforMultipleRows = sum,
32+
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
33+
) {
34+
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
35+
log_file_path,
36+
base = "MSstatsTMT_converter_log_")
37+
38+
input = MSstatsConvert::MSstatsImport(list(input = input),
39+
"MSstatsTMT", "ProteomeDiscoverer", ...)
40+
input = MSstatsConvert::MSstatsClean(
41+
input,
42+
protein_id_column = which.proteinid,
43+
remove_shared = useNumProteinsColumn,
44+
remove_protein_groups = useNumProteinsColumn)
45+
annotation = MSstatsConvert::MSstatsMakeAnnotation(input, annotation)
46+
47+
feature_columns = c("PeptideSequence", "PrecursorCharge")
48+
input = MSstatsConvert::MSstatsPreprocess(
49+
input,
50+
annotation,
51+
feature_columns = feature_columns,
52+
remove_shared_peptides = useUniquePeptide,
53+
remove_single_feature_proteins = rmProtein_with1Feature,
54+
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
55+
summarize_multiple_psms = summaryforMultipleRows)
56+
)
57+
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
58+
fix_missing = "zero_to_na")
59+
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)
60+
61+
msg_final = paste("** Finished preprocessing. The dataset is ready",
62+
"to be processed by the proteinSummarization function.")
63+
getOption("MSstatsLog")("INFO", msg_final)
64+
getOption("MSstatsMsg")("INFO", msg_final)
65+
getOption("MSstatsLog")("INFO", "\n")
66+
input
67+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#' Convert Philosopher (Fragpipe) output to MSstatsTMT format.
2+
#'
3+
#' @param input data.frame of `msstats.csv` file produced by Philosopher
4+
#' @param annotation annotation with Run, Fraction, TechRepMixture, Mixture, Channel,
5+
#' BioReplicate, Condition columns or a path to file. Refer to the example 'annotation' for the meaning of each column. Channel column should be
6+
#' consistent with the channel columns (Ignore the prefix "Channel ") in msstats.csv file. Run column should be consistent with the Spectrum.File columns in msstats.csv file.
7+
#' @param protein_id_col Use 'Protein'(default) column for protein name.
8+
#' 'Master.Protein.Accessions' can be used instead to get the protein ID with single protein.
9+
#' @param peptide_id_col Use 'Peptide.Sequence'(default) column for peptide sequence.
10+
#' 'Modified.Peptide.Sequence' can be used instead to get the modified peptide sequence.
11+
#' @param Purity_cutoff Cutoff for purity. Default is 0.6
12+
#' @param PeptideProphet_prob_cutoff Cutoff for the peptide identification probability. Default is 0.7.
13+
#' The probability is confidence score determined by PeptideProphet and higher values indicate greater confidence.
14+
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
15+
#' @param rmPeptide_OxidationM TRUE (default) will remove the peptides including oxidation (M) sequence.
16+
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
17+
#' @param ... additional parameters to `data.table::fread`.
18+
#' @inheritParams .sharedParametersAmongConverters
19+
#'
20+
#' @return `data.frame` of class `MSstatsTMT`
21+
#'
22+
#' @examples
23+
#' input_file_path = system.file("tinytest/raw_data/Philosopher/msstats.csv",
24+
#' package = "MSstatsConvert")
25+
#' annotation_file_path = system.file("tinytest/raw_data/Philosopher/MSstatsTMT_annotation.csv",
26+
#' package = "MSstatsConvert")
27+
#' input = data.table::fread(input_file_path)
28+
#' annotation = data.table::fread(annotation_file_path)
29+
#' msstats_format = PhilosophertoMSstatsTMTFormat(input, annotation)
30+
#' head(msstats_format)
31+
#'
32+
#' @export
33+
PhilosophertoMSstatsTMTFormat = function(
34+
input, annotation, protein_id_col = "Protein",
35+
peptide_id_col = "Peptide.Sequence", Purity_cutoff = 0.6,
36+
PeptideProphet_prob_cutoff = 0.7, useUniquePeptide = TRUE,
37+
rmPSM_withfewMea_withinRun = TRUE, rmPeptide_OxidationM = TRUE,
38+
rmProtein_with1Feature = FALSE, summaryforMultipleRows = sum,
39+
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
40+
) {
41+
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
42+
log_file_path,
43+
base = "MSstatsTMT_converter_log_")
44+
checkmate::assertTRUE(!is.null(input))
45+
46+
input[["Is.Unique"]] = as.logical(input[["Is.Unique"]])
47+
mixture_files = list(Mixture1=data.table(input))
48+
49+
input = MSstatsConvert::MSstatsImport(c(mixture_files,
50+
list(annotation = annotation)),
51+
type = "MSstatsTMT",
52+
tool = "Philosopher")
53+
channels = unique(annotation[["Channel"]])
54+
input = MSstatsConvert::MSstatsClean(input, protein_id_col, peptide_id_col,
55+
channels, useUniquePeptide)
56+
annotation = MSstatsMakeAnnotation(input, annotation)
57+
58+
purity_filter = list(score_column = "Purity",
59+
score_threshold = Purity_cutoff,
60+
direction = "greater",
61+
behavior = "remove",
62+
handle_na = "keep",
63+
fill_value = NULL,
64+
filter = TRUE,
65+
drop_column = FALSE)
66+
probability_filter = list(score_column = "PeptideProphetProbability",
67+
score_threshold = PeptideProphet_prob_cutoff,
68+
direction = "greater",
69+
behavior = "remove",
70+
handle_na = "keep",
71+
fill_value = NULL,
72+
filter = TRUE,
73+
drop_column = FALSE)
74+
oxidation_filter = list(col_name = "PeptideSequence",
75+
pattern = "Oxidation",
76+
filter = rmPeptide_OxidationM,
77+
drop_column = FALSE)
78+
79+
feature_columns = c("PeptideSequence", "PrecursorCharge")
80+
input = MSstatsPreprocess(
81+
input,
82+
annotation,
83+
feature_columns,
84+
remove_shared_peptides = useUniquePeptide,
85+
remove_single_feature_proteins = rmProtein_with1Feature,
86+
score_filtering = list(pur = purity_filter, prob = probability_filter),
87+
pattern_filtering = list(ox = oxidation_filter),
88+
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
89+
summarize_multiple_psms = summaryforMultipleRows)
90+
)
91+
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
92+
fix_missing = "zero_to_na")
93+
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)
94+
95+
msg_final = paste("** Finished preprocessing. The dataset is ready",
96+
"to be processed by the proteinSummarization function.")
97+
getOption("MSstatsLog")("INFO", msg_final)
98+
getOption("MSstatsMsg")("INFO", msg_final)
99+
getOption("MSstatsLog")("INFO", "\n")
100+
input
101+
}
102+
103+
104+
#' Convert Philosopher parameters to consistent format
105+
#' @inheritParams PhilosophertoMSstatsTMTFormat
106+
#' @param path character. Path to a file or directory containing msstats.csv output(s) from Philosopher. Used when \code{input} is NULL.
107+
#' @param folder logical. If TRUE, \code{path} is treated as a directory and all msstats files within it are read. If FALSE, \code{path} is treated as a single file path.
108+
#' @keywords internal
109+
.getPhilosopherInput = function(input, path, folder) {
110+
if (!is.null(input)) {
111+
mixture_files = input
112+
} else {
113+
if (folder) {
114+
mixture_files = list.files(path, pattern = "msstats",
115+
full.names = TRUE)
116+
} else {
117+
mixture_files = path
118+
}
119+
}
120+
mixture_files = as.list(mixture_files)
121+
names(mixture_files) = paste0("Mixture", seq_along(mixture_files))
122+
mixture_files
123+
}

0 commit comments

Comments
 (0)