From f5af7cd99f21004f2ab79f37807e629322396472 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 12 Dec 2023 12:44:17 -0600 Subject: [PATCH 1/3] Edited the MatchedFramgentIon Equals method --- mzLib/Omics/Fragmentation/MatchedFragmentIon.cs | 4 ++-- mzLib/Test/TestFragments.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs index 20a522bf4..7120acf85 100644 --- a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs +++ b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs @@ -78,8 +78,8 @@ public override bool Equals(object obj) return this.NeutralTheoreticalProduct.Equals(other.NeutralTheoreticalProduct) && this.Charge == other.Charge - && this.Mz == other.Mz - && this.Intensity == other.Intensity; + && Math.Abs(Mz - other.Mz) < 0.0001 + && Math.Abs(Intensity - other.Intensity) < 0.0001; } public override int GetHashCode() diff --git a/mzLib/Test/TestFragments.cs b/mzLib/Test/TestFragments.cs index 872d941e7..fa7c0dce7 100644 --- a/mzLib/Test/TestFragments.cs +++ b/mzLib/Test/TestFragments.cs @@ -887,6 +887,15 @@ public static void Test_MatchedFragmentGetHashCode() Assert.AreEqual(1072693248, m.GetHashCode()); } + [Test] + public static void TestMatchedFragmentIonEquals() + { + Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); + MatchedFragmentIon ion1 = new MatchedFragmentIon(P, experMz: 150, experIntensity: 99.99999, charge: 2); + MatchedFragmentIon ion2 = new MatchedFragmentIon(P, experMz: 149.99999, experIntensity: 100, charge: 2); + Assert.AreEqual(ion1, ion2); + } + [Test] public static void Test_CID_Fragmentation_No_Unmodified_B1_ions() { From b378eb848e568d79b6bf1d5fe52e77eb60605d1d Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 28 Dec 2023 14:51:08 -0600 Subject: [PATCH 2/3] Report mbr predicted rt --- mzLib/FlashLFQ/ChromatographicPeak.cs | 4 +++- mzLib/mzLib.nuspec | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mzLib/FlashLFQ/ChromatographicPeak.cs b/mzLib/FlashLFQ/ChromatographicPeak.cs index a8cc1de95..5d1e238d6 100644 --- a/mzLib/FlashLFQ/ChromatographicPeak.cs +++ b/mzLib/FlashLFQ/ChromatographicPeak.cs @@ -75,6 +75,7 @@ public static string TabSeparatedHeader sb.Append("Full Sequences Mapped" + "\t"); sb.Append("Peak Split Valley RT" + "\t"); sb.Append("Peak Apex Mass Error (ppm)"); + sb.Append("\tMBR Predicted RT"); //sb.Append("Timepoints"); return sb.ToString(); } @@ -249,7 +250,8 @@ public override string ToString() sb.Append("" + NumIdentificationsByFullSeq + "\t"); sb.Append("" + SplitRT + "\t"); sb.Append("" + MassError); - + sb.Append("\t" + (IsMbrPeak ? RtHypothesis.ToString() : "")); + return sb.ToString(); } } diff --git a/mzLib/mzLib.nuspec b/mzLib/mzLib.nuspec index 67bfe4fa1..21998a393 100644 --- a/mzLib/mzLib.nuspec +++ b/mzLib/mzLib.nuspec @@ -2,7 +2,7 @@ mzLib - 5.0.543 + 5.1.001 mzLib Stef S. Stef S. From ac3b2b1b5978e8610e42435397ec988892897d4c Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Jan 2024 17:45:00 -0600 Subject: [PATCH 3/3] Fixed Equals and GetHashCode method for MatchedFragmentIon --- .../Omics/Fragmentation/MatchedFragmentIon.cs | 21 +++++++++++++++---- mzLib/Test/TestFragments.cs | 9 +++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs index 7120acf85..9f1c31c0f 100644 --- a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs +++ b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs @@ -72,19 +72,32 @@ public override string ToString() return NeutralTheoreticalProduct.ProductType + "" + NeutralTheoreticalProduct.FragmentNumber + "+" + Charge + "\t;" + NeutralTheoreticalProduct.NeutralMass; } + // Doubles are accurate to within 15-17 significant digits. Rounding to 10 decimal places ensures accurate comparison up to 100,000 m/z (non-inclusive) + internal const int MzDecimalDigits = 10; + // Rounding to 6 decimal places ensures accurate comparison up to 1,000,000,000 AU (non-inclusive) + internal const int IntensityDecimalDigits = 6; + public override bool Equals(object obj) { - MatchedFragmentIon other = (MatchedFragmentIon)obj; + return obj is MatchedFragmentIon otherIon && this.Equals(otherIon); + } + + public bool Equals(MatchedFragmentIon other) + { return this.NeutralTheoreticalProduct.Equals(other.NeutralTheoreticalProduct) && this.Charge == other.Charge - && Math.Abs(Mz - other.Mz) < 0.0001 - && Math.Abs(Intensity - other.Intensity) < 0.0001; + && Math.Round(Mz, MzDecimalDigits) - Math.Round(other.Mz, MzDecimalDigits) == 0 + && Math.Round(Intensity, IntensityDecimalDigits) - Math.Round(other.Intensity, IntensityDecimalDigits) == 0; } public override int GetHashCode() { - return Mz.GetHashCode(); + return HashCode.Combine( + NeutralTheoreticalProduct.GetHashCode(), + Charge.GetHashCode(), + Math.Round(Mz, MzDecimalDigits).GetHashCode(), + Math.Round(Intensity, IntensityDecimalDigits).GetHashCode()); } } } diff --git a/mzLib/Test/TestFragments.cs b/mzLib/Test/TestFragments.cs index fa7c0dce7..deaff5bdf 100644 --- a/mzLib/Test/TestFragments.cs +++ b/mzLib/Test/TestFragments.cs @@ -883,16 +883,19 @@ public static void Test_ProductMonoisotopicMass() public static void Test_MatchedFragmentGetHashCode() { Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); + Product pPrime = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); MatchedFragmentIon m = new MatchedFragmentIon(P, 1, 1, 1); - Assert.AreEqual(1072693248, m.GetHashCode()); + MatchedFragmentIon mPrime = new MatchedFragmentIon(pPrime, 1, 1, 1); + Assert.AreEqual(P.GetHashCode(), pPrime.GetHashCode()); + Assert.AreEqual(mPrime.GetHashCode(), m.GetHashCode()); } [Test] public static void TestMatchedFragmentIonEquals() { Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); - MatchedFragmentIon ion1 = new MatchedFragmentIon(P, experMz: 150, experIntensity: 99.99999, charge: 2); - MatchedFragmentIon ion2 = new MatchedFragmentIon(P, experMz: 149.99999, experIntensity: 100, charge: 2); + MatchedFragmentIon ion1 = new MatchedFragmentIon(P, experMz: 150, experIntensity: 99.99999999999, charge: 2); + MatchedFragmentIon ion2 = new MatchedFragmentIon(P, experMz: 149.99999999999, experIntensity: 100, charge: 2); Assert.AreEqual(ion1, ion2); }