use of net.sf.mzmine.datamodel.DataPoint 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()]);
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class SavitzkyGolayPeakDetector 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;
}
// Calculate intensity statistics.
double maxIntensity = 0.0;
double avgIntensity = 0.0;
for (final double intensity : intensities) {
maxIntensity = Math.max(intensity, maxIntensity);
avgIntensity += intensity;
}
avgIntensity /= scanCount;
final List<Feature> resolvedPeaks = new ArrayList<Feature>(2);
// noise return an empty array.
if (avgIntensity <= maxIntensity / 2.0) {
// Calculate second derivatives of intensity values.
final double[] secondDerivative = SGDerivative.calculateDerivative(intensities, false, SG_FILTER_LEVEL);
// Calculate noise threshold.
final double noiseThreshold = calcDerivativeThreshold(secondDerivative, parameters.getParameter(DERIVATIVE_THRESHOLD_LEVEL).getValue());
// Search for peaks.
Arrays.sort(scanNumbers);
final Feature[] resolvedOriginalPeaks = peaksSearch(chromatogram, scanNumbers, secondDerivative, noiseThreshold, mzCenterFunction, msmsRange, rTRangeMSMS);
final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue();
final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue();
// parameters.
for (final Feature p : resolvedOriginalPeaks) {
if (peakDuration.contains(RangeUtils.rangeLength(p.getRawDataPointsRTRange())) && p.getHeight() >= minimumPeakHeight) {
resolvedPeaks.add(p);
}
}
}
return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]);
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class ResolvedPeak method getDataPoint.
/**
* This method returns a representative datapoint of this peak in a given scan
*/
@Override
public DataPoint getDataPoint(int scanNumber) {
int index = Arrays.binarySearch(scanNumbers, scanNumber);
if (index < 0)
return null;
SimpleDataPoint dp = new SimpleDataPoint(dataPointMZValues[index], dataPointIntensityValues[index]);
return dp;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class SpectraVisualizerWindow method loadRawData.
public void loadRawData(Scan scan) {
logger.finest("Loading scan #" + scan.getScanNumber() + " from " + dataFile + " for spectra visualizer");
spectrumDataSet = new ScanDataSet(scan);
this.currentScan = scan;
// If the plot mode has not been set yet, set it accordingly
if (spectrumPlot.getPlotMode() == null) {
spectrumPlot.setPlotMode(currentScan.getSpectrumType());
toolBar.setCentroidButton(currentScan.getSpectrumType());
}
// Clean up the MS/MS selector combo
final JComboBox<String> msmsSelector = bottomPanel.getMSMSSelector();
// We disable the MSMS selector first and then enable it again later
// after updating the items. If we skip this, the size of the
// selector may not be adjusted properly (timing issues?)
msmsSelector.setEnabled(false);
msmsSelector.removeAllItems();
boolean msmsVisible = false;
// Add parent scan to MS/MS selector combo
NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
// Add all fragment scans to MS/MS selector combo
int[] fragmentScans = currentScan.getFragmentScanNumbers();
if (fragmentScans != null) {
for (int fragment : fragmentScans) {
Scan fragmentScan = dataFile.getScan(fragment);
if (fragmentScan == null)
continue;
final String itemText = "Fragment scan #" + fragment + ", RT: " + rtFormat.format(fragmentScan.getRetentionTime()) + ", precursor m/z: " + mzFormat.format(fragmentScan.getPrecursorMZ());
// Updating the combo in other than Swing thread may cause
// exception
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
msmsSelector.addItem(itemText);
}
});
msmsVisible = true;
}
}
msmsSelector.setEnabled(true);
// Update the visibility of MS/MS selection combo
bottomPanel.setMSMSSelectorVisible(msmsVisible);
// Set window and plot titles
String windowTitle = "Spectrum: [" + dataFile.getName() + "; scan #" + currentScan.getScanNumber() + "]";
String spectrumTitle = ScanUtils.scanToString(currentScan, true);
DataPoint basePeak = currentScan.getHighestDataPoint();
if (basePeak != null) {
spectrumTitle += ", base peak: " + mzFormat.format(basePeak.getMZ()) + " m/z (" + intensityFormat.format(basePeak.getIntensity()) + ")";
}
String spectrumSubtitle = null;
if (!Strings.isNullOrEmpty(currentScan.getScanDefinition())) {
spectrumSubtitle = "Scan definition: " + currentScan.getScanDefinition();
}
setTitle(windowTitle);
spectrumPlot.setTitle(spectrumTitle, spectrumSubtitle);
// Set plot data set
spectrumPlot.removeAllDataSets();
spectrumPlot.addDataSet(spectrumDataSet, scanColor, false);
// Reload feature list
bottomPanel.rebuildPeakListSelector();
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class SpectrumChartFactory method createMSMSDataSet.
public static PseudoSpectrumDataSet createMSMSDataSet(double precursorMZ, double rt, DataPoint[] dps, String label) {
NumberFormat mzForm = MZmineCore.getConfiguration().getMZFormat();
NumberFormat rtForm = MZmineCore.getConfiguration().getRTFormat();
if (label == null)
label = "";
else if (!label.isEmpty())
label = " (" + label + ")";
// data
PseudoSpectrumDataSet series = new PseudoSpectrumDataSet(true, MessageFormat.format("MSMS for m/z={0} RT={1}{2}", mzForm.format(precursorMZ), rtForm.format(rt), label));
// for each row
for (DataPoint dp : dps) {
series.addDP(dp.getMZ(), dp.getIntensity(), null);
}
return series;
}
Aggregations