Search in sources :

Example 1 with SpectraPlot

use of net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot 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 SpectraPlot

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

the class SpectraIdentificationSumFormulaTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.finest("Starting search for formulas for " + massRange + " Da");
    // 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;
    // loop through every peak in mass list
    if (getStatus() != TaskStatus.PROCESSING) {
        return;
    }
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    for (int i = 0; i < massList.length; i++) {
        massRange = mzTolerance.getToleranceRange((massList[i].getMZ() - ionType.getAddedMass()) / charge);
        generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
        IMolecularFormula cdkFormula;
        String annotation = "";
        // create a map to store ResultFormula and relative mass deviation for sorting
        Map<Double, String> possibleFormulas = new TreeMap<>();
        while ((cdkFormula = generator.getNextFormula()) != null) {
            if (isCanceled())
                return;
            // Mass is ok, so test other constraints
            if (checkConstraints(cdkFormula) == true) {
                String formula = MolecularFormulaManipulator.getString(cdkFormula);
                // calc rel mass deviation
                Double relMassDev = ((((// 
                massList[i].getMZ() - ionType.getAddedMass()) / // 
                charge) - (// 
                FormulaUtils.calculateExactMass(MolecularFormulaManipulator.getString(cdkFormula))) / charge) / ((// 
                massList[i].getMZ() - ionType.getAddedMass()) / charge)) * 1000000;
                // write to map
                possibleFormulas.put(relMassDev, formula);
            }
        }
        Map<Double, String> treeMap = new TreeMap<>((Comparator<Double>) (o1, o2) -> Double.compare(Math.abs(o1), Math.abs(o2)));
        treeMap.putAll(possibleFormulas);
        // get top 3
        int ctr = 0;
        for (Map.Entry<Double, String> entry : treeMap.entrySet()) {
            int number = ctr + 1;
            if (ctr > 2)
                break;
            annotation = annotation + number + ". " + entry.getValue() + " Δ " + NumberFormat.getInstance().format(entry.getKey()) + " ppm; ";
            ctr++;
            if (isCanceled())
                return;
        }
        if (annotation != "") {
            allCompoundIDs.add(annotation);
            massListAnnotated.add(massList[i]);
        }
        logger.finest("Finished formula search for " + massRange + " m/z, found " + foundFormulas + " formulas");
    }
    // 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 : Color(java.awt.Color) Scan(net.sf.mzmine.datamodel.Scan) MZmineCore(net.sf.mzmine.main.MZmineCore) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RDBERestrictionChecker(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.restrictions.rdbe.RDBERestrictionChecker) TextAnchor(org.jfree.chart.ui.TextAnchor) MolecularFormulaManipulator(org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator) NumberFormat(java.text.NumberFormat) DataPoint(net.sf.mzmine.datamodel.DataPoint) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) ArrayList(java.util.ArrayList) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Map(java.util.Map) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) FormulaUtils(net.sf.mzmine.util.FormulaUtils) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) SilentChemObjectBuilder(org.openscience.cdk.silent.SilentChemObjectBuilder) Range(com.google.common.collect.Range) Logger(java.util.logging.Logger) IonizationType(net.sf.mzmine.datamodel.IonizationType) ElementalHeuristicChecker(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.restrictions.elements.ElementalHeuristicChecker) MassSpectrumType(net.sf.mzmine.datamodel.MassSpectrumType) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) TreeMap(java.util.TreeMap) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) Comparator(java.util.Comparator) ItemLabelAnchor(org.jfree.chart.labels.ItemLabelAnchor) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) SpectraPlot(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) ArrayList(java.util.ArrayList) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) DataPoint(net.sf.mzmine.datamodel.DataPoint) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) 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) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) TreeMap(java.util.TreeMap) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) DataPoint(net.sf.mzmine.datamodel.DataPoint) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) Map(java.util.Map) TreeMap(java.util.TreeMap) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 3 with SpectraPlot

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

the class ParameterSetupDialogWithScanPreview method addDialogComponents.

/**
 * This function add all the additional components for this dialog over the original
 * ParameterSetupDialog.
 */
@Override
protected void addDialogComponents() {
    super.addDialogComponents();
    dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
    if (dataFiles.length == 0)
        return;
    RawDataFile[] selectedFiles = MZmineCore.getDesktop().getSelectedDataFiles();
    if (selectedFiles.length > 0)
        previewDataFile = selectedFiles[0];
    else
        previewDataFile = dataFiles[0];
    previewCheckBox = new JCheckBox("Show preview");
    previewCheckBox.addActionListener(this);
    previewCheckBox.setHorizontalAlignment(SwingConstants.CENTER);
    mainPanel.add(new JSeparator(), 0, getNumberOfParameters() + 1, 3, 1, 0, 0, GridBagConstraints.HORIZONTAL);
    mainPanel.add(previewCheckBox, 0, getNumberOfParameters() + 2, 3, 1, 0, 0, GridBagConstraints.HORIZONTAL);
    // Elements of pnlLab
    JPanel pnlLab = new JPanel();
    pnlLab.setLayout(new BoxLayout(pnlLab, BoxLayout.Y_AXIS));
    pnlLab.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    pnlLab.add(new JLabel("Data file "));
    pnlLab.add(Box.createVerticalStrut(25));
    pnlLab.add(new JLabel("Scan number "));
    // Elements of pnlFlds
    JPanel pnlFlds = new JPanel();
    pnlFlds.setLayout(new BoxLayout(pnlFlds, BoxLayout.Y_AXIS));
    pnlFlds.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    comboDataFileName = new JComboBox<RawDataFile>(dataFiles);
    comboDataFileName.setSelectedItem(previewDataFile);
    comboDataFileName.addActionListener(this);
    int[] scanNumbers = previewDataFile.getScanNumbers();
    Integer[] scanNumbersObj = CollectionUtils.toIntegerArray(scanNumbers);
    comboScanNumber = new JComboBox<Integer>(scanNumbersObj);
    comboScanNumber.setSelectedIndex(0);
    comboScanNumber.addActionListener(this);
    pnlFlds.add(comboDataFileName);
    pnlFlds.add(Box.createVerticalStrut(10));
    // --> Elements of pnlScanArrows
    JPanel pnlScanArrows = new JPanel();
    pnlScanArrows.setLayout(new BoxLayout(pnlScanArrows, BoxLayout.X_AXIS));
    String leftArrow = new String(new char[] { '\u2190' });
    GUIUtils.addButton(pnlScanArrows, leftArrow, null, this, "PREVIOUS_SCAN");
    pnlScanArrows.add(Box.createHorizontalStrut(5));
    pnlScanArrows.add(comboScanNumber);
    pnlScanArrows.add(Box.createHorizontalStrut(5));
    String rightArrow = new String(new char[] { '\u2192' });
    GUIUtils.addButton(pnlScanArrows, rightArrow, null, this, "NEXT_SCAN");
    pnlFlds.add(pnlScanArrows);
    // Put all together
    pnlPreviewFields = new JPanel(new BorderLayout());
    pnlPreviewFields.add(pnlLab, BorderLayout.WEST);
    pnlPreviewFields.add(pnlFlds, BorderLayout.CENTER);
    pnlPreviewFields.setVisible(false);
    spectrumPlot = new SpectraPlot(this);
    spectrumPlot.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
    spectrumPlot.setMinimumSize(new Dimension(400, 300));
    mainPanel.add(pnlPreviewFields, 0, getNumberOfParameters() + 3, 3, 1, 0, 0);
    updateMinimumSize();
    pack();
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JSeparator(javax.swing.JSeparator) JCheckBox(javax.swing.JCheckBox) BorderLayout(java.awt.BorderLayout) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SpectraPlot(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot)

Aggregations

SpectraPlot (net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot)3 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 JLabel (javax.swing.JLabel)2 Scan (net.sf.mzmine.datamodel.Scan)2 DataPointsDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)2 Range (com.google.common.collect.Range)1 BorderLayout (java.awt.BorderLayout)1 Font (java.awt.Font)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Logger (java.util.logging.Logger)1 BoxLayout (javax.swing.BoxLayout)1 JCheckBox (javax.swing.JCheckBox)1 JPanel (javax.swing.JPanel)1 JSeparator (javax.swing.JSeparator)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1