From 8be2574a0939e8db66ecc2126be4904d944b1025 Mon Sep 17 00:00:00 2001 From: nbollis Date: Tue, 21 May 2024 15:08:45 -0500 Subject: [PATCH 01/11] Updated to MzLib 1.0.548 and fixed custom ions in search tasks --- MetaMorpheus/CMD/CMD.csproj | 2 +- .../ClassicSearch/ClassicSearchEngine.cs | 9 +++++++++ .../ClassicSearch/MiniClassicSearchEngine.cs | 2 +- MetaMorpheus/EngineLayer/EngineLayer.csproj | 2 +- .../ModernSearch/ModernSearchEngine.cs | 7 +++++++ .../NonSpecificEnzymeSearchEngine.cs | 8 ++++++++ .../SpectralLibrarySearchFunction.cs | 7 +++++-- MetaMorpheus/GUI/GUI.csproj | 2 +- MetaMorpheus/GuiFunctions/GuiFunctions.csproj | 2 +- .../CalibrationTask/CalibrationTask.cs | 4 +++- MetaMorpheus/TaskLayer/TaskLayer.csproj | 2 +- MetaMorpheus/Test/CustomFragmentationTest.cs | 17 +++++++++++------ MetaMorpheus/Test/Test.csproj | 2 +- 13 files changed, 50 insertions(+), 16 deletions(-) diff --git a/MetaMorpheus/CMD/CMD.csproj b/MetaMorpheus/CMD/CMD.csproj index 2570c57f1..69e265fd3 100644 --- a/MetaMorpheus/CMD/CMD.csproj +++ b/MetaMorpheus/CMD/CMD.csproj @@ -24,7 +24,7 @@ - + diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs index ee15ab360..c35007011 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Omics.Fragmentation.Peptide; using Omics.Modifications; namespace EngineLayer.ClassicSearch @@ -67,6 +68,10 @@ protected override MetaMorpheusEngineResults RunSpecific() myLocks[i] = new object(); } + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = + CommonParameters.CustomIons; + Status("Performing classic search..."); if (Proteins.Any()) @@ -168,6 +173,10 @@ protected override MetaMorpheusEngineResults RunSpecific() psm.ResolveAllAmbiguities(); } + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = + new List(); + return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs index 854609313..80ad9eff7 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/MiniClassicSearchEngine.cs @@ -137,7 +137,7 @@ public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, Spec if (!Peptide.Parent.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) { SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, librarySpectrum.XArray, librarySpectrum.YArray, - SpectralSimilarity.SpectrumNormalizationScheme.squareRootSpectrumSum, fileSpecificParameters.ProductMassTolerance.Value, false); + SpectralSimilarity.SpectrumNormalizationScheme.SquareRootSpectrumSum, fileSpecificParameters.ProductMassTolerance.Value, false); if (s.SpectralContrastAngle().HasValue) { pwsms.Add((Notch, Peptide)); diff --git a/MetaMorpheus/EngineLayer/EngineLayer.csproj b/MetaMorpheus/EngineLayer/EngineLayer.csproj index f1d1a4102..b9fe7d104 100644 --- a/MetaMorpheus/EngineLayer/EngineLayer.csproj +++ b/MetaMorpheus/EngineLayer/EngineLayer.csproj @@ -21,7 +21,7 @@ - + diff --git a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs index 137bc00fb..b9c01d392 100644 --- a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Omics.Fragmentation.Peptide; namespace EngineLayer.ModernSearch { @@ -46,6 +47,8 @@ protected override MetaMorpheusEngineResults RunSpecific() int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile; int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray(); + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = CommonParameters.CustomIons; Parallel.ForEach(threads, (scanIndex) => { @@ -87,6 +90,10 @@ protected override MetaMorpheusEngineResults RunSpecific() psm.ResolveAllAmbiguities(); } + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = + new List(); + return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs index 1426bd4aa..f486835b8 100644 --- a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs @@ -56,6 +56,9 @@ protected override MetaMorpheusEngineResults RunSpecific() throw new NotImplementedException(); } + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = CommonParameters.CustomIons; + int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile; int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray(); Parallel.ForEach(threads, (i) => @@ -163,6 +166,11 @@ protected override MetaMorpheusEngineResults RunSpecific() } } }); + + if (CommonParameters.DissociationType == DissociationType.Custom) + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = + new List(); + return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/SpectralLibrarySearch/SpectralLibrarySearchFunction.cs b/MetaMorpheus/EngineLayer/SpectralLibrarySearch/SpectralLibrarySearchFunction.cs index 10bf04fd6..bc2a30c99 100644 --- a/MetaMorpheus/EngineLayer/SpectralLibrarySearch/SpectralLibrarySearchFunction.cs +++ b/MetaMorpheus/EngineLayer/SpectralLibrarySearch/SpectralLibrarySearchFunction.cs @@ -47,7 +47,8 @@ public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, Spec //if peptide is target, directly look for the target's spectrum in the spectral library if (!Peptide.Parent.IsDecoy && spectralLibrary.TryGetSpectrum(Peptide.FullSequence, scan.PrecursorCharge, out var librarySpectrum)) { - SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, librarySpectrum.XArray, librarySpectrum.YArray, SpectralSimilarity.SpectrumNormalizationScheme.squareRootSpectrumSum, commonParameters.ProductMassTolerance.Value, false); + SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, librarySpectrum.XArray, librarySpectrum.YArray, + SpectralSimilarity.SpectrumNormalizationScheme.SquareRootSpectrumSum, commonParameters.ProductMassTolerance.Value, false); if (s.SpectralContrastAngle().HasValue) { pwsms.Add((Notch, Peptide)); @@ -61,7 +62,9 @@ public static void CalculateSpectralAngles(SpectralLibrary spectralLibrary, Spec var decoyPeptideTheorProducts = new List(); Peptide.Fragment(commonParameters.DissociationType, commonParameters.DigestionParams.FragmentationTerminus, decoyPeptideTheorProducts); var decoylibrarySpectrum = GetDecoyLibrarySpectrumFromTargetByReverse(targetlibrarySpectrum, decoyPeptideTheorProducts); - SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, decoylibrarySpectrum.Select(x => x.Mz).ToArray(),decoylibrarySpectrum.Select(x => x.Intensity).ToArray(), SpectralSimilarity.SpectrumNormalizationScheme.squareRootSpectrumSum, commonParameters.ProductMassTolerance.Value, false); + SpectralSimilarity s = new SpectralSimilarity(scan.TheScan.MassSpectrum, decoylibrarySpectrum.Select(x => x.Mz).ToArray(), + decoylibrarySpectrum.Select(x => x.Intensity).ToArray(), SpectralSimilarity.SpectrumNormalizationScheme.SquareRootSpectrumSum, + commonParameters.ProductMassTolerance.Value, false); if (s.SpectralContrastAngle().HasValue) { pwsms.Add((Notch, Peptide)); diff --git a/MetaMorpheus/GUI/GUI.csproj b/MetaMorpheus/GUI/GUI.csproj index 64bb7e0f7..b1a326389 100644 --- a/MetaMorpheus/GUI/GUI.csproj +++ b/MetaMorpheus/GUI/GUI.csproj @@ -55,7 +55,7 @@ - + diff --git a/MetaMorpheus/GuiFunctions/GuiFunctions.csproj b/MetaMorpheus/GuiFunctions/GuiFunctions.csproj index b32fb72cc..b0692b247 100644 --- a/MetaMorpheus/GuiFunctions/GuiFunctions.csproj +++ b/MetaMorpheus/GuiFunctions/GuiFunctions.csproj @@ -14,7 +14,7 @@ - + diff --git a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs index 82b2762a1..9472e7a18 100644 --- a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs +++ b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs @@ -254,7 +254,9 @@ private static bool ImprovGlobal(double prevPrecTol, double prevProdTol, int pre return countRatio > 0.9 && precRatio + prodRatio < 1.8; } - private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, List variableModifications, List fixedModifications, List proteinList, string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) + private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, + List variableModifications, List fixedModifications, List proteinList, + string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentDataFile); MassDiffAcceptor searchMode = initPrecTol is PpmTolerance ? diff --git a/MetaMorpheus/TaskLayer/TaskLayer.csproj b/MetaMorpheus/TaskLayer/TaskLayer.csproj index 57b70d433..f25ed1e44 100644 --- a/MetaMorpheus/TaskLayer/TaskLayer.csproj +++ b/MetaMorpheus/TaskLayer/TaskLayer.csproj @@ -21,7 +21,7 @@ - + diff --git a/MetaMorpheus/Test/CustomFragmentationTest.cs b/MetaMorpheus/Test/CustomFragmentationTest.cs index 3f0d6bac1..54904bc3c 100644 --- a/MetaMorpheus/Test/CustomFragmentationTest.cs +++ b/MetaMorpheus/Test/CustomFragmentationTest.cs @@ -64,13 +64,18 @@ public static void CustomFragmentationManyTasks() var customIons = new List { ProductType.b, ProductType.c, ProductType.zDot }; DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = customIons; - CalibrationTask calibrationTask = new CalibrationTask(); - calibrationTask.CommonParameters.GetType().GetProperty("DissociationType")?.SetValue(calibrationTask.CommonParameters, DissociationType.Custom); - + var calibCommonParams = new CommonParameters( + dissociationType: DissociationType.Custom, + productMassTolerance: new PpmTolerance(25), + precursorMassTolerance: new PpmTolerance(15), + trimMsMsPeaks: false, + doPrecursorDeconvolution: false); + CalibrationTask calibrationTask = new CalibrationTask() {CommonParameters = calibCommonParams}; + DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = customIons; - GptmdTask gptmdTask = new GptmdTask(); - gptmdTask.CommonParameters.GetType().GetProperty("DissociationType")?.SetValue(gptmdTask.CommonParameters, DissociationType.Custom); - + var gptmdCommonParam = new CommonParameters(dissociationType: DissociationType.Custom); + GptmdTask gptmdTask = new GptmdTask() {CommonParameters = gptmdCommonParam}; + SearchTask searchTask = Toml.ReadFile( Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\customBCZ.toml"), MetaMorpheusTask.tomlConfig); diff --git a/MetaMorpheus/Test/Test.csproj b/MetaMorpheus/Test/Test.csproj index 427478765..9fe40fdd5 100644 --- a/MetaMorpheus/Test/Test.csproj +++ b/MetaMorpheus/Test/Test.csproj @@ -23,7 +23,7 @@ - + From a00af8a0c277dd52ac1b076d83e4c38ec856f432 Mon Sep 17 00:00:00 2001 From: nbollis Date: Tue, 21 May 2024 15:09:55 -0500 Subject: [PATCH 02/11] reverted calibration task change --- MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs index 9472e7a18..82b2762a1 100644 --- a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs +++ b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs @@ -254,9 +254,7 @@ private static bool ImprovGlobal(double prevPrecTol, double prevProdTol, int pre return countRatio > 0.9 && precRatio + prodRatio < 1.8; } - private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, - List variableModifications, List fixedModifications, List proteinList, - string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) + private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, List variableModifications, List fixedModifications, List proteinList, string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(currentDataFile); MassDiffAcceptor searchMode = initPrecTol is PpmTolerance ? From f4695bb0547902527b97a59628816d11d1064fab Mon Sep 17 00:00:00 2001 From: nbollis Date: Mon, 10 Jun 2024 16:59:46 -0500 Subject: [PATCH 03/11] merged in master bbbyy --- .../ClassicSearch/ClassicSearchEngine.cs | 9 --- .../ModernSearch/ModernSearchEngine.cs | 7 -- .../NonSpecificEnzymeSearchEngine.cs | 8 -- .../CrosslinkSpectrumMatchPlot.cs | 4 +- .../Test/MetaDraw/SpectrumMatchPlotTests.cs | 77 +++++++++++++++++++ 5 files changed, 79 insertions(+), 26 deletions(-) diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs index c35007011..ee15ab360 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Omics.Fragmentation.Peptide; using Omics.Modifications; namespace EngineLayer.ClassicSearch @@ -68,10 +67,6 @@ protected override MetaMorpheusEngineResults RunSpecific() myLocks[i] = new object(); } - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = - CommonParameters.CustomIons; - Status("Performing classic search..."); if (Proteins.Any()) @@ -173,10 +168,6 @@ protected override MetaMorpheusEngineResults RunSpecific() psm.ResolveAllAmbiguities(); } - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = - new List(); - return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs index b9c01d392..137bc00fb 100644 --- a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Omics.Fragmentation.Peptide; namespace EngineLayer.ModernSearch { @@ -47,8 +46,6 @@ protected override MetaMorpheusEngineResults RunSpecific() int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile; int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray(); - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = CommonParameters.CustomIons; Parallel.ForEach(threads, (scanIndex) => { @@ -90,10 +87,6 @@ protected override MetaMorpheusEngineResults RunSpecific() psm.ResolveAllAmbiguities(); } - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = - new List(); - return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs index f486835b8..1426bd4aa 100644 --- a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs @@ -56,9 +56,6 @@ protected override MetaMorpheusEngineResults RunSpecific() throw new NotImplementedException(); } - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = CommonParameters.CustomIons; - int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile; int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray(); Parallel.ForEach(threads, (i) => @@ -166,11 +163,6 @@ protected override MetaMorpheusEngineResults RunSpecific() } } }); - - if (CommonParameters.DissociationType == DissociationType.Custom) - DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = - new List(); - return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/SpectrumMatch/CrosslinkSpectrumMatchPlot.cs b/MetaMorpheus/GuiFunctions/MetaDraw/SpectrumMatch/CrosslinkSpectrumMatchPlot.cs index e4a01e443..e9945242f 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/SpectrumMatch/CrosslinkSpectrumMatchPlot.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/SpectrumMatch/CrosslinkSpectrumMatchPlot.cs @@ -58,7 +58,7 @@ public CrosslinkSpectrumMatchPlot(OxyPlot.Wpf.PlotView plotView, PsmFromTsv csm, double dpiScale = MetaDrawSettings.CanvasPdfExportDpi / 96.0; // render stationary sequence as bitmap and export as png - stationarySequence.Height += 30; + stationarySequence.Height += 80; stationarySequence.Width += 30; Size stationarySequenceSize = new Size((int)stationarySequence.Width, (int)stationarySequence.Height); stationarySequence.Measure(stationarySequenceSize); @@ -90,7 +90,7 @@ public CrosslinkSpectrumMatchPlot(OxyPlot.Wpf.PlotView plotView, PsmFromTsv csm, // render ptm legend as bitmap and export as png if used System.Drawing.Bitmap ptmLegendBitmap = null; Point ptmLegendPoint; - if (ptmLegend != null && MetaDrawSettings.ShowLegend) + if (ptmLegend != null && MetaDrawSettings.ShowLegend && ptmLegend.ActualHeight > 0) { // Saving Canvas as a usable Png RenderTargetBitmap ptmLegendRenderBitmap = new((int)(dpiScale * ptmLegend.ActualWidth), (int)(dpiScale * ptmLegend.ActualHeight), diff --git a/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs b/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs index fd77aaae3..f7f4e3232 100644 --- a/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs +++ b/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs @@ -12,6 +12,7 @@ using OxyPlot; using OxyPlot.Annotations; using Omics.Fragmentation; +using Readers; using TaskLayer; namespace Test.MetaDraw @@ -173,5 +174,81 @@ public void TestPeakColor(PeakAnnotationTestCase testCase) var annotation = ((TextAnnotation)plotView.Model.Annotations[testCase.FragmentIndex]); Assert.That(annotation.TextColor, Is.EqualTo(testCase.ExpectedColor)); } + + [Test] + public static void TestCrossLinkSpectrumMatchPlot() + { + // set up file paths + var outputFolderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestCrossLinkSpectrumMatchPlot"); + var psmFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "XlTestData", "XL_Interlinks.tsv"); + var dataFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "XlTestData", "2017-11-21_XL_DSSO_Ribosome_RT60min_28800-28898.mzML"); + + Directory.CreateDirectory(outputFolderPath); + + // load in files + MetaDrawLogic metaDrawLogic = new MetaDrawLogic(); + metaDrawLogic.SpectraFilePaths.Add(dataFilePath); + metaDrawLogic.PsmResultFilePaths.Add(psmFilePath); + + var errors = metaDrawLogic.LoadFiles(true, true); + + Assert.That(!errors.Any()); + Assert.That(metaDrawLogic.FilteredListOfPsms.Any()); + + // load in gui components + var plotView = new OxyPlot.Wpf.PlotView() { Name = "plotView" }; + var canvas = new Canvas(); + var scrollableCanvas = new Canvas(); + var stationaryCanvas = new Canvas(); + var sequenceAnnotationCanvas = new Canvas(); + var parentChildView = new ParentChildScanPlotsView(); + var psm = metaDrawLogic.FilteredListOfPsms.First(p => p.FullSequence == "GVTVDKMTELR(6)"); + + // perform black magic to set the scan number of the MS2 to match the mzML file number + var oldScanNum = psm.Ms2ScanNumber; + var field = typeof(PsmFromTsv).GetField("k__BackingField", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + field?.SetValue(psm, 28819); + + // display psm and check display has correct number of annotations + metaDrawLogic.DisplaySequences(stationaryCanvas, scrollableCanvas, sequenceAnnotationCanvas, psm); + int alphaPeptideAnnotations = psm.BaseSeq.Length + psm.MatchedIons.Count(p => p.NeutralTheoreticalProduct.ProductType is ProductType.b or ProductType.y); + int betaPeptideAnnotations = psm.BetaPeptideBaseSequence.Length + psm.BetaPeptideMatchedIons.Count(p => p.NeutralTheoreticalProduct.ProductType is ProductType.b or ProductType.y); + int crossLinkerAnnotations = 1; + int sequenceDisplayAnnotationCount = + alphaPeptideAnnotations + betaPeptideAnnotations + crossLinkerAnnotations; + Assert.That(stationaryCanvas.Children.Count, Is.EqualTo(sequenceDisplayAnnotationCount)); + Assert.That(scrollableCanvas.Children.Count, Is.EqualTo(alphaPeptideAnnotations)); + + var alphaPeptideSpectralMatchAnnotationCount = psm.MatchedIons.Count; + var betaPeptideSpectralMatchAnnotationCount = psm.BetaPeptideMatchedIons.Count; + var csmPlotIonAnnotationCount = alphaPeptideSpectralMatchAnnotationCount + betaPeptideSpectralMatchAnnotationCount; + metaDrawLogic.DisplaySpectrumMatch(plotView, psm, parentChildView, out errors); + Assert.That(plotView.Model.Annotations.Count, Is.EqualTo(csmPlotIonAnnotationCount + 1)); // Plus One for the annotation text describing the csm + + var scan = MsDataFileReader.GetDataFile(dataFilePath).LoadAllStaticData().GetOneBasedScan(oldScanNum); + var csmPlot = new CrosslinkSpectrumMatchPlot(plotView, psm, scan, stationaryCanvas, false); + Assert.That(csmPlot.Model.Annotations.Count, Is.EqualTo(csmPlotIonAnnotationCount)); + + // test each export type + foreach (var exportType in MetaDrawSettings.ExportTypes) + { + MetaDrawSettings.ExportType = exportType; + metaDrawLogic.ExportPlot(plotView, canvas, new List() { psm }, parentChildView, + outputFolderPath, out errors); + + Assert.That(File.Exists(Path.Combine(outputFolderPath, @$"{psm.Ms2ScanNumber}_{psm.FullSequence}{psm.BetaPeptideBaseSequence}.{exportType}"))); + } + + // clean up resources + metaDrawLogic.CleanUpSpectraFiles(); + Assert.That(!metaDrawLogic.SpectraFilePaths.Any()); + + metaDrawLogic.CleanUpPSMFiles(); + Assert.That(!metaDrawLogic.FilteredListOfPsms.Any()); + Assert.That(!metaDrawLogic.PsmResultFilePaths.Any()); + + // delete output + Directory.Delete(outputFolderPath, true); + } } } From 322235dde068f7f86e6cc8ccf5c15ab518578640 Mon Sep 17 00:00:00 2001 From: Nic Bollis Date: Tue, 23 Jul 2024 12:25:21 -0500 Subject: [PATCH 04/11] Spectral Library from Command Line (#2386) * Updated to MzLib 1.0.548 and fixed custom ions in search tasks * reverted calibration task change * merged in master bbbyy * Enabled Library Loading from command line --- MetaMorpheus/CMD/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MetaMorpheus/CMD/Program.cs b/MetaMorpheus/CMD/Program.cs index d328e44e1..c4f1a7640 100644 --- a/MetaMorpheus/CMD/Program.cs +++ b/MetaMorpheus/CMD/Program.cs @@ -178,7 +178,7 @@ private static int Run(CommandLineSettings settings) foreach (var db in settings.Databases) { - if (!Path.GetExtension(db).Equals(".fasta")) + if (Path.GetExtension(db).Equals(".xml")) { GlobalVariables.AddMods(UsefulProteomicsDatabases.ProteinDbLoader.GetPtmListFromProteinXml(db).OfType(), true); From 7f3d591791ef37bfdd6880439d1f3b5fc3236d29 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 15:15:49 -0500 Subject: [PATCH 05/11] Adjusted MetaDrawSettings IO to default to default values instead of a uniform default --- .../GuiFunctions/MetaDraw/MetaDrawSettings.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs index 3a47da2d1..2cde1ec13 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs @@ -479,6 +479,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) UnannotatedPeakColor = DrawnSequence.ParseOxyColorFromName(settings.UnannotatedPeakColor); InternalIonColor = DrawnSequence.ParseOxyColorFromName(settings.InternalIonColor); + bool flaggedError = false; try // Product Type Colors { var firstSplit = settings.ProductTypeToColorValues.First().Split(','); @@ -504,11 +505,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) break; } + default: + throw new MetaMorpheusException("Cannot parse Product Ion Color values"); } } catch (Exception e) { Debugger.Break(); + SetDefaultProductTypeColors(); + flaggedError = true; } try // Beta Product Type Colors @@ -537,11 +542,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) break; } + default: + throw new MetaMorpheusException("Cannot parse Beta Product Ion Color values"); } } catch (Exception e) { Debugger.Break(); + SetDefaultBetaProductTypeColors(); + flaggedError = true; } try // Modification Type Colors @@ -569,11 +578,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) break; } + default: + throw new MetaMorpheusException("Cannot parse Modification Color values"); } } catch (Exception e) { Debugger.Break(); + SetDefaultModificationColors(); + flaggedError = true; } try // Coverage Type Colors @@ -598,18 +611,25 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) if (CoverageTypeToColor.ContainsKey(key)) CoverageTypeToColor[key] = DrawnSequence.ParseOxyColorFromName(savedProductType.Split(',')[1]); } - break; } + default: + throw new MetaMorpheusException("Cannot parse Sequence Coverage color values"); + } } catch (Exception e) { - Debugger.Break(); + Debugger.Break(); + SetDefaultCoverageTypeColors(); + flaggedError = true; } try // Spectrum Descriptors { + if (!settings.SpectrumDescriptionValues.Any()) + throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values"); + var firstSplit = settings.SpectrumDescriptionValues.First().Split(','); switch (firstSplit.Length) { @@ -633,11 +653,15 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) break; } + default: + throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values"); } } catch (Exception e) { Debugger.Break(); + SetDefaultProductTypeColors(); + flaggedError = true; } } From 76c9435f1b9ab453b2ab0579b2981a6b6d06b123 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 18:45:18 -0500 Subject: [PATCH 06/11] Tested MetaDraw Settings loading under numerous conditions --- .../GuiFunctions/MetaDraw/MetaDrawSettings.cs | 14 +-- .../ViewModels/MetaDrawSettingsViewModel.cs | 5 +- .../MetaDraw/MetaDrawSettingsAndViewsTest.cs | 91 ++++++++++++++++++- 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs index 2cde1ec13..38fb9ee8f 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs @@ -452,8 +452,9 @@ public static MetaDrawSettingsSnapshot MakeSnapShot() /// /// Loads in settings based upon SettingsSnapshot parameter /// - public static void LoadSettings(MetaDrawSettingsSnapshot settings) + public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flaggedErrorOnRead) { + flaggedErrorOnRead = false; DisplayIonAnnotations = settings.DisplayIonAnnotations; AnnotateMzValues = settings.AnnotateMzValues; AnnotateCharges = settings.AnnotateCharges; @@ -479,7 +480,6 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) UnannotatedPeakColor = DrawnSequence.ParseOxyColorFromName(settings.UnannotatedPeakColor); InternalIonColor = DrawnSequence.ParseOxyColorFromName(settings.InternalIonColor); - bool flaggedError = false; try // Product Type Colors { var firstSplit = settings.ProductTypeToColorValues.First().Split(','); @@ -513,7 +513,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) { Debugger.Break(); SetDefaultProductTypeColors(); - flaggedError = true; + flaggedErrorOnRead = true; } try // Beta Product Type Colors @@ -550,7 +550,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) { Debugger.Break(); SetDefaultBetaProductTypeColors(); - flaggedError = true; + flaggedErrorOnRead = true; } try // Modification Type Colors @@ -586,7 +586,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) { Debugger.Break(); SetDefaultModificationColors(); - flaggedError = true; + flaggedErrorOnRead = true; } try // Coverage Type Colors @@ -622,7 +622,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) { Debugger.Break(); SetDefaultCoverageTypeColors(); - flaggedError = true; + flaggedErrorOnRead = true; } try // Spectrum Descriptors @@ -661,7 +661,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings) { Debugger.Break(); SetDefaultProductTypeColors(); - flaggedError = true; + flaggedErrorOnRead = true; } } diff --git a/MetaMorpheus/GuiFunctions/ViewModels/MetaDrawSettingsViewModel.cs b/MetaMorpheus/GuiFunctions/ViewModels/MetaDrawSettingsViewModel.cs index 8ffe71a02..40f006bbe 100644 --- a/MetaMorpheus/GuiFunctions/ViewModels/MetaDrawSettingsViewModel.cs +++ b/MetaMorpheus/GuiFunctions/ViewModels/MetaDrawSettingsViewModel.cs @@ -182,7 +182,10 @@ public void LoadSettings() { MetaDrawSettingsSnapshot settings = null; settings = XmlReaderWriter.ReadFromXmlFile(SettingsPath); - MetaDrawSettings.LoadSettings(settings); + MetaDrawSettings.LoadSettings(settings, out bool flaggedErrorOnRead); + + if (flaggedErrorOnRead) + SaveAsDefault(); } diff --git a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs index c9ebd9b9e..739570d77 100644 --- a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs +++ b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs @@ -82,7 +82,8 @@ public static void TestMetaDrawSettingsSnapshot() snapshot.ShowLegend = false; snapshot.DrawNumbersUnderStationary = false; snapshot.SubAndSuperScriptIons = false; - MetaDrawSettings.LoadSettings(snapshot); + MetaDrawSettings.LoadSettings(snapshot, out bool flaggedError); + Assert.That(!flaggedError); Assert.That(snapshot.DisplayIonAnnotations.Equals(MetaDrawSettings.DisplayIonAnnotations)); Assert.That(snapshot.AnnotateMzValues.Equals(MetaDrawSettings.AnnotateMzValues)); Assert.That(snapshot.AnnotateCharges.Equals(MetaDrawSettings.AnnotateCharges)); @@ -115,7 +116,8 @@ public static void TestMetaDrawSettingsSnapshot() snapshot.AxisTitleTextSize = 0; snapshot.StrokeThicknessAnnotated = 0; snapshot.StrokeThicknessUnannotated = 0; - MetaDrawSettings.LoadSettings(snapshot); + MetaDrawSettings.LoadSettings(snapshot, out flaggedError); + Assert.That(!flaggedError); Assert.That(MetaDrawSettings.AnnotatedFontSize, Is.EqualTo(14)); Assert.That(MetaDrawSettings.AxisLabelTextSize, Is.EqualTo(12)); Assert.That(MetaDrawSettings.AxisTitleTextSize, Is.EqualTo(14)); @@ -188,6 +190,79 @@ public static void TestSettingsViewLoading() Assert.That(BlankSettingsView.CanOpen); } + + [Test] + public static void TestLoadMetaDrawSettings() + { + // Set up testing environment + var metaDrawTestingDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "MetaDraw"); + var testingDir = Path.Combine(metaDrawTestingDirectory, "TempTestData"); + if (Directory.Exists(testingDir)) + Directory.Delete(testingDir, true); + Directory.CreateDirectory(testingDir); + + var masterSettings = Path.Combine(metaDrawTestingDirectory, @"105MetaDrawSettingsSaved.xml"); + string outdatedSettingsPath = Path.Combine(testingDir, @"105MetaDrawSettingsSaved_COPY.xml"); + File.Copy(masterSettings, outdatedSettingsPath); + + // Save default values currently stored in MetaDrawSettings + var defaultCoverageColors = MetaDrawSettings.CoverageTypeToColor.Values.ToList(); + var defaultColorValues = MetaDrawSettings.ProductTypeToColor.Values.ToList(); + + // CASE: user does not have a settings config file stored + // Desired outcome: All default values are used + MetaDrawSettingsViewModel viewModel = new MetaDrawSettingsViewModel(false); + var modelSettingsPath = MetaDrawSettingsViewModel.SettingsPath; + Assert.False(File.Exists(modelSettingsPath)); + NUnit.Framework.Assert.That(!viewModel.HasDefaultSaved); + + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(0), defaultCoverageColors[0]); + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(1), defaultCoverageColors[1]); + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(2), defaultCoverageColors[2]); + + // Make one change and save this viewModel as a modern settings config for next test case + viewModel.CoverageColors.First().SelectionChanged("Yellow"); + string modernSettingsPath = Path.Combine(testingDir, "temporaryCurrentSettingsConfig.xml"); + MetaDrawSettingsViewModel.SettingsPath = modernSettingsPath; + viewModel.SaveAsDefault(); + + // CASE: user has modern settings config file stored + // Desired outcome: Read in correctly + modelSettingsPath = MetaDrawSettingsViewModel.SettingsPath; + Assert.True(File.Exists(modelSettingsPath)); + var creationTime = File.GetLastWriteTime(modernSettingsPath); + viewModel = new MetaDrawSettingsViewModel(false); + // check that no new file was generated + var creationTimeAfterLoad = File.GetLastWriteTime(modernSettingsPath); + Assert.AreEqual(creationTimeAfterLoad, creationTime); + + Assert.AreNotEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(0), defaultCoverageColors[0]); + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(0), OxyColors.Yellow); + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(1), defaultCoverageColors[1]); + Assert.AreEqual(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(2), defaultCoverageColors[2]); + + + // CASE: user has old settings config file stored + // Desired outcome: We use what we can salvage, default the rest, delete old file, replace with modern + MetaDrawSettingsViewModel.SettingsPath = outdatedSettingsPath; + + // Ensure settings are in outdated format + int commaCount = File.ReadLines(outdatedSettingsPath).Sum(p => p.Count(m => m.Equals(','))); + Assert.AreEqual(0, commaCount); + + creationTime = File.GetLastWriteTime(outdatedSettingsPath); + viewModel = new MetaDrawSettingsViewModel(false); + creationTimeAfterLoad = File.GetLastWriteTime(outdatedSettingsPath); + Assert.AreNotEqual(creationTimeAfterLoad, creationTime); + + Assert.AreEqual(MetaDrawSettings.ProductTypeToColor.Values.ElementAt(0), defaultColorValues[0]); + Assert.AreEqual(MetaDrawSettings.ProductTypeToColor.Values.ElementAt(1), defaultColorValues[1]); + Assert.AreEqual(MetaDrawSettings.ProductTypeToColor.Values.ElementAt(2), defaultColorValues[2]); + + Directory.Delete(testingDir, true); + } + + [Test] public static void TestOldMetaDrawSettingsFileDoesNotCrash() { @@ -227,16 +302,24 @@ public static void TestOldMetaDrawSettingsFileDoesNotCrash() Assert.That(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(2), Is.Not.EqualTo(defaultCoverageColors[2])); } + [Test] + public static void TestMetaDrawSettingsLoadSettingsCases2() + { + + } + [Test] // This test passes by not crashing public static void TestMetaDrawSettingsLoadSettingsCases() { string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "MetaDraw", @"105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml"); var snapShot = XmlReaderWriter.ReadFromXmlFile(path); - MetaDrawSettings.LoadSettings(snapShot); + MetaDrawSettings.LoadSettings(snapShot, out bool flaggedError); + Assert.That(flaggedError); path = Path.Combine(TestContext.CurrentContext.TestDirectory, "MetaDraw", @"105MetaDrawSettingsSavedEditedForTestCoverageSuccess.xml"); snapShot = XmlReaderWriter.ReadFromXmlFile(path); - MetaDrawSettings.LoadSettings(snapShot); + MetaDrawSettings.LoadSettings(snapShot, out flaggedError); + Assert.That(flaggedError); } [Test] From f28770a06ec611af519c60771f3c4db978b05598 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 19:20:53 -0500 Subject: [PATCH 07/11] Fixed crash on MetaDraw tab switch while selecting ambiguous result --- MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs | 10 +++++++++- MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs | 2 +- .../Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs | 6 ------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs index c23820447..102f9fa9a 100644 --- a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs +++ b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs @@ -915,11 +915,19 @@ private void AmbiguousSequenceOptionBox_SelectionChanged(object sender, Selectio MetaDrawSettings.DrawMatchedIons = false; } } + SetSequenceDrawingPositionSettings(true); object obj = new object(); if (AmbiguousSequenceOptionBox.Items.Count > 0) + { dataGridScanNums_SelectedCellsChanged(obj, null); - MetaDrawLogic.DisplaySequences(stationarySequenceCanvas, scrollableSequenceCanvas, sequenceAnnotationCanvas, psm); + MetaDrawLogic.DisplaySequences(stationarySequenceCanvas, scrollableSequenceCanvas, + sequenceAnnotationCanvas, psm); + } + else + { + AmbiguousSequenceOptionBox.Visibility = Visibility.Hidden; + } } /// diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs index 3f953d065..a7deaa53b 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawLogic.cs @@ -781,7 +781,7 @@ public void FilterPsmsToChimerasOnly() { FilteredListOfPsms.Clear(); - var filteredChimericPsms = ChimericPsms.Where(p => MetaDrawSettings.FilterAcceptsPsm(p)); + var filteredChimericPsms = ChimericPsms.Where(MetaDrawSettings.FilterAcceptsPsm); foreach (var psm in filteredChimericPsms) { if (filteredChimericPsms.Count(p => p.Ms2ScanNumber == psm.Ms2ScanNumber && p.FileNameWithoutExtension == psm.FileNameWithoutExtension) > 1) diff --git a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs index 739570d77..df3c0129c 100644 --- a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs +++ b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs @@ -302,12 +302,6 @@ public static void TestOldMetaDrawSettingsFileDoesNotCrash() Assert.That(MetaDrawSettings.CoverageTypeToColor.Values.ElementAt(2), Is.Not.EqualTo(defaultCoverageColors[2])); } - [Test] - public static void TestMetaDrawSettingsLoadSettingsCases2() - { - - } - [Test] // This test passes by not crashing public static void TestMetaDrawSettingsLoadSettingsCases() { From 8c018c86d50c23d4a38bfd0c7b6a867576b3bf59 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 20:10:34 -0500 Subject: [PATCH 08/11] fixed crash on ambiguous selected on chimera tab to child scan --- MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs | 44 +++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs index 102f9fa9a..6780b0944 100644 --- a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs +++ b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs @@ -191,14 +191,16 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC // Chimera plotter if (MetaDrawTabControl.SelectedContent is Grid { Name: "chimeraPlotGrid" }) { + ClearPresentationArea(); + chimeraPlot.Visibility = Visibility.Visible; List chimericPsms = MetaDrawLogic.FilteredListOfPsms .Where(p => p.Ms2ScanNumber == psm.Ms2ScanNumber && p.FileNameWithoutExtension == psm.FileNameWithoutExtension).ToList(); MetaDrawLogic.DisplayChimeraSpectra(chimeraPlot, chimericPsms, out List error); if (error != null && error.Count > 0) Debugger.Break(); - ClearPresentationArea(); wholeSequenceCoverageHorizontalScroll.Visibility = Visibility.Collapsed; - + AmbiguousWarningTextBlocks.Visibility = Visibility.Collapsed; + AmbiguousSequenceOptionBox.Visibility = Visibility.Collapsed; if (MetaDrawSettings.ShowLegend) { @@ -217,7 +219,27 @@ private void dataGridScanNums_SelectedCellsChanged(object sender, SelectedCellsC // Clicking the research button on an ambiguous psm => research with new ions if (psm.FullSequence.Contains('|') && (sender.ToString() == "System.Object" || sender is FragmentationReanalysisViewModel)) { - psm = (PsmFromTsv)AmbiguousSequenceOptionBox.SelectedItem; + // From chimeric scan view to child scan view with ambiguous selected + if (AmbiguousSequenceOptionBox.SelectedItem == null) + { + // set to first and break the loop if casted successfully + foreach (var ambiguousResult in AmbiguousSequenceOptionBox.Items) + { + psm = ambiguousResult as PsmFromTsv; + if (psm != null) + break; + } + + AmbiguousWarningTextBlocks.Visibility = Visibility.Collapsed; + AmbiguousSequenceOptionBox.Visibility = Visibility.Visible; + AmbiguousSequenceOptionBox.SelectedItem = psm; + } + // selecting a different ambiguous result from the combobox in child scan view + else + { + psm = (PsmFromTsv)AmbiguousSequenceOptionBox.SelectedItem; + } + if (FragmentationReanalysisViewModel.Persist || sender is FragmentationReanalysisViewModel) { oldMatchedIons = psm.MatchedIons; @@ -1041,6 +1063,7 @@ private void MetaDrawTabControl_OnSelectionChanged(object sender, SelectionChang if (e.RemovedItems.Count > 0 && ((TabItem)e.RemovedItems[0]).Name == "ChimeraScanPlot") { MetaDrawLogic.FilterPsms(); + ClearPresentationArea(); // reselect what was selected if (selectedPsm != null && MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm)) @@ -1055,12 +1078,15 @@ private void MetaDrawTabControl_OnSelectionChanged(object sender, SelectionChang if (e.AddedItems.Count > 0 && ((TabItem)e.AddedItems[0]).Name == "ChimeraScanPlot") { MetaDrawLogic.FilterPsmsToChimerasOnly(); + ClearPresentationArea(); - // reselect what was selected - if (selectedPsm == null || !MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm)) return; - int psmIndex = MetaDrawLogic.FilteredListOfPsms.IndexOf(selectedPsm); - dataGridScanNums.SelectedIndex = psmIndex; - dataGridScanNums_SelectedCellsChanged(new object(), null); + // reselect what was selected if possible + if (selectedPsm != null && MetaDrawLogic.FilteredListOfPsms.Contains(selectedPsm)) + { + int psmIndex = MetaDrawLogic.FilteredListOfPsms.IndexOf(selectedPsm); + dataGridScanNums.SelectedIndex = psmIndex; + dataGridScanNums_SelectedCellsChanged(new object(), null); + } } } @@ -1074,11 +1100,11 @@ private void ClearPresentationArea() DrawnSequence.ClearCanvas(map); DrawnSequence.ClearCanvas(sequenceText); DrawnSequence.ClearCanvas(sequenceAnnotationCanvas); - plotView.Visibility = Visibility.Hidden; GrayBox.Opacity = 0; wholeSequenceCoverageHorizontalScroll.Visibility = Visibility.Collapsed; AmbiguousSequenceOptionBox.Items.Clear(); plotView.Visibility = Visibility.Hidden; + chimeraPlot.Visibility = Visibility.Hidden; if (ChimeraLegend != null) ChimeraLegend.Visibility = false; From 3ce88b338af6d6b575b12a44e16d5bc8a53a34fa Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 20:13:18 -0500 Subject: [PATCH 09/11] general cleanup --- MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs | 1 - MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs index 6780b0944..4a524c6d3 100644 --- a/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs +++ b/MetaMorpheus/GUI/MetaDraw/MetaDraw.xaml.cs @@ -937,7 +937,6 @@ private void AmbiguousSequenceOptionBox_SelectionChanged(object sender, Selectio MetaDrawSettings.DrawMatchedIons = false; } } - SetSequenceDrawingPositionSettings(true); object obj = new object(); if (AmbiguousSequenceOptionBox.Items.Count > 0) diff --git a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs index df3c0129c..c94868f6b 100644 --- a/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs +++ b/MetaMorpheus/Test/MetaDraw/MetaDrawSettingsAndViewsTest.cs @@ -262,7 +262,6 @@ public static void TestLoadMetaDrawSettings() Directory.Delete(testingDir, true); } - [Test] public static void TestOldMetaDrawSettingsFileDoesNotCrash() { From 5a03e38524a627662c1cfa75eab55844fc2e1279 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 20:19:07 -0500 Subject: [PATCH 10/11] Adjusted test data to expand code coverage --- .../105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MetaMorpheus/Test/MetaDraw/105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml b/MetaMorpheus/Test/MetaDraw/105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml index f706023ee..6a3ce89f9 100644 --- a/MetaMorpheus/Test/MetaDraw/105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml +++ b/MetaMorpheus/Test/MetaDraw/105MetaDrawSettingsSavedEditedForTestCoverageFailures.xml @@ -24,6 +24,7 @@ true true true + gobbledygook Aqua @@ -3823,6 +3824,7 @@ Hullabaloo Aqua Aqua + Claptrap LightGray Purple From 3df63d343ee94ea506401a18e5a65240402ebcc4 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 18 Sep 2024 20:42:33 -0500 Subject: [PATCH 11/11] Added ability to select your own tolerance for MetaDraw fragmentation reanalysis --- .../GUI/Views/FragmentReanalysisControl.xaml | 56 +++++++++++-------- .../FragmentationReanalysisViewModel.cs | 14 ++++- .../Test/MetaDraw/FragmentReanalysis.cs | 20 +++++-- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml b/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml index 71de1ed97..e0e555126 100644 --- a/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml +++ b/MetaMorpheus/GUI/Views/FragmentReanalysisControl.xaml @@ -18,34 +18,46 @@ - - - - - - + + + + -