Search in sources :

Example 41 with DataPoint

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

the class SpectraIdentificationLipidSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    // create mass list for scan
    DataPoint[] massList = null;
    ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
    MassDetector massDetector = null;
    ArrayList<String> allCompoundIDs = new ArrayList<>();
    // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
    if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
        massDetector = new CentroidMassDetector();
        CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
        CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    } else {
        massDetector = new ExactMassDetector();
        ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
        ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    }
    totalSteps = massList.length;
    // loop through every peak in mass list
    if (getStatus() != TaskStatus.PROCESSING) {
        return;
    }
    // Check if lipids should be modified
    if (searchForModifications == true) {
        lipidModificationMasses = getLipidModificationMasses(lipidModification);
    }
    // Calculate how many possible lipids we will try
    totalSteps = (((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length);
    // Combine Strings
    String annotation = "";
    // Try all combinations of fatty acid lengths and double bonds
    for (int j = 0; j < selectedLipids.length; j++) {
        int numberOfAcylChains = selectedLipids[j].getNumberOfAcylChains();
        int numberOfAlkylChains = selectedLipids[j].getNumberofAlkyChains();
        for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
            for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
                for (int i = 0; i < massList.length; i++) {
                    searchedMass = massList[i].getMZ();
                    // Task canceled?
                    if (isCanceled())
                        return;
                    // than minimal length, skip this lipid
                    if (((chainLength > 0) && (chainLength < minChainLength))) {
                        continue;
                    }
                    // doesn't make sense, so let's skip such lipids
                    if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
                        continue;
                    }
                    // Prepare a lipid instance
                    LipidIdentity lipidChain = new LipidIdentity(selectedLipids[j], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
                    annotation = findPossibleLipid(lipidChain, searchedMass);
                    if (annotation != "") {
                        allCompoundIDs.add(annotation);
                        massListAnnotated.add(massList[i]);
                    }
                    annotation = findPossibleLipidModification(lipidChain, searchedMass);
                    if (annotation != "") {
                        allCompoundIDs.add(annotation);
                        massListAnnotated.add(massList[i]);
                    }
                }
                finishedSteps++;
            }
        }
    }
    // new mass list
    DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
    massListAnnotated.toArray(annotatedMassList);
    String[] annotations = new String[annotatedMassList.length];
    allCompoundIDs.toArray(annotations);
    DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
    // Add label generator for the dataset
    SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
    spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
    setStatus(TaskStatus.FINISHED);
}
Also used : CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) LipidIdentity(net.sf.mzmine.modules.peaklistmethods.identification.lipididentification.lipidutils.LipidIdentity) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 42 with DataPoint

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

the class DPPMassDetectionTask method run.

@Override
public void run() {
    if (!checkParameterSet() || !checkValues()) {
        setStatus(TaskStatus.ERROR);
        return;
    }
    if (getStatus() == TaskStatus.CANCELED) {
        return;
    }
    setStatus(TaskStatus.PROCESSING);
    MassDetector detector = massDetector.getModule();
    DataPoint[] masses = detector.getMassValues(getDataPoints(), massDetector.getParameterSet());
    if (masses == null || masses.length <= 0) {
        Logger.info("Data point/Spectra processing: No masses were detected with the given parameters.");
        setStatus(TaskStatus.CANCELED);
        return;
    }
    ProcessedDataPoint[] dp = ProcessedDataPoint.convert(masses);
    currentIndex = dataPoints.length;
    setResults(dp);
    setStatus(TaskStatus.FINISHED);
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector)

Example 43 with DataPoint

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

the class SpectralMatchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    // check for mass list
    DataPoint[] spectraMassList;
    try {
        spectraMassList = getDataPoints(currentScan);
    } catch (MissingMassListException e) {
        // no mass list
        setStatus(TaskStatus.ERROR);
        setErrorMessage(MessageFormat.format("No masslist for name: {0} in scan {1} of raw file {2}", massListName, currentScan.getScanNumber(), currentScan.getDataFile().getName()));
        return;
    }
    // remove 13C isotopes
    if (removeIsotopes)
        spectraMassList = removeIsotopes(spectraMassList);
    setStatus(TaskStatus.PROCESSING);
    try {
        totalSteps = list.size();
        matches = new ArrayList<>();
        for (SpectralDBEntry ident : list) {
            if (isCanceled()) {
                logger.info("Added " + count + " spectral library matches (before being cancelled)");
                repaintWindow();
                return;
            }
            SpectralSimilarity sim = spectraDBMatch(spectraMassList, ident);
            if (sim != null && (!needsIsotopePattern || checkForIsotopePattern(sim, mzToleranceSpectra, minMatchedIsoSignals))) {
                count++;
                // use SpectralDBPeakIdentity to store all results similar to peaklist method
                matches.add(new SpectralDBPeakIdentity(currentScan, massListName, ident, sim, SpectraIdentificationSpectralDatabaseModule.MODULE_NAME));
            }
            // next row
            finishedSteps++;
        }
        addIdentities(matches);
        logger.info("Added " + count + " spectral library matches");
        // check if no match was found
        if (count == 0) {
            logger.log(Level.WARNING, "No data base matches found");
            setErrorMessage("No data base matches found. Spectral data base matching failed");
            list = null;
            return;
        }
    } catch (Exception e) {
        setStatus(TaskStatus.ERROR);
        logger.log(Level.SEVERE, "Spectral data base matching failed", e);
        setErrorMessage("Spectral data base matching failed");
        return;
    }
    // Repaint the window to reflect the change in the feature list
    repaintWindow();
    list = null;
    setStatus(TaskStatus.FINISHED);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SpectralDBPeakIdentity(net.sf.mzmine.util.spectraldb.entry.SpectralDBPeakIdentity) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) SpectralDBEntry(net.sf.mzmine.util.spectraldb.entry.SpectralDBEntry) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException)

Example 44 with DataPoint

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

the class DPPIsotopeGrouperTask method compressIsotopeDataSets.

/**
 * This method generates a single IsotopesDataSet from all detected isotope patterns in the
 * results.
 *
 * @param dataPoints
 * @return
 */
private IsotopesDataSet compressIsotopeDataSets(ProcessedDataPoint[] dataPoints) {
    List<IsotopePattern> list = new ArrayList<>();
    for (ProcessedDataPoint dp : dataPoints) {
        if (dp.resultTypeExists(ResultType.ISOTOPEPATTERN)) {
            list.add(((DPPIsotopePatternResult) dp.getFirstResultByType(ResultType.ISOTOPEPATTERN)).getValue());
        }
    }
    if (list.isEmpty())
        return null;
    List<DataPoint> dpList = new ArrayList<>();
    for (IsotopePattern pattern : list) {
        for (DataPoint dp : pattern.getDataPoints()) dpList.add(dp);
    }
    if (dpList.isEmpty())
        return null;
    IsotopePattern full = new SimpleIsotopePattern(dpList.toArray(new DataPoint[0]), IsotopePatternStatus.DETECTED, "Isotope patterns");
    return new IsotopesDataSet(full);
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) IsotopesDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet)

Example 45 with DataPoint

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

the class HighestDataPointConnector method addScan.

public void addScan(int scanNumber, DataPoint[] mzValues) {
    // Sort m/z peaks by descending intensity
    Arrays.sort(mzValues, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    // Set of already connected chromatograms in each iteration
    Set<Chromatogram> connectedChromatograms = new LinkedHashSet<Chromatogram>();
    // TODO: these two nested cycles should be optimized for speed
    for (DataPoint mzPeak : mzValues) {
        // Search for best chromatogram, which has highest last data point
        Chromatogram bestChromatogram = null;
        for (Chromatogram testChrom : buildingChromatograms) {
            DataPoint lastMzPeak = testChrom.getLastMzPeak();
            Range<Double> toleranceRange = mzTolerance.getToleranceRange(lastMzPeak.getMZ());
            if (toleranceRange.contains(mzPeak.getMZ())) {
                if ((bestChromatogram == null) || (testChrom.getLastMzPeak().getIntensity() > bestChromatogram.getLastMzPeak().getIntensity())) {
                    bestChromatogram = testChrom;
                }
            }
        }
        // haven't found a chromatogram, we may create a new one.
        if (bestChromatogram != null) {
            if (connectedChromatograms.contains(bestChromatogram)) {
                continue;
            }
        } else {
            bestChromatogram = new Chromatogram(dataFile, allScanNumbers);
        }
        // Add this mzPeak to the chromatogram
        bestChromatogram.addMzPeak(scanNumber, mzPeak);
        // Move the chromatogram to the set of connected chromatograms
        connectedChromatograms.add(bestChromatogram);
    }
    // Process those chromatograms which were not connected to any m/z peak
    for (Chromatogram testChrom : buildingChromatograms) {
        // Skip those which were connected
        if (connectedChromatograms.contains(testChrom)) {
            continue;
        }
        // Check if we just finished a long-enough segment
        if (testChrom.getBuildingSegmentLength() >= minimumTimeSpan) {
            testChrom.commitBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
        // Check if we have any committed segments in the chromatogram
        if (testChrom.getNumberOfCommittedSegments() > 0) {
            testChrom.removeBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
    }
    // All remaining chromatograms in buildingChromatograms are discarded
    // and buildingChromatograms is replaced with connectedChromatograms
    buildingChromatograms = connectedChromatograms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

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