use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.
the class IsotopePeakScannerSetupDialog method calculateIsotopePattern.
private ExtendedIsotopePattern calculateIsotopePattern() {
if (!checkParameters())
return null;
String strPattern = "";
int currentCarbonPattern = Integer.parseInt(txtCurrentPatternIndex.getText());
if (autoCarbon)
strPattern = "C" + String.valueOf(currentCarbonPattern) + element;
else
strPattern = element;
if (strPattern.equals(""))
return null;
logger.info("Calculating isotope pattern: " + strPattern);
ExtendedIsotopePattern pattern;
PolarityType pol = (charge > 0) ? PolarityType.POSITIVE : PolarityType.NEGATIVE;
charge = (charge > 0) ? charge : charge * -1;
try {
// *0.2 so the user can see the peaks below the threshold
pattern = (ExtendedIsotopePattern) IsotopePatternCalculator.calculateIsotopePattern(strPattern, minIntensity * 0.1, mergeWidth, charge, pol, true);
} catch (Exception e) {
logger.warning("The entered Sum formula is invalid.");
return null;
}
return pattern;
}
use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern 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 net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.
the class IsotopePatternUtils method convertIsotopicPeakResultsToPattern.
/**
* Takes all DPPIsotopicPeakResults of one charge and puts them into one isotope pattern (per
* charge).
*
* @param dp A ProcessedDataPoint
* @param keepResults if false, all DPPIsotopicPeakResults will be removed from this data point.
*/
public static void convertIsotopicPeakResultsToPattern(ProcessedDataPoint dp, boolean keepResults) {
sortAndRemoveDuplicateIsotopicPeakResult(dp);
List<DPPIsotopicPeakResult> iprs = getIsotopicPeakResults(dp);
if (iprs.isEmpty())
return;
List<Integer> charges = getChargeStates(iprs);
List<ProcessedDataPoint> peaks = new ArrayList<>();
List<String> isotopes = new ArrayList<>();
peaks.add(dp);
isotopes.add("");
for (int charge : charges) {
for (DPPIsotopicPeakResult ipr : iprs) {
if (ipr.getCharge() == charge) {
peaks.add(ipr.getValue());
isotopes.add(mergeIsotopicPeakDescription(ipr.getIsotope()));
}
}
ProcessedDataPoint[] dps = peaks.toArray(new ProcessedDataPoint[0]);
String[] isos = isotopes.toArray(new String[0]);
ExtendedIsotopePattern pattern = new ExtendedIsotopePattern(dps, IsotopePatternStatus.DETECTED, format.format(dp.getMZ()), /*+ Arrays.toString(isos)*/
isos);
dp.addResult(new DPPIsotopePatternResult(pattern, (ProcessedDataPoint[]) pattern.getDataPoints(), charge));
peaks.clear();
isotopes.clear();
}
if (!keepResults)
dp.removeAllResultsByType(ResultType.ISOTOPICPEAK);
}
use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.
the class IsotopePatternCalculator method removeDataPointsBelowIntensity.
public static IsotopePattern removeDataPointsBelowIntensity(IsotopePattern pattern, double minIntensity) {
DataPoint[] dp = pattern.getDataPoints();
for (int i = 0; i < pattern.getNumberOfDataPoints(); i++) {
if (dp[i].getIntensity() < minIntensity) {
dp[i] = null;
}
}
ArrayList<DataPoint> newDP = new ArrayList<DataPoint>();
ArrayList<String> newComp = new ArrayList<String>();
for (int i = 0; i < dp.length; i++) {
DataPoint p = dp[i];
if (dp[i] != null) {
newDP.add(p);
if (pattern instanceof ExtendedIsotopePattern) {
newComp.add(((ExtendedIsotopePattern) pattern).getIsotopeComposition(i));
}
}
}
if (pattern instanceof ExtendedIsotopePattern)
return new ExtendedIsotopePattern(newDP.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription(), newComp.toArray(new String[0]));
else
return new SimpleIsotopePattern(newDP.toArray(new DataPoint[0]), pattern.getStatus(), pattern.getDescription());
}
use of net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern in project mzmine2 by mzmine.
the class DPPAnyElementIsotopeGrouperTask method run.
@Override
public void run() {
if (!checkParameterSet() || !checkValues()) {
setStatus(TaskStatus.ERROR);
return;
}
// check formula
if (elements == null || elements.equals("") || !FormulaUtils.checkMolecularFormula(elements)) {
setErrorMessage("Invalid element parameter in " + getTaskDescription());
setStatus(TaskStatus.ERROR);
logger.warning("Invalid element parameter in " + getTaskDescription());
return;
}
if (!FormulaUtils.checkMolecularFormula(elements)) {
setStatus(TaskStatus.ERROR);
logger.warning("Data point/Spectra processing: Invalid element parameter in " + getTaskDescription());
}
if (getDataPoints().length == 0) {
logger.info("Data point/Spectra processing: 0 data points were passed to " + getTaskDescription() + " Please check the parameters.");
setStatus(TaskStatus.CANCELED);
return;
}
if (!(getDataPoints() instanceof ProcessedDataPoint[])) {
logger.warning("Data point/Spectra processing: The data points passed to Isotope Grouper were not an instance of processed data points." + " Make sure to run mass detection first.");
setStatus(TaskStatus.CANCELED);
return;
}
setStatus(TaskStatus.PROCESSING);
ExtendedIsotopePattern[] elementPattern = getIsotopePatterns(elements, mergeWidth, minAbundance);
ProcessedDataPoint[] originalDataPoints = (ProcessedDataPoint[]) getDataPoints();
totalSteps = originalDataPoints.length * 2 + 1;
// one loop for every element
for (ExtendedIsotopePattern pattern : elementPattern) {
// we search by ascending mz
for (int i_dp = 0; i_dp < originalDataPoints.length; i_dp++) {
// dp is the peak we are currently searching an isotope pattern for
ProcessedDataPoint dp = originalDataPoints[i_dp];
if (!mzrange.contains(dp.getMZ()))
continue;
IsotopePatternUtils.findIsotopicPeaks(dp, originalDataPoints, mzTolerance, pattern, mzrange, maxCharge);
processedSteps++;
}
if (isCanceled())
return;
}
for (int x = 0; x < originalDataPoints.length; x++) {
ProcessedDataPoint dp = originalDataPoints[x];
if (!mzrange.contains(dp.getMZ()))
continue;
if (isCanceled())
return;
IsotopePatternUtils.mergeIsotopicPeakResults(dp);
}
for (int x = 0; x < originalDataPoints.length; x++) {
ProcessedDataPoint dp = originalDataPoints[x];
if (!mzrange.contains(dp.getMZ()))
continue;
if (isCanceled())
return;
IsotopePatternUtils.convertIsotopicPeakResultsToPattern(dp, false);
}
List<ProcessedDataPoint> results = new ArrayList<>();
for (ProcessedDataPoint dp : originalDataPoints) {
if (autoRemove) {
if (dp.resultTypeExists(ResultType.ISOTOPEPATTERN))
results.add(dp);
} else
results.add(dp);
}
setResults(results.toArray(new ProcessedDataPoint[0]));
setStatus(TaskStatus.FINISHED);
}
Aggregations