-
Notifications
You must be signed in to change notification settings - Fork 5
Tmt converters #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Tmt converters #127
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| #' | ||
| #' @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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ) | ||
|
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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
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) | ||
|
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 | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.