use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ShapeModelerTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
Class<?> shapeModelClass = shapeModelerType.getModelClass();
Constructor<?> shapeModelConstruct;
shapeModelConstruct = shapeModelClass.getConstructors()[0];
// Get data file information
RawDataFile dataFile = originalPeakList.getRawDataFile(0);
// Create new feature list
newPeakList = new SimplePeakList(originalPeakList + " " + suffix, dataFile);
totalRows = originalPeakList.getNumberOfRows();
int[] scanNumbers;
double[] retentionTimes, intensities;
SimplePeakListRow newRow;
for (PeakListRow row : originalPeakList.getRows()) {
if (isCanceled())
return;
newRow = new SimplePeakListRow(newPeakID);
try {
for (Feature peak : row.getPeaks()) {
// Load the intensities into array
dataFile = peak.getDataFile();
scanNumbers = peak.getScanNumbers();
retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = peak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(peak, scanNumbers, intensities, retentionTimes, resolution);
newRow.addPeak(shapePeak.getDataFile(), shapePeak);
}
} catch (Exception e) {
String message = "Error trying to make an instance of shape model class " + shapeModelClass;
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), message);
logger.severe(message);
return;
}
newPeakList.addRow(newRow);
newPeakID++;
processedRows++;
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
// Remove the original peaklist if requested
if (removeOriginal)
project.removePeakList(originalPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks shaped by " + shapeModelerType + " function", parameters));
logger.finest("Finished peak shape modeler " + processedRows + " rows processed");
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class PeakExtenderTask method getExtendedPeak.
private Feature getExtendedPeak(Feature oldPeak) {
double maxHeight = oldPeak.getHeight();
int originScanNumber = oldPeak.getRepresentativeScanNumber();
RawDataFile rawFile = oldPeak.getDataFile();
ExtendedPeak newPeak = new ExtendedPeak(rawFile);
int totalScanNumber = rawFile.getNumOfScans();
Range<Double> mzRange = mzTolerance.getToleranceRange(oldPeak.getMZ());
Scan scan;
DataPoint dataPoint;
// Look for dataPoint related to this peak to the left
int scanNumber = originScanNumber;
scanNumber--;
while (scanNumber > 0) {
scan = rawFile.getScan(scanNumber);
if (scan == null) {
scanNumber--;
continue;
}
if (scan.getMSLevel() != 1) {
scanNumber--;
continue;
}
dataPoint = ScanUtils.findBasePeak(scan, mzRange);
if (dataPoint == null)
break;
if (dataPoint.getIntensity() < minimumHeight)
break;
newPeak.addMzPeak(scanNumber, dataPoint);
if (dataPoint.getIntensity() > maxHeight)
maxHeight = dataPoint.getIntensity();
scanNumber--;
}
// Add original dataPoint
newPeak.addMzPeak(originScanNumber, oldPeak.getDataPoint(originScanNumber));
// Look to the right
scanNumber = originScanNumber;
scanNumber++;
while (scanNumber <= totalScanNumber) {
scan = rawFile.getScan(scanNumber);
if (scan == null) {
scanNumber++;
continue;
}
if (scan.getMSLevel() != 1) {
scanNumber++;
continue;
}
dataPoint = ScanUtils.findBasePeak(scan, mzRange);
if (dataPoint == null)
break;
if (dataPoint.getIntensity() < minimumHeight)
break;
newPeak.addMzPeak(scanNumber, dataPoint);
if (dataPoint.getIntensity() > maxHeight)
maxHeight = dataPoint.getIntensity();
scanNumber++;
}
newPeak.finishExtendedPeak();
newPeak.setMostIntenseFragmentScanNumber(oldPeak.getMostIntenseFragmentScanNumber());
int[] scanNumbers = newPeak.getScanNumbers();
logger.finest("Extended peak original " + originScanNumber + " from " + scanNumbers[0] + " - " + scanNumbers[scanNumbers.length - 1] + " height " + maxHeight);
return newPeak;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class PeakExtenderTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running peak extender on " + peakList);
// We assume source peakList contains one datafile
RawDataFile dataFile = peakList.getRawDataFile(0);
// Create a new deisotoped peakList
extendedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
// Sort peaks by descending height
Feature[] sortedPeaks = peakList.getPeaks(dataFile);
Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
// Loop through all peaks
totalPeaks = sortedPeaks.length;
Feature oldPeak;
for (int ind = 0; ind < totalPeaks; ind++) {
if (isCanceled())
return;
oldPeak = sortedPeaks[ind];
if (oldPeak.getHeight() >= minimumHeight) {
Feature newPeak = this.getExtendedPeak(oldPeak);
// Get previous pekaListRow
PeakListRow oldRow = peakList.getPeakRow(oldPeak);
// keep old ID
int oldID = oldRow.getID();
SimplePeakListRow newRow = new SimplePeakListRow(oldID);
PeakUtils.copyPeakListRowProperties(oldRow, newRow);
newRow.addPeak(dataFile, newPeak);
extendedPeakList.addRow(newRow);
}
// Update completion rate
processedPeaks++;
}
// Add new peakList to the project
project.addPeakList(extendedPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(extendedPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
extendedPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
extendedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak extender", parameters));
// Remove the original peakList if requested
if (removeOriginal)
project.removePeakList(peakList);
logger.info("Finished peak extender on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ShapeModelerSetupDialog method loadPreviewPeak.
private void loadPreviewPeak() {
PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
if (previewRow == null)
return;
logger.finest("Loading new preview peak " + previewRow);
Feature previewPeak = previewRow.getPeaks()[0];
ticPlot.removeAllTICDataSets();
// Load the intensities into array
RawDataFile dataFile = previewPeak.getDataFile();
int[] scanNumbers = previewPeak.getScanNumbers();
double[] retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
double[] intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
// Create shape model
updateParameterSetFromComponents();
JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType);
ShapeModel model = (ShapeModel) component.getSelectedItem();
JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution);
double resolution = ((Number) resolutionField.getValue()).doubleValue();
try {
Class<?> shapeModelClass = model.getModelClass();
Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0];
// shapePeakModel(ChromatographicPeak originalDetectedShape, int[]
// scanNumbers,
// double[] intensities, double[] retentionTimes, double resolution)
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution);
PeakDataSet peakDataSet = new PeakDataSet(shapePeak);
ticPlot.addPeakDataset(peakDataSet);
ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]);
ticPlot.addTICDataset(ticDataset);
// Set auto range to axes
ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
} catch (Exception e) {
String message = "Error trying to make an instance of Peak Builder " + model;
MZmineCore.getDesktop().displayErrorMessage(this, message);
logger.severe(message);
e.printStackTrace();
return;
}
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class MinimumSearchPeakDetector method resolvePeaks.
@Override
public ResolvedPeak[] resolvePeaks(final Feature chromatogram, ParameterSet parameters, RSessionWrapper rSession, CenterFunction mzCenterFunction, double msmsRange, double rTRangeMSMS) {
int[] scanNumbers = chromatogram.getScanNumbers();
final int scanCount = scanNumbers.length;
double[] retentionTimes = new double[scanCount];
double[] intensities = new double[scanCount];
RawDataFile dataFile = chromatogram.getDataFile();
for (int i = 0; i < scanCount; i++) {
final int scanNum = scanNumbers[i];
retentionTimes[i] = dataFile.getScan(scanNum).getRetentionTime();
DataPoint dp = chromatogram.getDataPoint(scanNum);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0.0;
}
final int lastScan = scanCount - 1;
assert scanCount > 0;
final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
final double searchRTRange = parameters.getParameter(SEARCH_RT_RANGE).getValue();
final double minRatio = parameters.getParameter(MIN_RATIO).getValue();
final double minHeight = Math.max(parameters.getParameter(MIN_ABSOLUTE_HEIGHT).getValue(), parameters.getParameter(MIN_RELATIVE_HEIGHT).getValue() * chromatogram.getHeight());
final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>();
// First, remove all data points below chromatographic threshold.
final double chromatographicThresholdLevel = MathUtils.calcQuantile(intensities, parameters.getParameter(CHROMATOGRAPHIC_THRESHOLD_LEVEL).getValue());
for (int i = 0; i < intensities.length; i++) {
if (intensities[i] < chromatographicThresholdLevel) {
intensities[i] = 0.0;
}
}
// candidate for a resolved peak.
startSearch: for (int currentRegionStart = 0; currentRegionStart < lastScan - 2; currentRegionStart++) {
// Find at least two consecutive non-zero data points
if (intensities[currentRegionStart] == 0.0 || intensities[currentRegionStart + 1] == 0.0)
continue;
double currentRegionHeight = intensities[currentRegionStart];
endSearch: for (int currentRegionEnd = currentRegionStart + 1; currentRegionEnd < scanCount; currentRegionEnd++) {
// Update height of current region.
currentRegionHeight = Math.max(currentRegionHeight, intensities[currentRegionEnd]);
// have to stop here.
if (currentRegionEnd == lastScan || intensities[currentRegionEnd + 1] == 0.0) {
// Find the intensity at the sides (lowest data points).
final double peakMinLeft = intensities[currentRegionStart];
final double peakMinRight = intensities[currentRegionEnd];
// Check the shape of the peak.
if (currentRegionHeight >= minHeight && currentRegionHeight >= peakMinLeft * minRatio && currentRegionHeight >= peakMinRight * minRatio && peakDuration.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart])) {
resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd, mzCenterFunction, msmsRange, rTRangeMSMS));
}
// Set the next region start to current region end - 1
// because it will be immediately
// increased +1 as we continue the for-cycle.
currentRegionStart = currentRegionEnd - 1;
continue startSearch;
}
// Minimum duration of peak must be at least searchRTRange.
if (retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart] >= searchRTRange) {
// Set the RT range to check
final Range<Double> checkRange = Range.closed(retentionTimes[currentRegionEnd] - searchRTRange, retentionTimes[currentRegionEnd] + searchRTRange);
// current peak i.
for (int i = currentRegionEnd - 1; i > 0; i--) {
if (!checkRange.contains(retentionTimes[i]))
break;
if (intensities[i] < intensities[currentRegionEnd]) {
continue endSearch;
}
}
// Search on the right from current peak i.
for (int i = currentRegionEnd + 1; i < scanCount; i++) {
if (!checkRange.contains(retentionTimes[i]))
break;
if (intensities[i] < intensities[currentRegionEnd]) {
continue endSearch;
}
}
// Find the intensity at the sides (lowest data points).
final double peakMinLeft = intensities[currentRegionStart];
final double peakMinRight = intensities[currentRegionEnd];
// ratio condition, continue searching for next minimum.
if (currentRegionHeight >= peakMinRight * minRatio) {
// Check the shape of the peak.
if (currentRegionHeight >= minHeight && currentRegionHeight >= peakMinLeft * minRatio && currentRegionHeight >= peakMinRight * minRatio && peakDuration.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart])) {
resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd, mzCenterFunction, msmsRange, rTRangeMSMS));
}
// Set the next region start to current region end-1
// because it will be immediately
// increased +1 as we continue the for-cycle.
currentRegionStart = currentRegionEnd - 1;
continue startSearch;
}
}
}
}
return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
Aggregations