Search in sources :

Example 1 with MolecularFormulaRange

use of org.openscience.cdk.formula.MolecularFormulaRange 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 2 with MolecularFormulaRange

use of org.openscience.cdk.formula.MolecularFormulaRange in project mzmine2 by mzmine.

the class ElementsParameter method loadValueFromXML.

@Override
public void loadValueFromXML(Element xmlElement) {
    try {
        MolecularFormulaRange newValue = new MolecularFormulaRange();
        IsotopeFactory iFac = Isotopes.getInstance();
        String s = xmlElement.getTextContent();
        Pattern p = Pattern.compile("([a-zA-Z]+)\\[([0-9]+)-([0-9]+)\\]");
        Matcher m = p.matcher(s);
        while (m.find()) {
            String elementSymbol = m.group(1);
            int minCount = Integer.parseInt(m.group(2));
            int maxCount = Integer.parseInt(m.group(3));
            newValue.addIsotope(iFac.getMajorIsotope(elementSymbol), minCount, maxCount);
        }
        this.value = newValue;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IsotopeFactory(org.openscience.cdk.config.IsotopeFactory) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) IOException(java.io.IOException)

Example 3 with MolecularFormulaRange

use of org.openscience.cdk.formula.MolecularFormulaRange in project mzmine2 by mzmine.

the class SiriusParameters method createDefaultElements.

/**
 * Create default table of elements The table is used later to calculate FormulaConstraints
 *
 * @return
 */
private static MolecularFormulaRange createDefaultElements() {
    MolecularFormulaRange range = new MolecularFormulaRange();
    try {
        IsotopeFactory iFac = Isotopes.getInstance();
        range.addIsotope(iFac.getMajorIsotope("C"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("H"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("N"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("O"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("P"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("S"), ISOTOPE_MIN, ISOTOPE_MAX);
        range.addIsotope(iFac.getMajorIsotope("F"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("B"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("I"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Br"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Se"), ISOTOPE_MIN, ISOTOPE_MIN);
        range.addIsotope(iFac.getMajorIsotope("Cl"), ISOTOPE_MIN, ISOTOPE_MIN);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return range;
}
Also used : IsotopeFactory(org.openscience.cdk.config.IsotopeFactory) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) IOException(java.io.IOException)

Example 4 with MolecularFormulaRange

use of org.openscience.cdk.formula.MolecularFormulaRange 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 5 with MolecularFormulaRange

use of org.openscience.cdk.formula.MolecularFormulaRange 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)

Aggregations

MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)6 IIsotope (org.openscience.cdk.interfaces.IIsotope)3 IOException (java.io.IOException)2 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)2 IsotopeFactory (org.openscience.cdk.config.IsotopeFactory)2 MolecularFormulaGenerator (org.openscience.cdk.formula.MolecularFormulaGenerator)2 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)2 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)2 Range (com.google.common.collect.Range)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MassList (net.sf.mzmine.datamodel.MassList)1 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)1 DPPIsotopePatternResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult)1 DPPSumFormulaResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPSumFormulaResult)1 MZTolerance (net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance)1