Skip to content

Commit

Permalink
Add validation for cutoff score in ImportPeptideSearchDlg
Browse files Browse the repository at this point in the history
For whatever reason the cutoff score field in the "Import Peptide Search" dialog has never had any validation code, just cleaning that up. 

Not reported by any user.
  • Loading branch information
bspratt authored Nov 27, 2023
1 parent d61499c commit 746bce2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
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
11 changes: 9 additions & 2 deletions pwiz_tools/Skyline/TestFunctional/DdaSearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,24 @@ private void TestSearch()
// Add the test xml file to the search files list and try to
// build the document library.

RunUI(() =>
var errMsgDlg = ShowDialog<MessageDlg>(() =>
{
Assert.IsTrue(importPeptideSearchDlg.CurrentPage == ImportPeptideSearchDlg.Pages.spectra_page);
importPeptideSearchDlg.BuildPepSearchLibControl.PerformDDASearch = true;
importPeptideSearchDlg.BuildPepSearchLibControl.DdaSearchDataSources = SearchFiles.Select(o => (MsDataFileUri)new MsDataFilePath(o)).Take(1).ToArray();
importPeptideSearchDlg.BuildPepSearchLibControl.WorkflowType = ImportPeptideSearchDlg.Workflow.dia; // will go back and switch to DDA
importPeptideSearchDlg.BuildPepSearchLibControl.CutOffScore = 0.9;
importPeptideSearchDlg.BuildPepSearchLibControl.CutOffScoreText = @"12%"; // Intentionally bad
importPeptideSearchDlg.BuildPepSearchLibControl.IrtStandards = IrtStandard.AUTO;
Assert.IsTrue(importPeptideSearchDlg.ClickNextButton());
});
OkDialog(errMsgDlg, errMsgDlg.OkDialog); // Expect complaint about bad cutoff score

RunUI(() =>
{
Assert.IsTrue(importPeptideSearchDlg.CurrentPage == ImportPeptideSearchDlg.Pages.spectra_page); // Should not have advanced
importPeptideSearchDlg.BuildPepSearchLibControl.CutOffScore = 0.9;
Assert.IsTrue(importPeptideSearchDlg.ClickNextButton());
});
// With only 1 source, no add/remove prefix/suffix dialog

// We're on the "Match Modifications" page. Add M+16 mod.
Expand Down

0 comments on commit 746bce2

Please sign in to comment.