diff --git a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs index 9f1c31c0f..169c2b362 100644 --- a/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs +++ b/mzLib/Omics/Fragmentation/MatchedFragmentIon.cs @@ -3,7 +3,7 @@ namespace Omics.Fragmentation { - public class MatchedFragmentIon + public class MatchedFragmentIon : IEquatable { public readonly Product NeutralTheoreticalProduct; public readonly double Mz; @@ -20,27 +20,15 @@ public MatchedFragmentIon(Product neutralTheoreticalProduct, double experMz, dou Intensity = experIntensity; Charge = charge; } - public double MassErrorDa - { - get - { - return Mz.ToMass(Charge) - NeutralTheoreticalProduct.NeutralMass; - } - } - - public double MassErrorPpm - { - get - { - return (MassErrorDa / NeutralTheoreticalProduct.NeutralMass) * 1e6; - } - } - public string Annotation + public bool IsInternalFragment => NeutralTheoreticalProduct.IsInternalFragment; + public virtual double MassErrorDa => Mz.ToMass(Charge) - NeutralTheoreticalProduct.NeutralMass; + public virtual double MassErrorPpm => MassErrorDa / NeutralTheoreticalProduct.NeutralMass * 1e6; + public virtual string Annotation { get { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(8); bool containsNeutralLoss = NeutralTheoreticalProduct.NeutralLoss != 0; @@ -77,13 +65,12 @@ public override string ToString() // 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) + public override bool Equals(object? obj) { return obj is MatchedFragmentIon otherIon && this.Equals(otherIon); } - - public bool Equals(MatchedFragmentIon other) + public bool Equals(MatchedFragmentIon? other) { return this.NeutralTheoreticalProduct.Equals(other.NeutralTheoreticalProduct) && this.Charge == other.Charge @@ -100,4 +87,20 @@ public override int GetHashCode() Math.Round(Intensity, IntensityDecimalDigits).GetHashCode()); } } -} + + /// + /// Represents a matched fragment ion with additional caching capabilities. + /// Inherits from . + /// + public class MatchedFragmentIonWithCache(Product neutralTheoreticalProduct, double experMz, double experIntensity, int charge) + : MatchedFragmentIon(neutralTheoreticalProduct, experMz, experIntensity, charge) + { + private double? _massErrorDa = null!; + private double? _massErrorPpm = null!; + private string? _annotation = null!; + + public override string Annotation => _annotation ??= base.Annotation; + public override double MassErrorDa => _massErrorDa ??= base.MassErrorDa; + public override double MassErrorPpm => _massErrorPpm ??= base.MassErrorPpm; + } +} \ No newline at end of file diff --git a/mzLib/Omics/Fragmentation/Product.cs b/mzLib/Omics/Fragmentation/Product.cs index 928919c09..ed6753db7 100644 --- a/mzLib/Omics/Fragmentation/Product.cs +++ b/mzLib/Omics/Fragmentation/Product.cs @@ -15,6 +15,7 @@ public class Product : IHasMass, IEquatable public ProductType? SecondaryProductType { get; } //used for internal fragment ions public int SecondaryFragmentNumber { get; } //used for internal fragment ions public double MonoisotopicMass => NeutralMass; + public bool IsInternalFragment => SecondaryProductType != null; /// /// A product is the individual neutral fragment from an MS dissociation. A fragmentation product here contains one of the two termini (N- or C-). @@ -31,15 +32,17 @@ public Product(ProductType productType, FragmentationTerminus terminus, double n Terminus = terminus; FragmentNumber = fragmentNumber; ResiduePosition = residuePosition; + + // These two are set for internal ions only. SecondaryProductType = secondaryProductType; SecondaryFragmentNumber = secondaryFragmentNumber; } - public string Annotation + public virtual string Annotation { get { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(8); if (SecondaryProductType == null) { @@ -84,7 +87,7 @@ public override string ToString() } } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is Product other && Equals(other); } @@ -108,4 +111,17 @@ public override int GetHashCode() return NeutralMass.GetHashCode(); } } + + + /// + /// Product Class that caches the annotation information to avoid repeated calculations + /// + public class ProductWithCache(ProductType productType, FragmentationTerminus terminus, double neutralMass, int fragmentNumber, + int residuePosition, double neutralLoss, ProductType? secondaryProductType = null, int secondaryFragmentNumber = 0) + : Product(productType, terminus, neutralMass, fragmentNumber, residuePosition, neutralLoss, + secondaryProductType, secondaryFragmentNumber) + { + private string? _annotation; + public override string Annotation => _annotation ??= base.Annotation; + } } diff --git a/mzLib/Omics/SpectrumMatch/SpectrumMatchFromTsv.cs b/mzLib/Omics/SpectrumMatch/SpectrumMatchFromTsv.cs index a96be9e0c..1914e2679 100644 --- a/mzLib/Omics/SpectrumMatch/SpectrumMatchFromTsv.cs +++ b/mzLib/Omics/SpectrumMatch/SpectrumMatchFromTsv.cs @@ -250,7 +250,7 @@ protected static List ReadFragmentIonsFromString(string matc double neutralTheoreticalMass = neutralExperimentalMass - errorDa; //theoretical mass is measured mass - measured error //The product created here is the theoretical product, with the mass back-calculated from the measured mass and measured error - Product theoreticalProduct = new Product(productType, + Product theoreticalProduct = new ProductWithCache(productType, terminus, neutralTheoreticalMass, fragmentNumber, @@ -259,7 +259,7 @@ protected static List ReadFragmentIonsFromString(string matc secondaryProductType, secondaryFragmentNumber); - matchedIons.Add(new MatchedFragmentIon(theoreticalProduct, mz, intensity, z)); + matchedIons.Add(new MatchedFragmentIonWithCache(theoreticalProduct, mz, intensity, z)); } } return matchedIons; diff --git a/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs b/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs index 2018158b1..dab5bf8e3 100644 --- a/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs +++ b/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs @@ -170,14 +170,14 @@ public static void TestParseModification() // psm with single modificaiton PsmFromTsv singleMod = psms[0]; - var modDict = Omics.SpectrumMatch.SpectrumMatchFromTsv.ParseModifications(singleMod.FullSequence); + var modDict = SpectrumMatchFromTsv.ParseModifications(singleMod.FullSequence); Assert.That(modDict.Count == 1); Assert.That(modDict.ContainsKey(37)); Assert.That(modDict.Values.First().Contains("Common Fixed:Carbamidomethyl on C")); // psm with two modifications PsmFromTsv twoMods = psms[15]; - modDict = Omics.SpectrumMatch.SpectrumMatchFromTsv.ParseModifications(twoMods.FullSequence); + modDict = SpectrumMatchFromTsv.ParseModifications(twoMods.FullSequence); Assert.That(modDict.Count == 2); Assert.That(modDict.ContainsKey(0) && modDict.ContainsKey(104)); Assert.That(modDict[0].Count == 1); @@ -188,7 +188,7 @@ public static void TestParseModification() // psm with two mods on the same amino acid string fullSeq = "[Common Fixed:Carbamidomethyl on C]|[UniProt:N-acetylserine on S]KPRKIEEIKDFLLTARRKDAKSVKIKKNKDNVKFK"; - modDict = Omics.SpectrumMatch.SpectrumMatchFromTsv.ParseModifications(fullSeq); + modDict = SpectrumMatchFromTsv.ParseModifications(fullSeq); Assert.That(modDict.Count == 1); Assert.That(modDict.ContainsKey(0)); Assert.That(modDict[0].Count == 2); @@ -202,23 +202,23 @@ public static void TestRemoveSpecialCharacters() // successful removal of the default character string toRemove = "ANDVHAO|CNVASDF|ABVCUAE"; int length = toRemove.Length; - Omics.SpectrumMatch.SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove); + SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove); Assert.That(toRemove.Length == length - 2); Assert.That(toRemove.Equals("ANDVHAOCNVASDFABVCUAE")); // does not remove default character when prompted otherwise toRemove = "ANDVHAO|CNVASDF|ABVCUAE"; - Omics.SpectrumMatch.SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, specialCharacter: @"\["); + SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, specialCharacter: @"\["); Assert.That(toRemove.Length == length); Assert.That(toRemove.Equals("ANDVHAO|CNVASDF|ABVCUAE")); // replaces default symbol when prompted - Omics.SpectrumMatch.SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, replacement: @"%"); + SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, replacement: @"%"); Assert.That(toRemove.Length == length); Assert.That(toRemove.Equals("ANDVHAO%CNVASDF%ABVCUAE")); // replaces inputted symbol with non-default symbol - Omics.SpectrumMatch.SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, replacement: @"=", specialCharacter: @"%"); + SpectrumMatchFromTsv.RemoveSpecialCharacters(ref toRemove, replacement: @"=", specialCharacter: @"%"); Assert.That(toRemove.Length == length); Assert.That(toRemove.Equals("ANDVHAO=CNVASDF=ABVCUAE")); } @@ -242,7 +242,7 @@ public static void TestToString() public static void TestParenthesesRemovalForSilac() { string baseSequence = "ASDF(+8.01)ASDF"; - string cleanedSequence = Omics.SpectrumMatch.SpectrumMatchFromTsv.RemoveParentheses(baseSequence); + string cleanedSequence = SpectrumMatchFromTsv.RemoveParentheses(baseSequence); Assert.IsTrue(cleanedSequence.Equals("ASDFASDF")); } diff --git a/mzLib/Test/Omics/MatchedFragmentIonTests.cs b/mzLib/Test/Omics/MatchedFragmentIonTests.cs new file mode 100644 index 000000000..5a337392d --- /dev/null +++ b/mzLib/Test/Omics/MatchedFragmentIonTests.cs @@ -0,0 +1,144 @@ +using System; +using Omics.Fragmentation; +using NUnit.Framework; +using System.Diagnostics.CodeAnalysis; + +namespace Test.Omics +{ + [ExcludeFromCodeCoverage] + public class MatchedFragmentIonTests + { + [Test] + public void TestMatchedFragmentIonConstructor() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion.NeutralTheoreticalProduct, Is.EqualTo(product)); + Assert.That(ion.Mz, Is.EqualTo(101.0)); + Assert.That(ion.Intensity, Is.EqualTo(200.0)); + Assert.That(ion.Charge, Is.EqualTo(1)); + } + + [Test] + public void TestIsInternalFragment() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0, ProductType.aStar, 2); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion.IsInternalFragment, Is.True); + + product = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0, ProductType.aStar, 2); + ion = new MatchedFragmentIonWithCache(product, 101.0, 200.0, 1); + + Assert.That(ion.IsInternalFragment, Is.True); + } + + [Test] + public void TestMassErrorDa() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + + product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIonWithCache(product, 101.0, 200.0, 1); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + + product = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + + product = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIonWithCache(product, 101.0, 200.0, 1); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + Assert.That(ion.MassErrorDa, Is.EqualTo(1.0).Within(10)); + } + + [Test] + public void TestMassErrorPpm() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + + product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIonWithCache(product, 101, 200.0, 1); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + + product = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIon(product, 101, 200.0, 1); + ion = new MatchedFragmentIon(product, 101, 200.0, 1); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + + product = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + ion = new MatchedFragmentIonWithCache(product, 101, 200.0, 1); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + Assert.That(ion.MassErrorPpm, Is.EqualTo(-72.764).Within(0.001)); + } + + [Test] + public void TestAnnotation() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion.Annotation, Is.EqualTo("b1+1")); + } + + [Test] + public void TestToString() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion.ToString(), Is.EqualTo("b1+1\t;100")); + + Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); + MatchedFragmentIon m = new MatchedFragmentIon(P, 1, 1, 1); + Assert.That(m.ToString(), Is.EqualTo("b1+1\t;1")); + } + + [Test] + public void TestEquals() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion1 = new MatchedFragmentIon(product, 101.0, 200.0, 1); + var ion2 = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion1.Equals(ion2), Is.True); + } + + [Test] + public static void TestMatchedFragmentAndCachedIonEquals() + { + 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 MatchedFragmentIonWithCache(P, experMz: 149.99999999999, experIntensity: 100, charge: 2); + Assert.That(ion1, Is.EqualTo(ion2)); + } + + [Test] + public void TestGetHashCode() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var ion = new MatchedFragmentIon(product, 101.0, 200.0, 1); + + Assert.That(ion.GetHashCode(), Is.EqualTo(HashCode.Combine(product.GetHashCode(), 1.GetHashCode(), Math.Round(101.0, 10).GetHashCode(), Math.Round(200.0, 6).GetHashCode()))); + } + + [Test] + 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); + MatchedFragmentIon mPrime = new MatchedFragmentIonWithCache(pPrime, 1, 1, 1); + Assert.That(P.GetHashCode(), Is.EqualTo(pPrime.GetHashCode())); + Assert.That(mPrime.GetHashCode(), Is.EqualTo(m.GetHashCode())); + } + } +} diff --git a/mzLib/Test/Omics/ProductTests.cs b/mzLib/Test/Omics/ProductTests.cs new file mode 100644 index 000000000..8c44a0046 --- /dev/null +++ b/mzLib/Test/Omics/ProductTests.cs @@ -0,0 +1,98 @@ +using NUnit.Framework; +using Omics.Fragmentation; +using System.Diagnostics.CodeAnalysis; + +namespace Test.Omics +{ + [ExcludeFromCodeCoverage] + public class ProductTests + { + [Test] + public void TestProductConstructor() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + Assert.That(product.NeutralMass, Is.EqualTo(100.0)); + Assert.That(product.ProductType, Is.EqualTo(ProductType.b)); + Assert.That(product.NeutralLoss, Is.EqualTo(0.0)); + Assert.That(product.Terminus, Is.EqualTo(FragmentationTerminus.N)); + Assert.That(product.FragmentNumber, Is.EqualTo(1)); + Assert.That(product.ResiduePosition, Is.EqualTo(1)); + Assert.That(product.SecondaryProductType, Is.Null); + Assert.That(product.SecondaryFragmentNumber, Is.EqualTo(0)); + Assert.That(product.IsInternalFragment, Is.False); + } + + [Test] + public void TestProductAnnotation() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + Assert.That(product.Annotation, Is.EqualTo("b1")); + Assert.That(product.IsInternalFragment, Is.False); + + var productWithLoss = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 18.0); + Assert.That(productWithLoss.Annotation, Is.EqualTo("b1-18.00")); + + var internalProduct = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0, ProductType.y, 2); + Assert.That(internalProduct.Annotation, Is.EqualTo("bIy[1-2]")); + Assert.That(internalProduct.IsInternalFragment, Is.True); + } + + [Test] + public void TestProductToString() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + Assert.That(product.ToString(), Is.EqualTo("b1;100.00000-0")); + Assert.That(product.IsInternalFragment, Is.False); + + var productWithLoss = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 18.0); + Assert.That(productWithLoss.ToString(), Is.EqualTo("b1;100.00000-18")); + + var internalProduct = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0, ProductType.y, 2); + Assert.That(internalProduct.ToString(), Is.EqualTo("bIy[1-2];100.00000-0")); + Assert.That(internalProduct.IsInternalFragment, Is.True); + } + + [Test] + public void TestProductWithCacheAnnotation() + { + var productWithCache = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 3, 5, 0.0); + Assert.That(productWithCache.Annotation, Is.EqualTo("b3")); + + var productWithCacheWithLoss = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 3, 5, 18.0); + Assert.That(productWithCacheWithLoss.Annotation, Is.EqualTo("b3-18.00")); + + var internalProductWithCache = new ProductWithCache(ProductType.y, FragmentationTerminus.C, 200.0, 18, 5, 0.0, ProductType.b, 36); + Assert.That(internalProductWithCache.Annotation, Is.EqualTo("yIb[18-36]")); + } + + [Test] + public void TestProductEquality() + { + var product1 = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var product2 = new ProductWithCache(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + var product3 = new Product(ProductType.y, FragmentationTerminus.C, 200.0, 2, 2, 0.0); + + Assert.That(product1.Equals(product2), Is.True); + Assert.That(product1.Equals(product3), Is.False); + Assert.That(product1.Equals(null), Is.False); + } + + [Test] + public void TestProductHashCode() + { + var product = new Product(ProductType.b, FragmentationTerminus.N, 100.0, 1, 1, 0.0); + Assert.That(product.GetHashCode(), Is.EqualTo(product.NeutralMass.GetHashCode())); + + + Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); + Assert.That(1072693248, Is.EqualTo(P.GetHashCode())); + } + + [Test] + public static void Test_ProductMonoisotopicMass() + { + Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); + Assert.That(P.MonoisotopicMass.Equals(P.NeutralMass)); + } + } +} diff --git a/mzLib/Test/TestDigestionMotif.cs b/mzLib/Test/TestDigestionMotif.cs index b2240d62c..386ed1b2c 100644 --- a/mzLib/Test/TestDigestionMotif.cs +++ b/mzLib/Test/TestDigestionMotif.cs @@ -10,6 +10,7 @@ using System.IO; using System.Linq; using Omics.Digestion; +using Omics.Fragmentation; using Omics.Modifications; using UsefulProteomicsDatabases; using Stopwatch = System.Diagnostics.Stopwatch; @@ -569,8 +570,8 @@ public static void TestProteolyticDigestion() //check that there are no duplicates Assert.IsTrue(pwsms.Count == hashset.Count); //Speedy semi specific test - DigestionParams speedySemiN = new DigestionParams("trypsin", 10, 29, 30, 1024, InitiatorMethionineBehavior.Retain, 2, CleavageSpecificity.Semi, Omics.Fragmentation.FragmentationTerminus.N); - DigestionParams speedySemiC = new DigestionParams("trypsin", 10, 29, 30, 1024, InitiatorMethionineBehavior.Retain, 2, CleavageSpecificity.Semi, Omics.Fragmentation.FragmentationTerminus.C); + DigestionParams speedySemiN = new DigestionParams("trypsin", 10, 29, 30, 1024, InitiatorMethionineBehavior.Retain, 2, CleavageSpecificity.Semi, FragmentationTerminus.N); + DigestionParams speedySemiC = new DigestionParams("trypsin", 10, 29, 30, 1024, InitiatorMethionineBehavior.Retain, 2, CleavageSpecificity.Semi, FragmentationTerminus.C); List pwsmsN = humanInsulin.Digest(speedySemiN, null, null).ToList(); List pwsmsC = humanInsulin.Digest(speedySemiC, null, null).ToList(); Assert.IsTrue(pwsmsN.Count == 7); diff --git a/mzLib/Test/TestFragments.cs b/mzLib/Test/TestFragments.cs index ea4a307c3..31c9f5535 100644 --- a/mzLib/Test/TestFragments.cs +++ b/mzLib/Test/TestFragments.cs @@ -895,45 +895,6 @@ public static void Test_TerminusSpecificProductTypesFromPeptideWithSetMods() Assert.AreEqual(new List { }, fragments.Select(b => b.ProductType).Distinct().ToList()); } - [Test] - public static void Test_MatchedFragmentIonToString() - { - Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); - MatchedFragmentIon m = new MatchedFragmentIon(P, 1, 1, 1); - Assert.AreEqual("b1+1\t;1", m.ToString()); - } - [Test] - public static void Test_ProductGetHashCode() - { - Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); - Assert.AreEqual(1072693248, P.GetHashCode()); - } - [Test] - public static void Test_ProductMonoisotopicMass() - { - Product P = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 0); - Assert.That(P.MonoisotopicMass.Equals(P.NeutralMass)); - } - [Test] - 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); - 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] public static void Test_CID_Fragmentation_No_Unmodified_B1_ions() { @@ -1022,6 +983,7 @@ public static void TestInternalFragments() Assert.IsTrue(products.Count == expectedProducts.Count); for (int i = 0; i < products.Count; i++) { + Assert.IsTrue(products[i].IsInternalFragment); Assert.IsTrue(products[i].Annotation.Equals(expectedProducts[i].Annotation)); Assert.IsTrue(Math.Round(products[i].NeutralMass).Equals(Math.Round(expectedProducts[i].NeutralMass))); } @@ -1038,6 +1000,7 @@ public static void TestInternalFragments() Assert.IsTrue(products.Count == expectedProducts.Count); for (int i = 0; i < products.Count; i++) { + Assert.IsTrue(products[i].IsInternalFragment); Assert.IsTrue(products[i].Annotation.Equals(expectedProducts[i].Annotation)); Assert.IsTrue(Math.Round(products[i].NeutralMass).Equals(Math.Round(expectedProducts[i].NeutralMass))); } diff --git a/mzLib/Test/Transcriptomics/TestFragmentation.cs b/mzLib/Test/Transcriptomics/TestFragmentation.cs index 5f570f2a9..e2e13003a 100644 --- a/mzLib/Test/Transcriptomics/TestFragmentation.cs +++ b/mzLib/Test/Transcriptomics/TestFragmentation.cs @@ -185,6 +185,7 @@ public void TestRnaFragments(TestNucleicAcid.SixmerTestCase testCase) Assert.That(testCase.NeutralMasses[i], Is.EqualTo(product.MonoisotopicMass).Within(0.01)); Assert.That(0, Is.EqualTo(product.NeutralLoss)); Assert.That(null, Is.EqualTo(product.SecondaryProductType)); + Assert.That(!product.IsInternalFragment); Assert.That(0, Is.EqualTo(product.SecondaryFragmentNumber)); string annotation = $"{product.ProductType}{product.FragmentNumber}";