Search in sources :

Example 16 with IsotopePattern

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

the class SingleRowPredictionTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    resultWindow = new ResultWindow("Searching for " + MZmineCore.getConfiguration().getMZFormat().format(searchedMass), peakListRow, searchedMass, charge, this);
    resultWindow.setVisible(true);
    logger.finest("Starting search for formulas for " + massRange + " Da");
    IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
    if ((checkIsotopes) && (detectedPattern == null)) {
        final String msg = "Cannot calculate isotope pattern scores, because selected" + " peak does not have any isotopes. Have you run the isotope peak grouper?";
        MZmineCore.getDesktop().displayMessage(resultWindow, msg);
    }
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
    IMolecularFormula cdkFormula;
    while ((cdkFormula = generator.getNextFormula()) != null) {
        if (isCanceled())
            return;
        // Mass is ok, so test other constraints
        checkConstraints(cdkFormula);
    }
    if (isCanceled())
        return;
    logger.finest("Finished formula search for " + massRange + " m/z, found " + foundFormulas + " formulas");
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            resultWindow.setTitle("Finished searching for " + MZmineCore.getConfiguration().getMZFormat().format(searchedMass) + " amu, " + foundFormulas + " formulas found");
        }
    });
    setStatus(TaskStatus.FINISHED);
}
Also used : MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder)

Example 17 with IsotopePattern

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

the class ResultWindow method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("EXPORT")) {
        // Ask for filename
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setApproveButtonText("Export");
        int result = fileChooser.showSaveDialog(MZmineCore.getDesktop().getMainWindow());
        if (result != JFileChooser.APPROVE_OPTION)
            return;
        File outputFile = fileChooser.getSelectedFile();
        try {
            FileWriter fileWriter = new FileWriter(outputFile);
            BufferedWriter writer = new BufferedWriter(fileWriter);
            writer.write("Formula,Mass,RDBE,Isotope pattern score,MS/MS score");
            writer.newLine();
            for (int row = 0; row < resultsTable.getRowCount(); row++) {
                int modelRow = resultsTable.convertRowIndexToModel(row);
                ResultFormula formula = resultsTableModel.getFormula(modelRow);
                writer.write(formula.getFormulaAsString());
                writer.write(",");
                writer.write(String.valueOf(formula.getExactMass()));
                writer.write(",");
                if (formula.getRDBE() != null)
                    writer.write(String.valueOf(formula.getRDBE()));
                writer.write(",");
                if (formula.getIsotopeScore() != null)
                    writer.write(String.valueOf(formula.getIsotopeScore()));
                writer.write(",");
                if (formula.getMSMSScore() != null)
                    writer.write(String.valueOf(formula.getMSMSScore()));
                writer.newLine();
            }
            writer.close();
        } catch (Exception ex) {
            MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error writing to file " + outputFile + ": " + ExceptionUtils.exceptionToString(ex));
        }
        return;
    }
    // The following actions require a single row to be selected
    int index = resultsTable.getSelectedRow();
    if (index < 0) {
        MZmineCore.getDesktop().displayMessage(MZmineCore.getDesktop().getMainWindow(), "Please select one result");
        return;
    }
    index = resultsTable.convertRowIndexToModel(index);
    ResultFormula formula = resultsTableModel.getFormula(index);
    if (command.equals("ADD")) {
        SimplePeakIdentity newIdentity = new SimplePeakIdentity(formula.getFormulaAsString());
        peakListRow.addPeakIdentity(newIdentity, false);
        // Notify the GUI about the change in the project
        MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(peakListRow, false);
        // Repaint the window to reflect the change in the feature list
        MZmineCore.getDesktop().getMainWindow().repaint();
        dispose();
    }
    if (command.equals("COPY")) {
        String formulaString = formula.getFormulaAsString();
        StringSelection stringSelection = new StringSelection(formulaString);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
    }
    if (command.equals("SHOW_ISOTOPES")) {
        logger.finest("Showing isotope pattern for formula " + formula.getFormulaAsString());
        IsotopePattern predictedPattern = formula.getPredictedIsotopes();
        if (predictedPattern == null)
            return;
        Feature peak = peakListRow.getBestPeak();
        RawDataFile dataFile = peak.getDataFile();
        int scanNumber = peak.getRepresentativeScanNumber();
        SpectraVisualizerModule.showNewSpectrumWindow(dataFile, scanNumber, null, peak.getIsotopePattern(), predictedPattern);
    }
    if (command.equals("SHOW_MSMS")) {
        Feature bestPeak = peakListRow.getBestPeak();
        RawDataFile dataFile = bestPeak.getDataFile();
        int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
        if (msmsScanNumber < 1)
            return;
        SpectraVisualizerWindow msmsPlot = SpectraVisualizerModule.showNewSpectrumWindow(dataFile, msmsScanNumber);
        if (msmsPlot == null)
            return;
        Map<DataPoint, String> annotation = formula.getMSMSannotation();
        if (annotation == null)
            return;
        msmsPlot.addAnnotation(annotation);
    }
}
Also used : FileWriter(java.io.FileWriter) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) BufferedWriter(java.io.BufferedWriter) StringSelection(java.awt.datatransfer.StringSelection) SpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerWindow) JFileChooser(javax.swing.JFileChooser) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) Clipboard(java.awt.datatransfer.Clipboard) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File)

Example 18 with IsotopePattern

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

the class IsotopePatternScoreCalculator method getSimilarityScore.

/**
 * Returns a calculated similarity score of two isotope patterns in the range of 0 (not similar at
 * all) to 1 (100% same).
 */
public static double getSimilarityScore(IsotopePattern ip1, IsotopePattern ip2, ParameterSet parameters) {
    assert ip1 != null;
    assert ip2 != null;
    MZTolerance mzTolerance = parameters.getParameter(IsotopePatternScoreParameters.mzTolerance).getValue();
    assert mzTolerance != null;
    final double patternIntensity = Math.max(ip1.getHighestDataPoint().getIntensity(), ip2.getHighestDataPoint().getIntensity());
    final double noiseIntensity = parameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
    // Normalize the isotopes to intensity 0..1
    IsotopePattern nip1 = IsotopePatternCalculator.normalizeIsotopePattern(ip1);
    IsotopePattern nip2 = IsotopePatternCalculator.normalizeIsotopePattern(ip2);
    // Merge the data points from both isotope patterns into a single array.
    // Data points from first pattern will have positive intensities, data
    // points from second pattern will have negative intensities.
    ArrayList<DataPoint> mergedDataPoints = new ArrayList<DataPoint>();
    for (DataPoint dp : nip1.getDataPoints()) {
        if (dp.getIntensity() * patternIntensity < noiseIntensity)
            continue;
        mergedDataPoints.add(dp);
    }
    for (DataPoint dp : nip2.getDataPoints()) {
        if (dp.getIntensity() * patternIntensity < noiseIntensity)
            continue;
        DataPoint negativeDP = new SimpleDataPoint(dp.getMZ(), dp.getIntensity() * -1);
        mergedDataPoints.add(negativeDP);
    }
    DataPoint[] mergedDPArray = mergedDataPoints.toArray(new DataPoint[0]);
    // Sort the merged data points by m/z
    Arrays.sort(mergedDPArray, new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // tolerance
    for (int i = 0; i < mergedDPArray.length - 1; i++) {
        Range<Double> toleranceRange = mzTolerance.getToleranceRange(mergedDPArray[i].getMZ());
        if (!toleranceRange.contains(mergedDPArray[i + 1].getMZ()))
            continue;
        double summedIntensity = mergedDPArray[i].getIntensity() + mergedDPArray[i + 1].getIntensity();
        double newMZ = mergedDPArray[i + 1].getMZ();
        // Update the next data point and remove the current one
        mergedDPArray[i + 1] = new SimpleDataPoint(newMZ, summedIntensity);
        mergedDPArray[i] = null;
    }
    // Calculate the resulting score. Ideal score is 1, in case the final
    // data point array is empty.
    double result = 1;
    for (DataPoint dp : mergedDPArray) {
        if (dp == null)
            continue;
        double remainingIntensity = Math.abs(dp.getIntensity());
        // intensity may be over 1
        if (remainingIntensity > 1)
            remainingIntensity = 1;
        // Decrease the score with each remaining peak
        result *= 1 - remainingIntensity;
    }
    return result;
}
Also used : MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) DataPointSorter(net.sf.mzmine.util.DataPointSorter) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 19 with IsotopePattern

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

the class IsotopePatternCalculator method showIsotopePredictionDialog.

public static IsotopePattern showIsotopePredictionDialog(Window parent, boolean valueCheckRequired) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(IsotopePatternCalculator.class);
    ExitCode exitCode = parameters.showSetupDialog(parent, valueCheckRequired);
    if (exitCode != ExitCode.OK)
        return null;
    String formula = parameters.getParameter(IsotopePatternCalculatorParameters.formula).getValue();
    int charge = parameters.getParameter(IsotopePatternCalculatorParameters.charge).getValue();
    PolarityType polarity = parameters.getParameter(IsotopePatternCalculatorParameters.polarity).getValue();
    double minAbundance = parameters.getParameter(IsotopePatternCalculatorParameters.minAbundance).getValue();
    try {
        IsotopePattern predictedPattern = calculateIsotopePattern(formula, minAbundance, charge, polarity);
        return predictedPattern;
    } catch (Exception e) {
        MZmineCore.getDesktop().displayException(MZmineCore.getDesktop().getMainWindow(), e);
    }
    return null;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) PolarityType(net.sf.mzmine.datamodel.PolarityType) ExitCode(net.sf.mzmine.util.ExitCode) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 20 with IsotopePattern

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

the class IsotopePatternExportModule method exportIsotopePattern.

public static void exportIsotopePattern(PeakListRow row) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(IsotopePatternExportModule.class);
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return;
    File outputFile = parameters.getParameter(IsotopePatternExportParameters.outputFile).getValue();
    if (outputFile == null)
        return;
    IsotopePattern pattern = row.getBestIsotopePattern();
    DataPoint[] isotopes;
    if (pattern != null) {
        isotopes = pattern.getDataPoints();
    } else {
        isotopes = new DataPoint[1];
        Feature bestPeak = row.getBestPeak();
        isotopes[0] = new SimpleDataPoint(bestPeak.getMZ(), bestPeak.getHeight());
    }
    try {
        FileWriter fileWriter = new FileWriter(outputFile);
        BufferedWriter writer = new BufferedWriter(fileWriter);
        for (DataPoint isotope : isotopes) {
            writer.write(isotope.getMZ() + " " + isotope.getIntensity());
            writer.newLine();
        }
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error writing to file " + outputFile + ": " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ExitCode(net.sf.mzmine.util.ExitCode) FileWriter(java.io.FileWriter) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) File(java.io.File) Feature(net.sf.mzmine.datamodel.Feature) BufferedWriter(java.io.BufferedWriter)

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