From 8be2574a0939e8db66ecc2126be4904d944b1025 Mon Sep 17 00:00:00 2001 From: nbollis Date: Tue, 21 May 2024 15:08:45 -0500 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 bc8319849cb0a27bbd5c6f135b77489590b1e685 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 2 Oct 2024 19:57:53 -0500 Subject: [PATCH 5/6] Dealt with all of the warnings we get every pull request --- .../EngineLayer/PsmTsv/PsmTsvReader.cs | 2 +- .../FragmentationReanalysisViewModel.cs | 4 +- .../GuiFunctions/MetaDraw/MetaDrawSettings.cs | 16 +++--- .../SpectralAveragingParametersViewModel.cs | 54 +++++++++---------- MetaMorpheus/MetaMorpheus.sln.DotSettings | 34 ++++++++++++ .../AveragingTask/SpectralAveragingTask.cs | 5 +- .../PostGlycoSearchAnalysisTask.cs | 2 - 7 files changed, 73 insertions(+), 44 deletions(-) create mode 100644 MetaMorpheus/MetaMorpheus.sln.DotSettings diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs index 45345ed08..8375b4cd3 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs @@ -13,7 +13,7 @@ public static List ReadTsv(string filePath, out List warning List psms = new List(); warnings = new List(); - StreamReader reader = null; + StreamReader reader; try { reader = new StreamReader(filePath); diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/FragmentResearching/FragmentationReanalysisViewModel.cs b/MetaMorpheus/GuiFunctions/MetaDraw/FragmentResearching/FragmentationReanalysisViewModel.cs index 6e2315cde..681601582 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/FragmentResearching/FragmentationReanalysisViewModel.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/FragmentResearching/FragmentationReanalysisViewModel.cs @@ -31,7 +31,7 @@ public FragmentationReanalysisViewModel(bool isProtein = true) if (isProtein) { DissociationTypes = new ObservableCollection(Enum.GetValues() - .Where(p => p != DissociationType.AnyActivationType && Omics.Fragmentation.Peptide.DissociationTypeCollection.ProductsFromDissociationType.TryGetValue(p, out var prod) && prod.Any())); + .Where(p => p != DissociationType.AnyActivationType && Omics.Fragmentation.Peptide.DissociationTypeCollection.ProductsFromDissociationType.TryGetValue(p, out var prod) && prod.Count != 0)); PossibleProducts = new ObservableCollection(GetPossibleProducts(_isProtein)); SelectedDissociationType = DissociationType.HCD; } @@ -187,7 +187,7 @@ private void SetUseForFragmentsBasedUponDissociationType(DissociationType dissoc Omics.Fragmentation.Peptide.DissociationTypeCollection.ProductsFromDissociationType[dissociationType].ToArray() : Omics.Fragmentation.Oligo.DissociationTypeCollection.GetRnaProductTypesFromDissociationType(dissociationType).ToArray(); } - catch (Exception e) + catch (Exception) { _selectedDissociationType = DissociationType.HCD; dissociationTypeProducts = isProtein ? diff --git a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs index 38fb9ee8f..a38b939b7 100644 --- a/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs +++ b/MetaMorpheus/GuiFunctions/MetaDraw/MetaDrawSettings.cs @@ -15,12 +15,12 @@ public static class MetaDrawSettings { #region Constants - public static char[] SubScriptNumbers = { + public static readonly char[] SubScriptNumbers = { '\u2080', '\u2081', '\u2082', '\u2083', '\u2084', '\u2085', '\u2086', '\u2087', '\u2088', '\u2089' }; - public static char[] SuperScriptNumbers = { + public static readonly char[] SuperScriptNumbers = { '\u2070', '\u00b9', '\u00b2', '\u00b3', '\u2074', '\u2075', '\u2076', '\u2077', '\u2078', '\u2079' }; @@ -509,7 +509,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag throw new MetaMorpheusException("Cannot parse Product Ion Color values"); } } - catch (Exception e) + catch (Exception) { Debugger.Break(); SetDefaultProductTypeColors(); @@ -546,7 +546,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag throw new MetaMorpheusException("Cannot parse Beta Product Ion Color values"); } } - catch (Exception e) + catch (Exception) { Debugger.Break(); SetDefaultBetaProductTypeColors(); @@ -582,7 +582,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag throw new MetaMorpheusException("Cannot parse Modification Color values"); } } - catch (Exception e) + catch (Exception) { Debugger.Break(); SetDefaultModificationColors(); @@ -618,7 +618,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag } } - catch (Exception e) + catch (Exception) { Debugger.Break(); SetDefaultCoverageTypeColors(); @@ -627,7 +627,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag try // Spectrum Descriptors { - if (!settings.SpectrumDescriptionValues.Any()) + if (settings.SpectrumDescriptionValues.Count == 0) throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values"); var firstSplit = settings.SpectrumDescriptionValues.First().Split(','); @@ -657,7 +657,7 @@ public static void LoadSettings(MetaDrawSettingsSnapshot settings, out bool flag throw new MetaMorpheusException("Cannot parse Spectrum Descriptor values"); } } - catch (Exception e) + catch (Exception) { Debugger.Break(); SetDefaultProductTypeColors(); diff --git a/MetaMorpheus/GuiFunctions/ViewModels/SpectralAveragingParametersViewModel.cs b/MetaMorpheus/GuiFunctions/ViewModels/SpectralAveragingParametersViewModel.cs index 41656fa53..cd375066a 100644 --- a/MetaMorpheus/GuiFunctions/ViewModels/SpectralAveragingParametersViewModel.cs +++ b/MetaMorpheus/GuiFunctions/ViewModels/SpectralAveragingParametersViewModel.cs @@ -18,9 +18,7 @@ public class SpectralAveragingParametersViewModel : BaseViewModel, IEquatable spectralAveragingParameters; - set { spectralAveragingParameters = value; OnPropertyChanged(nameof(SpectralAveragingParameters)); UpdateVisualRepresentation(); } + get => _spectralAveragingParameters; + set { _spectralAveragingParameters = value; OnPropertyChanged(nameof(SpectralAveragingParameters)); UpdateVisualRepresentation(); } } public OutlierRejectionType RejectionType { - get => spectralAveragingParameters.OutlierRejectionType; - set { spectralAveragingParameters.OutlierRejectionType = value; OnPropertyChanged(nameof(RejectionType)); } + get => _spectralAveragingParameters.OutlierRejectionType; + set { _spectralAveragingParameters.OutlierRejectionType = value; OnPropertyChanged(nameof(RejectionType)); } } public SpectraWeightingType WeightingType { - get => spectralAveragingParameters.SpectralWeightingType; - set { spectralAveragingParameters.SpectralWeightingType = value; OnPropertyChanged(nameof(WeightingType)); } + get => _spectralAveragingParameters.SpectralWeightingType; + set { _spectralAveragingParameters.SpectralWeightingType = value; OnPropertyChanged(nameof(WeightingType)); } } public SpectraFileAveragingType SpectraFileAveragingType { - get => spectralAveragingParameters.SpectraFileAveragingType; - set { spectralAveragingParameters.SpectraFileAveragingType = value; OnPropertyChanged(nameof(SpectraFileAveragingType)); } + get => _spectralAveragingParameters.SpectraFileAveragingType; + set { _spectralAveragingParameters.SpectraFileAveragingType = value; OnPropertyChanged(nameof(SpectraFileAveragingType)); } } public bool PerformNormalization { - get => spectralAveragingParameters.NormalizationType == NormalizationType.RelativeToTics ? true : false; + get => _spectralAveragingParameters.NormalizationType == NormalizationType.RelativeToTics ? true : false; set { - spectralAveragingParameters.NormalizationType = value == true ? NormalizationType.RelativeToTics : NormalizationType.NoNormalization; + _spectralAveragingParameters.NormalizationType = value ? NormalizationType.RelativeToTics : NormalizationType.NoNormalization; OnPropertyChanged(nameof(PerformNormalization)); } } public double Percentile { - get => spectralAveragingParameters.Percentile; - set { spectralAveragingParameters.Percentile = value; OnPropertyChanged(nameof(Percentile)); } + get => _spectralAveragingParameters.Percentile; + set { _spectralAveragingParameters.Percentile = value; OnPropertyChanged(nameof(Percentile)); } } public double MinSigmaValue { - get => spectralAveragingParameters.MinSigmaValue; - set { spectralAveragingParameters.MinSigmaValue = value; OnPropertyChanged(nameof(MinSigmaValue)); } + get => _spectralAveragingParameters.MinSigmaValue; + set { _spectralAveragingParameters.MinSigmaValue = value; OnPropertyChanged(nameof(MinSigmaValue)); } } public double MaxSigmaValue { - get => spectralAveragingParameters.MaxSigmaValue; - set { spectralAveragingParameters.MaxSigmaValue = value; OnPropertyChanged(nameof(MaxSigmaValue)); } + get => _spectralAveragingParameters.MaxSigmaValue; + set { _spectralAveragingParameters.MaxSigmaValue = value; OnPropertyChanged(nameof(MaxSigmaValue)); } } public double BinSize { - get => spectralAveragingParameters.BinSize; - set { spectralAveragingParameters.BinSize = value; OnPropertyChanged(nameof(BinSize)); } + get => _spectralAveragingParameters.BinSize; + set { _spectralAveragingParameters.BinSize = value; OnPropertyChanged(nameof(BinSize)); } } public int NumberOfScansToAverage { - get => spectralAveragingParameters.NumberOfScansToAverage; + get => _spectralAveragingParameters.NumberOfScansToAverage; set { - spectralAveragingParameters.NumberOfScansToAverage = value; - spectralAveragingParameters.ScanOverlap = value - 1; + _spectralAveragingParameters.NumberOfScansToAverage = value; + _spectralAveragingParameters.ScanOverlap = value - 1; OnPropertyChanged(nameof(NumberOfScansToAverage)); } } public int MaxThreads { - get => spectralAveragingParameters.MaxThreadsToUsePerFile; + get => _spectralAveragingParameters.MaxThreadsToUsePerFile; set { - spectralAveragingParameters.MaxThreadsToUsePerFile = value; + _spectralAveragingParameters.MaxThreadsToUsePerFile = value; OnPropertyChanged(nameof(MaxThreads)); } } @@ -123,7 +121,7 @@ public int MaxThreads public SpectralAveragingParametersViewModel(SpectralAveragingParameters parameters) { // value initialization - spectralAveragingParameters = parameters; + _spectralAveragingParameters = parameters; RejectionTypes = (OutlierRejectionType[])Enum.GetValues(typeof(OutlierRejectionType)); WeightingTypes = new [] { SpectraWeightingType.WeightEvenly, SpectraWeightingType.TicValue}; SpectraFileAveragingTypes = new[] { SpectraFileAveragingType.AverageAll, SpectraFileAveragingType.AverageDdaScans, SpectraFileAveragingType.AverageEverynScansWithOverlap}; @@ -180,7 +178,7 @@ public void SetOtherParameters(object settingsNameToSet) throw new ArgumentException("This should never be hit!"); } - spectralAveragingParameters = parameters; + _spectralAveragingParameters = parameters; UpdateVisualRepresentation(); } diff --git a/MetaMorpheus/MetaMorpheus.sln.DotSettings b/MetaMorpheus/MetaMorpheus.sln.DotSettings new file mode 100644 index 000000000..3cb2a8c2a --- /dev/null +++ b/MetaMorpheus/MetaMorpheus.sln.DotSettings @@ -0,0 +1,34 @@ + + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/MetaMorpheus/TaskLayer/AveragingTask/SpectralAveragingTask.cs b/MetaMorpheus/TaskLayer/AveragingTask/SpectralAveragingTask.cs index 04f8d621e..b44281e60 100644 --- a/MetaMorpheus/TaskLayer/AveragingTask/SpectralAveragingTask.cs +++ b/MetaMorpheus/TaskLayer/AveragingTask/SpectralAveragingTask.cs @@ -81,15 +81,14 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List { taskId, "Individual Spectra Files", originalUnaveragedFilepathWithoutExtenstion }); diff --git a/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs b/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs index bc00fe9f8..a63750858 100644 --- a/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs +++ b/MetaMorpheus/TaskLayer/GlycoSearchTask/PostGlycoSearchAnalysisTask.cs @@ -31,8 +31,6 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List dbFilenameList, List currentRawFileList, string taskId, FileSpecificParameters[] fileSettingsList, List allPsms, CommonParameters commonParameters, GlycoSearchParameters glycoSearchParameters, List proteinList, List variableModifications, List fixedModifications, List localizeableModificationTypes, MyTaskResults MyTaskResults) { - List proteinGroups = null; - if (!Parameters.GlycoSearchParameters.WriteDecoys) { allPsms.RemoveAll(b => b.IsDecoy); From cca22e6b282817922332d8808d9d1541c008d162 Mon Sep 17 00:00:00 2001 From: nbollis Date: Wed, 2 Oct 2024 20:01:13 -0500 Subject: [PATCH 6/6] removed more warnings --- MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs | 2 +- MetaMorpheus/Test/SpectralRecoveryTest.cs | 1 - MetaMorpheus/Test/TestDataFile.cs | 2 +- MetaMorpheus/Test/XLTest.cs | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs index 8375b4cd3..2714fab20 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvReader.cs @@ -46,7 +46,7 @@ public static List ReadTsv(string filePath, out List warning } catch (Exception e) { - warnings.Add("Could not read line: " + lineCount); + warnings.Add($"Could not read line: {lineCount} with error message: {e.Message}"); } } diff --git a/MetaMorpheus/Test/SpectralRecoveryTest.cs b/MetaMorpheus/Test/SpectralRecoveryTest.cs index c69e03aa2..6a9cbb18b 100644 --- a/MetaMorpheus/Test/SpectralRecoveryTest.cs +++ b/MetaMorpheus/Test/SpectralRecoveryTest.cs @@ -97,7 +97,6 @@ public void SpectralRecoveryTestSetup() Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", @"SpectralRecoveryTest\K13_20ng_1min_frac1.mzML") }; databaseList = new List() {new DbForTask( Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", @"SpectralRecoveryTest\HumanFastaSlice.fasta"), false) }; - outputFolder = outputFolder; SearchTask searchTask = new SearchTask { diff --git a/MetaMorpheus/Test/TestDataFile.cs b/MetaMorpheus/Test/TestDataFile.cs index 3289041d2..f24a04b4d 100644 --- a/MetaMorpheus/Test/TestDataFile.cs +++ b/MetaMorpheus/Test/TestDataFile.cs @@ -419,7 +419,7 @@ public TestDataFile(PeptideWithSetModifications pepWithSetMods) Scans = ScansHere.ToArray(); } - public string FilePath + public new string FilePath { get { diff --git a/MetaMorpheus/Test/XLTest.cs b/MetaMorpheus/Test/XLTest.cs index f8a136ed7..515dd1c43 100644 --- a/MetaMorpheus/Test/XLTest.cs +++ b/MetaMorpheus/Test/XLTest.cs @@ -1636,7 +1636,7 @@ internal class XLTestDataFile : MsDataFile Scans = ScansHere.ToArray(); } - public static string FilePath + public new static string FilePath { get { @@ -1718,7 +1718,7 @@ internal class XLTestDataFileDiffSite : MsDataFile Scans = ScansHere.ToArray(); } - public string FilePath + public new string FilePath { get {