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