Search in sources :

Example 1 with ExtendedIsotopePattern

use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.

the class IsotopePatternCalculator method normalizeIsotopePattern.

/**
 * Returns same isotope pattern (same ratios between isotope intensities) with maximum intensity
 * normalized to given intensity
 */
public static IsotopePattern normalizeIsotopePattern(IsotopePattern pattern, double normalizedValue) {
    DataPoint highestIsotope = pattern.getHighestDataPoint();
    DataPoint[] dataPoints = pattern.getDataPoints();
    double maxIntensity = highestIsotope.getIntensity();
    DataPoint[] newDataPoints = new DataPoint[dataPoints.length];
    for (int i = 0; i < dataPoints.length; i++) {
        double mz = dataPoints[i].getMZ();
        double intensity = dataPoints[i].getIntensity() / maxIntensity * normalizedValue;
        newDataPoints[i] = new SimpleDataPoint(mz, intensity);
    }
    if (pattern instanceof ExtendedIsotopePattern && ((ExtendedIsotopePattern) pattern).getIsotopeCompositions() != null)
        return new ExtendedIsotopePattern(newDataPoints, pattern.getStatus(), pattern.getDescription(), ((ExtendedIsotopePattern) pattern).getIsotopeCompositions());
    else
        return new SimpleIsotopePattern(newDataPoints, pattern.getStatus(), pattern.getDescription());
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Example 2 with ExtendedIsotopePattern

use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.

the class IsotopePatternCalculator method mergeIsotopes.

/**
 * Merges the isotopes falling within the given m/z tolerance. If the m/z difference between the
 * isotopes is smaller than mzTolerance, their intensity is added together and new m/z value is
 * calculated as a weighted average.
 */
public static IsotopePattern mergeIsotopes(IsotopePattern pattern, double mzTolerance) {
    DataPoint[] dataPoints = pattern.getDataPoints().clone();
    String[] newIsotopeComposition = new String[pattern.getNumberOfDataPoints()];
    if (pattern instanceof ExtendedIsotopePattern && ((ExtendedIsotopePattern) pattern).getIsotopeCompositions() != null)
        newIsotopeComposition = ((ExtendedIsotopePattern) pattern).getIsotopeCompositions();
    for (int i = 0; i < dataPoints.length - 1; i++) {
        if (Math.abs(dataPoints[i].getMZ() - dataPoints[i + 1].getMZ()) < mzTolerance) {
            double newIntensity = dataPoints[i].getIntensity() + dataPoints[i + 1].getIntensity();
            double newMZ = (dataPoints[i].getMZ() * dataPoints[i].getIntensity() + dataPoints[i + 1].getMZ() * dataPoints[i + 1].getIntensity()) / newIntensity;
            dataPoints[i + 1] = new SimpleDataPoint(newMZ, newIntensity);
            dataPoints[i] = null;
            if (pattern instanceof ExtendedIsotopePattern && ((ExtendedIsotopePattern) pattern).getIsotopeCompositions() != null) {
                newIsotopeComposition[i + 1] = ((ExtendedIsotopePattern) pattern).getIsotopeComposition(i) + ", " + ((ExtendedIsotopePattern) pattern).getIsotopeComposition(i + 1);
                newIsotopeComposition[i] = null;
            }
        }
    }
    ArrayList<DataPoint> newDataPoints = new ArrayList<DataPoint>();
    for (DataPoint dp : dataPoints) {
        if (dp != null)
            newDataPoints.add(dp);
    }
    if (pattern instanceof ExtendedIsotopePattern && ((ExtendedIsotopePattern) pattern).getIsotopeCompositions() != null) {
        ArrayList<String> newComp = new ArrayList<String>();
        for (String comp : newIsotopeComposition) {
            if (comp != null)
                newComp.add(comp);
        }
        return new ExtendedIsotopePattern(newDataPoints.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription(), newComp.toArray(new String[0]));
    }
    return new SimpleIsotopePattern(newDataPoints.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription());
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ArrayList(java.util.ArrayList) 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 3 with ExtendedIsotopePattern

use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.

the class IsotopePatternCalculator method calculateIsotopePattern.

public static IsotopePattern calculateIsotopePattern(IMolecularFormula cdkFormula, double minAbundance, double mergeWidth, int charge, PolarityType polarity, boolean storeFormula) {
    // TODO: check if the formula is not too big (>100 of a single atom?).
    // if so, just cancel the prediction
    // Set the minimum abundance of isotope
    // TODO: in the CDK minAbundance is now called minIntensity and refers to the relative intensity
    // in the isotope pattern, should change it here, too
    IsotopePatternGenerator generator = new IsotopePatternGenerator(minAbundance);
    generator.setMinResolution(mergeWidth);
    generator.setStoreFormulas(storeFormula);
    org.openscience.cdk.formula.IsotopePattern pattern = generator.getIsotopes(cdkFormula);
    int numOfIsotopes = pattern.getNumberOfIsotopes();
    DataPoint[] dataPoints = new DataPoint[numOfIsotopes];
    String[] isotopeComposition = new String[numOfIsotopes];
    for (int i = 0; i < numOfIsotopes; i++) {
        IsotopeContainer isotope = pattern.getIsotope(i);
        // For each unit of charge, we have to add or remove a mass of a
        // single electron. If the charge is positive, we remove electron
        // mass. If the charge is negative, we add it.
        double mass = isotope.getMass() + (polarity.getSign() * -1 * charge * ELECTRON_MASS);
        if (charge != 0)
            mass /= charge;
        double intensity = isotope.getIntensity();
        dataPoints[i] = new SimpleDataPoint(mass, intensity);
        if (storeFormula)
            isotopeComposition[i] = formatCDKString(isotope.toString());
    }
    String formulaString = MolecularFormulaManipulator.getString(cdkFormula);
    if (storeFormula)
        return new ExtendedIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, formulaString, isotopeComposition);
    else
        return new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, formulaString);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IsotopePatternGenerator(org.openscience.cdk.formula.IsotopePatternGenerator) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) IsotopeContainer(org.openscience.cdk.formula.IsotopeContainer) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Example 4 with ExtendedIsotopePattern

use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.

the class IsotopePeakScannerTask method setUpDiffAutoCarbon.

/**
 * This calculates the isotope pattern using ExtendedIsotopePattern and creates an
 * ArrayList<Double> that will contain the mass shift for every expected isotope peak relative to
 * the one with the lowest mass.
 *
 * @return
 */
private double[][] setUpDiffAutoCarbon() {
    // ArrayList<Double> diff = new ArrayList<Double>(2);
    double[][] diff;
    if (scanType == ScanType.AUTOCARBON) {
        String[] strPattern = new String[carbonRange];
        ExtendedIsotopePattern[] patternBuffer = new ExtendedIsotopePattern[carbonRange];
        // in the following for we calculate up the patterns
        for (int p = 0; p < carbonRange; p++) {
            if (p + autoCarbonMin != 0)
                strPattern[p] = "C" + (p + autoCarbonMin) + element;
            else
                strPattern[p] = element;
            try {
                patternBuffer[p] = (ExtendedIsotopePattern) IsotopePatternCalculator.calculateIsotopePattern(strPattern[p], 0.001, mergeWidth, charge, polarityType, true);
                patternBuffer[p] = (ExtendedIsotopePattern) IsotopePatternCalculator.removeDataPointsBelowIntensity(patternBuffer[p], minPatternIntensity);
            } catch (Exception e) {
                logger.warning("The entered Sum formula is invalid.");
                return null;
            }
        }
        int sizeCounter = 0;
        // if they dont fit we null them
        for (int p = 0; p < carbonRange; p++) {
            if (patternBuffer[p].getNumberOfDataPoints() >= autoCarbonMinPatternSize) {
                sizeCounter++;
            } else {
                patternBuffer[p] = null;
            }
        }
        if (sizeCounter == 0)
            throw new MSDKRuntimeException("Min pattern size excludes every calculated isotope pattern.\nPlease increase min pattern intensity for more data points or decrease the minimum pattern size.");
        logger.info("about to add " + sizeCounter + " patterns to the scan.");
        diff = new double[sizeCounter][];
        int addCounter = 0;
        pattern = new ExtendedIsotopePattern[sizeCounter];
        for (int p = 0; p < carbonRange; p++) {
            if (patternBuffer[p] == null)
                continue;
            pattern[addCounter] = patternBuffer[p];
            DataPoint[] points = patternBuffer[p].getDataPoints();
            diff[addCounter] = new double[points.length];
            if (maxPatternSize < diff[addCounter].length) {
                maxPatternSize = diff[addCounter].length;
                maxPatternIndex = addCounter;
            }
            for (int i = 0; i < pattern[addCounter].getNumberOfDataPoints(); i++) {
                diff[addCounter][i] = points[i].getMZ() - points[0].getMZ();
            }
            addCounter++;
        }
    } else /* if(scanType == ScanType.SPECIFIC) */
    {
        diff = new double[1][];
        pattern = new ExtendedIsotopePattern[1];
        pattern[0] = (ExtendedIsotopePattern) IsotopePatternCalculator.calculateIsotopePattern(element, 0.001, mergeWidth, charge, polarityType, true);
        pattern[0] = (ExtendedIsotopePattern) IsotopePatternCalculator.removeDataPointsBelowIntensity(pattern[0], minPatternIntensity);
        DataPoint[] points = pattern[0].getDataPoints();
        diff[0] = new double[points.length];
        if (maxPatternSize < diff[0].length) {
            maxPatternSize = diff[0].length;
            maxPatternIndex = 0;
        }
        for (int i = 0; i < pattern[0].getNumberOfDataPoints(); i++) {
            diff[0][i] = points[i].getMZ() - points[0].getMZ();
        }
    }
    logger.info("diff set up...");
    return diff;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException)

Example 5 with ExtendedIsotopePattern

use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.

the class IsotopePeakScannerSetupDialog method updatePreview.

// -----------------------------------------------------
// methods
// -----------------------------------------------------
private void updatePreview() {
    if (!updateParameters()) {
        logger.warning("updatePreview() failed. Could not update parameters or parameters are invalid. Please check the parameters.");
        return;
    }
    ExtendedIsotopePattern pattern = calculateIsotopePattern();
    if (pattern == null) {
        logger.warning("Could not calculate isotope pattern. Please check the parameters.");
        return;
    }
    updateChart(pattern);
}
Also used : ExtendedIsotopePattern(net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)

Aggregations

ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)11 DataPoint (net.sf.mzmine.datamodel.DataPoint)8 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)6 ArrayList (java.util.ArrayList)4 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)4 ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)4 DPPIsotopePatternResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopePatternResult)2 IIsotope (org.openscience.cdk.interfaces.IIsotope)2 IMolecularFormula (org.openscience.cdk.interfaces.IMolecularFormula)2 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)1 PolarityType (net.sf.mzmine.datamodel.PolarityType)1 DPPIsotopicPeakResult (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.results.DPPIsotopicPeakResult)1 IsotopeContainer (org.openscience.cdk.formula.IsotopeContainer)1 IsotopePatternGenerator (org.openscience.cdk.formula.IsotopePatternGenerator)1 MolecularFormulaRange (org.openscience.cdk.formula.MolecularFormulaRange)1 SilentChemObjectBuilder (org.openscience.cdk.silent.SilentChemObjectBuilder)1