Search in sources :

Example 66 with PeakListRow

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

the class ClusteringTask method createMatrix.

/**
 * Creates a matrix of heights of areas
 *
 * @param isForSamples
 * @return
 */
private double[][] createMatrix(boolean isForSamples) {
    // Generate matrix of raw data (input to CDA)
    boolean useArea = true;
    if (parameters.getParameter(ClusteringParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA) {
        useArea = true;
    }
    if (parameters.getParameter(ClusteringParameters.peakMeasurementType).getValue() == PeakMeasurementType.HEIGHT) {
        useArea = false;
    }
    double[][] rawData;
    if (isForSamples) {
        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();
                    }
                }
            }
        }
    } else {
        rawData = new double[selectedRows.length][selectedRawDataFiles.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[rowIndex][fileIndex] = p.getArea();
                    } else {
                        rawData[rowIndex][fileIndex] = p.getHeight();
                    }
                }
            }
        }
    }
    return rawData;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Feature(net.sf.mzmine.datamodel.Feature)

Example 67 with PeakListRow

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

the class RansacAlignerSetupDialog method getVectorAlignment.

/**
 * Create the vector which contains all the possible aligned peaks.
 *
 * @return vector which contains all the possible aligned peaks.
 */
private Vector<AlignStructMol> getVectorAlignment(PeakList peakListX, PeakList peakListY, RawDataFile file, RawDataFile file2) {
    Vector<AlignStructMol> alignMol = new Vector<AlignStructMol>();
    for (PeakListRow row : peakListX.getRows()) {
        // Calculate limits for a row with which the row can be aligned
        MZTolerance mzTolerance = super.parameterSet.getParameter(RansacAlignerParameters.MZTolerance).getValue();
        RTTolerance rtTolerance = super.parameterSet.getParameter(RansacAlignerParameters.RTToleranceBefore).getValue();
        Range<Double> mzRange = mzTolerance.getToleranceRange(row.getAverageMZ());
        Range<Double> rtRange = rtTolerance.getToleranceRange(row.getAverageRT());
        // Get all rows of the aligned peaklist within parameter limits
        PeakListRow[] candidateRows = peakListY.getRowsInsideScanAndMZRange(rtRange, mzRange);
        for (PeakListRow candidateRow : candidateRows) {
            if (file == null || file2 == null) {
                alignMol.addElement(new AlignStructMol(row, candidateRow));
            } else {
                if (candidateRow.getPeak(file2) != null) {
                    alignMol.addElement(new AlignStructMol(row, candidateRow, file, file2));
                }
            }
        }
    }
    return alignMol;
}
Also used : MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RTTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.RTTolerance) Vector(java.util.Vector)

Example 68 with PeakListRow

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

the class RansacAlignerTask method getAlignmentMap.

/**
 * @param peakList
 * @return
 */
private HashMap<PeakListRow, PeakListRow> getAlignmentMap(PeakList peakList) {
    // Create a table of mappings for best scores
    HashMap<PeakListRow, PeakListRow> alignmentMapping = new HashMap<PeakListRow, PeakListRow>();
    if (alignedPeakList.getNumberOfRows() < 1) {
        return alignmentMapping;
    }
    // Create a sorted set of scores matching
    TreeSet<RowVsRowScore> scoreSet = new TreeSet<RowVsRowScore>();
    // RANSAC algorithm
    List<AlignStructMol> list = ransacPeakLists(alignedPeakList, peakList);
    PolynomialFunction function = this.getPolynomialFunction(list);
    PeakListRow[] allRows = peakList.getRows();
    for (PeakListRow row : allRows) {
        // Calculate limits for a row with which the row can be aligned
        Range<Double> mzRange = mzTolerance.getToleranceRange(row.getAverageMZ());
        double rt;
        try {
            rt = function.value(row.getAverageRT());
        } catch (NullPointerException e) {
            rt = row.getAverageRT();
        }
        if (Double.isNaN(rt) || rt == -1) {
            rt = row.getAverageRT();
        }
        Range<Double> rtRange = rtToleranceAfter.getToleranceRange(rt);
        // Get all rows of the aligned peaklist within parameter limits
        PeakListRow[] candidateRows = alignedPeakList.getRowsInsideScanAndMZRange(rtRange, mzRange);
        for (PeakListRow candidate : candidateRows) {
            RowVsRowScore score;
            if (sameChargeRequired && (!PeakUtils.compareChargeState(row, candidate))) {
                continue;
            }
            try {
                score = new RowVsRowScore(row, candidate, RangeUtils.rangeLength(mzRange) / 2.0, RangeUtils.rangeLength(rtRange) / 2.0, rt);
                scoreSet.add(score);
                setErrorMessage(score.getErrorMessage());
            } catch (Exception e) {
                e.printStackTrace();
                setStatus(TaskStatus.ERROR);
                return null;
            }
        }
        processedRows++;
    }
    // Iterate scores by descending order
    Iterator<RowVsRowScore> scoreIterator = scoreSet.iterator();
    while (scoreIterator.hasNext()) {
        RowVsRowScore score = scoreIterator.next();
        // Check if the row is already mapped
        if (alignmentMapping.containsKey(score.getPeakListRow())) {
            continue;
        }
        // Check if the aligned row is already filled
        if (alignmentMapping.containsValue(score.getAlignedRow())) {
            continue;
        }
        alignmentMapping.put(score.getPeakListRow(), score.getAlignedRow());
    }
    return alignmentMapping;
}
Also used : HashMap(java.util.HashMap) PolynomialFunction(org.apache.commons.math.analysis.polynomials.PolynomialFunction) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) TreeSet(java.util.TreeSet)

Example 69 with PeakListRow

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

the class PeakListRowLearnerTask 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>
     */
    // get all rows and sort by m/z
    PeakListRow[] rows = peakList.getRows();
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
    totalRows = rows.length;
    for (int i = 0; i < totalRows; i++) {
        // check for cancelled state and stop
        if (isCanceled())
            return;
        PeakListRow row = rows[i];
        // 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 70 with PeakListRow

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

the class HeatMapTask method modifySimpleDataset.

private double[][] modifySimpleDataset(UserParameter<?, ?> selectedParameter, String referenceGroup) {
    // Collect all data files
    Vector<RawDataFile> allDataFiles = new Vector<RawDataFile>();
    allDataFiles.addAll(Arrays.asList(peakList.getRawDataFiles()));
    // Determine the reference group and non reference group (the rest of
    // the samples) for raw data files
    List<RawDataFile> referenceDataFiles = new ArrayList<RawDataFile>();
    List<RawDataFile> nonReferenceDataFiles = new ArrayList<RawDataFile>();
    for (RawDataFile rawDataFile : allDataFiles) {
        Object paramValue = project.getParameterValue(selectedParameter, rawDataFile);
        if (paramValue.equals(referenceGroup)) {
            referenceDataFiles.add(rawDataFile);
        } else {
            nonReferenceDataFiles.add(rawDataFile);
        }
    }
    int numRows = 0;
    for (int row = 0; row < peakList.getNumberOfRows(); row++) {
        if (!onlyIdentified || (onlyIdentified && peakList.getRow(row).getPeakIdentities().length > 0)) {
            numRows++;
        }
    }
    // Create a new aligned feature list with all the samples if the reference
    // group has to be shown or with only
    // the non reference group if not.
    double[][] dataMatrix;
    if (rcontrol) {
        dataMatrix = new double[allDataFiles.size()][numRows];
    } else {
        dataMatrix = new double[nonReferenceDataFiles.size()][numRows];
    }
    // Data files that should be in the heat map
    List<RawDataFile> shownDataFiles = null;
    if (rcontrol) {
        shownDataFiles = allDataFiles;
    } else {
        shownDataFiles = nonReferenceDataFiles;
    }
    for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
        PeakListRow rowPeak = peakList.getRow(row);
        if (!onlyIdentified || (onlyIdentified && rowPeak.getPeakIdentities().length > 0)) {
            // Average area or height of the reference group
            double referenceAverage = 0;
            int referencePeakCount = 0;
            for (int column = 0; column < referenceDataFiles.size(); column++) {
                if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {
                    if (area) {
                        referenceAverage += rowPeak.getPeak(referenceDataFiles.get(column)).getArea();
                    } else {
                        referenceAverage += rowPeak.getPeak(referenceDataFiles.get(column)).getHeight();
                    }
                    referencePeakCount++;
                }
            }
            if (referencePeakCount > 0) {
                referenceAverage /= referencePeakCount;
            }
            // area or height of the reference peaks in each row
            for (int column = 0; column < shownDataFiles.size(); column++) {
                double value = Double.NaN;
                if (rowPeak.getPeak(shownDataFiles.get(column)) != null) {
                    Feature peak = rowPeak.getPeak(shownDataFiles.get(column));
                    if (area) {
                        value = peak.getArea() / referenceAverage;
                    } else {
                        value = peak.getHeight() / referenceAverage;
                    }
                    if (log) {
                        value = Math.log(value);
                    }
                }
                dataMatrix[column][rowIndex] = value;
            }
            rowIndex++;
        }
    }
    // deviation of each column
    if (scale) {
        scale(dataMatrix);
    }
    // Create two arrays: row and column names
    rowNames = new String[dataMatrix[0].length];
    colNames = new String[shownDataFiles.size()];
    for (int column = 0; column < shownDataFiles.size(); column++) {
        colNames[column] = shownDataFiles.get(column).getName();
    }
    for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
        if (!onlyIdentified || (onlyIdentified && peakList.getRow(row).getPeakIdentities().length > 0)) {
            if (peakList.getRow(row).getPeakIdentities() != null && peakList.getRow(row).getPeakIdentities().length > 0) {
                rowNames[rowIndex++] = peakList.getRow(row).getPreferredPeakIdentity().getName();
            } else {
                rowNames[rowIndex++] = "Unknown";
            }
        }
    }
    return dataMatrix;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) Vector(java.util.Vector) Feature(net.sf.mzmine.datamodel.Feature)

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