Skip to content

Commit

Permalink
Added ScorerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Sol committed Dec 12, 2022
1 parent c9174ea commit b744f49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mzLib/MassSpectrometry/Deconvolution/MinimalSpectrum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MinimalSpectrum
public readonly double MostAbundantMz;
public readonly int Charge;

internal MinimalSpectrum(double[] mzArray, double[] intensityArray, int charge = 0)
public MinimalSpectrum(double[] mzArray, double[] intensityArray, int charge = 0)
{
MzArray = mzArray;
IntensityArray = intensityArray;
Expand Down
32 changes: 30 additions & 2 deletions mzLib/Test/TestDeconvolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Easy.Common.Extensions;
using MassSpectrometry.Deconvolution;
using MassSpectrometry.Deconvolution.Algorithms;
using MassSpectrometry.Deconvolution.Scoring;
using TopDownProteomics.MassSpectrometry;
using IsotopicDistribution = Chemistry.IsotopicDistribution;

Expand Down Expand Up @@ -320,13 +321,40 @@ public static void CheckSpectralGetMostAbundantObservedIsotopicMass(string pepti
//List<IsotopicEnvelope> lie3 = deconvoluter.ClassicDeconvoluteMzSpectra(singlespec, singleRange).ToList();
//Assert.AreEqual(lie2.Select(p => p.MostAbundantObservedIsotopicMass), lie3.Select(p => p.MostAbundantObservedIsotopicMass));
}
#endregion

#region scorerTests

[Test]
public static void ScorerTest()
{
// Test goes here
Assert.That(true);
Scorer.ScoringMethods kullbackMethod = Scorer.ScoringMethods.KullbackLeibler;
Scorer.ScoringMethods spectralContrastMethod = Scorer.ScoringMethods.SpectralContrastAngle;

// KullbackLeibler hasn't been implemented yet
Assert.That(() => new Scorer(kullbackMethod, new PpmTolerance(5.0)), Throws.Exception.TypeOf<NotImplementedException>());
// Assert.That(kullbackScorer.PoorScore > 10);
// In kullback leibler, low scores are better. In spectral contrast angle, high scores are better
// Assert.That(kullbackScorer.TestForScoreImprovement(0.01, 0.03, out var better));


Scorer spectralScorer = new Scorer(spectralContrastMethod, new PpmTolerance(5.0));
Assert.That(spectralScorer.PoorScore <= 0);
Assert.That(!spectralScorer.TestForScoreImprovement(0.01, 0.03, out var betterScore));


MinimalSpectrum testSpectrum =
new MinimalSpectrum(new double[] { 1.0, 2.0, 3.0, 4.0 }, new double[] { 1.0, 2.0, 3.0, 4.0 });
MinimalSpectrum comparisonSpectrum =
new MinimalSpectrum(new double[] { 1.0, 2.0, 3.0, 4.0 }, new double[] { 2.0, 1.0, 4.0, 3.0 });

double spectralScore = spectralScorer.Score(testSpectrum, comparisonSpectrum);
Assert.That(spectralScore, Is.EqualTo(0.766).Within(0.001));
Assert.That(spectralScore, Is.EqualTo(spectralScorer.Score(comparisonSpectrum, testSpectrum) ).Within(0.01));

}

#endregion

}
}

0 comments on commit b744f49

Please sign in to comment.