Skip to content

Commit

Permalink
Edited the MatchedFramgentIon Equals method (#751)
Browse files Browse the repository at this point in the history
* Edited the MatchedFramgentIon Equals method

* Report mbr predicted rt

* Fixed Equals and GetHashCode method for MatchedFragmentIon

---------

Co-authored-by: Nic Bollis <[email protected]>
Co-authored-by: trishorts <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2024
1 parent c7bdfc1 commit 4790e3e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
4 changes: 3 additions & 1 deletion mzLib/FlashLFQ/ChromatographicPeak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
21 changes: 17 additions & 4 deletions mzLib/Omics/Fragmentation/MatchedFragmentIon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 80 in mzLib/Omics/Fragmentation/MatchedFragmentIon.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 80 in mzLib/Omics/Fragmentation/MatchedFragmentIon.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 80 in mzLib/Omics/Fragmentation/MatchedFragmentIon.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
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
&& this.Mz == other.Mz
&& this.Intensity == other.Intensity;
&& 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());
}
}
}
14 changes: 13 additions & 1 deletion mzLib/Test/TestFragments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,20 @@ 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.99999999999, charge: 2);
MatchedFragmentIon ion2 = new MatchedFragmentIon(P, experMz: 149.99999999999, experIntensity: 100, charge: 2);
Assert.AreEqual(ion1, ion2);
}

[Test]
Expand Down

0 comments on commit 4790e3e

Please sign in to comment.