Skip to content

Commit

Permalink
Added test with real data
Browse files Browse the repository at this point in the history
  • Loading branch information
nbollis committed Nov 15, 2023
1 parent dc42c7a commit 699b515
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mzLib/Test/AveragingTests/TestSpectraFileAveraging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,45 @@ public static void TestAverageDdaScans(int numScansToAverage, string listPropert
Assert.That(averagedScans.Count(p => p.MsnOrder == 2), Is.EqualTo(ms2Count));
CollectionAssert.AreEquivalent(precursorScanNumbers, averagedScans.Select(p => p.OneBasedPrecursorScanNumber));
CollectionAssert.AreEquivalent(scanNumbers, averagedScans.Select(p => p.OneBasedScanNumber));

// ensure no duplicates in scan numbers and precursor scan numbers
CollectionAssert.AllItemsAreUnique(averagedScans.Select(p => p.OneBasedScanNumber));
CollectionAssert.AllItemsAreUnique(averagedScans.Select(p => (p.OneBasedScanNumber, p.OneBasedPrecursorScanNumber)));
}

[Test]
public static void TestOnRealData()
{
string datapath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles",
"SmallCalibratibleYeast.mzml");
var scansToAverage = MsDataFileReader.GetDataFile(datapath).GetAllScansList();
SpectralAveragingParameters.SpectraFileAveragingType = SpectraFileAveragingType.AverageDdaScans;
SpectralAveragingParameters.NumberOfScansToAverage = 5;

int ms1Count = scansToAverage.Count(p => p.MsnOrder == 1);
int ms2Count = scansToAverage.Count(p => p.MsnOrder == 2);
int?[] precursorScanNumbers = scansToAverage.Select(p => p.OneBasedPrecursorScanNumber).ToArray();
int[] scanNumbers = scansToAverage.Select(p => p.OneBasedScanNumber).ToArray();

MsDataScan[] averagedScans = SpectraFileAveraging.AverageSpectraFile(scansToAverage, SpectralAveragingParameters);

// Assert that there are the same number of ms1 and ms2 scans, and that they are in the same order
Assert.That(averagedScans.Count(p => p.MsnOrder == 1), Is.EqualTo(ms1Count));
Assert.That(averagedScans.Count(p => p.MsnOrder == 2), Is.EqualTo(ms2Count));
CollectionAssert.AreEquivalent(precursorScanNumbers, averagedScans.Select(p => p.OneBasedPrecursorScanNumber));
CollectionAssert.AreEquivalent(scanNumbers, averagedScans.Select(p => p.OneBasedScanNumber));

// ensure no duplicates in scan numbers and precursor scan numbers
CollectionAssert.AllItemsAreUnique(averagedScans.Select(p => p.OneBasedScanNumber));
CollectionAssert.AllItemsAreUnique(averagedScans.Select(p =>(p.OneBasedScanNumber, p.OneBasedPrecursorScanNumber)));

// ensure retention times are sequentially increasing
double previousRt = 0;
foreach (var rt in averagedScans.Select(p => p.RetentionTime))
{
Assert.That(rt > previousRt);
previousRt = rt;
}
}
}
}

0 comments on commit 699b515

Please sign in to comment.