Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Fixed the manual peak picker in case no data point is found
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-pluskal committed Dec 9, 2016
1 parent ee772c1 commit 1a49049
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 72 deletions.
8 changes: 7 additions & 1 deletion src/main/java/net/sf/mzmine/datamodel/PeakListRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*/
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,109 +54,112 @@ class ManualPickerTask extends AbstractTask {
private Range<Double> 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<PeakListRow> 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<PeakListRow> 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);

}

Expand Down

0 comments on commit 1a49049

Please sign in to comment.