Skip to content

Commit

Permalink
Add option to export mProphet features through the command line (#2746)
Browse files Browse the repository at this point in the history
* Add new arguments for exporting mProphet features

* Add command line option to exclude scores from the exported file

* Update escape sequences
  • Loading branch information
henrytsanford authored Oct 13, 2023
1 parent 8e2c5b4 commit bde6557
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 17 deletions.
44 changes: 40 additions & 4 deletions pwiz_tools/Skyline/CommandArgUsage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions pwiz_tools/Skyline/CommandArgUsage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ first occurrence of any peptide.</value>
will be removed from the document:

Green = 1.0
Orange &amp;gt;= 0.5
Red &amp;lt; 0.5</value>
Orange &gt;= 0.5
Red &lt; 0.5</value>
</data>
<data name="_refine_max_peptide_peak_rank" xml:space="preserve">
<value>All transitions with an average area peak ranking
Expand All @@ -709,8 +709,8 @@ removed from the document.</value>
will be removed from the document:

Green = 1.0
Orange &amp;gt;= 0.5
Red &amp;lt; 0.5</value>
Orange &gt;= 0.5
Red &lt; 0.5</value>
</data>
<data name="_refine_min_time_correlation" xml:space="preserve">
<value>Precursors will be removed from the document
Expand Down Expand Up @@ -934,4 +934,16 @@ greater peak area.</value>
<data name="_exp_speclib_file" xml:space="preserve">
<value>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.</value>
</data>
<data name="_exp_mprophet_exclude_feature" xml:space="preserve">
<value>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.</value>
</data>
<data name="_exp_mprophet_file" xml:space="preserve">
<value>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.</value>
</data>
<data name="_exp_mprophet_best_peaks_only" xml:space="preserve">
<value>Include feature scores only for the best scoring peaks. Requires the --exp-mprophet-file argument.</value>
</data>
<data name="_exp_mprophet_targets_only" xml:space="preserve">
<value>Include feature scores only for targets. Requires the --exp-mprophet-file argument.</value>
</data>
</root>
34 changes: 28 additions & 6 deletions pwiz_tools/Skyline/CommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -789,9 +789,9 @@ private List<double> ParseNumberList(NameValuePair pair)
}
}

private bool ParseReintegrateExcludeFeature(NameValuePair pair)
private bool ParseExcludeFeature(NameValuePair pair, ICollection<IPeakFeatureCalculator> 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)
Expand All @@ -811,8 +811,8 @@ private bool ParseReintegrateExcludeFeature(NameValuePair pair)

return false;
}

ExcludeFeatures.Add(calc);
featureList.Add(calc);
return true;
}

Expand Down Expand Up @@ -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<IPeakFeatureCalculator> 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);
Expand Down Expand Up @@ -2157,6 +2177,8 @@ public CommandArgs(CommandStatusWriter output, bool isDocumentLoaded)
ExcludeFeatures = new List<IPeakFeatureCalculator>();
SharedFileType = ShareType.DEFAULT;

MProphetExcludeScores = new List<IPeakFeatureCalculator>();

ImportBeforeDate = null;
ImportOnOrAfterDate = null;
}
Expand Down
70 changes: 67 additions & 3 deletions pwiz_tools/Skyline/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand Down Expand Up @@ -3149,6 +3162,57 @@ public bool ExportSpecLib(string specLibFile)
return true;
}

/// <summary>
/// Export mProphet features as a .csv file
/// </summary>
/// <param name="mProphetFile">File path to export the mProphet file to</param>
/// <param name="targetPeptidesOnly">Do not include decoys, only targets</param>
/// <param name="bestOnly">Export best scoring peaks only</param>
/// <param name="excludeScores">A list of features to exclude from the exported file</param>
/// <returns>True upon successful import, false upon error</returns>
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,
Expand Down
6 changes: 6 additions & 0 deletions pwiz_tools/Skyline/FileUI/MProphetFeaturesDlg.resx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="checkBoxBestOnly.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="checkBoxBestOnly.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
Expand Down Expand Up @@ -261,6 +264,9 @@
<data name="&gt;&gt;checkBoxBestOnly.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="checkBoxTargetsOnly.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="checkBoxTargetsOnly.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
Expand Down
40 changes: 40 additions & 0 deletions pwiz_tools/Skyline/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pwiz_tools/Skyline/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -13899,4 +13899,16 @@ If you choose Disable, you can enable Auto-select later with the "Refine &gt; Ad
<data name="CommandLine_ExportSpecLib_Error__Failure_attempting_to_save_spectral_library_file__0__" xml:space="preserve">
<value>Error: Failure attempting to save spectral library file {0}.</value>
</data>
<data name="CommandLine_ExportMProphetFeatures_mProphet_features_file__0__exported_successfully_" xml:space="preserve">
<value>mProphet features file {0} exported successfully.</value>
</data>
<data name="CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_targets_for_which_to_export_mProphet_features_" xml:space="preserve">
<value>Error: The document must contain targets for which to export mProphet features.</value>
</data>
<data name="CommandLine_ExportMProphetFeatures_Error__The_document_must_contain_results_to_export_mProphet_features_" xml:space="preserve">
<value>Error: The document must contain results to export mProphet features.</value>
</data>
<data name="CommandLine_ExportMProphetFeatures_Error__Failure_attempting_to_save_mProphet_features_file__0__" xml:space="preserve">
<value>Error: Failure attempting to save mProphet features file {0}.</value>
</data>
</root>
Loading

0 comments on commit bde6557

Please sign in to comment.