Search in sources :

Example 1 with IIsotope

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

the class ElementalHeuristicChecker method checkFormula.

public static boolean checkFormula(IMolecularFormula formula, ParameterSet parameters) {
    double eH = 0, eC = 0, eN = 0, eO = 0, eP = 0, eS = 0;
    for (IIsotope isotope : formula.isotopes()) {
        if (isotope.getSymbol().equals("C"))
            eC += formula.getIsotopeCount(isotope);
        if (isotope.getSymbol().equals("N"))
            eN += formula.getIsotopeCount(isotope);
        if (isotope.getSymbol().equals("O"))
            eO += formula.getIsotopeCount(isotope);
        if (isotope.getSymbol().equals("P"))
            eP += formula.getIsotopeCount(isotope);
        if (isotope.getSymbol().equals("S"))
            eS += formula.getIsotopeCount(isotope);
        if (isotope.getSymbol().equals("H"))
            eH += formula.getIsotopeCount(isotope);
    }
    // If there is no carbon, consider the formula OK
    if (eC == 0)
        return true;
    boolean checkHC = parameters.getParameter(ElementalHeuristicParameters.checkHC).getValue();
    boolean checkNOPS = parameters.getParameter(ElementalHeuristicParameters.checkNOPS).getValue();
    boolean checkMultiple = parameters.getParameter(ElementalHeuristicParameters.checkMultiple).getValue();
    if (checkHC) {
        double rHC = eH / eC;
        if ((rHC < 0.1) || (rHC > 6))
            return false;
    }
    if (checkNOPS) {
        double rPC = eP / eC;
        double rNC = eN / eC;
        double rOC = eO / eC;
        double rSC = eS / eC;
        if ((rNC > 4) || (rOC > 3) || (rPC > 2) || (rSC > 3))
            return false;
    }
    if (checkMultiple) {
        // Multiple rule #1
        if ((eN > 1) && (eO > 1) && (eP > 1) && (eS > 1)) {
            if ((eN >= 10) || (eO >= 20) || (eP >= 4) || (eS >= 3))
                return false;
        }
        // Multiple rule #2
        if ((eN > 3) && (eO > 3) && (eP > 3)) {
            if ((eN >= 11) || (eO >= 22) || (eP >= 6))
                return false;
        }
        // Multiple rule #3
        if ((eO > 1) && (eP > 1) && (eS > 1)) {
            if ((eO >= 14) || (eP >= 3) || (eS >= 3))
                return false;
        }
        // Multiple rule #4
        if ((eN > 1) && (eP > 1) && (eS > 1)) {
            if ((eN >= 4) || (eP >= 3) || (eS >= 3))
                return false;
        }
        // Multiple rule #5
        if ((eN > 6) && (eO > 6) && (eS > 6)) {
            if ((eN >= 19) || (eO >= 14) || (eS >= 8))
                return false;
        }
    }
    return true;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope)

Example 2 with IIsotope

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

the class RDBERestrictionChecker method calculateRDBE.

/**
 * Calculates possible RDBE (degree of unsaturation) values according to the formula:
 *
 * RDBE = 1 + Sum(ni x vi - 2) / 2
 *
 * where ni is the number of atoms with valence vi. If multiple valences are allowed (e.g. N may
 * have valence 3 or 5), there may be multiple results for RDBE.
 */
public static Double calculateRDBE(IMolecularFormula formula) {
    double sum = 0;
    Map<String, Integer> valences2 = new HashMap<String, Integer>();
    valences2.put("H", 1);
    valences2.put("C", 4);
    valences2.put("N", 3);
    valences2.put("O", 2);
    valences2.put("Si", 4);
    valences2.put("P", 3);
    valences2.put("S", 2);
    valences2.put("F", 1);
    valences2.put("Cl", 1);
    valences2.put("Br", 1);
    valences2.put("I", 1);
    valences2.put("Na", 1);
    valences2.put("K", 1);
    for (IIsotope isotope : formula.isotopes()) {
        Integer valence = valences2.get(isotope.getSymbol());
        if (valence == null)
            return null;
        sum += (valence - 2) * formula.getIsotopeCount(isotope);
    }
    sum /= 2;
    sum += 1;
    return sum;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) HashMap(java.util.HashMap)

Example 3 with IIsotope

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

the class DynamicParameterUtils method buildFormulaRangeOnIsotopePatternResults.

/**
 * Creates an ElementParameter based on the previous processing results. If no results were
 * detected, the default value is returned. Upper and lower boundaries are chosen according to
 * lowerElementBoundaryPercentage and upperElementBoundaryPercentage values of this utility class.
 * These values can be set via {@link #setLowerElementBoundaryPercentage} and
 * {@link #setUpperElementBoundaryPercentage}. The elements contained in
 *
 * @param dp The data point to build a parameter for.
 * @param def The default set of parameters.
 * @return The built ElementsParameter
 */
public static MolecularFormulaRange buildFormulaRangeOnIsotopePatternResults(ProcessedDataPoint dp, MolecularFormulaRange def) {
    DPPIsotopePatternResult result = (DPPIsotopePatternResult) dp.getFirstResultByType(ResultType.ISOTOPEPATTERN);
    if (result == null)
        return def;
    if (!(result.getValue() instanceof ExtendedIsotopePattern))
        return def;
    ExtendedIsotopePattern pattern = (ExtendedIsotopePattern) result.getValue();
    String form = IsotopePatternUtils.makePatternSuggestion(pattern.getIsotopeCompositions());
    MolecularFormulaRange range = new MolecularFormulaRange();
    IMolecularFormula formula = FormulaUtils.createMajorIsotopeMolFormula(form);
    if (formula == null) {
        logger.finest("could not generate formula for m/z " + dp.getMZ() + " " + form);
        return def;
    }
    for (IIsotope isotope : def.isotopes()) range.addIsotope(isotope, def.getIsotopeCountMin(isotope), def.getIsotopeCountMax(isotope));
    for (IIsotope isotope : formula.isotopes()) {
        if (range.contains(isotope))
            continue;
        int count = formula.getIsotopeCount(isotope);
        range.addIsotope(isotope, (int) (count * lowerElementBoundaryPercentage), (int) (count * upperElementBoundaryPercentage));
    }
    for (IIsotope isotope : range.isotopes()) {
        int min = range.getIsotopeCountMin(isotope);
        int max = range.getIsotopeCountMax(isotope);
    // logger.info("m/z = " + dp.getMZ() + " " + isotope.getSymbol() + " " + min + " - " + max);
    }
    return range;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) DPPIsotopePatternResult(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 4 with IIsotope

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

the class IsotopePatternUtils method checkOverlappingIsotopes.

public static IsotopePattern checkOverlappingIsotopes(IsotopePattern pattern, IIsotope[] isotopes, double mergeWidth, double minAbundance) {
    DataPoint[] dp = pattern.getDataPoints();
    double basemz = dp[0].getMZ();
    List<DataPoint> newPeaks = new ArrayList<DataPoint>();
    double isotopeBaseMass = 0d;
    for (IIsotope isotope : isotopes) {
        if (isotope.getNaturalAbundance() > minAbundance) {
            isotopeBaseMass = isotope.getExactMass();
            logger.info("isotopeBaseMass of " + isotope.getSymbol() + " = " + isotopeBaseMass);
            break;
        }
    }
    // loop all new isotopes
    for (IIsotope isotope : isotopes) {
        if (isotope.getNaturalAbundance() < minAbundance)
            continue;
        // the difference added by the heavier isotope peak
        double possiblemzdiff = isotope.getExactMass() - isotopeBaseMass;
        if (possiblemzdiff < 0.000001)
            continue;
        boolean add = true;
        for (DataPoint patternDataPoint : dp) {
            // here check for every peak in the pattern, if a new peak would overlap
            // if it overlaps good, we dont need to add a new peak
            int i = 1;
            do {
                if (Math.abs(patternDataPoint.getMZ() * i - possiblemzdiff) <= mergeWidth) {
                    // TODO: maybe we should do a average of the masses? i can'T say if it makes sense,
                    // since
                    // we're just looking for isotope mass differences and dont look at the total
                    // composition,
                    // so we dont know the intensity ratios
                    logger.info("possible overlap found: " + i + " * pattern dp = " + patternDataPoint.getMZ() + "\toverlaps with " + isotope.getMassNumber() + isotope.getSymbol() + " (" + (isotopeBaseMass - isotope.getExactMass()) + ")\tdiff: " + Math.abs(patternDataPoint.getMZ() * i - possiblemzdiff));
                    add = false;
                }
                i++;
            // logger.info("do");
            } while (patternDataPoint.getMZ() * i <= possiblemzdiff + mergeWidth && patternDataPoint.getMZ() != 0.0);
        }
        if (add)
            newPeaks.add(new SimpleDataPoint(possiblemzdiff, 1));
    }
    // DataPoint[] newDataPoints = new SimpleDataPoint[dp.length + newPeaks.size()];
    for (DataPoint p : dp) {
        newPeaks.add(p);
    }
    newPeaks.sort((o1, o2) -> {
        return Double.compare(o1.getMZ(), o2.getMZ());
    });
    return new SimpleIsotopePattern(newPeaks.toArray(new DataPoint[0]), IsotopePatternStatus.PREDICTED, "");
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ArrayList(java.util.ArrayList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)

Example 5 with IIsotope

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

the class FormulaUtils method subtractFormula.

/**
 * @param result is going to be changed. is also the returned value
 * @param sub
 * @return
 */
public static IMolecularFormula subtractFormula(IMolecularFormula result, IMolecularFormula sub) {
    for (IIsotope isotope : sub.isotopes()) {
        int count = sub.getIsotopeCount(isotope);
        boolean found = false;
        do {
            found = false;
            for (IIsotope realIsotope : result.isotopes()) {
                // there can be different implementations of IIsotope
                if (equalIsotopes(isotope, realIsotope)) {
                    found = true;
                    int realCount = result.getIsotopeCount(realIsotope);
                    int remaining = realCount - count;
                    result.removeIsotope(realIsotope);
                    if (remaining > 0)
                        result.addIsotope(realIsotope, remaining);
                    count -= realCount;
                    break;
                }
            }
        } while (count > 0 && found);
    }
    return result;
}
Also used : IIsotope(org.openscience.cdk.interfaces.IIsotope)

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