BinningCentroidingAlgorithm implements MSDKCentroidingAlgorithm { @Override public @Nonnull MsScan centroidScan(@Nonnull MsScan inputScan) { this.newScan = MsScanUtil.clone(inputScan, false); mzBuffer = inputScan.getMzValues(); intensityBuffer = inputScan.getIntensityValues(); numOfDataPoints = inputScan.getNumberOfDataPoints(); newNumOfDataPoints = 0; if (numOfDataPoints == 0) { newScan.setDataPoints(mzBuffer, intensityBuffer, 0); return newScan; } double currentBinMzStart = mzBuffer[0]; float currentBinIntensity = 0f; for (int i = 0; i < numOfDataPoints; i++) { if (mzBuffer[i] < (currentBinMzStart + binSize)) { currentBinIntensity += intensityBuffer[i]; continue; } final double currentBinMzValue = currentBinMzStart + (binSize / 2); mzBuffer[newNumOfDataPoints] = currentBinMzValue; intensityBuffer[newNumOfDataPoints] = currentBinIntensity; newNumOfDataPoints++; currentBinMzStart += binSize; currentBinIntensity = 0f; } newScan.setDataPoints(mzBuffer, intensityBuffer, newNumOfDataPoints); return newScan; } BinningCentroidingAlgorithm(@Nonnull Double binSize); @Override @Nonnull MsScan centroidScan(@Nonnull MsScan inputScan);  }
@Test public void testOrbitrap() throws Exception { File inputFile = new File(this.getClass().getClassLoader().getResource("profile_orbitrap.mzML").toURI()); Assert.assertTrue(inputFile.canRead()); MzMLFileImportMethod importer = new MzMLFileImportMethod(inputFile); RawDataFile rawFile = importer.execute(); Assert.assertNotNull(rawFile); Assert.assertEquals(1.0, importer.getFinishedPercentage(), 0.0001); List<MsScan> scans = rawFile.getScans(); Assert.assertNotNull(scans); MsScan lastScan = scans.get(scans.size() - 1); final double binSize = 1.0; BinningCentroidingAlgorithm centroider = new BinningCentroidingAlgorithm(binSize); final MsScan centroidedScan = centroider.centroidScan(lastScan); double mzBuffer[] = centroidedScan.getMzValues(); float intensityBuffer[] = centroidedScan.getIntensityValues(); int numOfDataPoints = centroidedScan.getNumberOfDataPoints(); Assert.assertTrue(numOfDataPoints > 50); Integer basePeak = MsSpectrumUtil.getBasePeakIndex(intensityBuffer, numOfDataPoints); Assert.assertEquals(1.49854E8f, intensityBuffer[basePeak], 1E5); Assert.assertEquals(281.4996043, mzBuffer[basePeak], 0.000001); rawFile.dispose(); }