Skip to content

Commit

Permalink
Undo Rounding (#831)
Browse files Browse the repository at this point in the history
* Undo Rounding

* reverted remaining test

* FixedFlashLFQ test
  • Loading branch information
Alexander-Sol authored Jan 31, 2025
1 parent 5d2b774 commit 981fc57
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 32 deletions.
2 changes: 1 addition & 1 deletion mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public byte[] Get64BitYarray()

public byte[] Get64BitXarray()
{
return Get64Bitarray(XArray.Select(x => Math.Round(x, 4)));
return Get64Bitarray(XArray);
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void TestWriting(string filePath, string outfile, int loop)
Assert.That(readInScan.MsnOrder.Equals(writtenScan.MsnOrder));
Assert.That(readInScan.IsCentroid.Equals(writtenScan.IsCentroid));
Assert.That(readInScan.MassSpectrum.YArray, Is.EquivalentTo(writtenScan.MassSpectrum.YArray));
Assert.That(readInScan.MassSpectrum.XArray, Is.EquivalentTo(writtenScan.MassSpectrum.XArray.Select(x => Math.Round(x, 4))));
Assert.That(readInScan.MassSpectrum.XArray, Is.EquivalentTo(writtenScan.MassSpectrum.XArray));
}

File.Delete(outfile);
Expand Down
29 changes: 1 addition & 28 deletions mzLib/Test/FileReadingTests/TestMzML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,7 @@ public void WriteMzmlTest()
Assert.AreEqual(2, reader.GetClosestOneBasedSpectrumNumber(2));

var newFirstValue = reader.GetOneBasedScan(1).MassSpectrum.FirstX;
Assert.AreNotEqual(oldFirstValue.Value, newFirstValue.Value);
Assert.AreEqual(Math.Round((double)oldFirstValue, 4), newFirstValue.Value, 1e-6);
Assert.AreEqual(oldFirstValue.Value, newFirstValue.Value);

var secondScan2 = reader.GetOneBasedScan(2);

Expand Down Expand Up @@ -1452,32 +1451,6 @@ public void MzmlFindPrecursorReferenceScan()
Assert.AreEqual(1, fakeMzml1.GetAllScansList().ElementAt(3).OneBasedPrecursorScanNumber);
}

[Test]
public void TestMzmlWriterRounding()
{
// This test ensure the CreateAndWriteMzml method only writes m/z values out to 4 decimal places of precision
MsDataScan[] scans = new MsDataScan[1];

double[] intensities0 = new double[] { 1, 1, 1, 1 };
double[] mz0 = new double[] { 50.00014, 50.00015, 50.0004, 50.0005 };
MzSpectrum massSpec0 = new MzSpectrum(mz0, intensities0, false);
scans[0] = new MsDataScan(massSpec0, 1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec0.SumOfAllY, null, null, "1");

FakeMsDataFile fakeFile = new FakeMsDataFile(scans);
MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(fakeFile, Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML"), false);
var fakeMzml =
MsDataFileReader.GetDataFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML"));
fakeMzml.LoadAllStaticData();

var readSpectrum = fakeMzml.Scans[0].MassSpectrum;

// Ensure that the spectrum was rounded to the fourth decimal place on write
Assert.That(readSpectrum.XArray[0], Is.EqualTo(50.0001).Within(0.000001));
Assert.That(readSpectrum.XArray[1], Is.EqualTo(50.0002).Within(0.000001));
Assert.That(readSpectrum.XArray[2], Is.EqualTo(50.0004).Within(0.000001));
Assert.That(readSpectrum.XArray[3], Is.EqualTo(50.0005).Within(0.000001));
}

[Test]
[TestCase("tester.mzml")]
[TestCase("SmallCalibratibleYeast.mzml")]
Expand Down
3 changes: 2 additions & 1 deletion mzLib/Test/FileReadingTests/TestRawFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ public static void TestPeakFilteringRawFileReader(string infile)
for (int j = 0; j < mzmlScan.MassSpectrum.XArray.Length; j++)
{
double roundedRawMz = Math.Round(rawScan.MassSpectrum.XArray[j], 4);
double roundedMzmlMz = Math.Round(mzmlScan.MassSpectrum.XArray[j], 4);

// XArray is rounded to the 4th digit during CreateAndWrite
Assert.AreEqual(mzmlScan.MassSpectrum.XArray[j], roundedRawMz);
Assert.AreEqual(roundedMzmlMz, roundedRawMz);

double roundedMzmlIntensity = Math.Round(mzmlScan.MassSpectrum.XArray[j], 0);
double roundedRawIntensity = Math.Round(rawScan.MassSpectrum.XArray[j], 0);
Expand Down
2 changes: 1 addition & 1 deletion mzLib/TestFlashLFQ/TestFlashLFQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ public static void ProteoformPeakfindingTest()

Assert.That((int)results.PeptideModifiedSequences[sequence].GetIntensity(file1) == 1386491);
ChromatographicPeak peak = results.Peaks[file1].First(p => p.Identifications.First().ModifiedSequence == sequence);
Assert.That(Math.Round(peak.MassError, 3), Is.EqualTo(0.006).Within(0.0001));
Assert.That(Math.Round(peak.MassError, 3), Is.EqualTo(0));
Assert.That(peak.IsotopicEnvelopes.Count == 10);
}

Expand Down

0 comments on commit 981fc57

Please sign in to comment.