Skip to content

Commit

Permalink
Merge branch 'master' into Skyline/work/20231126_FixChromIdAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
nickshulman authored Nov 27, 2023
2 parents b3826e3 + 746bce2 commit 8f9fa6e
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 21 deletions.
38 changes: 38 additions & 0 deletions pwiz_tools/Skyline/CommandArgUsage.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/CommandArgUsage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -946,4 +946,16 @@ greater peak area.</value>
<data name="_exp_mprophet_targets_only" xml:space="preserve">
<value>Include feature scores only for targets. Requires the --exp-mprophet-file argument.</value>
</data>
<data name="_pep_exclude_nterminal_aas" xml:space="preserve">
<value>Exclude all peptides starting before this amino acid position in each protein.</value>
</data>
<data name="_pep_exclude_potential_ragged_ends" xml:space="preserve">
<value>Exclude peptides resulting from cleavage sites with immediate preceding or following cleavage sites. e.g. RR, KK, RK, KR for trypsin</value>
</data>
<data name="_pep_max_length" xml:space="preserve">
<value>The maximum length of a peptide to add to the document.</value>
</data>
<data name="_pep_min_length" xml:space="preserve">
<value>The minimum length of a peptide to add to the document.</value>
</data>
</root>
22 changes: 22 additions & 0 deletions pwiz_tools/Skyline/CommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,17 @@ public bool ImportingSearch
(c, p) => c.FullScanRetentionTimeFilter = p);
public static readonly Argument ARG_FULL_SCAN_RT_FILTER_TOLERANCE = new DocArgument(@"full-scan-rt-filter-tolerance", MINUTES_VALUE,
(c, p) => c.FullScanRetentionTimeFilterLength = p.ValueDouble) { WrapValue = true };

public static readonly Argument ARG_PEPTIDE_MIN_LENGTH = new DocArgument(@"pep-min-length", INT_VALUE,
(c, p) => c.PeptideFilterMinLength = p.GetValueInt(PeptideFilter.MIN_MIN_LENGTH, PeptideFilter.MAX_MIN_LENGTH));
public static readonly Argument ARG_PEPTIDE_MAX_LENGTH = new DocArgument(@"pep-max-length", INT_VALUE,
(c, p) => c.PeptideFilterMaxLength = p.GetValueInt(PeptideFilter.MIN_MAX_LENGTH, PeptideFilter.MAX_MAX_LENGTH));
public static readonly Argument ARG_PEPTIDE_EXCLUDE_NTERMINAL_AAS = new DocArgument(@"pep-exclude-nterminal-aas", INT_VALUE,
(c, p) => c.PeptideFilterExcludeNTerminalAAs = p.GetValueInt(PeptideFilter.MIN_EXCLUDE_NTERM_AA, PeptideFilter.MAX_EXCLUDE_NTERM_AA));
public static readonly Argument ARG_PEPTIDE_EXCLUDE_POTENTIAL_RAGGED_ENDS = new DocArgument(@"pep-exclude-potential-ragged-ends",
(c, p) => c.PeptideFilterExcludePotentialRaggedEnds = p.IsNameOnly || bool.Parse(p.Value))
{ OptionalValue = true };

public static readonly Argument ARG_IMS_LIBRARY_RES = new DocArgument(@"ims-library-res", RP_VALUE,
(c, p) => c.IonMobilityLibraryRes = p.ValueDouble);

Expand Down Expand Up @@ -1415,6 +1426,7 @@ public bool ImportingSearch
ARG_FULL_SCAN_ACQUISITION_METHOD, ARG_FULL_SCAN_PRODUCT_ISOLATION_SCHEME,
ARG_FULL_SCAN_PRODUCT_ANALYZER, ARG_FULL_SCAN_PRODUCT_RES, ARG_FULL_SCAN_PRODUCT_RES_MZ,
ARG_FULL_SCAN_RT_FILTER, ARG_FULL_SCAN_RT_FILTER_TOLERANCE, ARG_IMS_LIBRARY_RES,
ARG_PEPTIDE_MIN_LENGTH, ARG_PEPTIDE_MAX_LENGTH, ARG_PEPTIDE_EXCLUDE_NTERMINAL_AAS, ARG_PEPTIDE_EXCLUDE_POTENTIAL_RAGGED_ENDS,
ARG_INST_MIN_MZ, ARG_INST_MAX_MZ, ARG_INST_DYNAMIC_MIN_MZ,
ARG_INST_METHOD_TOLERANCE, ARG_INST_MIN_TIME, ARG_INST_MAX_TIME,
ARG_INST_TRIGGERED_CHROMATOGRAMS)
Expand Down Expand Up @@ -1581,6 +1593,16 @@ public bool FullScanSettings
}
}

public int? PeptideFilterMinLength { get; private set; }
public int? PeptideFilterMaxLength { get; private set; }
public int? PeptideFilterExcludeNTerminalAAs { get; private set; }
public bool? PeptideFilterExcludePotentialRaggedEnds { get; private set; }

public bool PeptideFilterSettings => PeptideFilterExcludeNTerminalAAs.HasValue ||
PeptideFilterExcludePotentialRaggedEnds.HasValue ||
PeptideFilterMaxLength.HasValue ||
PeptideFilterMinLength.HasValue;

public double? IonMobilityLibraryRes { get; private set; }

public bool ImsSettings
Expand Down
50 changes: 50 additions & 0 deletions pwiz_tools/Skyline/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ private bool ProcessDocument(CommandArgs commandArgs)
if (!SetFullScanSettings(commandArgs))
return false;
}
if (commandArgs.PeptideFilterSettings)
{
if (!SetPeptideFilterSettings(commandArgs))
return false;
}

if (commandArgs.ImsSettings)
{
Expand Down Expand Up @@ -1158,6 +1163,51 @@ private bool SetFullScanSettings(CommandArgs commandArgs)
}
}

private bool SetPeptideFilterSettings(CommandArgs commandArgs)
{
try
{
ModifyDocumentWithLogging(d => d.ChangeSettings(d.Settings.ChangePeptideSettings(p =>
{
var filterSettings = p.Filter;

if (commandArgs.PeptideFilterMinLength.HasValue)
{
filterSettings = filterSettings.ChangeMinPeptideLength(commandArgs.PeptideFilterMinLength.Value);
p = p.ChangeFilter(filterSettings);
}

if (commandArgs.PeptideFilterMaxLength.HasValue)
{
filterSettings = filterSettings.ChangeMaxPeptideLength(commandArgs.PeptideFilterMaxLength.Value);
p = p.ChangeFilter(filterSettings);
}

if (commandArgs.PeptideFilterExcludeNTerminalAAs.HasValue)
{
filterSettings = filterSettings.ChangeExcludeNTermAAs(commandArgs.PeptideFilterExcludeNTerminalAAs.Value);
p = p.ChangeFilter(filterSettings);
}

if (commandArgs.PeptideFilterExcludePotentialRaggedEnds.HasValue)
{
var digestSettings = p.DigestSettings;
digestSettings = new DigestSettings(digestSettings.MaxMissedCleavages, commandArgs.PeptideFilterExcludePotentialRaggedEnds.Value);
p = p.ChangeDigestSettings(digestSettings);
}

return p;
})), AuditLogEntry.SettingsLogFunction);
return true;
}
catch (Exception x)
{
_out.WriteLine(Resources.CommandLine_SetPeptideFilterSettings_Error__Failed_attempting_to_change_the_peptide_filter_settings_);
_out.WriteLine(x.Message);
return false;
}
}

private bool SetImsSettings(CommandArgs commandArgs)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,40 @@ public void AddSearchFiles(IEnumerable<string> fileNames)
SearchFilenames = BuildLibraryDlg.AddInputFiles(WizardForm, SearchFilenames, fileNames, PerformDDASearch);
}

// For test purposes, lets us test error handling
public string CutOffScoreText
{
set { textCutoff.Text = value; } // Can be a null or empty string under some circumstances
}

public bool NeedsCutoffScore => comboInputFileType.SelectedIndex > 0; // Only needed if Skyline is conducting the search

private double? _cutoffScore; // May be null when Skyline is not doing the search

public double? CutOffScore
{
// Only valid when Skyline performs the search
get { return comboInputFileType.SelectedIndex > 0 ? double.Parse(textCutoff.Text) : (double?) null; }
set { textCutoff.Text = value.HasValue ? value.Value.ToString(CultureInfo.CurrentCulture) : string.Empty; }
get { return NeedsCutoffScore ? _cutoffScore : null; }
set
{
_cutoffScore = value;
textCutoff.Text = _cutoffScore.HasValue ? _cutoffScore.Value.ToString(CultureInfo.CurrentCulture) : string.Empty;
}
}

public bool ValidateCutoffScore()
{
if (!NeedsCutoffScore)
{
return true; // Doesn't matter what's in the text box, we won't use it
}
var helper = new MessageBoxHelper(this.ParentForm);
if (helper.ValidateDecimalTextBox(textCutoff, out var cutoffScore))
{
_cutoffScore = cutoffScore;
return true;
}
return false;
}

public bool IncludeAmbiguousMatches
Expand Down Expand Up @@ -643,5 +672,6 @@ private void comboInputFileType_SelectedIndexChanged(object sender, EventArgs e)
{
UpdatePerformDDASearch();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ private void NextPage()
{
_pagesToSkip.Clear();

if (!BuildPepSearchLibControl.ValidateCutoffScore())
{
return;
}
ImportPeptideSearch.IsDDASearch = BuildPepSearchLibControl.PerformDDASearch;
ImportFastaControl.IsDDASearch = BuildPepSearchLibControl.PerformDDASearch;
if (!BuildPepSearchLibControl.UseExistingLibrary)
Expand Down
10 changes: 10 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.

3 changes: 3 additions & 0 deletions pwiz_tools/Skyline/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -13830,4 +13830,7 @@ If you choose Disable, you can enable Auto-select later with the "Refine &gt; Ad
<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>
<data name="CommandLine_SetPeptideFilterSettings_Error__Failed_attempting_to_change_the_peptide_filter_settings_" xml:space="preserve">
<value>Error: Failed attempting to change the peptide filter settings.</value>
</data>
</root>
60 changes: 43 additions & 17 deletions pwiz_tools/Skyline/TestData/CommandLineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ public void ConsoleNewDocumentTest()
"--tran-product-end-ion=" + TransitionFilter.EndFragmentFinder.LAST_ION_MINUS_1.Label,
"--tran-product-clear-special-ions",
"--tran-use-dia-window-exclusion",
"--pep-min-length=4",
"--pep-max-length=42",
"--pep-exclude-nterminal-aas=2",
"--pep-exclude-potential-ragged-ends",
"--library-product-ions=6",
"--library-min-product-ions=6",
"--library-match-tolerance=" + 0.05 + "mz",
Expand Down Expand Up @@ -360,6 +364,10 @@ public void ConsoleNewDocumentTest()
Assert.AreEqual(TransitionFilter.EndFragmentFinder.LAST_ION_MINUS_1.Label, doc.Settings.TransitionSettings.Filter.EndFragmentFinderLabel.Label);
Assert.AreEqual(0, doc.Settings.TransitionSettings.Filter.MeasuredIons.Count);
Assert.AreEqual(true, doc.Settings.TransitionSettings.Filter.ExclusionUseDIAWindow);
Assert.AreEqual(4, doc.Settings.PeptideSettings.Filter.MinPeptideLength);
Assert.AreEqual(42, doc.Settings.PeptideSettings.Filter.MaxPeptideLength);
Assert.AreEqual(2, doc.Settings.PeptideSettings.Filter.ExcludeNTermAAs);
Assert.AreEqual(true, doc.Settings.PeptideSettings.DigestSettings.ExcludeRaggedEnds);
Assert.AreEqual(6, doc.Settings.TransitionSettings.Libraries.IonCount);
Assert.AreEqual(6, doc.Settings.TransitionSettings.Libraries.MinIonCount);
Assert.AreEqual(new MzTolerance(0.05), doc.Settings.TransitionSettings.Libraries.IonMatchMzTolerance);
Expand Down Expand Up @@ -442,43 +450,61 @@ public void ConsoleNewDocumentTest()

File.Delete(docPath);

// test parameter validation: analyzer specified with isotopes=none
// run command that should cause an error and validate the output contains the expected output
void RunCommandAndValidateError(string[] extraSettings, string expectedOutput)
{
output = RunCommand(new[] { "--new=" + docPath }.Concat(extraSettings).ToArray());
StringAssert.Contains(output, expectedOutput);
}

// parameter validation: analyzer specified with isotopes=none
settings = new[]
{
"--new=" + docPath,
"--full-scan-precursor-isotopes=None",
"--full-scan-precursor-analyzer=centroided",
};

output = RunCommand(settings);
StringAssert.Contains(output, string.Format(
RunCommandAndValidateError(settings, string.Format(
Resources.CommandArgs_WarnArgRequirment_Warning__Use_of_the_argument__0__requires_the_argument__1_,
CommandArgs.ARG_FULL_SCAN_PRECURSOR_ANALYZER.ArgumentText,
CommandArgs.ARG_FULL_SCAN_PRECURSOR_RES.ArgumentText));

// test parameter validation: DDA method with isolation scheme
// parameter validation: DDA method with isolation scheme
settings = new[]
{
"--new=" + docPath,
"--full-scan-acquisition-method=DDA",
"--full-scan-isolation-scheme=All Ions",
};

output = RunCommand(settings);
StringAssert.Contains(output, string.Format(
RunCommandAndValidateError(settings, string.Format(
Resources.TransitionFullScan_DoValidate_An_isolation_window_width_value_is_not_allowed_in__0___mode,
FullScanAcquisitionMethod.DDA.Label));

// test parameter validation: DIA method without isolation scheme
settings = new[]
{
"--new=" + docPath,
"--full-scan-acquisition-method=DIA",
};
// parameter validation: DIA method without isolation scheme
settings = new[] { "--full-scan-acquisition-method=DIA" };

output = RunCommand(settings);
StringAssert.Contains(output,
Resources.TransitionFullScan_DoValidate_An_isolation_window_width_value_is_required_in_DIA_mode);
RunCommandAndValidateError(settings, Resources.TransitionFullScan_DoValidate_An_isolation_window_width_value_is_required_in_DIA_mode);

// parameter validation: int min
settings = new[] { "--pep-min-length=" + (PeptideFilter.MIN_MIN_LENGTH - 1) };

RunCommandAndValidateError(settings, string.Format(
Resources.ValueOutOfRangeDoubleException_ValueOutOfRangeException_The_value___0___for_the_argument__1__must_be_between__2__and__3__,
PeptideFilter.MIN_MIN_LENGTH - 1, CommandArgs.ARG_PEPTIDE_MIN_LENGTH.ArgumentText, PeptideFilter.MIN_MIN_LENGTH, PeptideFilter.MAX_MIN_LENGTH));

// parameter validation: int max
settings = new[] { "--pep-max-length=" + (PeptideFilter.MAX_MAX_LENGTH + 1) };

RunCommandAndValidateError(settings, string.Format(
Resources.ValueOutOfRangeDoubleException_ValueOutOfRangeException_The_value___0___for_the_argument__1__must_be_between__2__and__3__,
PeptideFilter.MAX_MAX_LENGTH + 1, CommandArgs.ARG_PEPTIDE_MAX_LENGTH.ArgumentText, PeptideFilter.MIN_MAX_LENGTH, PeptideFilter.MAX_MAX_LENGTH));

// parameter validation: bad bool
settings = new[] { "--pep-exclude-potential-ragged-ends=maybe" };

RunCommandAndValidateError(settings, string.Format(
Resources.ValueUnexpectedException_ValueUnexpectedException_The_argument__0__should_not_have_a_value_specified,
CommandArgs.ARG_PEPTIDE_EXCLUDE_POTENTIAL_RAGGED_ENDS.ArgumentText));
}

[TestMethod]
Expand Down
Loading

0 comments on commit 8f9fa6e

Please sign in to comment.