|
| 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