use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class WaveletMassDetector method getMzPeaks.
/**
* This function searches for maximums from wavelet data points
*/
private DataPoint[] getMzPeaks(double noiseLevel, DataPoint[] originalDataPoints, DataPoint[] waveletDataPoints) {
TreeSet<DataPoint> mzPeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
Vector<DataPoint> rawDataPoints = new Vector<DataPoint>();
int peakMaxInd = 0;
int stopInd = waveletDataPoints.length - 1;
for (int ind = 0; ind <= stopInd; ind++) {
while ((ind <= stopInd) && (waveletDataPoints[ind].getIntensity() == 0)) {
ind++;
}
peakMaxInd = ind;
if (ind >= stopInd) {
break;
}
// While peak is on
while ((ind <= stopInd) && (waveletDataPoints[ind].getIntensity() > 0)) {
// Check if this is the maximum point of the peak
if (waveletDataPoints[ind].getIntensity() > waveletDataPoints[peakMaxInd].getIntensity()) {
peakMaxInd = ind;
}
rawDataPoints.add(originalDataPoints[ind]);
ind++;
}
if (ind >= stopInd) {
break;
}
rawDataPoints.add(originalDataPoints[ind]);
if (originalDataPoints[peakMaxInd].getIntensity() > noiseLevel) {
SimpleDataPoint peakDataPoint = new SimpleDataPoint(originalDataPoints[peakMaxInd].getMZ(), calcAproxIntensity(rawDataPoints));
mzPeaks.add(peakDataPoint);
}
rawDataPoints.clear();
}
return mzPeaks.toArray(new DataPoint[0]);
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class GridMassTask method addMaxDatumFromScans.
int addMaxDatumFromScans(SpotByProbes s, Chromatogram peak) {
int i, j;
int adds = 0;
for (i = s.minScan; i <= s.maxScan; i++) {
Datum[] di = roi[i];
if (di != null && di.length > 0) {
Datum max = new Datum(new SimpleDataPoint(0, -1), 0, new SimpleDataPoint(0, -1));
int idx = findFirstMass(s.minMZ, di);
for (j = idx; j < di.length && di[j].mz <= s.maxMZ; j++) {
Datum d = di[j];
if (d.spotId == s.spotId) {
if (d.intensity > max.intensity && d.mz >= s.minMZ && d.intensity > minimumHeight) {
max = d;
}
}
}
if (max.intensity > 0) {
adds++;
peak.addMzPeak(scans[i].getScanNumber(), new SimpleDataPoint(max.mzOriginal, max.intensityOriginal));
}
}
}
return adds;
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class TwoDDataSet method getCentroidedDataPointsInRTMZRange.
// Sets the private list to contain the rt values for each data point scan of scans that fall in
// the user
// range. returns an array of the data points but not the rt.
ArrayList getCentroidedDataPointsInRTMZRange(Range<Double> rtRange, Range<Double> mzRange) {
ArrayList<DataPoint> dataPointsInRanges = new ArrayList<DataPoint>();
ArrayList rtInRange = new ArrayList();
curMaxIntensity = 0.0;
double[] searchRetentionTimes = retentionTimes;
if (processedScans < totalScans) {
searchRetentionTimes = new double[processedScans];
System.arraycopy(retentionTimes, 0, searchRetentionTimes, 0, searchRetentionTimes.length);
}
// Find the rt of the scan at the bottom of our rtRange
int startScanIndex = Arrays.binarySearch(searchRetentionTimes, rtRange.lowerEndpoint());
// a couple of checks
if (startScanIndex < 0) {
startScanIndex = (startScanIndex * -1) - 1;
}
if (startScanIndex >= searchRetentionTimes.length) {
startScanIndex = 0;
}
for (int scanIndex = startScanIndex; ((scanIndex < searchRetentionTimes.length) && (searchRetentionTimes[scanIndex] <= rtRange.upperEndpoint())); scanIndex++) {
// get the list of data points
DataPoint[] dataPoints = dataPointMatrix[scanIndex].get();
// Binary search for the mz values in the range you want
DataPoint searchMZ = new SimpleDataPoint(mzRange.lowerEndpoint(), 0);
int startMZIndex = Arrays.binarySearch(dataPoints, searchMZ, new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
if (startMZIndex < 0)
startMZIndex = (startMZIndex * -1) - 1;
if (startMZIndex >= dataPoints.length)
startMZIndex = 0;
for (int mzIndex = startMZIndex; ((mzIndex < dataPoints.length) && (dataPoints[mzIndex].getMZ() <= mzRange.upperEndpoint())); mzIndex++) {
DataPoint curFoundDataPoint;
curFoundDataPoint = dataPoints[mzIndex];
// System.out.println("curFoundDataPoint.getMZ()");
// System.out.println(curFoundDataPoint.getMZ());
dataPointsInRanges.add(curFoundDataPoint);
Double toAddRt = new Double(searchRetentionTimes[scanIndex]);
rtInRange.add(toAddRt);
double curIntensity = curFoundDataPoint.getIntensity();
if (curIntensity > curMaxIntensity)
curMaxIntensity = curIntensity;
}
}
rtValuesInUserRange = rtInRange;
return dataPointsInRanges;
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class TwoDDataSet method upperEndpointIntensity.
private double upperEndpointIntensity(DataPoint[] dataPoints, Range<Double> mzRange, PlotMode plotMode) {
double maxIntensity = 0;
DataPoint searchMZ = new SimpleDataPoint(mzRange.lowerEndpoint(), 0);
int startMZIndex = Arrays.binarySearch(dataPoints, searchMZ, new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
if (startMZIndex < 0)
startMZIndex = (startMZIndex * -1) - 1;
if (startMZIndex >= dataPoints.length)
return 0;
if (dataPoints[startMZIndex].getMZ() > mzRange.upperEndpoint()) {
if (plotMode != PlotMode.CENTROID) {
if (startMZIndex == 0)
return 0;
if (startMZIndex == dataPoints.length - 1)
return dataPoints[startMZIndex - 1].getIntensity();
// find which data point is closer
double diffNext = dataPoints[startMZIndex].getMZ() - mzRange.upperEndpoint();
double diffPrev = mzRange.lowerEndpoint() - dataPoints[startMZIndex - 1].getMZ();
if (diffPrev < diffNext)
return dataPoints[startMZIndex - 1].getIntensity();
else
return dataPoints[startMZIndex].getIntensity();
} else {
return 0;
}
}
for (int mzIndex = startMZIndex; ((mzIndex < dataPoints.length) && (dataPoints[mzIndex].getMZ() <= mzRange.upperEndpoint())); mzIndex++) {
if (dataPoints[mzIndex].getIntensity() > maxIntensity)
maxIntensity = dataPoints[mzIndex].getIntensity();
}
return maxIntensity;
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class PeakSummaryComponent method actionPerformed.
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("SHOW")) {
String visualizerType = (String) comboShow.getSelectedItem();
int[] indexesRow = peaksInfoList.getSelectedRows();
Feature[] selectedPeaks = new Feature[indexesRow.length];
RawDataFile[] dataFiles = new RawDataFile[indexesRow.length];
Range<Double> rtRange = null, mzRange = null;
for (int i = 0; i < indexesRow.length; i++) {
selectedPeaks[i] = listElementModel.getElementAt(indexesRow[i]);
dataFiles[i] = selectedPeaks[i].getDataFile();
if ((rtRange == null) || (mzRange == null)) {
rtRange = dataFiles[i].getDataRTRange(1);
mzRange = selectedPeaks[i].getRawDataPointsMZRange();
} else {
rtRange = rtRange.span(dataFiles[i].getDataRTRange(1));
mzRange = mzRange.span(selectedPeaks[i].getRawDataPointsMZRange());
}
}
if (dataFiles.length == 0) {
return;
}
if (visualizerType.equals("Chromatogram")) {
// Label best peak with preferred identity.
final Feature bestPeak = row.getBestPeak();
final PeakIdentity peakIdentity = row.getPreferredPeakIdentity();
final Map<Feature, String> labelMap = new HashMap<Feature, String>(1);
if (bestPeak != null && peakIdentity != null) {
labelMap.put(bestPeak, peakIdentity.getName());
}
ScanSelection scanSelection = new ScanSelection(rtRange, 1);
TICVisualizerModule.showNewTICVisualizerWindow(dataFiles, selectedPeaks, labelMap, scanSelection, TICPlotType.BASEPEAK, mzRange);
return;
} else if (visualizerType.equals("Mass spectrum")) {
for (int i = 0; i < selectedPeaks.length; ++i) {
final Feature peak = selectedPeaks[i];
final IsotopePattern ip = peak.getIsotopePattern();
if (ip != null) {
// ------------------------------
// Multiply isotope pattern by -1
// ------------------------------
DataPoint[] newDataPoints = Arrays.stream(ip.getDataPoints()).map(p -> new SimpleDataPoint(p.getMZ(), -p.getIntensity())).toArray(DataPoint[]::new);
// ---------------------------
// Construct identity spectrum
// ---------------------------
List<DataPoint> identityDataPoints = new ArrayList<>();
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity != null) {
String spectrum = identity.getPropertyValue(PeakIdentity.PROPERTY_SPECTRUM);
if (spectrum != null && spectrum.length() > 2) {
spectrum = spectrum.substring(1, spectrum.length() - 1);
for (String strPair : spectrum.split(",")) {
String[] pair = strPair.split("=", 2);
if (pair.length == 2)
identityDataPoints.add(new SimpleDataPoint(Double.parseDouble(pair[0]), Double.parseDouble(pair[1])));
}
}
}
if (// Plot raw spectrum and isotope pattern
identityDataPoints.isEmpty())
SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, null, null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
else
// Plot raw spectrum, isotope pattern, and identity spectrum
SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, new SimpleIsotopePattern(identityDataPoints.toArray(new DataPoint[identityDataPoints.size()]), IsotopePatternStatus.DETECTED, identity.getPropertyValue(PeakIdentity.PROPERTY_FORMULA)), null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
} else
// Plot raw spectrum without isotope pattern
SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber());
}
} else if (visualizerType.equals("Peak in 2D")) {
for (int i = 0; i < selectedPeaks.length; i++) {
Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
TwoDVisualizerModule.show2DVisualizerSetupDialog(dataFiles[i], localMZRange, localRTRange);
}
} else if (visualizerType.equals("Peak in 3D")) {
for (int i = 0; i < selectedPeaks.length; i++) {
Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
Fx3DVisualizerModule.setupNew3DVisualizer(dataFiles[i], localMZRange, localRTRange);
}
} else if (visualizerType.equals("MS/MS")) {
for (int i = 0; i < selectedPeaks.length; i++) {
int scanNumber = selectedPeaks[i].getMostIntenseFragmentScanNumber();
if (scanNumber > 0) {
SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], scanNumber);
} else {
JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
MZmineCore.getDesktop().displayMessage(frame, "There is no fragment for the mass " + MZmineCore.getConfiguration().getMZFormat().format(selectedPeaks[i].getMZ()) + "m/z in the current raw data.");
return;
}
}
} else if (visualizerType.equals("Isotope pattern")) {
for (int i = 0; i < selectedPeaks.length; i++) {
IsotopePattern ip = selectedPeaks[i].getIsotopePattern();
if (ip == null) {
return;
}
SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], selectedPeaks[i].getMostIntenseFragmentScanNumber(), ip);
}
}
return;
}
if (command.equals("CHANGE")) {
int indexRow = peaksInfoList.getSelectedRow();
if (indexRow == -1) {
return;
}
Feature selectedPeak = listElementModel.getElementAt(indexRow);
ManualPeakPickerModule.runManualDetection(selectedPeak.getDataFile(), row, null, null);
return;
}
}
Aggregations