From a6b16392ff5536b6588dc0b14228a790b0d33866 Mon Sep 17 00:00:00 2001 From: MICHAEL SHORTREED Date: Thu, 18 Nov 2021 12:30:51 -0600 Subject: [PATCH 1/4] correct Within calculation --- MassSpectrometry/MzSpectra/SpectralSimilarity.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MassSpectrometry/MzSpectra/SpectralSimilarity.cs b/MassSpectrometry/MzSpectra/SpectralSimilarity.cs index e9600bfdd..4fcc00e77 100644 --- a/MassSpectrometry/MzSpectra/SpectralSimilarity.cs +++ b/MassSpectrometry/MzSpectra/SpectralSimilarity.cs @@ -14,7 +14,7 @@ public SpectralSimilarity(MzSpectrum primary, MzSpectrum secondary, SpectrumNorm primaryXArray = primary.XArray; secondaryYarray = Normalize(secondary.YArray, scheme); secondaryXArray = secondary.XArray; - localTolerance = toleranceInPpm / 1000000.0; + ppmTolerance = toleranceInPpm; _intensityPairs = IntensityPairs(allPeaks); } @@ -24,7 +24,7 @@ public SpectralSimilarity(MzSpectrum primary, double[] secondaryX, double[] seco primaryXArray = primary.XArray; secondaryYarray = Normalize(secondaryY, scheme); secondaryXArray = secondaryX; - localTolerance = toleranceInPpm / 1000000.0; + ppmTolerance = toleranceInPpm; _intensityPairs = IntensityPairs(allPeaks); } @@ -32,7 +32,7 @@ public SpectralSimilarity(MzSpectrum primary, double[] secondaryX, double[] seco public double[] primaryXArray { get; private set; } public double[] secondaryYarray { get; private set; } public double[] secondaryXArray { get; private set; } - private double localTolerance; + private double ppmTolerance; private List<(double, double)> _intensityPairs = new List<(double, double)>(); public List<(double, double)> intensityPairs @@ -236,7 +236,7 @@ public double DotProduct() private bool Within(double mz1, double mz2) { - return (Math.Abs(mz1 - mz2) < localTolerance); + return (Math.Abs(mz1 - mz2)/mz1*1000000.0 < ppmTolerance); } public enum SpectrumNormalizationScheme From fa4da8bb9e174a4343c6b530b47172f1449c730e Mon Sep 17 00:00:00 2001 From: MICHAEL SHORTREED Date: Thu, 18 Nov 2021 12:42:10 -0600 Subject: [PATCH 2/4] update unit tests --- Test/TestSpectralSimilarity.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/TestSpectralSimilarity.cs b/Test/TestSpectralSimilarity.cs index 356158e04..ebc19e9af 100644 --- a/Test/TestSpectralSimilarity.cs +++ b/Test/TestSpectralSimilarity.cs @@ -117,10 +117,10 @@ public void TestAllSpectrumSimilarities() //explore bounds of binary search primary = new MzSpectrum(new double[] { 1, 2, 3, 4 }, new double[] { 1, 2, 3, 4 }, false); - secondary = new MzSpectrum(new double[] { 1.000009, 1.99999, 3.00004, 3.99995 }, new double[] { 1, 2, 3, 4 }, false); + secondary = new MzSpectrum(new double[] { 1.000011, 1.99997, 3.000031, 3.99995 }, new double[] { 1, 2, 3, 4 }, false); s = new SpectralSimilarity(primary, secondary, SpectralSimilarity.SpectrumNormalizationScheme.spectrumSum, ppmTolerance, true); - Assert.AreEqual(7, s.intensityPairs.Count); + Assert.AreEqual(8, s.intensityPairs.Count); //Test alternate constructor primary = new MzSpectrum(new double[] { 1, 2, 3 }, new double[] { 2, 4, 6 }, false); From 892fa451204f0b54f3e54301a0bc5b250410f48a Mon Sep 17 00:00:00 2001 From: MICHAEL SHORTREED Date: Fri, 18 Feb 2022 09:57:06 -0600 Subject: [PATCH 3/4] this is the spot --- FlashLFQ/FlashLfqEngine.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FlashLFQ/FlashLfqEngine.cs b/FlashLFQ/FlashLfqEngine.cs index 0bc9d5818..6037e2098 100644 --- a/FlashLFQ/FlashLfqEngine.cs +++ b/FlashLFQ/FlashLfqEngine.cs @@ -914,6 +914,8 @@ private void QuantifyMatchBetweenRunsPeaks(SpectraFileInfo idAcceptorFile) } } + //here is where we get the cosine similarity. + _results.Peaks[idAcceptorFile].Add(best); } From f312da74818aba3525f3ce79fac70bf5860f5f12 Mon Sep 17 00:00:00 2001 From: MICHAEL SHORTREED Date: Fri, 25 Feb 2022 12:59:46 -0600 Subject: [PATCH 4/4] first full test of ms1 and ms2 --- Test/SpectrumProcessingAndFiltering.cs | 75 ++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/Test/SpectrumProcessingAndFiltering.cs b/Test/SpectrumProcessingAndFiltering.cs index 5a84fb099..d7dd9f24e 100644 --- a/Test/SpectrumProcessingAndFiltering.cs +++ b/Test/SpectrumProcessingAndFiltering.cs @@ -241,19 +241,17 @@ public static void ProcessXcorrInB6MzSpectrum() List xArrayProcessed = new List(); foreach (MsDataScan scan in scans.Where(s => s.MsnOrder > 1)) { - if(scan.OneBasedScanNumber == 86) + if (scan.OneBasedScanNumber == 86) { scan.MassSpectrum.XCorrPrePreprocessing(0, 1969, scan.IsolationMz.Value); xArrayProcessed = scan.MassSpectrum.XArray.ToList(); } - } for (int i = 0; i < expectedResults.Count; i++) { Assert.That(double.Parse(expectedResults[i]), Is.EqualTo(xArrayProcessed[i]).Within(0.001)); } - } [Test] @@ -282,5 +280,76 @@ public static void XcorrTestBorrowedFromMM() Assert.AreEqual(Y[i], Math.Round(ms2.YArray[i], 2)); } } + + [Test] + public static void TestMSDataScan() + { + Dictionary MyMsDataFiles = new Dictionary(); + string origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"DatabaseTests\sliced_b6.mzML"); + FilteringParams filter = new FilteringParams(200, 0.01, null, 1, false, false, false); + + MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, 1); + + var scans = MyMsDataFiles[origDataFile].GetAllScansList(); + + MsDataScan[] ms1scans = scans.Where(s => s.MsnOrder == 1).ToArray(); + MsDataScan[] ms2scans = scans.Where(s => s.MsnOrder == 2).ToArray(); + + MsDataScan ms1scanExample = ms1scans.Where(s => s.OneBasedScanNumber == 148).First(); + MsDataScan ms2scanExample = ms2scans.Where(s => s.OneBasedPrecursorScanNumber == 148).First(); + + Assert.IsNull(ms1scanExample.DissociationType); + Assert.IsNull(ms1scanExample.HcdEnergy); + Assert.That(2.35, Is.EqualTo(ms1scanExample.InjectionTime).Within(0.01)); + Assert.IsTrue(ms1scanExample.IsCentroid); + Assert.IsNull(ms1scanExample.IsolationMz); + Assert.IsNull(ms1scanExample.IsolationRange); + Assert.IsNull(ms1scanExample.IsolationWidth); + Assert.AreEqual(2951, ms1scanExample.MassSpectrum.XArray.Length); + Assert.AreEqual(1, ms1scanExample.MsnOrder); + Assert.AreEqual(MZAnalyzerType.Quadrupole, ms1scanExample.MzAnalyzer); + Assert.AreEqual("controllerType=0 controllerNumber=1 scan=148", ms1scanExample.NativeId); + Assert.IsNull(ms1scanExample.NoiseData); + Assert.IsNull(ms1scanExample.OneBasedPrecursorScanNumber); + Assert.AreEqual(148, ms1scanExample.OneBasedScanNumber); + Assert.AreEqual(Polarity.Positive, ms1scanExample.Polarity); + Assert.That(77.08, Is.EqualTo(ms1scanExample.RetentionTime).Within(0.01)); + Assert.AreEqual("FTMS + p NSI Full ms [350.0000-1350.0000]", ms1scanExample.ScanFilter); + Assert.AreEqual(350, ms1scanExample.ScanWindowRange.Minimum); + Assert.AreEqual(1350, ms1scanExample.ScanWindowRange.Maximum); + Assert.IsNull(ms1scanExample.SelectedIonChargeStateGuess); + Assert.IsNull(ms1scanExample.SelectedIonIntensity); + Assert.IsNull(ms1scanExample.SelectedIonMonoisotopicGuessIntensity); + Assert.IsNull(ms1scanExample.SelectedIonMonoisotopicGuessMz); + Assert.IsNull(ms1scanExample.SelectedIonMZ); + Assert.AreEqual(1222352000, ms1scanExample.TotalIonCurrent); + + Assert.AreEqual(DissociationType.HCD, ms2scanExample.DissociationType); + Assert.IsNull(ms2scanExample.HcdEnergy); + Assert.That(15, Is.EqualTo(ms2scanExample.InjectionTime).Within(0.01)); + Assert.IsTrue(ms2scanExample.IsCentroid); + Assert.That(518.23, Is.EqualTo(ms2scanExample.IsolationMz).Within(0.01)); + Assert.That(517.88, Is.EqualTo(ms2scanExample.IsolationRange.Minimum).Within(0.01)); + Assert.That(518.58, Is.EqualTo(ms2scanExample.IsolationRange.Maximum).Within(0.01)); + Assert.That(0.70, Is.EqualTo(ms2scanExample.IsolationWidth).Within(0.01)); + Assert.AreEqual(871, ms2scanExample.MassSpectrum.XArray.Length); + Assert.AreEqual(2, ms2scanExample.MsnOrder); + Assert.AreEqual(MZAnalyzerType.Quadrupole, ms2scanExample.MzAnalyzer); + Assert.AreEqual("controllerType=0 controllerNumber=1 scan=149", ms2scanExample.NativeId); + Assert.IsNull(ms2scanExample.NoiseData); + Assert.AreEqual(148, ms2scanExample.OneBasedPrecursorScanNumber); + Assert.AreEqual(149, ms2scanExample.OneBasedScanNumber); + Assert.AreEqual(Polarity.Positive, ms2scanExample.Polarity); + Assert.That(77.08, Is.EqualTo(ms2scanExample.RetentionTime).Within(0.01)); + Assert.AreEqual("ITMS + c NSI t d Full ms2 518.2317@hcd25.00 [200.0000-1200.0000]", ms2scanExample.ScanFilter); + Assert.AreEqual(200, ms2scanExample.ScanWindowRange.Minimum); + Assert.AreEqual(1200, ms2scanExample.ScanWindowRange.Maximum); + Assert.AreEqual(3, ms2scanExample.SelectedIonChargeStateGuess); + Assert.AreEqual(8984495, ms2scanExample.SelectedIonIntensity); + Assert.IsNull(ms2scanExample.SelectedIonMonoisotopicGuessIntensity); + Assert.That(518.23, Is.EqualTo(ms2scanExample.SelectedIonMonoisotopicGuessMz).Within(0.01)); + Assert.That(518.23, Is.EqualTo(ms2scanExample.SelectedIonMZ).Within(0.01)); + Assert.That(3748516.16, Is.EqualTo(ms2scanExample.TotalIonCurrent).Within(0.01)); + } } } \ No newline at end of file