Search in sources :

Example 1 with Peak

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

the class ADAP3DecompositionV1_5SetupDialog method shapeCluster.

/**
 * Cluster list of PeakInfo based on the chromatographic shapes
 *
 * @param peaks list of ADAP peaks
 * @param outClusters output of clusters
 * @param outText output of tooltip text
 * @param outColors output of colors
 */
private void shapeCluster(List<Peak> peaks, List<List<NavigableMap<Double, Double>>> outClusters, List<List<String>> outText, List<Double> outColors) {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    Double edgeToHeightRatio = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.EDGE_TO_HEIGHT_RATIO).getValue();
    Double deltaToHeightRatio = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.DELTA_TO_HEIGHT_RATIO).getValue();
    Boolean useIsShared = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.USE_ISSHARED).getValue();
    Double shapeSimThreshold = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.SHAPE_SIM_THRESHOLD).getValue();
    Double minModelPeakSharpness = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.MIN_MODEL_SHARPNESS).getValue();
    List<Range<Double>> deprecatedMZValues = parameterSet.getParameter(ADAP3DecompositionV1_5Parameters.MZ_VALUES).getValue();
    if (edgeToHeightRatio == null || deltaToHeightRatio == null || useIsShared == null || shapeSimThreshold == null || minModelPeakSharpness == null || deprecatedMZValues == null)
        return;
    List<Peak> modelPeakCandidates = TwoStepDecomposition.filterPeaks(peaks, useIsShared, edgeToHeightRatio, deltaToHeightRatio, minModelPeakSharpness, deprecatedMZValues);
    if (modelPeakCandidates.isEmpty())
        return;
    List<List<Peak>> clusters = TwoStepDecomposition.getShapeClusters(modelPeakCandidates, shapeSimThreshold);
    outClusters.clear();
    outText.clear();
    outColors.clear();
    Random rand = new Random();
    rand.setSeed(0);
    int colorIndex = 0;
    final int numColors = 10;
    final double[] colors = new double[numColors];
    for (int i = 0; i < numColors; ++i) colors[i] = rand.nextDouble();
    for (List<Peak> cluster : clusters) {
        List<NavigableMap<Double, Double>> c = new ArrayList<>(cluster.size());
        List<String> texts = new ArrayList<>(cluster.size());
        for (Peak peak : cluster) {
            c.add(peak.getChromatogram());
            texts.add(peak.getInfo() + "\nSharpness: " + numberFormat.format(FeatureTools.sharpnessYang(peak.getChromatogram())));
        }
        outClusters.add(c);
        outText.add(texts);
        outColors.add(colors[colorIndex % numColors]);
        ++colorIndex;
    }
}
Also used : NavigableMap(java.util.NavigableMap) ArrayList(java.util.ArrayList) Range(com.google.common.collect.Range) Random(java.util.Random) Peak(dulab.adap.datamodel.Peak) PeakList(net.sf.mzmine.datamodel.PeakList) ArrayList(java.util.ArrayList) List(java.util.List) NumberFormat(java.text.NumberFormat)

Example 2 with Peak

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

the class ADAP3DecompositionV1_5Task method getPeaks.

/**
 * Convert MZmine PeakList to a list of ADAP Peaks
 *
 * @param peakList MZmine PeakList object
 * @param edgeToHeightThreshold edge-to-height threshold to determine peaks that can be merged
 * @param deltaToHeightThreshold delta-to-height threshold to determine peaks that can be merged
 * @return list of ADAP Peaks
 */
@Nonnull
public static List<Peak> getPeaks(final PeakList peakList, final double edgeToHeightThreshold, final double deltaToHeightThreshold) {
    RawDataFile dataFile = peakList.getRawDataFile(0);
    List<Peak> peaks = new ArrayList<>();
    for (PeakListRow row : peakList.getRows()) {
        Feature peak = row.getBestPeak();
        int[] scanNumbers = peak.getScanNumbers();
        // Build chromatogram
        NavigableMap<Double, Double> chromatogram = new TreeMap<>();
        for (int scanNumber : scanNumbers) {
            DataPoint dataPoint = peak.getDataPoint(scanNumber);
            if (dataPoint != null)
                chromatogram.put(dataFile.getScan(scanNumber).getRetentionTime(), dataPoint.getIntensity());
        }
        if (chromatogram.size() <= 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) {
                double intensity = peak.getDataPoint(scan).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;
        }
        peaks.add(new Peak(chromatogram, info));
    }
    FeatureTools.correctPeakBoundaries(peaks, edgeToHeightThreshold, deltaToHeightThreshold);
    return peaks;
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IOException(java.io.IOException) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Peak(dulab.adap.datamodel.Peak) Nonnull(javax.annotation.Nonnull)

Example 3 with Peak

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

the class ADAP3DecompositionV1_5Task method decomposePeaks.

private PeakList decomposePeaks(PeakList peakList) throws CloneNotSupportedException, IOException {
    RawDataFile dataFile = peakList.getRawDataFile(0);
    // Create new feature list.
    final PeakList resolvedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(ADAP3DecompositionV1_5Parameters.SUFFIX).getValue(), dataFile);
    // Load previous applied methods.
    for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        resolvedPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    resolvedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak deconvolution by ADAP-3", parameters));
    // Collect peak information
    List<Peak> peaks = getPeaks(peakList, this.parameters.getParameter(ADAP3DecompositionV1_5Parameters.EDGE_TO_HEIGHT_RATIO).getValue(), this.parameters.getParameter(ADAP3DecompositionV1_5Parameters.DELTA_TO_HEIGHT_RATIO).getValue());
    // Find components (a.k.a. clusters of peaks with fragmentation spectra)
    List<Component> components = getComponents(peaks);
    // Create PeakListRow for each components
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    int rowID = 0;
    for (final Component component : components) {
        if (component.getSpectrum().isEmpty())
            continue;
        PeakListRow row = new SimplePeakListRow(++rowID);
        // Add the reference peak
        PeakListRow refPeakRow = originalPeakList.getRow(component.getBestPeak().getInfo().peakID);
        Feature refPeak = new SimpleFeature(refPeakRow.getBestPeak());
        // Add spectrum
        List<DataPoint> dataPoints = new ArrayList<>();
        for (Map.Entry<Double, Double> entry : component.getSpectrum().entrySet()) {
            dataPoints.add(new SimpleDataPoint(entry.getKey(), entry.getValue()));
        }
        refPeak.setIsotopePattern(new SimpleIsotopePattern(dataPoints.toArray(new DataPoint[dataPoints.size()]), IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
        row.addPeak(dataFile, refPeak);
        // Add PeakInformation
        if (refPeakRow.getPeakInformation() == null) {
            SimplePeakInformation information = new SimplePeakInformation(new HashMap<>(refPeakRow.getPeakInformation().getAllProperties()));
            row.setPeakInformation(information);
        }
        // Set row properties
        row.setAverageMZ(refPeakRow.getAverageMZ());
        row.setAverageRT(refPeakRow.getAverageRT());
        // resolvedPeakList.addRow(row);
        newPeakListRows.add(row);
    }
    // ------------------------------------
    // Sort new peak rows by retention time
    // ------------------------------------
    Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {

        @Override
        public int compare(PeakListRow row1, PeakListRow row2) {
            double retTime1 = row1.getAverageRT();
            double retTime2 = row2.getAverageRT();
            return Double.compare(retTime1, retTime2);
        }
    });
    for (PeakListRow row : newPeakListRows) resolvedPeakList.addRow(row);
    return resolvedPeakList;
}
Also used : ArrayList(java.util.ArrayList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Peak(dulab.adap.datamodel.Peak) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Component(dulab.adap.datamodel.Component) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap)

Example 4 with Peak

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

the class ADAP3AlignerTask method alignPeaks.

private PeakList alignPeaks() {
    // Collect all data files
    List<RawDataFile> allDataFiles = new ArrayList<>(peakLists.length);
    for (final PeakList peakList : peakLists) {
        RawDataFile[] dataFiles = peakList.getRawDataFiles();
        if (dataFiles.length != 1)
            throw new IllegalArgumentException("Found more then one data " + "file in some of the peaks lists");
        allDataFiles.add(dataFiles[0]);
    }
    for (int i = 0; i < peakLists.length; ++i) {
        PeakList peakList = peakLists[i];
        Sample sample = new Sample(i);
        for (final PeakListRow row : peakList.getRows()) {
            Component component = getComponent(row);
            if (component != null)
                sample.addComponent(component);
        }
        alignment.addSample(sample);
    }
    process();
    // Create new feature list
    final PeakList alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
    int rowID = 0;
    List<ReferenceComponent> alignedComponents = alignment.getComponents();
    Collections.sort(alignedComponents);
    for (final ReferenceComponent referenceComponent : alignedComponents) {
        SimplePeakListRow newRow = new SimplePeakListRow(++rowID);
        for (int i = 0; i < referenceComponent.size(); ++i) {
            Component component = referenceComponent.getComponent(i);
            Peak peak = component.getBestPeak();
            peak.getInfo().mzValue(component.getMZ());
            PeakListRow row = findPeakListRow(referenceComponent.getSampleID(i), peak.getInfo().peakID);
            if (row == null)
                throw new IllegalStateException(String.format("Cannot find a feature list row for fileId = %d and peakId = %d", referenceComponent.getSampleID(), peak.getInfo().peakID));
            RawDataFile file = row.getRawDataFiles()[0];
            // Create a new MZmine feature
            Feature feature = ADAPInterface.peakToFeature(file, peak);
            // Add spectrum as an isotopic pattern
            DataPoint[] spectrum = component.getSpectrum().entrySet().stream().map(e -> new SimpleDataPoint(e.getKey(), e.getValue())).toArray(DataPoint[]::new);
            feature.setIsotopePattern(new SimpleIsotopePattern(spectrum, IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
            newRow.addPeak(file, feature);
        }
        // Save alignment score
        SimplePeakInformation peakInformation = (SimplePeakInformation) newRow.getPeakInformation();
        if (peakInformation == null)
            peakInformation = new SimplePeakInformation();
        peakInformation.addProperty("Alignment score", Double.toString(referenceComponent.getScore()));
        newRow.setPeakInformation(peakInformation);
        alignedPeakList.addRow(newRow);
    }
    return alignedPeakList;
}
Also used : Peak(dulab.adap.datamodel.Peak) Project(dulab.adap.datamodel.Project) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) net.sf.mzmine.datamodel.impl(net.sf.mzmine.datamodel.impl) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakList(net.sf.mzmine.datamodel.PeakList) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) Feature(net.sf.mzmine.datamodel.Feature) ParameterSet(net.sf.mzmine.parameters.ParameterSet) QualityParameters(net.sf.mzmine.modules.peaklistmethods.qualityparameters.QualityParameters) ADAPInterface(net.sf.mzmine.util.adap.ADAPInterface) PeakInfo(dulab.adap.datamodel.PeakInfo) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) AlignmentParameters(dulab.adap.workflow.AlignmentParameters) Nullable(javax.annotation.Nullable) OptimizationParameters(dulab.adap.common.algorithms.machineleanring.OptimizationParameters) NavigableMap(java.util.NavigableMap) Logger(java.util.logging.Logger) List(java.util.List) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) Sample(dulab.adap.datamodel.Sample) TreeMap(java.util.TreeMap) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) Collections(java.util.Collections) Sample(dulab.adap.datamodel.Sample) ArrayList(java.util.ArrayList) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) Peak(dulab.adap.datamodel.Peak) PeakList(net.sf.mzmine.datamodel.PeakList) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent)

Example 5 with Peak

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

the class ADAP3AlignerTask method getComponent.

/**
 * Convert a {@link PeakListRow} with one {@link Feature} into {@link Component}.
 *
 * @param row an instance of {@link PeakListRow}. This parameter cannot be null.
 * @return an instance of {@link Component} or null if the row doesn't contain any peaks or isotope patterns.
 */
@Nullable
private Component getComponent(final PeakListRow row) {
    if (row.getNumberOfPeaks() == 0)
        return null;
    // Read Spectrum information
    NavigableMap<Double, Double> spectrum = new TreeMap<>();
    IsotopePattern pattern = row.getBestIsotopePattern();
    if (pattern == null)
        throw new IllegalArgumentException("ADAP Alignment requires mass " + "spectra (or isotopic patterns) of peaks. No spectra found.");
    for (DataPoint dataPoint : pattern.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
    // Read Chromatogram
    final Feature peak = row.getBestPeak();
    final RawDataFile dataFile = peak.getDataFile();
    NavigableMap<Double, Double> chromatogram = new TreeMap<>();
    for (final int scan : peak.getScanNumbers()) {
        final DataPoint dataPoint = peak.getDataPoint(scan);
        if (dataPoint != null)
            chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
    }
    return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Peak(dulab.adap.datamodel.Peak) TreeMap(java.util.TreeMap) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) Feature(net.sf.mzmine.datamodel.Feature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) Nullable(javax.annotation.Nullable)

Aggregations

Peak (dulab.adap.datamodel.Peak)7 ArrayList (java.util.ArrayList)5 TreeMap (java.util.TreeMap)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 Feature (net.sf.mzmine.datamodel.Feature)5 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)5 Component (dulab.adap.datamodel.Component)4 PeakInfo (dulab.adap.datamodel.PeakInfo)4 PeakList (net.sf.mzmine.datamodel.PeakList)4 List (java.util.List)3 NavigableMap (java.util.NavigableMap)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)3 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)3 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)3 ReferenceComponent (dulab.adap.datamodel.ReferenceComponent)2 Nullable (javax.annotation.Nullable)2 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)2 Range (com.google.common.collect.Range)1 OptimizationParameters (dulab.adap.common.algorithms.machineleanring.OptimizationParameters)1