Skip to content

Commit 920c548

Browse files
trishortsclaude
andcommitted
test(metadraw): assert .msl<->.msp render parity + dispose readers
Address review of TestMetaDrawWithMslSpectralLibrary: - Dispose the inline SpectralLibrary readers before the SearchTask re-opens the same .msp files (avoids a file-in-use race on Win CI). - Render the PSM with both the .msl and .msp libraries and assert equal mirror-plot peak counts (true lossless parity) instead of only matching the hardcoded literal 52 (kept as an anchor). - Guard FilteredListOfPsms.First() and assert the full set of resource collections are emptied after CleanUpResources, matching the .msp sibling test. Extract a shared CountMetaDrawMirrorPlotLibraryPeaks helper for the two renders. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011gcrsvLBgMKmDNpnbM3iE8
1 parent f564866 commit 920c548

1 file changed

Lines changed: 36 additions & 19 deletions

File tree

MetaMorpheus/Test/MetaDraw/MetaDrawTest.cs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,13 +1593,14 @@ public static void TestMetaDrawWithMslSpectralLibrary()
15931593

15941594
Directory.CreateDirectory(outputFolder);
15951595

1596-
// Convert the .msp test libraries to binary .msl for MetaDraw to load.
1596+
// Convert the .msp test libraries to binary .msl for MetaDraw to load. Dispose each reader
1597+
// before the SearchTask re-opens the same .msp files (avoids a file-in-use race on Windows CI).
15971598
string mslLibrary1 = Path.Combine(outputFolder, "P16858_target.msl");
15981599
string mslLibrary2 = Path.Combine(outputFolder, "P16858_decoy.msl");
1599-
Readers.SpectralLibrary.MslWriter.WriteFromLibrarySpectra(mslLibrary1,
1600-
new Readers.SpectralLibrary.SpectralLibrary(new List<string> { mspLibrary1 }).GetAllLibrarySpectra().ToList());
1601-
Readers.SpectralLibrary.MslWriter.WriteFromLibrarySpectra(mslLibrary2,
1602-
new Readers.SpectralLibrary.SpectralLibrary(new List<string> { mspLibrary2 }).GetAllLibrarySpectra().ToList());
1600+
using (var srcLib = new Readers.SpectralLibrary.SpectralLibrary(new List<string> { mspLibrary1 }))
1601+
Readers.SpectralLibrary.MslWriter.WriteFromLibrarySpectra(mslLibrary1, srcLib.GetAllLibrarySpectra().ToList());
1602+
using (var srcLib = new Readers.SpectralLibrary.SpectralLibrary(new List<string> { mspLibrary2 }))
1603+
Readers.SpectralLibrary.MslWriter.WriteFromLibrarySpectra(mslLibrary2, srcLib.GetAllLibrarySpectra().ToList());
16031604

16041605
// run search task (libraries supplied as .msp; produces the PSM file MetaDraw displays)
16051606
var searchtask = new SearchTask();
@@ -1614,17 +1615,35 @@ public static void TestMetaDrawWithMslSpectralLibrary()
16141615

16151616
var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv");
16161617

1617-
// load results into metadraw, pointing the spectral library at the .msl files
1618+
// Render the same PSM once with the binary .msl libraries and once with the text .msp
1619+
// libraries, then assert the mirror-plot library-peak counts are equal — proving the .msl
1620+
// display is lossless/identical to .msp rather than matching a hardcoded literal.
1621+
int mslMirrorPeaks = CountMetaDrawMirrorPlotLibraryPeaks(spectraFile, psmFile, new List<string> { mslLibrary1, mslLibrary2 });
1622+
int mspMirrorPeaks = CountMetaDrawMirrorPlotLibraryPeaks(spectraFile, psmFile, new List<string> { mspLibrary1, mspLibrary2 });
1623+
1624+
Assert.That(mslMirrorPeaks, Is.EqualTo(mspMirrorPeaks));
1625+
Assert.That(mslMirrorPeaks, Is.EqualTo(52)); // anchor: matches the sibling .msp test
1626+
1627+
// delete output
1628+
Directory.Delete(outputFolder, true);
1629+
}
1630+
1631+
/// <summary>
1632+
/// Loads a PSM file + spectral libraries into MetaDraw, renders the first filtered PSM, and
1633+
/// returns the number of library (mirror-plot) peaks drawn. Used to compare .msl vs .msp
1634+
/// rendering. Asserts a clean load, a non-empty PSM list, and full resource cleanup.
1635+
/// </summary>
1636+
private static int CountMetaDrawMirrorPlotLibraryPeaks(string spectraFile, string psmFile, List<string> spectralLibraryPaths)
1637+
{
16181638
var metadrawLogic = new MetaDrawLogic();
16191639
metadrawLogic.SpectraFilePaths.Add(spectraFile);
16201640
metadrawLogic.SpectralMatchResultFilePaths.Add(psmFile);
1621-
metadrawLogic.SpectralLibraryPaths.Add(mslLibrary1);
1622-
metadrawLogic.SpectralLibraryPaths.Add(mslLibrary2);
1641+
foreach (var libPath in spectralLibraryPaths)
1642+
metadrawLogic.SpectralLibraryPaths.Add(libPath);
16231643
var errors = metadrawLogic.LoadFiles(true, true);
1624-
16251644
Assert.That(!errors.Any());
1645+
Assert.That(metadrawLogic.FilteredListOfPsms.Any());
16261646

1627-
// draw PSM
16281647
var plotView = new OxyPlot.Wpf.PlotView() { Name = "plotView" };
16291648
var scrollableCanvas = new Canvas();
16301649
var stationaryCanvas = new Canvas();
@@ -1633,23 +1652,21 @@ public static void TestMetaDrawWithMslSpectralLibrary()
16331652
var psm = metadrawLogic.FilteredListOfPsms.First();
16341653

16351654
MetaDrawSettings.FirstAAonScreenIndex = 0;
1636-
MetaDrawSettings.NumberOfAAOnScreen = metadrawLogic.FilteredListOfPsms.First().BaseSeq.Length;
1655+
MetaDrawSettings.NumberOfAAOnScreen = psm.BaseSeq.Length;
16371656
metadrawLogic.DisplaySequences(stationaryCanvas, scrollableCanvas, sequenceAnnotationCanvas, psm);
16381657
metadrawLogic.DisplaySpectrumMatch(plotView, psm, parentChildView, out errors);
16391658
Assert.That(errors == null || !errors.Any());
16401659

1641-
// library peaks (negative intensities in the mirror plot) were drawn from the .msl library —
1642-
// identical count to the .msp library in TestMetaDrawWithSpectralLibrary, confirming lossless display
1643-
var plotSeries = plotView.Model.Series;
1644-
var mirrorPlotPeaks = plotSeries.Where(p => ((LineSeries)p).Points[1].Y < 0).ToList();
1645-
Assert.That(mirrorPlotPeaks.Count == 52);
1660+
// library peaks are the negative-intensity series in the mirror plot
1661+
int mirrorPlotPeaks = plotView.Model.Series.Count(p => ((LineSeries)p).Points[1].Y < 0);
16461662

1647-
// clean up resources
16481663
metadrawLogic.CleanUpResources();
1664+
Assert.That(!metadrawLogic.FilteredListOfPsms.Any());
1665+
Assert.That(!metadrawLogic.SpectralMatchResultFilePaths.Any());
1666+
Assert.That(!metadrawLogic.SpectraFilePaths.Any());
16491667
Assert.That(!metadrawLogic.SpectralLibraryPaths.Any());
16501668

1651-
// delete output
1652-
Directory.Delete(outputFolder, true);
1669+
return mirrorPlotPeaks;
16531670
}
16541671

16551672
[Test]

0 commit comments

Comments
 (0)