use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class SmoothingTask method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
try {
// Get filter weights.
final double[] filterWeights = SavitzkyGolayFilter.getNormalizedWeights(filterWidth);
// Create new feature list
newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
// Process each row.
for (final PeakListRow row : origPeakList.getRows()) {
if (!isCanceled()) {
// Create a new peak-list row.
final int originalID = row.getID();
final PeakListRow newRow = new SimplePeakListRow(originalID);
// Process each peak.
for (final Feature peak : row.getPeaks()) {
if (!isCanceled()) {
// Copy original peak intensities.
final int[] scanNumbers = peak.getScanNumbers();
final int numScans = scanNumbers.length;
final double[] intensities = new double[numScans];
for (int i = 0; i < numScans; i++) {
final DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
intensities[i] = dataPoint == null ? 0.0 : dataPoint.getIntensity();
}
// Smooth peak.
final double[] smoothed = convolve(intensities, filterWeights);
// Measure peak (max, ranges, area etc.)
final RawDataFile dataFile = peak.getDataFile();
final DataPoint[] newDataPoints = new DataPoint[numScans];
double maxIntensity = 0.0;
int maxScanNumber = -1;
DataPoint maxDataPoint = null;
Range<Double> intensityRange = null;
double area = 0.0;
for (int i = 0; i < numScans; i++) {
final int scanNumber = scanNumbers[i];
final DataPoint dataPoint = peak.getDataPoint(scanNumber);
final double intensity = smoothed[i];
if (dataPoint != null && intensity > 0.0) {
// Create a new data point.
final double mz = dataPoint.getMZ();
final double rt = dataFile.getScan(scanNumber).getRetentionTime();
final DataPoint newDataPoint = new SimpleDataPoint(mz, intensity);
newDataPoints[i] = newDataPoint;
// Track maximum intensity data point.
if (intensity > maxIntensity) {
maxIntensity = intensity;
maxScanNumber = scanNumber;
maxDataPoint = newDataPoint;
}
// Update ranges.
if (intensityRange == null) {
intensityRange = Range.singleton(intensity);
} else {
intensityRange = intensityRange.span(Range.singleton(intensity));
}
// Accumulate peak area.
if (i != 0) {
final DataPoint lastDP = newDataPoints[i - 1];
final double lastIntensity = lastDP == null ? 0.0 : lastDP.getIntensity();
final double lastRT = dataFile.getScan(scanNumbers[i - 1]).getRetentionTime();
area += (rt - lastRT) * 60d * (intensity + lastIntensity) / 2.0;
}
}
}
assert maxDataPoint != null;
if (!isCanceled() && maxScanNumber >= 0) {
// Create a new peak.
newRow.addPeak(dataFile, new SimpleFeature(dataFile, maxDataPoint.getMZ(), peak.getRT(), maxIntensity, area, scanNumbers, newDataPoints, peak.getFeatureStatus(), maxScanNumber, peak.getMostIntenseFragmentScanNumber(), peak.getAllMS2FragmentScanNumbers(), peak.getRawDataPointsRTRange(), peak.getRawDataPointsMZRange(), intensityRange));
}
}
}
newPeakList.addRow(newRow);
progress++;
}
}
// Finish up.
if (!isCanceled()) {
// Add new peak-list to the project.
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
// Remove the original peak-list if requested.
if (removeOriginal) {
project.removePeakList(origPeakList);
}
// Copy previously applied methods
for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to peak-list.
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks smoothed by Savitzky-Golay filter", parameters));
LOG.finest("Finished peak smoothing: " + progress + " rows processed");
setStatus(TaskStatus.FINISHED);
}
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Smoothing error", t);
setErrorMessage(t.getMessage());
setStatus(TaskStatus.ERROR);
}
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class DeconvolutionTask method resolvePeaks.
/**
* Deconvolve a chromatogram into separate peaks.
*
* @param peakList holds the chromatogram to deconvolve.
* @param mzCenterFunction2
* @return a new feature list holding the resolved peaks.
* @throws RSessionWrapperException
*/
private PeakList resolvePeaks(final PeakList peakList, RSessionWrapper rSession) throws RSessionWrapperException {
// Get data file information.
final RawDataFile dataFile = peakList.getRawDataFile(0);
// Peak resolver.
final MZmineProcessingStep<PeakResolver> resolver = parameters.getParameter(PEAK_RESOLVER).getValue();
// set msms pairing range
this.setMSMSRange = parameters.getParameter(mzRangeMSMS).getValue();
if (setMSMSRange)
this.msmsRange = parameters.getParameter(mzRangeMSMS).getEmbeddedParameter().getValue();
else
this.msmsRange = 0;
this.setMSMSRT = parameters.getParameter(RetentionTimeMSMS).getValue();
if (setMSMSRT)
this.RTRangeMSMS = parameters.getParameter(RetentionTimeMSMS).getEmbeddedParameter().getValue();
else
this.RTRangeMSMS = 0;
// Create new feature list.
final PeakList resolvedPeaks = new SimplePeakList(peakList + " " + parameters.getParameter(SUFFIX).getValue(), dataFile);
// Load previous applied methods.
for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
resolvedPeaks.addDescriptionOfAppliedTask(method);
}
// Add task description to feature list.
resolvedPeaks.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak deconvolution by " + resolver, resolver.getParameterSet()));
// Initialise counters.
processedRows = 0;
totalRows = peakList.getNumberOfRows();
int peakId = 1;
// Process each chromatogram.
final PeakListRow[] peakListRows = peakList.getRows();
final int chromatogramCount = peakListRows.length;
for (int index = 0; !isCanceled() && index < chromatogramCount; index++) {
final PeakListRow currentRow = peakListRows[index];
final Feature chromatogram = currentRow.getPeak(dataFile);
// Resolve peaks.
final PeakResolver resolverModule = resolver.getModule();
final ParameterSet resolverParams = resolver.getParameterSet();
final ResolvedPeak[] peaks = resolverModule.resolvePeaks(chromatogram, resolverParams, rSession, mzCenterFunction, msmsRange, RTRangeMSMS);
// Add peaks to the new feature list.
for (final ResolvedPeak peak : peaks) {
peak.setParentChromatogramRowID(currentRow.getID());
final PeakListRow newRow = new SimplePeakListRow(peakId++);
newRow.addPeak(dataFile, peak);
newRow.setPeakInformation(peak.getPeakInformation());
resolvedPeaks.addRow(newRow);
}
processedRows++;
}
return resolvedPeaks;
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class MsMsBottomPanel method getIntensityThresholdPeakList.
/**
* Returns a feature list with the peaks which intensity is above the parameter "intensity"
*/
PeakList getIntensityThresholdPeakList(double intensity) {
PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
if (selectedPeakList == null)
return null;
SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
for (PeakListRow peakRow : selectedPeakList.getRows()) {
Feature peak = peakRow.getPeak(dataFile);
if (peak == null)
continue;
if (peak.getRawDataPointsIntensityRange().upperEndpoint() > intensity) {
newList.addRow(peakRow);
}
}
return newList;
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class MsMsBottomPanel method getTopThresholdPeakList.
/**
* Returns a feature list with the top peaks defined by the parameter "threshold"
*/
PeakList getTopThresholdPeakList(int threshold) {
PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
if (selectedPeakList == null)
return null;
SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
Vector<PeakListRow> peakRows = new Vector<PeakListRow>();
Range<Double> mzRange = selectedPeakList.getRowsMZRange();
Range<Double> rtRange = selectedPeakList.getRowsRTRange();
PeakThresholdMode selectedPeakOption = (PeakThresholdMode) thresholdCombo.getSelectedItem();
if (selectedPeakOption == PeakThresholdMode.TOP_PEAKS_AREA) {
XYPlot xyPlot = masterFrame.getPlot().getXYPlot();
org.jfree.data.Range yAxis = xyPlot.getRangeAxis().getRange();
org.jfree.data.Range xAxis = xyPlot.getDomainAxis().getRange();
rtRange = Range.closed(xAxis.getLowerBound(), xAxis.getUpperBound());
mzRange = Range.closed(yAxis.getLowerBound(), yAxis.getUpperBound());
}
for (PeakListRow peakRow : selectedPeakList.getRows()) {
if (mzRange.contains(peakRow.getAverageMZ()) && rtRange.contains(peakRow.getAverageRT())) {
peakRows.add(peakRow);
}
}
Collections.sort(peakRows, new PeakListRowSorter(SortingProperty.Intensity, SortingDirection.Descending));
if (threshold > peakRows.size())
threshold = peakRows.size();
for (int i = 0; i < threshold; i++) {
newList.addRow(peakRows.elementAt(i));
}
return newList;
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class TwoDBottomPanel method getIntensityThresholdPeakList.
/**
* Returns a feature list with the peaks which intensity is above the parameter "intensity"
*/
PeakList getIntensityThresholdPeakList(double intensity) {
PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem();
if (selectedPeakList == null)
return null;
SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles());
for (PeakListRow peakRow : selectedPeakList.getRows()) {
Feature peak = peakRow.getPeak(dataFile);
if (peak == null)
continue;
if (peak.getRawDataPointsIntensityRange().upperEndpoint() > intensity) {
newList.addRow(peakRow);
}
}
return newList;
}
Aggregations