Search in sources :

Example 1 with BetterPeak

use of dulab.adap.datamodel.BetterPeak in project mzmine2 by mzmine.

the class ADAP3DecompositionV2SetupDialog method shapeCluster.

/**
 * Cluster list of PeakInfo based on the chromatographic shapes
 */
private void shapeCluster() {
    ChromatogramPeakPair chromatogramPeakPair = cboPeakLists.getItemAt(cboPeakLists.getSelectedIndex());
    if (chromatogramPeakPair == null)
        return;
    PeakList chromatogramList = chromatogramPeakPair.chromatograms;
    PeakList peakList = chromatogramPeakPair.peaks;
    if (chromatogramList == null || peakList == null)
        return;
    final RetTimeClusterer.Cluster cluster = cboClusters.getItemAt(cboClusters.getSelectedIndex());
    if (cluster == null)
        return;
    Double retTimeTolerance = parameterSet.getParameter(ADAP3DecompositionV2Parameters.RET_TIME_TOLERANCE).getValue();
    Boolean adjustApexRetTime = parameterSet.getParameter(ADAP3DecompositionV2Parameters.ADJUST_APEX_RET_TIME).getValue();
    Integer minClusterSize = parameterSet.getParameter(ADAP3DecompositionV2Parameters.MIN_CLUSTER_SIZE).getValue();
    if (retTimeTolerance == null || retTimeTolerance <= 0.0 || adjustApexRetTime == null || minClusterSize == null || minClusterSize <= 0)
        return;
    List<BetterPeak> chromatograms = new ADAP3DecompositionV2Utils().getPeaks(chromatogramList);
    List<BetterComponent> components = null;
    try {
        components = new ComponentSelector().execute(chromatograms, cluster, retTimeTolerance, adjustApexRetTime, minClusterSize);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (components != null)
        // chromatograms
        retTimeIntensityPlot.updateData(chromatograms, components);
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) ComponentSelector(dulab.adap.workflow.decomposition.ComponentSelector) BetterComponent(dulab.adap.datamodel.BetterComponent) RetTimeClusterer(dulab.adap.workflow.decomposition.RetTimeClusterer) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 2 with BetterPeak

use of dulab.adap.datamodel.BetterPeak 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);
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) Chromatogram(dulab.adap.datamodel.Chromatogram) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nonnull(javax.annotation.Nonnull)

Example 3 with BetterPeak

use of dulab.adap.datamodel.BetterPeak in project mzmine2 by mzmine.

the class ADAP3DecompositionV2SetupDialog method retTimeCluster.

/**
 * Cluster all peaks in PeakList based on retention time
 */
private void retTimeCluster() {
    ChromatogramPeakPair chromatogramPeakPair = cboPeakLists.getItemAt(cboPeakLists.getSelectedIndex());
    if (chromatogramPeakPair == null)
        return;
    PeakList chromatogramList = chromatogramPeakPair.chromatograms;
    PeakList peakList = chromatogramPeakPair.peaks;
    if (chromatogramList == null || peakList == null)
        return;
    Double minDistance = parameterSet.getParameter(ADAP3DecompositionV2Parameters.PREF_WINDOW_WIDTH).getValue();
    if (minDistance == null || minDistance <= 0.0)
        return;
    // Convert peakList into ranges
    List<RetTimeClusterer.Interval> ranges = Arrays.stream(peakList.getRows()).map(PeakListRow::getBestPeak).map(p -> new RetTimeClusterer.Interval(p.getRawDataPointsRTRange(), p.getMZ())).collect(Collectors.toList());
    List<BetterPeak> peaks = new ADAP3DecompositionV2Utils().getPeaks(peakList);
    // Form clusters of ranges
    List<RetTimeClusterer.Cluster> retTimeClusters = new RetTimeClusterer(minDistance).execute(peaks);
    cboClusters.removeAllItems();
    cboClusters.removeActionListener(this);
    for (RetTimeClusterer.Cluster cluster : retTimeClusters) {
        int i;
        for (i = 0; i < cboClusters.getItemCount(); ++i) {
            double retTime = cboClusters.getItemAt(i).retTime;
            if (cluster.retTime < retTime) {
                cboClusters.insertItemAt(cluster, i);
                break;
            }
        }
        if (i == cboClusters.getItemCount())
            cboClusters.addItem(cluster);
    }
    cboClusters.addActionListener(this);
    retTimeMZPlot.updateData(retTimeClusters);
    shapeCluster();
}
Also used : RetTimeClusterer(dulab.adap.workflow.decomposition.RetTimeClusterer) java.util(java.util) MZmineCore(net.sf.mzmine.main.MZmineCore) Parameter(net.sf.mzmine.parameters.Parameter) BetterComponent(dulab.adap.datamodel.BetterComponent) GUIUtils(net.sf.mzmine.util.GUIUtils) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) PeakList(net.sf.mzmine.datamodel.PeakList) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) java.awt(java.awt) List(java.util.List) ComponentSelector(dulab.adap.workflow.decomposition.ComponentSelector) ParameterSet(net.sf.mzmine.parameters.ParameterSet) BetterPeak(dulab.adap.datamodel.BetterPeak) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) Nonnull(javax.annotation.Nonnull) javax.swing(javax.swing) BetterPeak(dulab.adap.datamodel.BetterPeak) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RetTimeClusterer(dulab.adap.workflow.decomposition.RetTimeClusterer) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 4 with BetterPeak

use of dulab.adap.datamodel.BetterPeak 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;
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) ArrayList(java.util.ArrayList) Chromatogram(dulab.adap.datamodel.Chromatogram) PeakInfo(dulab.adap.datamodel.PeakInfo) Nonnull(javax.annotation.Nonnull)

Example 5 with BetterPeak

use of dulab.adap.datamodel.BetterPeak in project mzmine2 by mzmine.

the class EICPlot method updateData.

// public void updateData(@Nonnull List <List <NavigableMap <Double, Double>>> clusters,
// @Nonnull List <Double> colors,
// @Nonnull List <List <String>> info,
// @Nonnull List <List<Boolean>> models)
// {
// final float DEFAULT_LINE_WIDTH = 1.0f;
// final float THICK_LINE_WIDTH = 2.0f;
// 
// 
// // for (int i = 0; i < xyDataset.getSeriesCount(); ++i)
// // xyDataset.removeSeries(i);
// xyDataset.removeAllSeries();
// colorDataset.clear();
// toolTips.clear();
// widths.clear();
// 
// int seriesID = 0;
// 
// for (int i = 0; i < clusters.size(); ++i)
// {
// List <NavigableMap <Double, Double>> cluster = clusters.get(i);
// double color = colors.get(i);
// 
// for (int j = 0; j < cluster.size(); ++j)
// {
// XYSeries series = new XYSeries(seriesID++);
// 
// for (Entry <Double, Double> e : cluster.get(j).entrySet())
// series.add(e.getKey(), e.getValue());
// 
// float width = DEFAULT_LINE_WIDTH;
// if (models.get(i).get(j)) width = THICK_LINE_WIDTH;
// 
// xyDataset.addSeries(series);
// colorDataset.add(color);
// toolTips.add(info.get(i).get(j));
// widths.add(width);
// }
// }
// }
void updateData(@Nonnull List<BetterPeak> peaks, @Nonnull List<BetterComponent> modelPeaks) {
    xyDataset.removeAllSeries();
    xyDataset.setNotify(false);
    toolTips.clear();
    // Find retention-time range
    double startRetTime = Double.MAX_VALUE;
    double endRetTime = -Double.MAX_VALUE;
    for (BetterPeak peak : modelPeaks) {
        if (peak.getFirstRetTime() < startRetTime)
            startRetTime = peak.getFirstRetTime();
        if (peak.getLastRetTime() > endRetTime)
            endRetTime = peak.getLastRetTime();
    }
    if (endRetTime < startRetTime)
        return;
    int seriesID = 0;
    for (BetterPeak peak : peaks) {
        XYSeries series = new XYSeries(seriesID++);
        series.setDescription(PeakType.SIMPLE.name());
        for (int i = 0; i < peak.chromatogram.length; ++i) {
            double retTime = peak.chromatogram.getRetTime(i);
            if (startRetTime <= retTime && retTime <= endRetTime)
                series.add(peak.chromatogram.getRetTime(i), peak.chromatogram.getIntensity(i));
        }
        xyDataset.addSeries(series);
        toolTips.add(String.format("M/z: %.2f\nIntensity: %.0f", peak.getMZ(), peak.getIntensity()));
    }
    for (BetterPeak peak : modelPeaks) {
        XYSeries series = new XYSeries((seriesID++));
        series.setDescription(PeakType.MODEL.name());
        for (int i = 0; i < peak.chromatogram.length; ++i) series.add(peak.chromatogram.getRetTime(i), peak.chromatogram.getIntensity(i));
        xyDataset.addSeries(series);
        toolTips.add(String.format("Model peak\nM/z: %.2f\nIntensity: %.0f", peak.getMZ(), peak.getIntensity()));
    }
    xyDataset.setNotify(true);
}
Also used : BetterPeak(dulab.adap.datamodel.BetterPeak) XYSeries(org.jfree.data.xy.XYSeries) Paint(java.awt.Paint)

Aggregations

BetterPeak (dulab.adap.datamodel.BetterPeak)6 RetTimeClusterer (dulab.adap.workflow.decomposition.RetTimeClusterer)3 Nonnull (javax.annotation.Nonnull)3 BetterComponent (dulab.adap.datamodel.BetterComponent)2 Chromatogram (dulab.adap.datamodel.Chromatogram)2 ComponentSelector (dulab.adap.workflow.decomposition.ComponentSelector)2 PeakList (net.sf.mzmine.datamodel.PeakList)2 XYSeries (org.jfree.data.xy.XYSeries)2 Sets (com.google.common.collect.Sets)1 PeakInfo (dulab.adap.datamodel.PeakInfo)1 java.awt (java.awt)1 Paint (java.awt.Paint)1 ActionEvent (java.awt.event.ActionEvent)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 javax.swing (javax.swing)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)1