use of dulab.adap.datamodel.Chromatogram in project mzmine2 by mzmine.
the class ADAPInterface method peakToFeature.
@Nonnull
public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull Peak peak) {
NavigableMap<Double, Double> chromatogram = peak.getChromatogram();
double[] retTimes = new double[chromatogram.size()];
double[] intensities = new double[chromatogram.size()];
int index = 0;
for (Entry<Double, Double> e : chromatogram.entrySet()) {
retTimes[index] = e.getKey();
intensities[index] = e.getValue();
++index;
}
BetterPeak betterPeak = new BetterPeak(peak.getInfo().peakID, new Chromatogram(retTimes, intensities), peak.getInfo());
return peakToFeature(file, betterPeak);
}
use of dulab.adap.datamodel.Chromatogram in project mzmine2 by mzmine.
the class ADAP3DecompositionV2Utils method getPeaks.
/**
* Convert MZmine PeakList to a list of ADAP Peaks
*
* @param peakList MZmine PeakList object
* @return list of ADAP Peaks
*/
@Nonnull
public List<BetterPeak> getPeaks(@Nonnull final PeakList peakList) {
RawDataFile dataFile = peakList.getRawDataFile(0);
List<BetterPeak> peaks = new ArrayList<>();
for (PeakListRow row : peakList.getRows()) {
Feature peak = row.getBestPeak();
int[] scanNumbers = peak.getScanNumbers();
// Build chromatogram
double[] retTimes = new double[scanNumbers.length];
double[] intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; ++i) {
int scan = scanNumbers[i];
retTimes[i] = getRetTime(dataFile, scan);
DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
intensities[i] = dataPoint.getIntensity();
}
Chromatogram chromatogram = new Chromatogram(retTimes, intensities);
if (chromatogram.length <= 1)
continue;
// Fill out PeakInfo
PeakInfo info = new PeakInfo();
try {
// Note: info.peakID is the index of PeakListRow in PeakList.peakListRows (starts from 0)
// row.getID is row.myID (starts from 1)
info.peakID = row.getID() - 1;
double height = -Double.MIN_VALUE;
for (int scan : scanNumbers) {
DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint == null)
continue;
double intensity = dataPoint.getIntensity();
if (intensity > height) {
height = intensity;
info.peakIndex = scan;
}
}
info.leftApexIndex = scanNumbers[0];
info.rightApexIndex = scanNumbers[scanNumbers.length - 1];
info.retTime = peak.getRT();
info.mzValue = peak.getMZ();
info.intensity = peak.getHeight();
info.leftPeakIndex = info.leftApexIndex;
info.rightPeakIndex = info.rightApexIndex;
} catch (Exception e) {
log.info("Skipping " + row + ": " + e.getMessage());
continue;
}
BetterPeak betterPeak = new BetterPeak(row.getID(), chromatogram, info);
betterPeak.setParentId(peak.getParentChromatogramRowID());
peaks.add(betterPeak);
}
return peaks;
}
use of dulab.adap.datamodel.Chromatogram in project mzmine2 by mzmine.
the class ADAPInterface method peakToFeature.
@Nonnull
public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull BetterPeak peak) {
Chromatogram chromatogram = peak.chromatogram;
// Retrieve scan numbers
int representativeScan = 0;
int[] scanNumbers = new int[chromatogram.length];
int count = 0;
for (int num : file.getScanNumbers()) {
double retTime = file.getScan(num).getRetentionTime();
Double intensity = chromatogram.getIntensity(retTime, false);
if (intensity != null)
scanNumbers[count++] = num;
if (retTime == peak.getRetTime())
representativeScan = num;
}
// Calculate peak area
double area = 0.0;
for (int i = 1; i < chromatogram.length; ++i) {
double base = (chromatogram.xs[i] - chromatogram.xs[i - 1]) * 60d;
double height = 0.5 * (chromatogram.ys[i] + chromatogram.ys[i - 1]);
area += base * height;
}
// Create array of DataPoints
DataPoint[] dataPoints = new DataPoint[chromatogram.length];
count = 0;
for (double intensity : chromatogram.ys) dataPoints[count++] = new SimpleDataPoint(peak.getMZ(), intensity);
return new SimpleFeature(file, peak.getMZ(), peak.getRetTime(), peak.getIntensity(), area, scanNumbers, dataPoints, Feature.FeatureStatus.ESTIMATED, representativeScan, representativeScan, new int[] {}, Range.closed(peak.getFirstRetTime(), peak.getLastRetTime()), Range.closed(peak.getMZ() - 0.01, peak.getMZ() + 0.01), Range.closed(0.0, peak.getIntensity()));
}
Aggregations