Search in sources :

Example 71 with PeakListRow

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

the class PeakLearnerTask method copyPeakRow.

/**
 * Create a copy of a feature list row.
 *
 * @param row the row to copy.
 * @return the newly created copy.
 */
private static PeakListRow copyPeakRow(final PeakListRow row) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    for (final Feature peak : row.getPeaks()) {
        final Feature newPeak = new SimpleFeature(peak);
        PeakUtils.copyPeakProperties(peak, newPeak);
        newRow.addPeak(peak.getDataFile(), newPeak);
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 72 with PeakListRow

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

the class StreamPeakListRowLearnerTask method run.

/**
 * @see Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running learner task on " + peakList);
    // Create a new results peakList which is added at the end
    resultPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
    /**
     * - A PeakList is a list of Features (peak in retention time dimension with accurate m/z)<br>
     * ---- contains one or multiple RawDataFiles <br>
     * ---- access mean retention time, mean m/z, maximum intensity, ...<br>
     */
    // use streams to filter, sort and create list
    List<PeakListRow> rowList = Arrays.stream(peakList.getRows()).filter(r -> r.getAverageHeight() > 5000).sorted(new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending)).collect(Collectors.toList());
    totalRows = rowList.size();
    // ###########################################################
    // OPTION 1: Streams
    // either use stream to process all rows
    rowList.stream().forEachOrdered(row -> {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        // access details
        double mz = row.getAverageMZ();
        double intensity = row.getAverageHeight();
        double rt = row.getAverageRT();
        Feature peak = row.getBestPeak();
        // do stuff
        // ...
        // add row to peaklist result
        PeakListRow copy = copyPeakRow(row);
        resultPeakList.addRow(copy);
        // Update completion rate
        processedPeaks++;
    });
    // OPTION 2: For loop
    for (PeakListRow row : rowList) {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        // access details
        double mz = row.getAverageMZ();
        double intensity = row.getAverageHeight();
        double rt = row.getAverageRT();
        Feature peak = row.getBestPeak();
        // do stuff
        // ...
        // add row to peaklist result
        PeakListRow copy = copyPeakRow(row);
        resultPeakList.addRow(copy);
        // Update completion rate
        processedPeaks++;
    }
    // add to project
    addResultToProject();
    logger.info("Finished on " + peakList);
    setStatus(TaskStatus.FINISHED);
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 73 with PeakListRow

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

the class CDADataset method run.

@Override
public void run() {
    status = TaskStatus.PROCESSING;
    if (selectedRows.length == 0) {
        this.status = TaskStatus.ERROR;
        errorMessage = "No peaks selected for CDA plot";
        return;
    }
    if (selectedRawDataFiles.length == 0) {
        this.status = TaskStatus.ERROR;
        errorMessage = "No raw data files selected for CDA plot";
        return;
    }
    logger.info("Computing projection plot");
    // Generate matrix of raw data (input to CDA)
    boolean useArea = false;
    if (parameters.getParameter(ProjectionPlotParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA)
        useArea = true;
    double[][] rawData = new double[selectedRawDataFiles.length][selectedRows.length];
    for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
        PeakListRow peakListRow = selectedRows[rowIndex];
        for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
            RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
            Feature p = peakListRow.getPeak(rawDataFile);
            if (p != null) {
                if (useArea)
                    rawData[fileIndex][rowIndex] = p.getArea();
                else
                    rawData[fileIndex][rowIndex] = p.getHeight();
            }
        }
    }
    int numComponents = xAxisDimension;
    if (yAxisDimension > numComponents)
        numComponents = yAxisDimension;
    // Scale data and do CDA
    Preprocess.scaleToUnityVariance(rawData);
    CDA cdaProj = new CDA(rawData);
    cdaProj.iterate(100);
    if (status == TaskStatus.CANCELED)
        return;
    double[][] result = cdaProj.getState();
    if (status == TaskStatus.CANCELED)
        return;
    component1Coords = result[xAxisDimension - 1];
    component2Coords = result[yAxisDimension - 1];
    ProjectionPlotWindow newFrame = new ProjectionPlotWindow(peakList, this, parameters);
    newFrame.setVisible(true);
    status = TaskStatus.FINISHED;
    logger.info("Finished computing projection plot.");
}
Also used : CDA(jmprojection.CDA) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Feature(net.sf.mzmine.datamodel.Feature)

Example 74 with PeakListRow

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

the class PCADataset method run.

@Override
public void run() {
    status = TaskStatus.PROCESSING;
    logger.info("Computing PCA projection plot");
    // Generate matrix of raw data (input to PCA)
    final boolean useArea = (parameters.getParameter(ProjectionPlotParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA);
    if (selectedRows.length == 0) {
        this.status = TaskStatus.ERROR;
        errorMessage = "No peaks selected for PCA plot";
        return;
    }
    if (selectedRawDataFiles.length == 0) {
        this.status = TaskStatus.ERROR;
        errorMessage = "No raw data files selected for PCA plot";
        return;
    }
    double[][] rawData = new double[selectedRawDataFiles.length][selectedRows.length];
    for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
        PeakListRow peakListRow = selectedRows[rowIndex];
        for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
            RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
            Feature p = peakListRow.getPeak(rawDataFile);
            if (p != null) {
                if (useArea)
                    rawData[fileIndex][rowIndex] = p.getArea();
                else
                    rawData[fileIndex][rowIndex] = p.getHeight();
            }
        }
    }
    int numComponents = xAxisPC;
    if (yAxisPC > numComponents)
        numComponents = yAxisPC;
    // Scale data and do PCA
    Preprocess.scaleToUnityVariance(rawData);
    // Replace NaN values with 0.0
    for (int i = 0; i < rawData.length; i++) {
        for (int j = 0; j < rawData[i].length; j++) {
            if (Double.isNaN(rawData[i][j]))
                rawData[i][j] = 0.0;
        }
    }
    PCA pcaProj = new PCA(rawData, numComponents);
    projectionStatus = pcaProj.getProjectionStatus();
    double[][] result = pcaProj.getState();
    if (status == TaskStatus.CANCELED)
        return;
    component1Coords = result[xAxisPC - 1];
    component2Coords = result[yAxisPC - 1];
    ProjectionPlotWindow newFrame = new ProjectionPlotWindow(peakList, this, parameters);
    newFrame.setVisible(true);
    status = TaskStatus.FINISHED;
    logger.info("Finished computing projection plot.");
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Feature(net.sf.mzmine.datamodel.Feature) PCA(jmprojection.PCA)

Example 75 with PeakListRow

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

the class RowVsRowDistanceProvider method getRankedDistance.

public double getRankedDistance(int i, int j, double mzMaxDiff, double rtMaxDiff, double minScore) {
    // Itself
    if (i == j)
        return 0d;
    // if (row_id > aligned_row_id) {
    // int tmp = row_id;
    // row_id = aligned_row_id;
    // aligned_row_id = tmp;
    // }
    // if (row_id < aligned_row_id) {
    // int tmp = row_id;
    // row_id = aligned_row_id;
    // aligned_row_id = tmp;
    // }
    PeakListRow row = full_rows_list.get(i);
    PeakListRow k_row = full_rows_list.get(j);
    // || (row_id >= 102 && aligned_row_id >= 102)) {
    if (row.getRawDataFiles()[0] == k_row.getRawDataFiles()[0]) {
        return 1000.0d;
    } else // Not candidate
    {
        // k_row.getBestPeak().getMZ()) >= mzMaxDiff/2.0));
        if ((Math.abs(row.getBestPeak().getRT() - k_row.getBestPeak().getRT()) >= rtMaxDiff / 2.0 || Math.abs(row.getBestPeak().getMZ() - k_row.getBestPeak().getMZ()) >= mzMaxDiff / 2.0)) {
            return 100.0d;
        }
    }
    double score = this.getScore(i, j, mzMaxDiff, rtMaxDiff).getScore();
    // Score too low
    if (score <= Math.max(HierarAlignerGCTask.MIN_SCORE_ABSOLUTE, minScore)) {
        // System.out.println("(2) Final dist: " + 10.0f);
        return 10.0d;
    }
    // Score OK
    return this.maximumScore - score;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow)

Aggregations

PeakListRow (net.sf.mzmine.datamodel.PeakListRow)148 Feature (net.sf.mzmine.datamodel.Feature)71 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)55 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)54 PeakList (net.sf.mzmine.datamodel.PeakList)44 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)39 ArrayList (java.util.ArrayList)31 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)29 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)26 Scan (net.sf.mzmine.datamodel.Scan)25 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)20 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)12 HashMap (java.util.HashMap)11 Vector (java.util.Vector)11 ParameterSet (net.sf.mzmine.parameters.ParameterSet)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)10 MassList (net.sf.mzmine.datamodel.MassList)10