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());
}
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());
}
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);
}
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;
}
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);
}
Aggregations