From 1a490492e5b5f447349130ef8dfb45485d72aa08 Mon Sep 17 00:00:00 2001 From: Tomas Pluskal Date: Fri, 9 Dec 2016 17:26:15 -0500 Subject: [PATCH] Fixed the manual peak picker in case no data point is found --- .../net/sf/mzmine/datamodel/PeakListRow.java | 8 +- .../peakpicking/manual/ManualPickerTask.java | 145 +++++++++--------- 2 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/main/java/net/sf/mzmine/datamodel/PeakListRow.java b/src/main/java/net/sf/mzmine/datamodel/PeakListRow.java index bcd9e16f1..b63d012fd 100644 --- a/src/main/java/net/sf/mzmine/datamodel/PeakListRow.java +++ b/src/main/java/net/sf/mzmine/datamodel/PeakListRow.java @@ -51,6 +51,11 @@ public interface PeakListRow { */ public void addPeak(RawDataFile rawData, Feature peak); + /** + * Remove a peak + */ + public void removePeak(RawDataFile file); + /** * Has a peak? */ @@ -77,7 +82,8 @@ public interface PeakListRow { public double getAverageHeight(); /** - * Returns the charge for peak on this row. If more charges are found 0 is returned + * Returns the charge for peak on this row. If more charges are found 0 is + * returned */ public int getRowCharge(); diff --git a/src/main/java/net/sf/mzmine/modules/rawdatamethods/peakpicking/manual/ManualPickerTask.java b/src/main/java/net/sf/mzmine/modules/rawdatamethods/peakpicking/manual/ManualPickerTask.java index ede419186..d703832be 100644 --- a/src/main/java/net/sf/mzmine/modules/rawdatamethods/peakpicking/manual/ManualPickerTask.java +++ b/src/main/java/net/sf/mzmine/modules/rawdatamethods/peakpicking/manual/ManualPickerTask.java @@ -54,109 +54,112 @@ class ManualPickerTask extends AbstractTask { private Range rtRange, mzRange; ManualPickerTask(MZmineProject project, PeakListRow peakListRow, - RawDataFile dataFiles[], ManualPickerParameters parameters, - PeakList peakList, PeakListTable table) { + RawDataFile dataFiles[], ManualPickerParameters parameters, + PeakList peakList, PeakListTable table) { - this.project = project; - this.peakListRow = peakListRow; - this.dataFiles = dataFiles; - this.peakList = peakList; - this.table = table; + this.project = project; + this.peakListRow = peakListRow; + this.dataFiles = dataFiles; + this.peakList = peakList; + this.table = table; - rtRange = parameters.getParameter( - ManualPickerParameters.retentionTimeRange).getValue(); - mzRange = parameters.getParameter(ManualPickerParameters.mzRange) - .getValue(); + rtRange = parameters + .getParameter(ManualPickerParameters.retentionTimeRange) + .getValue(); + mzRange = parameters.getParameter(ManualPickerParameters.mzRange) + .getValue(); } public double getFinishedPercentage() { - if (totalScans == 0) - return 0; - return (double) processedScans / totalScans; + if (totalScans == 0) + return 0; + return (double) processedScans / totalScans; } public String getTaskDescription() { - return "Manually picking peaks from " + Arrays.toString(dataFiles); + return "Manually picking peaks from " + Arrays.toString(dataFiles); } public void run() { - setStatus(TaskStatus.PROCESSING); + setStatus(TaskStatus.PROCESSING); - logger.finest("Starting manual peak picker, RT: " + rtRange + ", m/z: " - + mzRange); + logger.finest("Starting manual peak picker, RT: " + rtRange + ", m/z: " + + mzRange); - // Calculate total number of scans to process - for (RawDataFile dataFile : dataFiles) { - int[] scanNumbers = dataFile.getScanNumbers(1, rtRange); - totalScans += scanNumbers.length; - } + // Calculate total number of scans to process + for (RawDataFile dataFile : dataFiles) { + int[] scanNumbers = dataFile.getScanNumbers(1, rtRange); + totalScans += scanNumbers.length; + } - // Find peak in each data file - for (RawDataFile dataFile : dataFiles) { + // Find peak in each data file + for (RawDataFile dataFile : dataFiles) { - ManualPeak newPeak = new ManualPeak(dataFile); - boolean dataPointFound = false; + ManualPeak newPeak = new ManualPeak(dataFile); + boolean dataPointFound = false; - int[] scanNumbers = dataFile.getScanNumbers(1, rtRange); + int[] scanNumbers = dataFile.getScanNumbers(1, rtRange); - for (int scanNumber : scanNumbers) { + for (int scanNumber : scanNumbers) { - if (isCanceled()) - return; + if (isCanceled()) + return; - // Get next scan - Scan scan = dataFile.getScan(scanNumber); + // Get next scan + Scan scan = dataFile.getScan(scanNumber); - // Find most intense m/z peak - DataPoint basePeak = ScanUtils.findBasePeak(scan, mzRange); + // Find most intense m/z peak + DataPoint basePeak = ScanUtils.findBasePeak(scan, mzRange); - if (basePeak != null) { - if (basePeak.getIntensity() > 0) - dataPointFound = true; - newPeak.addDatapoint(scan.getScanNumber(), basePeak); - } else { - final double mzCenter = (mzRange.lowerEndpoint() + mzRange - .upperEndpoint()) / 2.0; - DataPoint fakeDataPoint = new SimpleDataPoint(mzCenter, 0); - newPeak.addDatapoint(scan.getScanNumber(), fakeDataPoint); - } + if (basePeak != null) { + if (basePeak.getIntensity() > 0) + dataPointFound = true; + newPeak.addDatapoint(scan.getScanNumber(), basePeak); + } else { + final double mzCenter = (mzRange.lowerEndpoint() + + mzRange.upperEndpoint()) / 2.0; + DataPoint fakeDataPoint = new SimpleDataPoint(mzCenter, 0); + newPeak.addDatapoint(scan.getScanNumber(), fakeDataPoint); + } - processedScans++; + processedScans++; - } + } - if (dataPointFound) { - newPeak.finalizePeak(); - if (newPeak.getArea() > 0) - peakListRow.addPeak(dataFile, newPeak); - } + if (dataPointFound) { + newPeak.finalizePeak(); + if (newPeak.getArea() > 0) + peakListRow.addPeak(dataFile, newPeak); + } else { + peakListRow.removePeak(dataFile); + } - } + } - // Notify the GUI that peaklist contents have changed - if (peakList != null) { - // Check if the peak list row has been added to the peak list, and - // if it has not, add it - List rows = Arrays.asList(peakList.getRows()); - if (!rows.contains(peakListRow)) { - peakList.addRow(peakListRow); - } + // Notify the GUI that peaklist contents have changed + if (peakList != null) { + // Check if the peak list row has been added to the peak list, and + // if it has not, add it + List rows = Arrays.asList(peakList.getRows()); + if (!rows.contains(peakListRow)) { + peakList.addRow(peakListRow); + } - // Add quality parameters to peaks - QualityParameters.calculateQualityParameters(peakList); + // Add quality parameters to peaks + QualityParameters.calculateQualityParameters(peakList); - project.notifyObjectChanged(peakList, true); - } - if (table != null) { - ((AbstractTableModel) table.getModel()).fireTableDataChanged(); - } + project.notifyObjectChanged(peakList, true); + } + if (table != null) { + ((AbstractTableModel) table.getModel()).fireTableDataChanged(); + } - logger.finest("Finished manual peak picker, " + processedScans - + " scans processed"); + logger.finest("Finished manual peak picker, " + processedScans + + " scans processed"); - setStatus(TaskStatus.FINISHED); + setStatus(TaskStatus.FINISHED); }