Search in sources :

Example 26 with IsotopePattern

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

the class FormulaPredictionPeakListTask method checkConstraints.

private boolean checkConstraints(IMolecularFormula cdkFormula, PeakListRow peakListRow) {
    // Check elemental ratios
    if (checkRatios) {
        boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
        if (!check) {
            return false;
        }
    }
    Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
    // Check RDBE condition
    if (checkRDBE && (rdbeValue != null)) {
        boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
        if (!check) {
            return false;
        }
    }
    // Calculate isotope similarity score
    IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
    IsotopePattern predictedIsotopePattern = null;
    Double isotopeScore = null;
    if ((checkIsotopes) && (detectedPattern != null)) {
        String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
        String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
        final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
        final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
        final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
        predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
        isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
        final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
        if (isotopeScore < minScore) {
            return false;
        }
    }
    // MS/MS evaluation is slowest, so let's do it last
    Double msmsScore = null;
    Feature bestPeak = peakListRow.getBestPeak();
    RawDataFile dataFile = bestPeak.getDataFile();
    int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
    if ((checkMSMS) && (msmsScanNumber > 0)) {
        Scan msmsScan = dataFile.getScan(msmsScanNumber);
        String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
        MassList ms2MassList = msmsScan.getMassList(massListName);
        if (ms2MassList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
            return false;
        }
        MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
        double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
        if (score != null) {
            msmsScore = score.getScore();
            // Check the MS/MS condition
            if (msmsScore < minMSMSScore) {
                return false;
            }
        }
    }
    return true;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Scan(net.sf.mzmine.datamodel.Scan) Feature(net.sf.mzmine.datamodel.Feature) MassList(net.sf.mzmine.datamodel.MassList) MSMSScore(net.sf.mzmine.modules.peaklistmethods.msms.msmsscore.MSMSScore)

Example 27 with IsotopePattern

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

the class AdapMgfExportTask method exportPeakList.

private void exportPeakList(PeakList peakList, FileWriter writer) throws IOException {
    for (PeakListRow row : peakList.getRows()) {
        IsotopePattern ip = row.getBestIsotopePattern();
        if (ip == null)
            continue;
        exportRow(writer, row, ip);
        finishedRows++;
    }
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern)

Example 28 with IsotopePattern

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

the class PeakListSaveHandler method fillPeakElement.

/**
 * Add the peaks information into the XML document
 *
 * @param peak
 * @param element
 * @param dataFileID
 * @throws IOException
 */
private void fillPeakElement(Feature peak, TransformerHandler hd) throws SAXException, IOException {
    AttributesImpl atts = new AttributesImpl();
    // <REPRESENTATIVE_SCAN>
    hd.startElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName(), atts);
    hd.characters(String.valueOf(peak.getRepresentativeScanNumber()).toCharArray(), 0, String.valueOf(peak.getRepresentativeScanNumber()).length());
    hd.endElement("", "", PeakListElementName.REPRESENTATIVE_SCAN.getElementName());
    // <FRAGMENT_SCAN>
    hd.startElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName(), atts);
    hd.characters(String.valueOf(peak.getMostIntenseFragmentScanNumber()).toCharArray(), 0, String.valueOf(peak.getMostIntenseFragmentScanNumber()).length());
    hd.endElement("", "", PeakListElementName.FRAGMENT_SCAN.getElementName());
    // <ALL_MS2_FRAGMENT_SCANS>
    fillAllMS2FragmentScanNumbers(peak.getAllMS2FragmentScanNumbers(), hd);
    int[] scanNumbers = peak.getScanNumbers();
    // <ISOTOPE_PATTERN>
    IsotopePattern isotopePattern = peak.getIsotopePattern();
    if (isotopePattern != null) {
        atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", String.valueOf(isotopePattern.getStatus()));
        atts.addAttribute("", "", PeakListElementName.DESCRIPTION.getElementName(), "CDATA", isotopePattern.getDescription());
        hd.startElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName(), atts);
        atts.clear();
        fillIsotopePatternElement(isotopePattern, hd);
        hd.endElement("", "", PeakListElementName.ISOTOPE_PATTERN.getElementName());
    }
    // <MZPEAK>
    atts.addAttribute("", "", PeakListElementName.QUANTITY.getElementName(), "CDATA", String.valueOf(scanNumbers.length));
    hd.startElement("", "", PeakListElementName.MZPEAKS.getElementName(), atts);
    atts.clear();
    // <SCAN_ID> <MASS> <HEIGHT>
    ByteArrayOutputStream byteScanStream = new ByteArrayOutputStream();
    DataOutputStream dataScanStream = new DataOutputStream(byteScanStream);
    ByteArrayOutputStream byteMassStream = new ByteArrayOutputStream();
    DataOutputStream dataMassStream = new DataOutputStream(byteMassStream);
    ByteArrayOutputStream byteHeightStream = new ByteArrayOutputStream();
    DataOutputStream dataHeightStream = new DataOutputStream(byteHeightStream);
    float mass, height;
    for (int scan : scanNumbers) {
        dataScanStream.writeInt(scan);
        dataScanStream.flush();
        DataPoint mzPeak = peak.getDataPoint(scan);
        if (mzPeak != null) {
            mass = (float) mzPeak.getMZ();
            height = (float) mzPeak.getIntensity();
        } else {
            mass = 0f;
            height = 0f;
        }
        dataMassStream.writeFloat(mass);
        dataMassStream.flush();
        dataHeightStream.writeFloat(height);
        dataHeightStream.flush();
    }
    byte[] bytes = Base64.encode(byteScanStream.toByteArray());
    hd.startElement("", "", PeakListElementName.SCAN_ID.getElementName(), atts);
    String sbytes = new String(bytes);
    hd.characters(sbytes.toCharArray(), 0, sbytes.length());
    hd.endElement("", "", PeakListElementName.SCAN_ID.getElementName());
    bytes = Base64.encode(byteMassStream.toByteArray());
    hd.startElement("", "", PeakListElementName.MZ.getElementName(), atts);
    sbytes = new String(bytes);
    hd.characters(sbytes.toCharArray(), 0, sbytes.length());
    hd.endElement("", "", PeakListElementName.MZ.getElementName());
    bytes = Base64.encode(byteHeightStream.toByteArray());
    hd.startElement("", "", PeakListElementName.HEIGHT.getElementName(), atts);
    sbytes = new String(bytes);
    hd.characters(sbytes.toCharArray(), 0, sbytes.length());
    hd.endElement("", "", PeakListElementName.HEIGHT.getElementName());
    hd.endElement("", "", PeakListElementName.MZPEAKS.getElementName());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataOutputStream(java.io.DataOutputStream) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 29 with IsotopePattern

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

the class SpectraVisualizerWindow method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("PEAKLIST_CHANGE")) {
        // If no scan is loaded yet, ignore
        if (currentScan == null)
            return;
        PeakList selectedPeakList = bottomPanel.getSelectedPeakList();
        loadPeaks(selectedPeakList);
    }
    if (command.equals("PREVIOUS_SCAN")) {
        if (dataFile == null)
            return;
        int msLevel = currentScan.getMSLevel();
        int[] scanNumbers = dataFile.getScanNumbers(msLevel);
        int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
        if (scanIndex > 0) {
            final int prevScanIndex = scanNumbers[scanIndex - 1];
            Runnable newThreadRunnable = new Runnable() {

                @Override
                public void run() {
                    loadRawData(dataFile.getScan(prevScanIndex));
                }
            };
            Thread newThread = new Thread(newThreadRunnable);
            newThread.start();
        }
    }
    if (command.equals("NEXT_SCAN")) {
        if (dataFile == null)
            return;
        int msLevel = currentScan.getMSLevel();
        int[] scanNumbers = dataFile.getScanNumbers(msLevel);
        int scanIndex = Arrays.binarySearch(scanNumbers, currentScan.getScanNumber());
        if (scanIndex < (scanNumbers.length - 1)) {
            final int nextScanIndex = scanNumbers[scanIndex + 1];
            Runnable newThreadRunnable = new Runnable() {

                @Override
                public void run() {
                    loadRawData(dataFile.getScan(nextScanIndex));
                }
            };
            Thread newThread = new Thread(newThreadRunnable);
            newThread.start();
        }
    }
    if (command.equals("SHOW_MSMS")) {
        String selectedScanString = (String) bottomPanel.getMSMSSelector().getSelectedItem();
        if (selectedScanString == null)
            return;
        int sharpIndex = selectedScanString.indexOf('#');
        int commaIndex = selectedScanString.indexOf(',');
        selectedScanString = selectedScanString.substring(sharpIndex + 1, commaIndex);
        int selectedScan = Integer.valueOf(selectedScanString);
        SpectraVisualizerModule.showNewSpectrumWindow(dataFile, selectedScan);
    }
    if (command.equals("TOGGLE_PLOT_MODE")) {
        if (spectrumPlot.getPlotMode() == MassSpectrumType.CENTROIDED) {
            spectrumPlot.setPlotMode(MassSpectrumType.PROFILE);
            toolBar.setCentroidButton(MassSpectrumType.PROFILE);
        } else {
            spectrumPlot.setPlotMode(MassSpectrumType.CENTROIDED);
            toolBar.setCentroidButton(MassSpectrumType.CENTROIDED);
        }
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        spectrumPlot.switchDataPointsVisible();
    }
    if (command.equals("SHOW_ANNOTATIONS")) {
        spectrumPlot.switchItemLabelsVisible();
    }
    if (command.equals("SHOW_PICKED_PEAKS")) {
        spectrumPlot.switchPickedPeaksVisible();
    }
    if (command.equals("SHOW_ISOTOPE_PEAKS")) {
        spectrumPlot.switchIsotopePeaksVisible();
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, spectrumPlot.getXYPlot());
        dialog.setVisible(true);
    }
    // library entry creation
    if (command.equals("CREATE_LIBRARY_ENTRY")) {
        // open window with all selected rows
        MSMSLibrarySubmissionWindow libraryWindow = new MSMSLibrarySubmissionWindow();
        libraryWindow.setData(currentScan);
        libraryWindow.setVisible(true);
    }
    if (command.equals("EXPORT_SPECTRA")) {
        ExportScansModule.showSetupDialog(currentScan);
    }
    if (command.equals("ADD_ISOTOPE_PATTERN")) {
        IsotopePattern newPattern = IsotopePatternCalculator.showIsotopePredictionDialog(this, true);
        if (newPattern == null)
            return;
        loadIsotopes(newPattern);
    }
    if ((command.equals("ZOOM_IN")) || (command.equals("ZOOM_IN_BOTH_COMMAND"))) {
        spectrumPlot.getXYPlot().getDomainAxis().resizeRange(1 / zoomCoefficient);
    }
    if ((command.equals("ZOOM_OUT")) || (command.equals("ZOOM_OUT_BOTH_COMMAND"))) {
        spectrumPlot.getXYPlot().getDomainAxis().resizeRange(zoomCoefficient);
    }
    if (command.equals("SET_SAME_RANGE")) {
        // Get current axes range
        NumberAxis xAxis = (NumberAxis) spectrumPlot.getXYPlot().getDomainAxis();
        NumberAxis yAxis = (NumberAxis) spectrumPlot.getXYPlot().getRangeAxis();
        double xMin = xAxis.getRange().getLowerBound();
        double xMax = xAxis.getRange().getUpperBound();
        double xTick = xAxis.getTickUnit().getSize();
        double yMin = yAxis.getRange().getLowerBound();
        double yMax = yAxis.getRange().getUpperBound();
        double yTick = yAxis.getTickUnit().getSize();
        // Get all frames of my class
        Window[] spectraFrames = JFrame.getWindows();
        // Set the range of these frames
        for (Window frame : spectraFrames) {
            if (!(frame instanceof SpectraVisualizerWindow))
                continue;
            SpectraVisualizerWindow spectraFrame = (SpectraVisualizerWindow) frame;
            spectraFrame.setAxesRange(xMin, xMax, xTick, yMin, yMax, yTick);
        }
    }
    if (command.equals("ONLINEDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                OnlineDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("CUSTOMDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                CustomDBSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("LIPIDSEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                LipidSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SUMFORMULA")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SumFormulaSpectraSearchModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SPECTRALDATABASESEARCH")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SpectraIdentificationSpectralDatabaseModule.showSpectraIdentificationDialog(currentScan, spectrumPlot);
            }
        });
    }
    if (command.equals("SET_PROCESSING_PARAMETERS")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                if (!dppmWindowOpen) {
                    dppmWindowOpen = true;
                    ExitCode exitCode = DataPointProcessingManager.getInst().getParameters().showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
                    dppmWindowOpen = false;
                    if (exitCode == ExitCode.OK && DataPointProcessingManager.getInst().isEnabled()) {
                        // if processing was run before, this removes the previous results.
                        getSpectrumPlot().removeDataPointProcessingResultDataSets();
                        getSpectrumPlot().checkAndRunController();
                    }
                }
            }
        });
    }
    if (command.equals("ENABLE_PROCESSING")) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                DataPointProcessingManager inst = DataPointProcessingManager.getInst();
                inst.setEnabled(!inst.isEnabled());
                bottomPanel.updateProcessingButton();
                getSpectrumPlot().checkAndRunController();
                // if the tick is removed, set the data back to default
                if (!inst.isEnabled()) {
                    getSpectrumPlot().removeDataPointProcessingResultDataSets();
                // loadRawData(currentScan);
                }
            }
        });
    }
}
Also used : MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) Window(java.awt.Window) NumberAxis(org.jfree.chart.axis.NumberAxis) MSMSLibrarySubmissionWindow(net.sf.mzmine.modules.peaklistmethods.io.spectraldbsubmit.view.MSMSLibrarySubmissionWindow) ExitCode(net.sf.mzmine.util.ExitCode) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) DataPointProcessingManager(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.DataPointProcessingManager) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 30 with IsotopePattern

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

the class PseudoSpectrum method createDataSet.

public static PseudoSpectrumDataSet createDataSet(PeakListRow[] group, RawDataFile raw, boolean sum) {
    // data
    PseudoSpectrumDataSet series = new PseudoSpectrumDataSet(true, "pseudo");
    // add all isotopes as a second series:
    XYSeries isoSeries = new XYSeries("Isotopes", true);
    // raw isotopes in a different color
    XYSeries rawIsoSeries = new XYSeries("Raw isotope pattern", true);
    // for each row
    for (PeakListRow row : group) {
        String annotation = null;
        // sum -> heighest peak
        if (sum)
            series.addDP(row.getAverageMZ(), row.getBestPeak().getHeight(), annotation);
        else {
            Feature f = raw == null ? row.getBestPeak() : row.getPeak(raw);
            if (f != null)
                series.addDP(f.getMZ(), f.getHeight(), null);
        }
        // add isotopes
        IsotopePattern pattern = row.getBestIsotopePattern();
        if (pattern != null) {
            for (DataPoint dp : pattern.getDataPoints()) isoSeries.add(dp.getMZ(), dp.getIntensity());
        }
    }
    series.addSeries(isoSeries);
    series.addSeries(rawIsoSeries);
    return series;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Feature(net.sf.mzmine.datamodel.Feature)

Aggregations

IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)19 Feature (net.sf.mzmine.datamodel.Feature)14 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)8 ArrayList (java.util.ArrayList)7 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 HashMap (java.util.HashMap)3 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)3 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Component (dulab.adap.datamodel.Component)2 Peak (dulab.adap.datamodel.Peak)2 PeakInfo (dulab.adap.datamodel.PeakInfo)2