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