ExactMassCentroidingAlgorithm implements MSDKCentroidingAlgorithm { @Override public @Nonnull MsScan centroidScan(@Nonnull MsScan inputScan) { this.newScan = MsScanUtil.clone(inputScan, false); mzBuffer = inputScan.getMzValues(); intensityBuffer = inputScan.getIntensityValues(); final int numOfDataPoints = inputScan.getNumberOfDataPoints(); if (numOfDataPoints == 0) { newScan.setDataPoints(mzBuffer, intensityBuffer, 0); return newScan; } int localMaximumIndex = 0; int rangeBeginning = 0, rangeEnd; boolean ascending = true; int newNumOfDataPoints = 0; for (int i = 0; i < numOfDataPoints - 1; i++) { final boolean nextIsBigger = intensityBuffer[i + 1] > intensityBuffer[i]; final boolean nextIsZero = intensityBuffer[i + 1] == 0f; final boolean currentIsZero = intensityBuffer[i] == 0f; if (currentIsZero) { continue; } rangeEnd = i; if (ascending && (!nextIsBigger)) { localMaximumIndex = i; ascending = false; continue; } if ((!ascending) && (nextIsBigger || nextIsZero)) { final int numOfPeakDataPoints = rangeEnd - rangeBeginning; if (numOfPeakDataPoints >= 4) { double calculatedMz = calculateExactMass(mzBuffer, intensityBuffer, rangeBeginning, localMaximumIndex, rangeEnd); float intensity = intensityBuffer[localMaximumIndex]; mzBuffer[newNumOfDataPoints] = calculatedMz; intensityBuffer[newNumOfDataPoints] = intensity; newNumOfDataPoints++; } ascending = true; rangeBeginning = i; } } newScan.setDataPoints(mzBuffer, intensityBuffer, newNumOfDataPoints); return newScan; }  @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); ExactMassCentroidingAlgorithm centroider = new ExactMassCentroidingAlgorithm(); 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(3.537E7f, intensityBuffer[basePeak], 1E5); Assert.assertEquals(281.24774060, mzBuffer[basePeak], 0.0000001); rawFile.dispose(); }