Search in sources :

Example 11 with PeakList

use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.

the class RansacAlignerModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    PeakList[] peakLists = parameters.getParameter(RansacAlignerParameters.peakLists).getValue().getMatchingPeakLists();
    Task task = new RansacAlignerTask(project, peakLists, parameters);
    tasks.add(task);
    return ExitCode.OK;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) PeakList(net.sf.mzmine.datamodel.PeakList) Nonnull(javax.annotation.Nonnull)

Example 12 with PeakList

use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.

the class RansacAlignerSetupDialog method updatePreview.

private void updatePreview() {
    PeakList peakListX = (PeakList) peakListsComboX.getSelectedItem();
    PeakList peakListY = (PeakList) peakListsComboY.getSelectedItem();
    if ((peakListX == null) || (peakListY == null))
        return;
    // Select the rawDataFile which has more peaks in each peakList
    int numPeaks = 0;
    RawDataFile file = null;
    RawDataFile file2 = null;
    for (RawDataFile rfile : peakListX.getRawDataFiles()) {
        if (peakListX.getPeaks(rfile).length > numPeaks) {
            numPeaks = peakListX.getPeaks(rfile).length;
            file = rfile;
        }
    }
    numPeaks = 0;
    for (RawDataFile rfile : peakListY.getRawDataFiles()) {
        if (peakListY.getPeaks(rfile).length > numPeaks) {
            numPeaks = peakListY.getPeaks(rfile).length;
            file2 = rfile;
        }
    }
    // Update the parameter set from dialog components
    updateParameterSetFromComponents();
    // Check the parameter values
    ArrayList<String> errorMessages = new ArrayList<String>();
    boolean parametersOK = super.parameterSet.checkParameterValues(errorMessages);
    if (!parametersOK) {
        StringBuilder message = new StringBuilder("Please check the parameter settings:\n\n");
        for (String m : errorMessages) {
            message.append(m);
            message.append("\n");
        }
        MZmineCore.getDesktop().displayMessage(this, message.toString());
        return;
    }
    // Ransac Alignment
    Vector<AlignStructMol> list = this.getVectorAlignment(peakListX, peakListY, file, file2);
    RANSAC ransac = new RANSAC(super.parameterSet);
    ransac.alignment(list);
    // Plot the result
    this.chart.removeSeries();
    this.chart.addSeries(list, peakListX.getName() + " vs " + peakListY.getName(), super.parameterSet.getParameter(RansacAlignerParameters.Linear).getValue());
    this.chart.printAlignmentChart(peakListX.getName() + " RT", peakListY.getName() + " RT");
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 13 with PeakList

use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.

the class RansacAlignerTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running Ransac aligner");
    // twice, first for score calculation, second for actual alignment.
    for (int i = 0; i < peakLists.length; i++) {
        totalRows += peakLists[i].getNumberOfRows() * 2;
    }
    // Collect all data files
    List<RawDataFile> allDataFiles = new ArrayList<RawDataFile>();
    for (PeakList peakList : peakLists) {
        for (RawDataFile dataFile : peakList.getRawDataFiles()) {
            // Each data file can only have one column in aligned feature list
            if (allDataFiles.contains(dataFile)) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Cannot run alignment, because file " + dataFile + " is present in multiple feature lists");
                return;
            }
            allDataFiles.add(dataFile);
        }
    }
    // Create a new aligned feature list
    alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
    // Iterate source feature lists
    for (PeakList peakList : peakLists) {
        HashMap<PeakListRow, PeakListRow> alignmentMapping = this.getAlignmentMap(peakList);
        PeakListRow[] allRows = peakList.getRows();
        // Align all rows using mapping
        for (PeakListRow row : allRows) {
            PeakListRow targetRow = alignmentMapping.get(row);
            // If we have no mapping for this row, add a new one
            if (targetRow == null) {
                targetRow = new SimplePeakListRow(newRowID);
                newRowID++;
                alignedPeakList.addRow(targetRow);
            }
            // Add all peaks from the original row to the aligned row
            for (RawDataFile file : row.getRawDataFiles()) {
                targetRow.addPeak(file, row.getPeak(file));
            }
            // Add all non-existing identities from the original row to the
            // aligned row
            PeakUtils.copyPeakListRowProperties(row, targetRow);
            processedRows++;
        }
    }
    // Next feature list
    // Add new aligned feature list to the project
    project.addPeakList(alignedPeakList);
    // Edit by Aleksandr Smirnov
    PeakListRow row = alignedPeakList.getRow(1);
    double alignedRetTime = row.getAverageRT();
    for (Feature peak : row.getPeaks()) {
        double retTimeDelta = alignedRetTime - peak.getRT();
        RawDataFile dataFile = peak.getDataFile();
        SortedMap<Double, Double> chromatogram = new TreeMap<>();
        for (int scan : peak.getScanNumbers()) {
            DataPoint dataPoint = peak.getDataPoint(scan);
            double retTime = dataFile.getScan(scan).getRetentionTime() + retTimeDelta;
            if (dataPoint != null)
                chromatogram.put(retTime, dataPoint.getIntensity());
        }
    }
    // End of Edit
    // Add task description to peakList
    alignedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Ransac aligner", parameters));
    logger.info("Finished RANSAC aligner");
    setStatus(TaskStatus.FINISHED);
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) 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) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 14 with PeakList

use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.

the class LearnerModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    // get parameters
    PeakList[] peakLists = parameters.getParameter(LearnerParameters.peakLists).getValue().getMatchingPeakLists();
    // create and start one task for each peaklist
    for (final PeakList peakList : peakLists) {
        Task newTask = new PeakListRowLearnerTask(project, peakList, parameters);
        tasks.add(newTask);
    }
    return ExitCode.OK;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) PeakList(net.sf.mzmine.datamodel.PeakList) Nonnull(javax.annotation.Nonnull)

Example 15 with PeakList

use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.

the class ADAP3AlignerTask method run.

@Override
public void run() {
    if (isCanceled())
        return;
    String errorMsg = null;
    setStatus(TaskStatus.PROCESSING);
    LOG.info("Started ADAP Peak Alignment");
    try {
        PeakList peakList = alignPeaks();
        if (!isCanceled()) {
            project.addPeakList(peakList);
            QualityParameters.calculateQualityParameters(peakList);
            setStatus(TaskStatus.FINISHED);
            LOG.info("Finished ADAP Peak Alignment");
        }
    } catch (IllegalArgumentException e) {
        errorMsg = "Incorrect Feature Lists:\n" + e.getMessage();
    } catch (Exception e) {
        errorMsg = "'Unknown error' during alignment. \n" + e.getMessage();
    } catch (Throwable t) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage(t.getMessage());
        LOG.log(Level.SEVERE, "ADAP Alignment error", t);
    }
    // Report error
    if (errorMsg != null) {
        setErrorMessage(errorMsg);
        setStatus(TaskStatus.ERROR);
    }
}
Also used : PeakList(net.sf.mzmine.datamodel.PeakList)

Aggregations

PeakList (net.sf.mzmine.datamodel.PeakList)120 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)41 Nonnull (javax.annotation.Nonnull)40 Task (net.sf.mzmine.taskcontrol.Task)37 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)36 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)26 Feature (net.sf.mzmine.datamodel.Feature)19 ArrayList (java.util.ArrayList)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)11 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)10 File (java.io.File)9 FileWriter (java.io.FileWriter)8 ParameterSet (net.sf.mzmine.parameters.ParameterSet)8 IOException (java.io.IOException)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)7 Vector (java.util.Vector)6 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)6