Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited the MatchedFramgentIon Equals method #751

Merged
merged 7 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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).
{
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
Loading