Search in sources :

Example 46 with DataPoint

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

the class ShoulderPeaksFilterSetupDialog method loadPreview.

/**
 * This function set all the information into the plot chart
 *
 * @param scanNumber
 */
protected void loadPreview(SpectraPlot spectrumPlot, Scan previewScan) {
    // Remove previous data sets
    spectrumPlot.removeAllDataSets();
    // Add scan data set
    ScanDataSet scanDataSet = new ScanDataSet(previewScan);
    spectrumPlot.addDataSet(scanDataSet, SpectraVisualizerWindow.scanColor, false);
    // If the scan is centroided, switch to centroid mode
    spectrumPlot.setPlotMode(previewScan.getSpectrumType());
    // If the parameters are not complete, exit
    ArrayList<String> errors = new ArrayList<String>();
    boolean paramsOK = parameters.checkParameterValues(errors);
    if (!paramsOK)
        return;
    // Get mass list
    String massListName = parameters.getParameter(ShoulderPeaksFilterParameters.massList).getValue();
    MassList massList = previewScan.getMassList(massListName);
    if (massList == null)
        return;
    // Perform filtering
    DataPoint[] mzValues = massList.getDataPoints();
    DataPoint[] remainingMzValues = ShoulderPeaksFilter.filterMassValues(mzValues, parameters);
    Vector<DataPoint> removedPeaks = new Vector<DataPoint>();
    removedPeaks.addAll(Arrays.asList(mzValues));
    removedPeaks.removeAll(Arrays.asList(remainingMzValues));
    DataPoint[] removedMzValues = removedPeaks.toArray(new DataPoint[0]);
    // Add mass list data sets
    DataPointsDataSet removedPeaksDataSet = new DataPointsDataSet("Removed peaks", removedMzValues);
    DataPointsDataSet remainingPeaksDataSet = new DataPointsDataSet("Remaining peaks", remainingMzValues);
    spectrumPlot.addDataSet(removedPeaksDataSet, removedPeaksColor, false);
    spectrumPlot.addDataSet(remainingPeaksDataSet, SpectraVisualizerWindow.peaksColor, false);
}
Also used : ScanDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) Vector(java.util.Vector) MassList(net.sf.mzmine.datamodel.MassList) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)

Example 47 with DataPoint

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

the class ChromatogramBuilderTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started chromatogram builder on " + dataFile);
    scans = scanSelection.getMatchingScans(dataFile);
    int[] allScanNumbers = scanSelection.getMatchingScanNumbers(dataFile);
    totalScans = scans.length;
    // Check if the scans are properly ordered by RT
    double prevRT = Double.NEGATIVE_INFINITY;
    for (Scan s : scans) {
        if (s.getRetentionTime() < prevRT) {
            setStatus(TaskStatus.ERROR);
            final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
            setErrorMessage(msg);
            return;
        }
        prevRT = s.getRetentionTime();
    }
    // Create new feature list
    newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
    Chromatogram[] chromatograms;
    HighestDataPointConnector massConnector = new HighestDataPointConnector(dataFile, allScanNumbers, minimumTimeSpan, minimumHeight, mzTolerance);
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        MassList massList = scan.getMassList(massListName);
        if (massList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
            return;
        }
        DataPoint[] mzValues = massList.getDataPoints();
        if (mzValues == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #" + scan.getScanNumber() + " of file " + dataFile);
            return;
        }
        massConnector.addScan(scan.getScanNumber(), mzValues);
        processedScans++;
    }
    chromatograms = massConnector.finishChromatograms();
    // Sort the final chromatograms by m/z
    Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Add the chromatograms to the new feature list
    for (Feature finishedPeak : chromatograms) {
        SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
        newPeakID++;
        newRow.addPeak(dataFile, finishedPeak);
        newPeakList.addRow(newRow);
    }
    // Add new peaklist to the project
    project.addPeakList(newPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished chromatogram builder on " + dataFile);
}
Also used : Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakSorter(net.sf.mzmine.util.PeakSorter) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) MassList(net.sf.mzmine.datamodel.MassList)

Example 48 with DataPoint

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

the class ShoulderPeaksFilter method filterMassValues.

public static DataPoint[] filterMassValues(DataPoint[] mzPeaks, ParameterSet parameters) {
    double resolution = parameters.getParameter(ShoulderPeaksFilterParameters.resolution).getValue();
    PeakModel peakModel = null;
    // Try to create an instance of the peak model
    try {
        PeakModelType type = parameters.getParameter(ShoulderPeaksFilterParameters.peakModel).getValue();
        if (type == null)
            type = PeakModelType.GAUSS;
        Class<?> modelClass = type.getModelClass();
        peakModel = (PeakModel) modelClass.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // If peakModel is null, just don't do any filtering
    if (peakModel == null)
        return mzPeaks;
    // Create a tree set of detected mzPeaks sorted by MZ in ascending order
    TreeSet<DataPoint> finalMZPeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Create a tree set of candidate mzPeaks sorted by intensity in
    // descending order.
    TreeSet<DataPoint> candidatePeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    candidatePeaks.addAll(Arrays.asList(mzPeaks));
    while (candidatePeaks.size() > 0) {
        // Always take the biggest (intensity) peak
        DataPoint currentCandidate = candidatePeaks.first();
        // Add this candidate to the final tree set sorted by MZ and remove
        // from tree set sorted by intensity
        finalMZPeaks.add(currentCandidate);
        candidatePeaks.remove(currentCandidate);
        // Remove from tree set sorted by intensity all FTMS shoulder peaks,
        // taking as a main peak the current candidate
        removeLateralPeaks(currentCandidate, candidatePeaks, peakModel, resolution);
    }
    return finalMZPeaks.toArray(new DataPoint[0]);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) TreeSet(java.util.TreeSet) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Example 49 with DataPoint

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

the class ShoulderPeaksFilter method removeLateralPeaks.

/**
 * This function remove peaks encountered in the lateral of a main peak (currentCandidate) that
 * are considered as garbage, for example FTMS shoulder peaks.
 *
 * First calculates a peak model (Gauss, Lorenzian, etc) defined by peakModelName parameter, with
 * the same position (m/z) and height (intensity) of the currentCandidate, and the defined
 * resolution (resolution parameter). Second search and remove all the lateral peaks that are
 * under the curve of the modeled peak.
 */
private static void removeLateralPeaks(DataPoint currentCandidate, TreeSet<DataPoint> candidates, PeakModel peakModel, double resolution) {
    // We set our peak model with same position(m/z), height(intensity) and
    // resolution of the current peak
    peakModel.setParameters(currentCandidate.getMZ(), currentCandidate.getIntensity(), resolution);
    // We search over all peak candidates and remove all of them that are
    // under the curve defined by our peak model
    Iterator<DataPoint> candidatesIterator = candidates.iterator();
    while (candidatesIterator.hasNext()) {
        DataPoint lateralCandidate = candidatesIterator.next();
        // Condition in x domain (m/z)
        if ((lateralCandidate.getIntensity() < peakModel.getIntensity(lateralCandidate.getMZ()))) {
            candidatesIterator.remove();
        }
    }
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 50 with DataPoint

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

the class ShoulderPeaksFilterTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started mass filter on " + dataFile);
    scanNumbers = dataFile.getScanNumbers();
    totalScans = scanNumbers.length;
    // Check if we have at least one scan with a mass list of given name
    boolean haveMassList = false;
    for (int i = 0; i < totalScans; i++) {
        Scan scan = dataFile.getScan(scanNumbers[i]);
        MassList massList = scan.getMassList(massListName);
        if (massList != null) {
            haveMassList = true;
            break;
        }
    }
    if (!haveMassList) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage(dataFile.getName() + " has no mass list called '" + massListName + "'");
        return;
    }
    // Process all scans
    for (int i = 0; i < totalScans; i++) {
        if (isCanceled())
            return;
        Scan scan = dataFile.getScan(scanNumbers[i]);
        MassList massList = scan.getMassList(massListName);
        // Skip those scans which do not have a mass list of given name
        if (massList == null) {
            processedScans++;
            continue;
        }
        DataPoint[] mzPeaks = massList.getDataPoints();
        DataPoint[] newMzPeaks = ShoulderPeaksFilter.filterMassValues(mzPeaks, parameters);
        SimpleMassList newMassList = new SimpleMassList(massListName + " " + suffix, scan, newMzPeaks);
        scan.addMassList(newMassList);
        // Remove old mass list
        if (autoRemove)
            scan.removeMassList(massList);
        processedScans++;
    }
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished shoulder peaks filter on " + dataFile);
}
Also used : SimpleMassList(net.sf.mzmine.datamodel.impl.SimpleMassList) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleMassList(net.sf.mzmine.datamodel.impl.SimpleMassList) MassList(net.sf.mzmine.datamodel.MassList)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)214 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)98 Scan (net.sf.mzmine.datamodel.Scan)64 ArrayList (java.util.ArrayList)50 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)44 Feature (net.sf.mzmine.datamodel.Feature)27 MassList (net.sf.mzmine.datamodel.MassList)24 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)22 IOException (java.io.IOException)20 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)18 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)17 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)16 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)15 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)15 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)12 DataPointSorter (net.sf.mzmine.util.DataPointSorter)12 HashMap (java.util.HashMap)10 Vector (java.util.Vector)10 Range (com.google.common.collect.Range)8 TreeMap (java.util.TreeMap)8