Search in sources :

Example 1 with ReferenceComponent

use of dulab.adap.datamodel.ReferenceComponent 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)

Aggregations

OptimizationParameters (dulab.adap.common.algorithms.machineleanring.OptimizationParameters)1 Component (dulab.adap.datamodel.Component)1 Peak (dulab.adap.datamodel.Peak)1 PeakInfo (dulab.adap.datamodel.PeakInfo)1 Project (dulab.adap.datamodel.Project)1 ReferenceComponent (dulab.adap.datamodel.ReferenceComponent)1 Sample (dulab.adap.datamodel.Sample)1 AlignmentParameters (dulab.adap.workflow.AlignmentParameters)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 NavigableMap (java.util.NavigableMap)1 TreeMap (java.util.TreeMap)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Nullable (javax.annotation.Nullable)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 Feature (net.sf.mzmine.datamodel.Feature)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1