Skip to content

Commit

Permalink
added test for negative mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nbollis committed Aug 5, 2024
1 parent ba54e46 commit 678dbc3
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions mzLib/Test/TestDeconvolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TestDeconvolutionProteoformMultiChargeState(double selectedIonMz, in

//The primary monoisotopic mass should be the same regardless of which peak in which charge state was selected for isolation.
//this case is interesting because other monoisotopic mass may have a sodium adduct. The unit test could be expanded to consider this.
Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
NUnit.Framework.Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
}

[Test]
Expand Down Expand Up @@ -94,7 +94,7 @@ public static void CheckGetMostAbundantObservedIsotopicMass(string peptide, stri
//check assigned correctly
List<IsotopicEnvelope> lie2 = singlespec.Deconvolute(singleRange, minAssumedChargeState, maxAssumedChargeState, deconvolutionTolerancePpm, intensityRatioLimit).ToList();
List<IsotopicEnvelope> lie2_charge = lie2.Where(p => p.Charge == charge).ToList();
Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));
NUnit.Framework.Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));

//check that if already assigned, skips assignment and just recalls same value
List<IsotopicEnvelope> lie3 = singlespec.Deconvolute(singleRange, minAssumedChargeState, maxAssumedChargeState, deconvolutionTolerancePpm, intensityRatioLimit).ToList();
Expand Down Expand Up @@ -149,8 +149,8 @@ public void TestClassicDeconvolutionProteoformMultiChargeState(double selectedIo

//The primary monoisotopic mass should be the same regardless of which peak in which charge state was selected for isolation.
//this case is interesting because other monoisotopic mass may have a sodium adduct. The unit test could be expanded to consider this.
Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
Assert.That(monoIsotopicMasses2[0], Is.EqualTo(14037.926829).Within(.0005));
NUnit.Framework.Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
NUnit.Framework.Assert.That(monoIsotopicMasses2[0], Is.EqualTo(14037.926829).Within(.0005));
}

[Test]
Expand Down Expand Up @@ -184,13 +184,42 @@ public static void CheckClassicGetMostAbundantObservedIsotopicMass(string peptid

List<IsotopicEnvelope> lie2 = Deconvoluter.Deconvolute(singlespec, deconParameters, singleRange).ToList();
List<IsotopicEnvelope> lie2_charge = lie2.Where(p => p.Charge == charge).ToList();
Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));
NUnit.Framework.Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));

//check that if already assigned, skips assignment and just recalls same value
List<IsotopicEnvelope> lie3 = Deconvoluter.Deconvolute(singlespec, deconParameters, singleRange).ToList();
Assert.AreEqual(lie2.Select(p => p.MostAbundantObservedIsotopicMass), lie3.Select(p => p.MostAbundantObservedIsotopicMass));
}

[Test]
[TestCase(373.85, -5, 1874.28)] // GUAGUC -5
[TestCase(467.57, -4, 1874.28)] // GUAGUC -4
[TestCase(623.75, -3, 1874.28)] // GUAGUC -3
[TestCase(936.13, -2, 1874.28)] // GUAGUC -2
[TestCase(473.05, -4, 1896.26)] // GUAGUC +Na -H -4
[TestCase(631.07, -3, 1896.26)] // GUAGUC +Na -H -3
[TestCase(947.121, -2, 1896.26)] // GUAGUC +Na -H -2
public void TestNegativeModeClassicDeconvolution(double expectedMz, int expectedCharge, double expectedMonoMass)
{
// get scan
string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles",
"GUACUG_NegativeMode_Sliced.mzML");
var scan = MsDataFileReader.GetDataFile(filePath).GetAllScansList().First();
var tolerance = new PpmTolerance(20);

// set up deconvolution
DeconvolutionParameters deconParams = new ClassicDeconvolutionParameters(-10, -1, 20, 3, Polarity.Negative);

List<IsotopicEnvelope> deconvolutionResults = Deconvoluter.Deconvolute(scan, deconParams).ToList();
// ensure each expected result is found, with correct mz, charge, and monoisotopic mass
var resultsWithPeakOfInterest = deconvolutionResults.FirstOrDefault(envelope =>
envelope.Peaks.Any(peak => tolerance.Within(peak.mz, expectedMz)));
if (resultsWithPeakOfInterest is null) NUnit.Framework.Assert.Fail();

NUnit.Framework.Assert.That(expectedMonoMass, Is.EqualTo(resultsWithPeakOfInterest.MonoisotopicMass).Within(0.01));
NUnit.Framework.Assert.That(expectedCharge, Is.EqualTo(resultsWithPeakOfInterest.Charge));
}

#endregion

#region IsoDec Deconvolution
Expand Down Expand Up @@ -239,8 +268,8 @@ public void TestIsoDecDeconvolutionProteoformMultiChargeState(double selectedIon

//The primary monoisotopic mass should be the same regardless of which peak in which charge state was selected for isolation.
//this case is interesting because other monoisotopic mass may have a sodium adduct. The unit test could be expanded to consider this.
Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
Assert.That(monoIsotopicMasses2[0], Is.EqualTo(14037.926829).Within(.0005));
NUnit.Framework.Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005));
NUnit.Framework.Assert.That(monoIsotopicMasses2[0], Is.EqualTo(14037.926829).Within(.0005));
}

[Test]
Expand All @@ -266,15 +295,13 @@ public static void CheckIsoDecGetMostAbundantObservedIsotopicMass(string peptide
//check assigned correctly
List<IsotopicEnvelope> lie2 = Deconvoluter.Deconvolute(singlespec, deconParameters, singleRange).ToList();
List<IsotopicEnvelope> lie2_charge = lie2.Where(p => p.Charge == charge).ToList();
Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));
NUnit.Framework.Assert.That(lie2_charge[0].MostAbundantObservedIsotopicMass / charge, Is.EqualTo(m).Within(0.1));

//check that if already assigned, skips assignment and just recalls same value
List<IsotopicEnvelope> lie3 = Deconvoluter.Deconvolute(singlespec, deconParameters, singleRange).ToList();
Assert.AreEqual(lie2.Select(p => p.MostAbundantObservedIsotopicMass), lie3.Select(p => p.MostAbundantObservedIsotopicMass));
}

#endregion

[Test]
[TestCase(373.85, -5, 1874.28)] // GUAGUC -5
[TestCase(467.57, -4, 1874.28)] // GUAGUC -4
Expand All @@ -283,7 +310,7 @@ public static void CheckIsoDecGetMostAbundantObservedIsotopicMass(string peptide
[TestCase(473.05, -4, 1896.26)] // GUAGUC +Na -H -4
[TestCase(631.07, -3, 1896.26)] // GUAGUC +Na -H -3
[TestCase(947.121, -2, 1896.26)] // GUAGUC +Na -H -2
public void TestNegativeModeClassicDeconvolution(double expectedMz, int expectedCharge, double expectedMonoMass)
public void TestNegativeModeIsoDecDeconvolution(double expectedMz, int expectedCharge, double expectedMonoMass)
{
// get scan
string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles",
Expand All @@ -292,18 +319,20 @@ public void TestNegativeModeClassicDeconvolution(double expectedMz, int expected
var tolerance = new PpmTolerance(20);

// set up deconvolution
DeconvolutionParameters deconParams = new ClassicDeconvolutionParameters(-10, -1, 20, 3, Polarity.Negative);
DeconvolutionParameters deconParams = new IsoDecDeconvolutionParameters(Polarity.Negative);

List<IsotopicEnvelope> deconvolutionResults = Deconvoluter.Deconvolute(scan, deconParams).ToList();
// ensure each expected result is found, with correct mz, charge, and monoisotopic mass
var resultsWithPeakOfInterest = deconvolutionResults.FirstOrDefault(envelope =>
envelope.Peaks.Any(peak => tolerance.Within(peak.mz, expectedMz)));
if (resultsWithPeakOfInterest is null) Assert.Fail();
if (resultsWithPeakOfInterest is null) NUnit.Framework.Assert.Fail();

Assert.That(tolerance.Within(expectedMonoMass, resultsWithPeakOfInterest.MonoisotopicMass));
Assert.That(expectedCharge, Is.EqualTo(resultsWithPeakOfInterest.Charge));
NUnit.Framework.Assert.That(expectedMonoMass, Is.EqualTo(resultsWithPeakOfInterest.MonoisotopicMass).Within(0.01));
NUnit.Framework.Assert.That(expectedCharge, Is.EqualTo(resultsWithPeakOfInterest.Charge));
}

#endregion

[Test]
public static void TestExampleNewDeconvolutionInDeconvoluter()
{
Expand All @@ -315,14 +344,14 @@ public static void TestExampleNewDeconvolutionInDeconvoluter()
dataFile.CloseDynamicConnection();

// test switch statements in Deconvoluter
Assert.Throws<NotImplementedException>(() => Deconvoluter.Deconvolute(spectrum, deconParams));
Assert.Throws<NotImplementedException>(() => Deconvoluter.Deconvolute(scan, deconParams));
NUnit.Framework.Assert.Throws<NotImplementedException>(() => Deconvoluter.Deconvolute(spectrum, deconParams));
NUnit.Framework.Assert.Throws<NotImplementedException>(() => Deconvoluter.Deconvolute(scan, deconParams));

// test default exceptions in deconvoluter
var badEnumValue = (DeconvolutionType)Int32.MaxValue;
deconParams.GetType().GetProperty("DeconvolutionType")!.SetValue(deconParams, badEnumValue);
Assert.Throws<MzLibException>(() => Deconvoluter.Deconvolute(spectrum, deconParams));
Assert.Throws<MzLibException>(() => Deconvoluter.Deconvolute(scan, deconParams));
NUnit.Framework.Assert.Throws<MzLibException>(() => Deconvoluter.Deconvolute(spectrum, deconParams));
NUnit.Framework.Assert.Throws<MzLibException>(() => Deconvoluter.Deconvolute(scan, deconParams));
}


Expand All @@ -340,15 +369,15 @@ public static void Test_MsDataScan_GetIsolatedMassesAndCharges()

// get isolated masses and charges on an MS1 scan. This means the isolation window is null.
var ms1Result = precursorScan.GetIsolatedMassesAndCharges(precursorScan.MassSpectrum, deconParams).ToList();
Assert.That(ms1Result.Count, Is.EqualTo(0));
NUnit.Framework.Assert.That(ms1Result.Count, Is.EqualTo(0));
ms1Result = precursorScan.GetIsolatedMassesAndCharges(precursorScan, deconParams).ToList();
Assert.That(ms1Result.Count, Is.EqualTo(0));
NUnit.Framework.Assert.That(ms1Result.Count, Is.EqualTo(0));

// get isolated masses and charges on an MS2 scan. This should work correctly
var ms2Result = fragmentationScan.GetIsolatedMassesAndCharges(precursorScan.MassSpectrum, deconParams).ToList();
Assert.That(ms2Result.Count, Is.EqualTo(1));
NUnit.Framework.Assert.That(ms2Result.Count, Is.EqualTo(1));
ms2Result = fragmentationScan.GetIsolatedMassesAndCharges(precursorScan, deconParams).ToList();
Assert.That(ms2Result.Count, Is.EqualTo(1));
NUnit.Framework.Assert.That(ms2Result.Count, Is.EqualTo(1));
}
}
}

0 comments on commit 678dbc3

Please sign in to comment.