Search in sources :

Example 11 with IIsotope

use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.

the class ElementsTableComponent method getElements.

public MolecularFormulaRange getElements() {
    MolecularFormulaRange newValue = new MolecularFormulaRange();
    for (int i = 0; i < elementsTableModel.getRowCount(); i++) {
        IIsotope isotope = (IIsotope) elementsTableModel.getValueAt(i, 0);
        int minCount = (Integer) elementsTableModel.getValueAt(i, 1);
        int maxCount = (Integer) elementsTableModel.getValueAt(i, 2);
        newValue.addIsotope(isotope, minCount, maxCount);
    }
    return newValue;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange)

Example 12 with IIsotope

use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.

the class MSMSScoreCalculator method evaluateMSMS.

/**
 * Returns a calculated similarity score of
 */
public static MSMSScore evaluateMSMS(IMolecularFormula parentFormula, Scan msmsScan, ParameterSet parameters) {
    MZTolerance msmsTolerance = parameters.getParameter(MSMSScoreParameters.msmsTolerance).getValue();
    String massListName = parameters.getParameter(MSMSScoreParameters.massList).getValue();
    MassList massList = msmsScan.getMassList(massListName);
    if (massList == null) {
        throw new IllegalArgumentException("Scan #" + msmsScan.getScanNumber() + " does not have a mass list called '" + massListName + "'");
    }
    DataPoint[] msmsIons = massList.getDataPoints();
    if (msmsIons == null) {
        throw new IllegalArgumentException("Mass list " + massList + " does not contain data for scan #" + msmsScan.getScanNumber());
    }
    MolecularFormulaRange msmsElementRange = new MolecularFormulaRange();
    for (IIsotope isotope : parentFormula.isotopes()) {
        msmsElementRange.addIsotope(isotope, 0, parentFormula.getIsotopeCount(isotope));
    }
    int totalMSMSpeaks = 0, interpretedMSMSpeaks = 0;
    Map<DataPoint, String> msmsAnnotations = new Hashtable<DataPoint, String>();
    msmsCycle: for (DataPoint dp : msmsIons) {
        // Check if this is an isotope
        Range<Double> isotopeCheckRange = Range.closed(dp.getMZ() - 1.4, dp.getMZ() - 0.6);
        for (DataPoint dpCheck : msmsIons) {
            // isotope and we should ignore it
            if (isotopeCheckRange.contains(dpCheck.getMZ()) && (dpCheck.getIntensity() > dp.getIntensity())) {
                continue msmsCycle;
            }
        }
        // If getPrecursorCharge() returns 0, it means charge is unknown. In
        // that case let's assume charge 1
        int precursorCharge = msmsScan.getPrecursorCharge();
        if (precursorCharge == 0)
            precursorCharge = 1;
        // We don't know the charge of the fragment, so we will simply
        // assume 1
        double neutralLoss = msmsScan.getPrecursorMZ() * precursorCharge - dp.getMZ();
        // good threshold
        if (neutralLoss < 5) {
            continue;
        }
        Range<Double> msmsTargetRange = msmsTolerance.getToleranceRange(neutralLoss);
        IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
        MolecularFormulaGenerator msmsEngine = new MolecularFormulaGenerator(builder, msmsTargetRange.lowerEndpoint(), msmsTargetRange.upperEndpoint(), msmsElementRange);
        IMolecularFormula formula = msmsEngine.getNextFormula();
        if (formula != null) {
            String formulaString = MolecularFormulaManipulator.getString(formula);
            msmsAnnotations.put(dp, formulaString);
            interpretedMSMSpeaks++;
        }
        totalMSMSpeaks++;
    }
    // If we did not evaluate any MS/MS peaks, we cannot calculate a score
    if (totalMSMSpeaks == 0) {
        return null;
    }
    double msmsScore = (double) interpretedMSMSpeaks / totalMSMSpeaks;
    MSMSScore result = new MSMSScore(msmsScore, msmsAnnotations);
    return result;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) Hashtable(java.util.Hashtable) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) Range(com.google.common.collect.Range) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) DataPoint(net.sf.mzmine.datamodel.DataPoint) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Example 13 with IIsotope

use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.

the class DPPAnyElementIsotopeGrouperTask method getIsotopePatterns.

/**
 * Returns an array of isotope patterns for the given string. Every element gets its own isotope
 * pattern.
 *
 * @param elements String of element symbols
 * @param mergeWidth
 * @param minAbundance
 * @return
 */
public static ExtendedIsotopePattern[] getIsotopePatterns(String elements, double mergeWidth, double minAbundance) {
    SilentChemObjectBuilder builder = (SilentChemObjectBuilder) SilentChemObjectBuilder.getInstance();
    IMolecularFormula form = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(elements, builder);
    ExtendedIsotopePattern[] isotopePatterns = new ExtendedIsotopePattern[form.getIsotopeCount()];
    int i = 0;
    // create a isotope pattern for every element
    for (IIsotope element : form.isotopes()) {
        isotopePatterns[i] = (ExtendedIsotopePattern) IsotopePatternCalculator.calculateIsotopePattern(element.getSymbol(), minAbundance, mergeWidth, 1, PolarityType.NEUTRAL, true);
        i++;
    }
    // also, we want to keep track of the isotope composition, to do that cleanly, we remove the
    // lightest isotope description
    ExtendedIsotopePattern[] cleanedPatterns = new ExtendedIsotopePattern[form.getIsotopeCount()];
    i = 0;
    for (ExtendedIsotopePattern p : isotopePatterns) {
        String[] composition = p.getIsotopeCompositions();
        composition[0] = "";
        cleanedPatterns[i] = new ExtendedIsotopePattern(p.getDataPoints(), p.getStatus(), p.getDescription(), composition);
        i++;
    }
    return cleanedPatterns;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) SilentChemObjectBuilder(org.openscience.cdk.silent.SilentChemObjectBuilder) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 14 with IIsotope

use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.

the class FormulaUtils method checkMolecularFormula.

/**
 * Checks if a formula string only contains valid isotopes/elements.
 *
 * @param formula String of the molecular formula.
 * @return true / false
 */
public static boolean checkMolecularFormula(String formula) {
    if (formula.matches(".*[äöüÄÖÜß°§$%&/()=?ß²³´`+*~'#;:<>|]")) {
        // check for this first
        logger.info("Formula contains illegal characters.");
        return false;
    }
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    IMolecularFormula molFormula;
    molFormula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(formula, builder);
    boolean valid = true;
    for (IIsotope iso : molFormula.isotopes()) {
        if ((iso.getAtomicNumber() == null) || (iso.getAtomicNumber() == 0)) {
            // iso.getAtomicNumber() != null has to be checked, e.g. for some reason an element with
            // Symbol "R" and number 0 exists in the CDK
            valid = false;
        }
    }
    if (!valid) {
        logger.warning("Formula invalid! Formula contains element symbols that do not exist.");
        return false;
    }
    return true;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder)

Example 15 with IIsotope

use of org.openscience.cdk.interfaces.IIsotope in project mzmine2 by mzmine.

the class FormulaUtils method getFormulaSize.

public static long getFormulaSize(String formula) {
    long size = 1;
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    IMolecularFormula molFormula;
    molFormula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(formula, builder);
    Isotopes isotopeFactory;
    try {
        isotopeFactory = Isotopes.getInstance();
        for (IIsotope iso : molFormula.isotopes()) {
            int naturalIsotopes = 0;
            for (IIsotope i : isotopeFactory.getIsotopes(iso.getSymbol())) {
                if (i.getNaturalAbundance() > 0.0) {
                    naturalIsotopes++;
                }
            }
            try {
                size = Math.multiplyExact(size, (molFormula.getIsotopeCount(iso) * naturalIsotopes));
            } catch (ArithmeticException e) {
                e.printStackTrace();
                logger.info("Formula size of " + formula + " is too big.");
                return -1;
            }
        }
    } catch (IOException e) {
        logger.warning("Unable to initialise Isotopes.");
        e.printStackTrace();
    }
    return size;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) IOException(java.io.IOException) Isotopes(org.openscience.cdk.config.Isotopes) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder)

Aggregations

IIsotope (org.openscience.cdk.interfaces.IIsotope)16 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)3 ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)3 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)3 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)3 IOException (java.io.IOException)2 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)2 Isotopes (org.openscience.cdk.config.Isotopes)2 Range (com.google.common.collect.Range)1 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 JComponent (javax.swing.JComponent)1 JFrame (javax.swing.JFrame)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 OverlayLayout (javax.swing.OverlayLayout)1 Border (javax.swing.border.Border)1