use of net.sf.mzmine.datamodel.impl.SimpleIsotopePattern 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.SimpleIsotopePattern in project mzmine2 by mzmine.
the class DPPIsotopeGrouperTask method run.
@Override
public void run() {
if (!checkParameterSet() || !checkValues()) {
setStatus(TaskStatus.ERROR);
return;
}
if (!FormulaUtils.checkMolecularFormula(element)) {
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);
ProcessedDataPoint[] dataPoints = (ProcessedDataPoint[]) getDataPoints();
int[] charges = new int[maximumCharge];
for (int i = 0; i < maximumCharge; i++) charges[i] = i + 1;
IsotopePattern pattern = IsotopePatternCalculator.calculateIsotopePattern(element, 0.01, 1, PolarityType.POSITIVE);
double isotopeDistance = pattern.getDataPoints()[1].getMZ() - pattern.getDataPoints()[0].getMZ();
ProcessedDataPoint[] sortedDataPoints = dataPoints.clone();
Arrays.sort(sortedDataPoints, (d1, d2) -> {
// *-1 to sort descending
return -1 * Double.compare(d1.getIntensity(), d2.getIntensity());
});
List<ProcessedDataPoint> deisotopedDataPoints = new ArrayList<>();
for (int i = 0; i < sortedDataPoints.length; i++) {
if (isCanceled())
return;
DataPoint aPeak = sortedDataPoints[i];
if (aPeak == null) {
processedPeaks++;
continue;
}
// Check which charge state fits best around this peak
int bestFitCharge = 0;
int bestFitScore = -1;
Vector<DataPoint> bestFitPeaks = null;
for (int charge : charges) {
Vector<DataPoint> fittedPeaks = new Vector<DataPoint>();
fittedPeaks.add(aPeak);
fitPattern(fittedPeaks, aPeak, charge, sortedDataPoints, isotopeDistance);
int score = fittedPeaks.size();
if ((score > bestFitScore) || ((score == bestFitScore) && (bestFitCharge > charge))) {
bestFitScore = score;
bestFitCharge = charge;
bestFitPeaks = fittedPeaks;
}
}
assert bestFitPeaks != null;
// isotope, we skip this left the original peak in the feature list.
if (bestFitPeaks.size() == 1) {
if (!autoRemove)
deisotopedDataPoints.add(sortedDataPoints[i]);
processedPeaks++;
continue;
}
DataPoint[] originalPeaks = bestFitPeaks.toArray(new DataPoint[0]);
SimpleIsotopePattern newPattern = new SimpleIsotopePattern(originalPeaks, IsotopePatternStatus.DETECTED, aPeak.toString());
sortedDataPoints[i].addResult(new DPPIsotopePatternResult(newPattern, bestFitCharge));
deisotopedDataPoints.add(sortedDataPoints[i]);
for (int j = 0; j < sortedDataPoints.length; j++) {
if (bestFitPeaks.contains(sortedDataPoints[j]))
sortedDataPoints[j] = null;
}
// Update completion rate
processedPeaks++;
}
deisotopedDataPoints.sort((d1, d2) -> {
return Double.compare(d1.getMZ(), d2.getMZ());
});
setResults(deisotopedDataPoints.toArray(new ProcessedDataPoint[0]));
setStatus(TaskStatus.FINISHED);
}
Aggregations