Search in sources :

Example 21 with SimplePeakListRow

use of net.sf.mzmine.datamodel.impl.SimplePeakListRow in project mzmine2 by mzmine.

the class NeutralLossFilterTask 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) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 22 with SimplePeakListRow

use of net.sf.mzmine.datamodel.impl.SimplePeakListRow in project mzmine2 by mzmine.

the class PeakFilterTask method copyPeakRow.

/**
 * Create a copy of a feature list row.
 */
private static PeakListRow copyPeakRow(final PeakListRow row, final boolean[] keepPeak) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    int i = 0;
    for (final Feature peak : row.getPeaks()) {
        // Only keep peak if it fulfills the filter criteria
        if (keepPeak[i]) {
            final Feature newPeak = new SimpleFeature(peak);
            PeakUtils.copyPeakProperties(peak, newPeak);
            newRow.addPeak(peak.getDataFile(), newPeak);
        }
        i++;
    }
    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 23 with SimplePeakListRow

use of net.sf.mzmine.datamodel.impl.SimplePeakListRow in project mzmine2 by mzmine.

the class RowsFilterTask 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);
    }
    // Add PeakInformation
    if (row.getPeakInformation() != null) {
        SimplePeakInformation information = new SimplePeakInformation(new HashMap<>(row.getPeakInformation().getAllProperties()));
        newRow.setPeakInformation(information);
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation)

Example 24 with SimplePeakListRow

use of net.sf.mzmine.datamodel.impl.SimplePeakListRow in project mzmine2 by mzmine.

the class PeakFinderTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running gap filler on " + peakList);
    // Calculate total number of scans in all files
    for (RawDataFile dataFile : peakList.getRawDataFiles()) {
        totalScans += dataFile.getNumOfScans(1);
    }
    processedScans = new AtomicInteger();
    // Create new feature list
    processedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
    // Fill new feature list with empty rows
    for (int row = 0; row < peakList.getNumberOfRows(); row++) {
        PeakListRow sourceRow = peakList.getRow(row);
        PeakListRow newRow = new SimplePeakListRow(sourceRow.getID());
        newRow.setComment(sourceRow.getComment());
        for (PeakIdentity ident : sourceRow.getPeakIdentities()) {
            newRow.addPeakIdentity(ident, false);
        }
        if (sourceRow.getPreferredPeakIdentity() != null) {
            newRow.setPreferredPeakIdentity(sourceRow.getPreferredPeakIdentity());
        }
        processedPeakList.addRow(newRow);
    }
    if (rtCorrection) {
        totalScans *= 2;
        // Fill the gaps of a random sample using all the other samples and
        // take it as master list
        // to fill the gaps of the other samples
        masterSample = (int) Math.floor(Math.random() * peakList.getNumberOfRawDataFiles());
        fillList(MASTERLIST);
        // Process all raw data files
        fillList(!MASTERLIST);
    } else {
        // Process all raw data files
        IntStream rawStream = IntStream.range(0, peakList.getNumberOfRawDataFiles());
        if (useParallelStream)
            rawStream = rawStream.parallel();
        rawStream.forEach(i -> {
            // Canceled?
            if (isCanceled()) {
                // inside stream - only skips this element
                return;
            }
            RawDataFile dataFile = peakList.getRawDataFile(i);
            List<Gap> gaps = new ArrayList<Gap>();
            // if necessary
            for (int row = 0; row < peakList.getNumberOfRows(); row++) {
                // Canceled?
                if (isCanceled()) {
                    // inside stream - only skips this element
                    return;
                }
                PeakListRow sourceRow = peakList.getRow(row);
                PeakListRow newRow = processedPeakList.getRow(row);
                Feature sourcePeak = sourceRow.getPeak(dataFile);
                if (sourcePeak == null) {
                    // Create a new gap
                    Range<Double> mzRange = mzTolerance.getToleranceRange(sourceRow.getAverageMZ());
                    Range<Double> rtRange = rtTolerance.getToleranceRange(sourceRow.getAverageRT());
                    Gap newGap = new Gap(newRow, dataFile, mzRange, rtRange, intTolerance);
                    gaps.add(newGap);
                } else {
                    newRow.addPeak(dataFile, sourcePeak);
                }
            }
            // Stop processing this file if there are no gaps
            if (gaps.size() == 0) {
                processedScans.addAndGet(dataFile.getNumOfScans());
                return;
            }
            // Get all scans of this data file
            int[] scanNumbers = dataFile.getScanNumbers(1);
            // Process each scan
            for (int scanNumber : scanNumbers) {
                // Canceled?
                if (isCanceled()) {
                    // inside stream - only skips this element
                    return;
                }
                // Get the scan
                Scan scan = dataFile.getScan(scanNumber);
                // Feed this scan to all gaps
                for (Gap gap : gaps) {
                    gap.offerNextScan(scan);
                }
                processedScans.incrementAndGet();
            }
            // Finalize gaps
            for (Gap gap : gaps) {
                gap.noMoreOffers();
            }
        });
    }
    // terminate - stream only skips all elements
    if (isCanceled())
        return;
    // Append processed feature list to the project
    project.addPeakList(processedPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(processedPeakList);
    // Add task description to peakList
    processedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Gap filling ", parameters));
    // Remove the original peaklist if requested
    if (removeOriginal)
        project.removePeakList(peakList);
    logger.info("Finished gap-filling on " + peakList);
    setStatus(TaskStatus.FINISHED);
}
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) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) IntStream(java.util.stream.IntStream)

Example 25 with SimplePeakListRow

use of net.sf.mzmine.datamodel.impl.SimplePeakListRow in project mzmine2 by mzmine.

the class MultiThreadPeakFinderMainTask method createResultsPeakList.

private PeakList createResultsPeakList() {
    SimplePeakList processedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
    // Fill new feature list with empty rows
    for (int row = 0; row < peakList.getNumberOfRows(); row++) {
        PeakListRow sourceRow = peakList.getRow(row);
        PeakListRow newRow = new SimplePeakListRow(sourceRow.getID());
        newRow.setComment(sourceRow.getComment());
        for (PeakIdentity ident : sourceRow.getPeakIdentities()) {
            newRow.addPeakIdentity(ident, false);
        }
        if (sourceRow.getPreferredPeakIdentity() != null) {
            newRow.setPreferredPeakIdentity(sourceRow.getPreferredPeakIdentity());
        }
        processedPeakList.addRow(newRow);
    }
    return processedPeakList;
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow)

Aggregations

SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)38 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)31 Feature (net.sf.mzmine.datamodel.Feature)29 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)22 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)19 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)17 DataPoint (net.sf.mzmine.datamodel.DataPoint)15 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)14 Scan (net.sf.mzmine.datamodel.Scan)9 ArrayList (java.util.ArrayList)8 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)8 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 Hashtable (java.util.Hashtable)3 List (java.util.List)3 Vector (java.util.Vector)3 ParameterSet (net.sf.mzmine.parameters.ParameterSet)3 PeakSorter (net.sf.mzmine.util.PeakSorter)3 SAXException (org.xml.sax.SAXException)3