ADAP3DFeatureDetectionMethod implements MSDKMethod<List<Feature>> { public List<Feature> execute() { logger.info("Starting ADAP3D feature detection on file " + rawFile.getName()); logger.debug("Loading the raw data into SliceSparceMatrix"); this.objSliceSparseMatrix = new SliceSparseMatrix(rawFile, msScanPredicate); logger.debug("Estimating FWHM values across all scans"); CurveTool objCurveTool = new CurveTool(objSliceSparseMatrix); double fwhm = objCurveTool.estimateFwhmMs(); int roundedFWHM = objSliceSparseMatrix.roundMZ(fwhm); logger.debug("Detecting 20 highest peaks to determine optimal parameters"); objPeakDetection = new ADAP3DPeakDetectionAlgorithm(objSliceSparseMatrix); List<ADAP3DPeakDetectionAlgorithm.GoodPeakInfo> goodPeakList = objPeakDetection.execute(20, parameters, roundedFWHM); if (canceled) return finalFeatureList; logger.debug("Converting 20 highest peaks to MSDK features"); convertPeaksToFeatures(goodPeakList, finalFeatureList); logger.debug("Estimating optimal parameters"); double[] peakWidth = new double[goodPeakList.size()]; double avgCoefOverArea = 0.0; double avgPeakWidth = 0.0; for (int i = 0; i < goodPeakList.size(); i++) { peakWidth[i] = objSliceSparseMatrix.getRetentionTime(goodPeakList.get(i).upperScanBound) / 60 - objSliceSparseMatrix.getRetentionTime(goodPeakList.get(i).lowerScanBound) / 60; avgPeakWidth += peakWidth[i]; avgCoefOverArea += goodPeakList.get(i).objResult.coefOverArea; } avgPeakWidth = avgPeakWidth / goodPeakList.size(); avgCoefOverArea = avgCoefOverArea / goodPeakList.size(); int highestWaveletScale = (int) (avgPeakWidth * 60 / 2); double coefOverAreaThreshold = avgCoefOverArea / 1.5; List<Double> peakWidthList = Arrays.asList(ArrayUtils.toObject(peakWidth)); double peakDurationLowerBound = avgPeakWidth - LOW_BOUND_PEAK_WIDTH_PERCENT * avgPeakWidth; double peakDurationUpperBound = Collections.max(peakWidthList) + LOW_BOUND_PEAK_WIDTH_PERCENT * avgPeakWidth; parameters.setLargeScaleIn(highestWaveletScale); parameters.setMinPeakWidth(peakDurationLowerBound); parameters.setMaxPeakWidth(peakDurationUpperBound); parameters.setCoefAreaRatioTolerance(coefOverAreaThreshold); logger.debug("Running ADAP3D using optimized parameters"); List<ADAP3DPeakDetectionAlgorithm.GoodPeakInfo> newGoodPeakList = objPeakDetection.execute(parameters, roundedFWHM); if (canceled) return null; logger.debug("Converting all peaks to MSDK features"); convertPeaksToFeatures(newGoodPeakList, finalFeatureList); logger.info("Finished ADAP3D feature detection on file " + rawFile.getName()); return finalFeatureList; } ADAP3DFeatureDetectionMethod(@Nonnull RawDataFile rawFile);  ADAP3DFeatureDetectionMethod(@Nonnull RawDataFile rawFile,
                                      @Nullable Predicate<MsScan> msScanPredicate);  ADAP3DFeatureDetectionMethod(@Nonnull RawDataFile rawFile,
                                      @Nonnull ADAP3DFeatureDetectionParameters params);  ADAP3DFeatureDetectionMethod(@Nonnull RawDataFile rawFile,
                                      @Nullable Predicate<MsScan> msScanPredicate,
                                      @Nonnull ADAP3DFeatureDetectionParameters parameters); List<Feature> execute(); @Override Float getFinishedPercentage(); @Override List<Feature> getResult(); @Override void cancel();  }
@Test @Ignore("Temporarily ignored, until ADAP3D work is resumed") public void testPeakDetection() throws MSDKException, IOException { ADAP3DFeatureDetectionMethod ob = new ADAP3DFeatureDetectionMethod(rawFile, new ADAP3DFeatureDetectionParameters()); List<Feature> featureList = ob.execute(); Assert.assertNotNull(featureList); Path path = getResourcePath("output.csv"); File inputFile = path.toFile(); BufferedReader reader = new BufferedReader(new FileReader(inputFile)); String line = null; int index = 0; while ((line = reader.readLine()) != null) { String[] values = line.split(","); Feature feature = featureList.get(index); float[] retentionTimeArray = feature.getChromatogram().getRetentionTimes(); Assert.assertEquals((double) Double.parseDouble(values[0]), (double) feature.getMz(), 0.1); Assert.assertEquals((double) Double.parseDouble(values[1]), (double) retentionTimeArray[0], 0.1); Assert.assertEquals((double) Double.parseDouble(values[2]), (double) retentionTimeArray[retentionTimeArray.length - 1], 0.1); Assert.assertEquals((double) Double.parseDouble(values[3]), (double) feature.getHeight(), 0.1); Assert.assertEquals((double) Double.parseDouble(values[4]), (double) feature.getRetentionTime(), 0.1); index++; } reader.close(); }