Search in sources :

Example 1 with DataPointsDataSet

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet in project mzmine2 by mzmine.

the class ScanSelectPanel method createChart.

/**
 * Create chart of selected scan
 */
public void createChart() {
    setValidSelection(false);
    pnChart.removeAll();
    if (scans != null && !scans.isEmpty()) {
        if (spectrumPlot == null) {
            spectrumPlot = new SpectraPlot(this, false);
            if (listener != null)
                // chart has changed
                listener.accept(spectrumPlot);
        }
        spectrumPlot.removeAllDataSets();
        DataPointsDataSet data = new DataPointsDataSet("Data", getFilteredDataPoints());
        // green
        spectrumPlot.addDataSet(data, colorUsedData, false);
        if (showRemovedData) {
            // orange
            DataPointsDataSet dataRemoved = new DataPointsDataSet("Removed", getFilteredDataPointsRemoved());
            spectrumPlot.addDataSet(dataRemoved, colorRemovedData, false);
        }
        spectrumPlot.getChart().getLegend().setVisible(showLegend);
        spectrumPlot.setMaximumSize(new Dimension(chartSize.width, 10000));
        spectrumPlot.setPreferredSize(chartSize);
        pnChart.add(spectrumPlot, BorderLayout.CENTER);
        Scan scan = scans.get(selectedScanI);
        analyzeScan(scan);
        applySelectionState();
        setValidSelection(true);
    } else {
        // add error label
        JLabel error = new JLabel(MessageFormat.format("NO MS2 SPECTRA: 0 of {0} match the minimum criteria", getTotalScans()));
        error.setFont(new Font("Tahoma", Font.BOLD, 13));
        error.setHorizontalAlignment(SwingConstants.CENTER);
        error.setForeground(new Color(220, 20, 60));
        pnChart.add(error, BorderLayout.CENTER);
    // 
    }
    // set next and prev button enabled
    btnPrev.setEnabled(selectedScanI - 1 >= 0);
    btnNext.setEnabled(scans != null && selectedScanI + 1 < scans.size());
    revalidate();
    repaint();
}
Also used : Color(java.awt.Color) JLabel(javax.swing.JLabel) SpectraPlot(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot) Scan(net.sf.mzmine.datamodel.Scan) Dimension(java.awt.Dimension) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) Font(java.awt.Font)

Example 2 with DataPointsDataSet

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet 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 3 with DataPointsDataSet

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet 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 4 with DataPointsDataSet

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet in project mzmine2 by mzmine.

the class MassDetectorSetupDialog method loadPreview.

protected void loadPreview(SpectraPlot spectrumPlot, Scan previewScan) {
    ScanDataSet spectraDataSet = new ScanDataSet(previewScan);
    // Set plot mode only if it hasn't been set before
    // if the scan is centroided, switch to centroid mode
    spectrumPlot.setPlotMode(previewScan.getSpectrumType());
    spectrumPlot.removeAllDataSets();
    spectrumPlot.addDataSet(spectraDataSet, SpectraVisualizerWindow.scanColor, false);
    // If there is some illegal value, do not load the preview but just exit
    ArrayList<String> errorMessages = new ArrayList<String>();
    boolean paramsOK = parameterSet.checkParameterValues(errorMessages);
    if (!paramsOK)
        return;
    DataPoint[] mzValues = massDetector.getMassValues(previewScan, parameters);
    DataPointsDataSet peaksDataSet = new DataPointsDataSet("Detected peaks", mzValues);
    spectrumPlot.addDataSet(peaksDataSet, 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) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)

Example 5 with DataPointsDataSet

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet in project mzmine2 by mzmine.

the class SpectraIdentificationOnlineDatabaseTask 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);
    }
    numItems = massList.length;
    for (int i = 0; i < massList.length; i++) {
        // loop through every peak in mass list
        if (getStatus() != TaskStatus.PROCESSING) {
            return;
        }
        searchedMass = massList[i].getMZ() - ionType.getAddedMass();
        try {
            // find candidate compounds
            String[] compoundIDs = gateway.findCompounds(searchedMass, mzTolerance, 1, db.getParameterSet());
            // Combine strings
            String annotation = "";
            // max number of compounds to top three for visualization
            int counter = 0;
            for (int j = 0; !isCanceled() && j < compoundIDs.length; j++) {
                final DBCompound compound = gateway.getCompound(compoundIDs[j], db.getParameterSet());
                // In case we failed to retrieve data, skip this compound
                if (compound == null)
                    continue;
                if (counter < 3) {
                    int number = counter + 1;
                    annotation = annotation + " " + number + ". " + compound.getName();
                    counter++;
                }
            }
            if (annotation != "") {
                allCompoundIDs.add(annotation);
                massListAnnotated.add(massList[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.log(Level.WARNING, "Could not connect to " + db, e);
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Could not connect to " + db + ": " + ExceptionUtils.exceptionToString(e));
            return;
        }
        finishedItems++;
    }
    // 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) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) 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)

Aggregations

DataPointsDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)8 DataPoint (net.sf.mzmine.datamodel.DataPoint)7 ArrayList (java.util.ArrayList)6 MassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector)4 CentroidMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector)4 CentroidMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters)4 ExactMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector)4 ExactMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters)4 SpectraDatabaseSearchLabelGenerator (net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)4 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)4 Color (java.awt.Color)3 Scan (net.sf.mzmine.datamodel.Scan)2 SpectraPlot (net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot)2 ScanDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet)2 Range (com.google.common.collect.Range)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 FileReader (java.io.FileReader)1 NumberFormat (java.text.NumberFormat)1 Comparator (java.util.Comparator)1