diff --git a/pwiz_tools/Skyline/CommandArgUsage.Designer.cs b/pwiz_tools/Skyline/CommandArgUsage.Designer.cs index 728715429e..593506a0cd 100644 --- a/pwiz_tools/Skyline/CommandArgUsage.Designer.cs +++ b/pwiz_tools/Skyline/CommandArgUsage.Designer.cs @@ -303,6 +303,42 @@ internal static string _exp_method_type { } } + /// + /// Looks up a localized string similar to Include feature scores only for the best scoring peaks. Requires the --exp-mprophet-file argument.. + /// + internal static string _exp_mprophet_best_peaks_only { + get { + return ResourceManager.GetString("_exp_mprophet_best_peaks_only", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use to exclude a particular feature score by name from the exported file. Names can be found in the user interface. This argument may be used multiple times to exclude multiple features. Requires the --exp-mprophet-file argument.. + /// + internal static string _exp_mprophet_exclude_feature { + get { + return ResourceManager.GetString("_exp_mprophet_exclude_feature", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Export all the individual feature scores for each peptide, as well as the composite score, the p value, and the q value into the mProphet format.. + /// + internal static string _exp_mprophet_file { + get { + return ResourceManager.GetString("_exp_mprophet_file", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Include feature scores only for targets. Requires the --exp-mprophet-file argument.. + /// + internal static string _exp_mprophet_targets_only { + get { + return ResourceManager.GetString("_exp_mprophet_targets_only", resourceCulture); + } + } + /// /// Looks up a localized string similar to Export a method with extra transitions for finding optimal collision energy or declustering potential.. /// @@ -1265,8 +1301,8 @@ internal static string _refine_label_type { ///will be removed from the document: /// ///Green = 1.0 - ///Orange &gt;= 0.5 - ///Red &lt; 0.5. + ///Orange >= 0.5 + ///Red < 0.5. /// internal static string _refine_max_peak_found_ratio { get { @@ -1332,8 +1368,8 @@ internal static string _refine_min_idotp { ///will be removed from the document: /// ///Green = 1.0 - ///Orange &gt;= 0.5 - ///Red &lt; 0.5. + ///Orange >= 0.5 + ///Red < 0.5. /// internal static string _refine_min_peak_found_ratio { get { diff --git a/pwiz_tools/Skyline/CommandArgUsage.resx b/pwiz_tools/Skyline/CommandArgUsage.resx index 5f037d4c40..3a25ce956d 100644 --- a/pwiz_tools/Skyline/CommandArgUsage.resx +++ b/pwiz_tools/Skyline/CommandArgUsage.resx @@ -681,8 +681,8 @@ first occurrence of any peptide. will be removed from the document: Green = 1.0 -Orange &gt;= 0.5 -Red &lt; 0.5 +Orange >= 0.5 +Red < 0.5 All transitions with an average area peak ranking @@ -709,8 +709,8 @@ removed from the document. will be removed from the document: Green = 1.0 -Orange &gt;= 0.5 -Red &lt; 0.5 +Orange >= 0.5 +Red < 0.5 Precursors will be removed from the document @@ -934,4 +934,16 @@ greater peak area. Export experimental data in the current document to a spectral library file. Peak areas are used as spectrum intensities, peak apex times are used as retention times, and if the document has iRT values they will also be stored in the library. + + Use to exclude a particular feature score by name from the exported file. Names can be found in the user interface. This argument may be used multiple times to exclude multiple features. Requires the --exp-mprophet-file argument. + + + Export all the individual feature scores for each peptide, as well as the composite score, the p value, and the q value into the mProphet format. + + + Include feature scores only for the best scoring peaks. Requires the --exp-mprophet-file argument. + + + Include feature scores only for targets. Requires the --exp-mprophet-file argument. + \ No newline at end of file diff --git a/pwiz_tools/Skyline/CommandArgs.cs b/pwiz_tools/Skyline/CommandArgs.cs index c953f93ae8..35eac88a88 100644 --- a/pwiz_tools/Skyline/CommandArgs.cs +++ b/pwiz_tools/Skyline/CommandArgs.cs @@ -692,7 +692,7 @@ public bool SettingLibraryPath private static readonly Argument ARG_REINTEGRATE_LOG_TRAINING = new DocArgument(@"reintegrate-log-training", (c, p) => c.IsLogTraining = true) {InternalUse = true}; private static readonly Argument ARG_REINTEGRATE_EXCLUDE_FEATURE = new DocArgument(@"reintegrate-exclude-feature", FEATURE_NAME_VALUE, - (c, p) => c.ParseReintegrateExcludeFeature(p)) + (c, p) => c.ParseExcludeFeature(p, c.ExcludeFeatures)) { WrapValue = true }; private static readonly ArgumentGroup GROUP_REINTEGRATE = new ArgumentGroup(() => CommandArgUsage.CommandArgs_GROUP_REINTEGRATE_Reintegrate_with_advanced_peak_picking_models, false, @@ -789,9 +789,9 @@ private List ParseNumberList(NameValuePair pair) } } - private bool ParseReintegrateExcludeFeature(NameValuePair pair) + private bool ParseExcludeFeature(NameValuePair pair, ICollection featureList) { - string featureName = pair.Value; + var featureName = pair.Value; var calc = PeakFeatureCalculator.Calculators.FirstOrDefault(c => Equals(featureName, c.HeaderName) || Equals(featureName, c.Name)); if (calc == null) @@ -811,8 +811,8 @@ private bool ParseReintegrateExcludeFeature(NameValuePair pair) return false; } - - ExcludeFeatures.Add(calc); + + featureList.Add(calc); return true; } @@ -1038,15 +1038,35 @@ private bool ValidateChromatogramArgs() // For exporting other file types public static readonly Argument ARG_SPECTRAL_LIBRARY_FILE = new DocArgument(@"exp-speclib-file", PATH_TO_BLIB, (c, p) => c.SpecLibFile= p.ValueFullPath); + public static readonly Argument ARG_MPROPHET_FEATURES_FILE = new DocArgument(@"exp-mprophet-file", PATH_TO_CSV, + (c, p) => c.MProphetFeaturesFile = p.ValueFullPath); + public static readonly Argument ARG_MPROPHET_FEATURES_BEST_SCORING_PEAKS = + new DocArgument(@"exp-mprophet-best-peaks-only", (c, p) => c.MProphetUseBestScoringPeaks = true); + public static readonly Argument ARG_MPROPHET_FEATURES_TARGETS_ONLY = + new DocArgument(@"exp-mprophet-targets-only", (c, p) => c.MProphetTargetsOnly = true); + public static readonly Argument ARG_MPROPHET_FEATURES_MPROPHET_EXCLUDE_SCORES = + new DocArgument(@"exp-mprophet-exclude-feature", FEATURE_NAME_VALUE, + (c, p) => c.ParseExcludeFeature(p, c.MProphetExcludeScores)){WrapValue = true}; private static readonly ArgumentGroup GROUP_OTHER_FILE_TYPES = new ArgumentGroup(() => CommandArgUsage.CommandArgs_GROUP_OTHER_FILE_TYPES, false, - ARG_SPECTRAL_LIBRARY_FILE + ARG_SPECTRAL_LIBRARY_FILE, ARG_MPROPHET_FEATURES_FILE, ARG_MPROPHET_FEATURES_BEST_SCORING_PEAKS, ARG_MPROPHET_FEATURES_TARGETS_ONLY, + ARG_MPROPHET_FEATURES_MPROPHET_EXCLUDE_SCORES ); public string SpecLibFile { get; private set; } public bool ExportingSpecLib { get { return !string.IsNullOrEmpty(SpecLibFile); } } + public string MProphetFeaturesFile { get; private set; } + + public bool ExportingMProphetFeatures { get { return !string.IsNullOrEmpty(MProphetFeaturesFile); } } + + public bool MProphetUseBestScoringPeaks { get; private set; } + + public bool MProphetTargetsOnly { get; private set; } + + public List MProphetExcludeScores { get; private set; } + // For publishing the document to Panorama public static readonly Argument ARG_PANORAMA_SERVER = new DocArgument(@"panorama-server", SERVER_URL_VALUE, (c, p) => c.PanoramaServerUri = p.Value); @@ -2157,6 +2177,8 @@ public CommandArgs(CommandStatusWriter output, bool isDocumentLoaded) ExcludeFeatures = new List(); SharedFileType = ShareType.DEFAULT; + MProphetExcludeScores = new List(); + ImportBeforeDate = null; ImportOnOrAfterDate = null; } diff --git a/pwiz_tools/Skyline/CommandLine.cs b/pwiz_tools/Skyline/CommandLine.cs index 666486579e..ed8ab90d18 100644 --- a/pwiz_tools/Skyline/CommandLine.cs +++ b/pwiz_tools/Skyline/CommandLine.cs @@ -808,11 +808,24 @@ private bool PerformExportOperations(CommandArgs commandArgs) } - if (commandArgs.ExportingSpecLib && !ExportSpecLib(commandArgs.SpecLibFile)) - { - return false; + if (commandArgs.ExportingSpecLib) + { + if (!ExportSpecLib(commandArgs.SpecLibFile)) + { + return false; + } } + if (commandArgs.ExportingMProphetFeatures) + { + if (!ExportMProphetFeatures(commandArgs.MProphetFeaturesFile, commandArgs.MProphetTargetsOnly, + commandArgs.MProphetUseBestScoringPeaks, + new FeatureCalculators(commandArgs.MProphetExcludeScores))) + { + return false; + } + } + var exportTypes = (string.IsNullOrEmpty(commandArgs.IsolationListInstrumentType) ? 0 : 1) + (string.IsNullOrEmpty(commandArgs.TransListInstrumentType) ? 0 : 1) + @@ -3149,6 +3162,57 @@ public bool ExportSpecLib(string specLibFile) return true; } + /// + /// Export mProphet features as a .csv file + /// + /// File path to export the mProphet file to + /// Do not include decoys, only targets + /// Export best scoring peaks only + /// A list of features to exclude from the exported file + /// True upon successful import, false upon error + public bool ExportMProphetFeatures(string mProphetFile, bool targetPeptidesOnly, bool bestOnly, FeatureCalculators excludeScores) + { + if (Document.MoleculeCount == 0) // The document must contain targets + { + _out.WriteLine(Resources.CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_targets_for_which_to_export_mProphet_features_); + return false; + } + + if (!Document.Settings.HasResults) // The document must contain results + { + _out.WriteLine(Resources.CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_results_to_export_mProphet_features_); + return false; + } + + try + { + var scoringModel = Document.Settings.PeptideSettings.Integration.PeakScoringModel; + var mProphetScoringModel = scoringModel as MProphetPeakScoringModel; + var handler = new MProphetResultsHandler(Document, mProphetScoringModel); + var status = new ProgressStatus(string.Empty); + var cultureInfo = LocalizationHelper.CurrentCulture; + IProgressMonitor progressMonitor = new CommandProgressMonitor(_out, status); + using (var fs = new FileSaver(mProphetFile)) + using (var writer = new StreamWriter(fs.SafeName)) + { + handler.ScoreFeatures(progressMonitor); + // Excluding any scores requested by the caller + var calcs = new FeatureCalculators(PeakFeatureCalculator.Calculators.Where(c => excludeScores.IndexOf(c) < 0)); + handler.WriteScores(writer, cultureInfo, calcs, bestOnly, !targetPeptidesOnly, progressMonitor); + writer.Close(); + fs.Commit(); + } + _out.WriteLine(Resources.CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_, mProphetFile); + } + catch (Exception x) + { + _out.WriteLine(Resources.CommandLine_ExportMProphetFeatures_Error__Failure_attempting_to_save_mProphet_features_file__0__, mProphetFile); + _out.WriteLine(x.Message); + return false; + } + return true; + } + public enum ResolveZipToolConflicts { terminate, diff --git a/pwiz_tools/Skyline/FileUI/MProphetFeaturesDlg.resx b/pwiz_tools/Skyline/FileUI/MProphetFeaturesDlg.resx index 0a0409fbfb..6f0d1ea03e 100644 --- a/pwiz_tools/Skyline/FileUI/MProphetFeaturesDlg.resx +++ b/pwiz_tools/Skyline/FileUI/MProphetFeaturesDlg.resx @@ -231,6 +231,9 @@ 2 + + Bottom, Left + True @@ -261,6 +264,9 @@ 1 + + Bottom, Left + True diff --git a/pwiz_tools/Skyline/Properties/Resources.Designer.cs b/pwiz_tools/Skyline/Properties/Resources.Designer.cs index 0eed5675ad..4671f1a4ee 100644 --- a/pwiz_tools/Skyline/Properties/Resources.Designer.cs +++ b/pwiz_tools/Skyline/Properties/Resources.Designer.cs @@ -5916,6 +5916,46 @@ public static string CommandLine_ExportLiveReport_Report__0__exported_successful } } + /// + /// Looks up a localized string similar to Error: Failure attempting to save mProphet features file {0}.. + /// + public static string CommandLine_ExportMProphetFeatures_Error__Failure_attempting_to_save_mProphet_features_file__0__ { + get { + return ResourceManager.GetString("CommandLine_ExportMProphetFeatures_Error__Failure_attempting_to_save_mProphet_fea" + + "tures_file__0__", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error: The document must contain results to export mProphet features.. + /// + public static string CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_results_to_export_mProphet_features_ { + get { + return ResourceManager.GetString("CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_results_to_ex" + + "port_mProphet_features_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error: The document must contain targets for which to export mProphet features.. + /// + public static string CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_targets_for_which_to_export_mProphet_features_ { + get { + return ResourceManager.GetString("CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_targets_for_w" + + "hich_to_export_mProphet_features_", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to mProphet features file {0} exported successfully.. + /// + public static string CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_ { + get { + return ResourceManager.GetString("CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successful" + + "ly_", resourceCulture); + } + } + /// /// Looks up a localized string similar to Error: If you specify a report, you must specify the --report-file=path/to/file.csv parameter.. /// diff --git a/pwiz_tools/Skyline/Properties/Resources.resx b/pwiz_tools/Skyline/Properties/Resources.resx index 533c4dd8f3..6625aac8cb 100644 --- a/pwiz_tools/Skyline/Properties/Resources.resx +++ b/pwiz_tools/Skyline/Properties/Resources.resx @@ -13899,4 +13899,16 @@ If you choose Disable, you can enable Auto-select later with the "Refine > Ad Error: Failure attempting to save spectral library file {0}. + + mProphet features file {0} exported successfully. + + + Error: The document must contain targets for which to export mProphet features. + + + Error: The document must contain results to export mProphet features. + + + Error: Failure attempting to save mProphet features file {0}. + \ No newline at end of file diff --git a/pwiz_tools/Skyline/TestData/CommandLineTest.cs b/pwiz_tools/Skyline/TestData/CommandLineTest.cs index 540bf06908..632a52aeac 100644 --- a/pwiz_tools/Skyline/TestData/CommandLineTest.cs +++ b/pwiz_tools/Skyline/TestData/CommandLineTest.cs @@ -664,6 +664,69 @@ public void ConsoleExportSpecLibTest() } + [TestMethod] + public void ConsoleExportMProphetTest() + { + TestFilesDir = new TestFilesDir(TestContext, @"TestData\ConsoleExportMProphetTest.zip"); + // Path to export mProphet file to + var exportPath = TestFilesDir.GetTestPath("out.csv"); + // A document with no results. Attempting to export mProphet features should + // provoke an error + var docWithNoResultsPath = TestFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); + // A document with results that should be able to export mProphet features + var docWithResults = TestFilesDir.GetTestPath("MProphetGold-trained-reduced.sky"); + // The expected .csv export + var expectedExport = TestFilesDir.GetTestPathLocale("MProphet_expected.csv"); + // The expected export with targets only and best scoring peaks only options + var expectedExportTargetsBestPeaks = TestFilesDir.GetTestPathLocale("MProphet_expected_targets_only_best_peaks_only.csv"); + // The expected export when excluding the "Intensity" and "Standard signal to noise" features. + var expectedExportExcludeFeatures = TestFilesDir.GetTestPathLocale("MProphet_expected_exclude_features.csv"); + // A string that is not a feature name or a mProphet file header + const string invalidFeatureName = "-la"; + + // Test error (no targets) + var output = RunCommand("--new=" + "new.sky", // Create a new document + "--overwrite", // Overwrite, as the file may already exist in the bin + "--exp-mprophet-file=" + exportPath // Export mProphet features + ); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_targets_for_which_to_export_mProphet_features_), output); + // Test error (no results) + output = RunCommand("--in=" + docWithNoResultsPath, // Load a document with no results + "--exp-mprophet-file=" + exportPath // Export mProphet features + ); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_results_to_export_mProphet_features_), output); + // Test error (invalid feature name) + output = RunCommand("--in=" + docWithResults, // Load a document with no results + "--exp-mprophet-file=" + exportPath, // Export mProphet features + "--exp-mprophet-exclude-feature=" + invalidFeatureName + ); + CheckRunCommandOutputContains(string.Format(Resources + .CommandArgs_ParseArgsInternal_Error__Attempting_to_exclude_an_unknown_feature_name___0____Try_one_of_the_following_, invalidFeatureName), output); + // Test export + output = RunCommand("--in=" + docWithResults, // Load a document with results + "--exp-mprophet-file=" + exportPath // Export mProphet features + ); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_, exportPath), output); + AssertEx.FileEquals(expectedExport, exportPath); + // Test export with target peptides only and best scoring peaks only + output = RunCommand("--in=" + docWithResults, // Load a document with results + "--exp-mprophet-file=" + exportPath, // Export mProphet features + "--exp-mprophet-targets-only", // Export should not include decoys peptides + "--exp-mprophet-best-peaks-only" // Export should contain best scoring peaks + ); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_, exportPath), output); + AssertEx.FileEquals(expectedExportTargetsBestPeaks, exportPath); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_, exportPath), output); + // Test export with some scores excluded + output = RunCommand("--in=" + docWithResults, // Load a document with results + "--exp-mprophet-file=" + exportPath, // Export mProphet features + "--exp-mprophet-exclude-feature=" + "Intensity", // Export should not contain an "Intensity" column + "--exp-mprophet-exclude-feature=" + "Standard signal to noise" // Export should not contain a "Standard signal to noise" column + ); + CheckRunCommandOutputContains(string.Format(Resources.CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_, exportPath), output); + AssertEx.FileEquals(expectedExportExcludeFeatures, exportPath); + } + private static void CheckRefSpectraAll(IList refSpectra) { diff --git a/pwiz_tools/Skyline/TestData/ConsoleExportMProphetTest.zip b/pwiz_tools/Skyline/TestData/ConsoleExportMProphetTest.zip new file mode 100644 index 0000000000..0c2afef035 Binary files /dev/null and b/pwiz_tools/Skyline/TestData/ConsoleExportMProphetTest.zip differ diff --git a/pwiz_tools/Skyline/TestData/TestData.csproj b/pwiz_tools/Skyline/TestData/TestData.csproj index d6ef333721..8bd8c175fc 100644 --- a/pwiz_tools/Skyline/TestData/TestData.csproj +++ b/pwiz_tools/Skyline/TestData/TestData.csproj @@ -240,6 +240,7 @@ +