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
5 changes: 5 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ Collate:
'converters_DIAUmpiretoMSstatsFormat.R'
'converters_FragPipetoMSstatsFormat.R'
'converters_MaxQtoMSstatsFormat.R'
'converters_MaxQtoMSstatsTMTFormat.R'
'converters_MetamorpheusToMSstatsFormat.R'
'converters_OpenMStoMSstatsFormat.R'
'converters_OpenMStoMSstatsTMTFormat.R'
'converters_OpenSWATHtoMSstatsFormat.R'
'converters_PDtoMSstatsFormat.R'
'converters_PDtoMSstatsTMTFormat.R'
'converters_PhilosophertoMSstatsTMTFormat.R'
'converters_ProgenesistoMSstatsFormat.R'
'converters_ProteinProspectortoMSstatsTMTFormat.R'
'converters_SkylinetoMSstatsFormat.R'
'converters_SpectroMinetoMSstatsTMTFormat.R'
'converters_SpectronauttoMSstatsFormat.R'
'utils_MSstatsConvert.R'
'utils_annotation.R'
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ export(MSstatsMakeAnnotation)
export(MSstatsPreprocess)
export(MSstatsSaveSessionInfo)
export(MaxQtoMSstatsFormat)
export(MaxQtoMSstatsTMTFormat)
export(MetamorpheusToMSstatsFormat)
export(OpenMStoMSstatsFormat)
export(OpenMStoMSstatsTMTFormat)
export(OpenSWATHtoMSstatsFormat)
export(PDtoMSstatsFormat)
export(PDtoMSstatsTMTFormat)
export(PhilosophertoMSstatsTMTFormat)
export(ProgenesistoMSstatsFormat)
export(ProteinProspectortoMSstatsTMTFormat)
export(SkylinetoMSstatsFormat)
export(SpectroMinetoMSstatsTMTFormat)
export(SpectronauttoMSstatsFormat)
export(getDataType)
export(getInputFile)
Expand Down
68 changes: 68 additions & 0 deletions R/converters_MaxQtoMSstatsTMTFormat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#' Generate MSstatsTMT required input format from MaxQuant output
#'
#' @param evidence name of 'evidence.txt' data, which includes feature-level data.
#' @param proteinGroups name of 'proteinGroups.txt' data.
#' @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.
#' @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.
#' @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.
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
#' @param ... additional parameters to `data.table::fread`.
#' @inheritParams .sharedParametersAmongConverters
Comment thread
coderabbitai[bot] marked this conversation as resolved.
#'
#' @return data.frame of class "MSstatsTMT"
#'
#' @export
#'
#' @examples
#' evidence = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_ev.csv",
#' package = "MSstatsConvert"))
#' proteinGroups = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_pg.csv",
#' package = "MSstatsConvert"))
#' annotation.mq = data.table::fread(system.file("tinytest/raw_data/MaxQuantTMT/mq_annotation.csv",
#' package = "MSstatsConvert"))
#' input.mq <- MaxQtoMSstatsTMTFormat(evidence, proteinGroups, annotation.mq)
#' head(input.mq)
#'
MaxQtoMSstatsTMTFormat = function(
evidence, proteinGroups, annotation, which.proteinid = 'Proteins',
rmProt_Only.identified.by.site = FALSE, useUniquePeptide = TRUE,
rmPSM_withfewMea_withinRun = TRUE, rmProtein_with1Feature = FALSE,
summaryforMultipleRows = sum,
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL,
...
) {
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
log_file_path,
base = "MSstatsTMT_converter_log_")

input = MSstatsConvert::MSstatsImport(list(evidence = evidence,
protein_groups = proteinGroups),
"MSstatsTMT", "MaxQuant", ...)
input = MSstatsConvert::MSstatsClean(
input,
protein_id_col = which.proteinid,
remove_by_site = rmProt_Only.identified.by.site,
channel_columns = "Reporterintensitycorrected")
annotation = MSstatsConvert::MSstatsMakeAnnotation(input, annotation)

feature_columns = c("PeptideSequence", "PrecursorCharge")
input = MSstatsConvert::MSstatsPreprocess(
input,
annotation,
feature_columns,
remove_shared_peptides = useUniquePeptide,
remove_single_feature_proteins = rmProtein_with1Feature,
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
summarize_multiple_psms = summaryforMultipleRows))
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
fix_missing = "zero_to_na")
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)

msg_final = paste("** Finished preprocessing. The dataset is ready",
"to be processed by the proteinSummarization function.")
getOption("MSstatsLog")("INFO", msg_final)
getOption("MSstatsMsg")("INFO", msg_final)
getOption("MSstatsLog")("INFO", "\n")
input
}
53 changes: 53 additions & 0 deletions R/converters_OpenMStoMSstatsTMTFormat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#' Generate MSstatsTMT required input format for OpenMS output
#' @param input MSstatsTMT report from OpenMS
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
#' @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.
#' @param ... additional parameters to `data.table::fread`.
#' @inheritParams .sharedParametersAmongConverters
#'
#' @return `data.frame` of class `MSstatsTMT`.
#'
#' @export
#'
#' @examples
#' raw.om = data.table::fread(system.file("tinytest/raw_data/OpenMSTMT/openmstmt_input.csv",
#' package = "MSstatsConvert"))
#' input.om <- OpenMStoMSstatsTMTFormat(raw.om)
#' head(input.om)
#'
OpenMStoMSstatsTMTFormat = function(
input, useUniquePeptide = TRUE, rmPSM_withfewMea_withinRun = TRUE,
rmProtein_with1Feature = FALSE, summaryforMultiplePSMs = sum,
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
) {
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
log_file_path,
base = "MSstatsTMT_converter_log_")

input = MSstatsConvert::MSstatsImport(list(input = input),
"MSstatsTMT", "OpenMS", ...)
input = MSstatsConvert::MSstatsClean(input)

feature_columns = c("PeptideSequence", "PrecursorCharge")
input = MSstatsConvert::MSstatsPreprocess(
input,
NULL,
feature_columns,
remove_shared_peptides = useUniquePeptide,
remove_single_feature_proteins = rmProtein_with1Feature,
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
summarize_multiple_psms = summaryforMultiplePSMs)
)
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
fix_missing = "zero_to_na")

data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)

msg_final = paste("** Finished preprocessing. The dataset is ready",
"to be processed by the proteinSummarization function.")
getOption("MSstatsLog")("INFO", msg_final)
getOption("MSstatsMsg")("INFO", msg_final)
getOption("MSstatsLog")("INFO", "\n")
input
}
67 changes: 67 additions & 0 deletions R/converters_PDtoMSstatsTMTFormat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#' Convert Proteome Discoverer output to MSstatsTMT format.
#'
#' @param input PD report or a path to it.
#' @param annotation annotation with Run, Fraction, TechRepMixture, Mixture, Channel,
#' BioReplicate, Condition columns or a path to file. Refer to the example 'annotation' for the meaning of each column.
#' @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.
#' @param useNumProteinsColumn logical, TRUE (default) removes shared peptides by information of # Proteins column in PSM sheet.
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
#' @param ... additional parameters to `data.table::fread`.
#' @inheritParams .sharedParametersAmongConverters
#'
#' @return `data.frame` of class `MSstatsTMT`
#'
#' @export
#'
#' @examples
#' raw.pd = data.table::fread(system.file("tinytest/raw_data/PDTMT/pdtmt_input.csv",
#' package = "MSstatsConvert"))
#' annotation.pd = data.table::fread(system.file("tinytest/raw_data/PDTMT/pd_annotation.csv",
#' package = "MSstatsConvert"))
#' head(raw.pd)
#' head(annotation.pd)
#' input.pd <- PDtoMSstatsTMTFormat(raw.pd, annotation.pd)
#' head(input.pd)
#'
PDtoMSstatsTMTFormat <- function(
input, annotation, which.proteinid = 'Protein.Accessions',
useNumProteinsColumn = TRUE, useUniquePeptide = TRUE,
rmPSM_withfewMea_withinRun = TRUE, rmProtein_with1Feature = FALSE,
summaryforMultipleRows = sum,
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
) {
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
log_file_path,
base = "MSstatsTMT_converter_log_")

input = MSstatsConvert::MSstatsImport(list(input = input),
"MSstatsTMT", "ProteomeDiscoverer", ...)
input = MSstatsConvert::MSstatsClean(
input,
protein_id_column = which.proteinid,
remove_shared = useNumProteinsColumn,
remove_protein_groups = useNumProteinsColumn)
annotation = MSstatsConvert::MSstatsMakeAnnotation(input, annotation)

feature_columns = c("PeptideSequence", "PrecursorCharge")
input = MSstatsConvert::MSstatsPreprocess(
input,
annotation,
feature_columns = feature_columns,
remove_shared_peptides = useUniquePeptide,
remove_single_feature_proteins = rmProtein_with1Feature,
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
summarize_multiple_psms = summaryforMultipleRows)
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
fix_missing = "zero_to_na")
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)

msg_final = paste("** Finished preprocessing. The dataset is ready",
"to be processed by the proteinSummarization function.")
getOption("MSstatsLog")("INFO", msg_final)
getOption("MSstatsMsg")("INFO", msg_final)
getOption("MSstatsLog")("INFO", "\n")
input
}
123 changes: 123 additions & 0 deletions R/converters_PhilosophertoMSstatsTMTFormat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#' Convert Philosopher (Fragpipe) output to MSstatsTMT format.
#'
#' @param input data.frame of `msstats.csv` file produced by Philosopher
#' @param annotation annotation with Run, Fraction, TechRepMixture, Mixture, Channel,
#' BioReplicate, Condition columns or a path to file. Refer to the example 'annotation' for the meaning of each column. Channel column should be
#' 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.
#' @param protein_id_col Use 'Protein'(default) column for protein name.
#' 'Master.Protein.Accessions' can be used instead to get the protein ID with single protein.
#' @param peptide_id_col Use 'Peptide.Sequence'(default) column for peptide sequence.
#' 'Modified.Peptide.Sequence' can be used instead to get the modified peptide sequence.
#' @param Purity_cutoff Cutoff for purity. Default is 0.6
#' @param PeptideProphet_prob_cutoff Cutoff for the peptide identification probability. Default is 0.7.
#' The probability is confidence score determined by PeptideProphet and higher values indicate greater confidence.
#' @param rmPSM_withfewMea_withinRun TRUE (default) will remove the features that have 1 or 2 measurements within each Run.
#' @param rmPeptide_OxidationM TRUE (default) will remove the peptides including oxidation (M) sequence.
#' @param rmProtein_with1Feature TRUE will remove the proteins which have only 1 peptide and charge. Default is FALSE.
#' @param ... additional parameters to `data.table::fread`.
#' @inheritParams .sharedParametersAmongConverters
#'
#' @return `data.frame` of class `MSstatsTMT`
#'
#' @examples
#' input_file_path = system.file("tinytest/raw_data/Philosopher/msstats.csv",
#' package = "MSstatsConvert")
#' annotation_file_path = system.file("tinytest/raw_data/Philosopher/MSstatsTMT_annotation.csv",
#' package = "MSstatsConvert")
#' input = data.table::fread(input_file_path)
#' annotation = data.table::fread(annotation_file_path)
#' msstats_format = PhilosophertoMSstatsTMTFormat(input, annotation)
#' head(msstats_format)
#'
#' @export
PhilosophertoMSstatsTMTFormat = function(
input, annotation, protein_id_col = "Protein",
peptide_id_col = "Peptide.Sequence", Purity_cutoff = 0.6,
PeptideProphet_prob_cutoff = 0.7, useUniquePeptide = TRUE,
rmPSM_withfewMea_withinRun = TRUE, rmPeptide_OxidationM = TRUE,
rmProtein_with1Feature = FALSE, summaryforMultipleRows = sum,
use_log_file = TRUE, append = FALSE, verbose = TRUE, log_file_path = NULL, ...
) {
MSstatsConvert::MSstatsLogsSettings(use_log_file, append, verbose,
log_file_path,
base = "MSstatsTMT_converter_log_")
checkmate::assertTRUE(!is.null(input))

input[["Is.Unique"]] = as.logical(input[["Is.Unique"]])
mixture_files = list(Mixture1=data.table(input))

input = MSstatsConvert::MSstatsImport(c(mixture_files,
list(annotation = annotation)),
type = "MSstatsTMT",
tool = "Philosopher")
channels = unique(annotation[["Channel"]])
input = MSstatsConvert::MSstatsClean(input, protein_id_col, peptide_id_col,
channels, useUniquePeptide)
annotation = MSstatsMakeAnnotation(input, annotation)
Comment thread
tonywu1999 marked this conversation as resolved.

purity_filter = list(score_column = "Purity",
score_threshold = Purity_cutoff,
direction = "greater",
behavior = "remove",
handle_na = "keep",
fill_value = NULL,
filter = TRUE,
drop_column = FALSE)
probability_filter = list(score_column = "PeptideProphetProbability",
score_threshold = PeptideProphet_prob_cutoff,
direction = "greater",
behavior = "remove",
handle_na = "keep",
fill_value = NULL,
filter = TRUE,
drop_column = FALSE)
oxidation_filter = list(col_name = "PeptideSequence",
pattern = "Oxidation",
filter = rmPeptide_OxidationM,
drop_column = FALSE)
Comment thread
tonywu1999 marked this conversation as resolved.

feature_columns = c("PeptideSequence", "PrecursorCharge")
input = MSstatsPreprocess(
input,
annotation,
feature_columns,
remove_shared_peptides = useUniquePeptide,
remove_single_feature_proteins = rmProtein_with1Feature,
score_filtering = list(pur = purity_filter, prob = probability_filter),
pattern_filtering = list(ox = oxidation_filter),
feature_cleaning = list(remove_features_with_few_measurements = rmPSM_withfewMea_withinRun,
summarize_multiple_psms = summaryforMultipleRows)
)
input = MSstatsConvert::MSstatsBalancedDesign(input, feature_columns,
fix_missing = "zero_to_na")
data.table::setnames(input, "PrecursorCharge", "Charge", skip_absent = TRUE)

msg_final = paste("** Finished preprocessing. The dataset is ready",
"to be processed by the proteinSummarization function.")
getOption("MSstatsLog")("INFO", msg_final)
getOption("MSstatsMsg")("INFO", msg_final)
getOption("MSstatsLog")("INFO", "\n")
input
}


#' Convert Philosopher parameters to consistent format
#' @inheritParams PhilosophertoMSstatsTMTFormat
#' @param path character. Path to a file or directory containing msstats.csv output(s) from Philosopher. Used when \code{input} is NULL.
#' @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.
#' @keywords internal
.getPhilosopherInput = function(input, path, folder) {
if (!is.null(input)) {
mixture_files = input
} else {
if (folder) {
mixture_files = list.files(path, pattern = "msstats",
full.names = TRUE)
} else {
mixture_files = path
}
}
mixture_files = as.list(mixture_files)
names(mixture_files) = paste0("Mixture", seq_along(mixture_files))
mixture_files
}
Loading
Loading