use of net.sf.mzmine.datamodel.IsotopePattern 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);
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class SpectraToolTipGenerator method generateToolTip.
/**
* @see org.jfree.chart.labels.XYToolTipGenerator#generateToolTip(org.jfree.data.xy.XYDataset,
* int, int)
*/
public String generateToolTip(XYDataset dataset, int series, int item) {
double intValue = dataset.getYValue(series, item);
double mzValue = dataset.getXValue(series, item);
if (dataset instanceof PeakListDataSet) {
PeakListDataSet peakListDataSet = (PeakListDataSet) dataset;
Feature peak = peakListDataSet.getPeak(series, item);
PeakList peakList = peakListDataSet.getPeakList();
PeakListRow row = peakList.getPeakRow(peak);
String tooltip = "Peak: " + peak + "\nStatus: " + peak.getFeatureStatus() + "\nFeature list row: " + row + "\nData point m/z: " + mzFormat.format(mzValue) + "\nData point intensity: " + intensityFormat.format(intValue);
return tooltip;
}
if (dataset instanceof IsotopesDataSet) {
IsotopesDataSet isotopeDataSet = (IsotopesDataSet) dataset;
IsotopePattern pattern = isotopeDataSet.getIsotopePattern();
double relativeIntensity = intValue / pattern.getHighestDataPoint().getIntensity() * 100;
String tooltip = "Isotope pattern: " + pattern.getDescription() + "\nStatus: " + pattern.getStatus() + "\nData point m/z: " + mzFormat.format(mzValue) + "\nData point intensity: " + intensityFormat.format(intValue) + "\nRelative intensity: " + percentFormat.format(relativeIntensity) + "%";
return tooltip;
}
if (dataset instanceof ExtendedIsotopePatternDataSet) {
return "Isotope pattern: " + ((ExtendedIsotopePatternDataSet) dataset).getIsotopePattern().getDescription() + "\nm/z: " + mzFormat.format(mzValue) + "\nIdentity: " + ((ExtendedIsotopePatternDataSet) dataset).getItemDescription(series, item) + "\nRelative intensity: " + percentFormat.format((dataset.getY(series, item).doubleValue() * 100)) + "%";
}
String tooltip = "m/z: " + mzFormat.format(mzValue) + "\nIntensity: " + intensityFormat.format(intValue);
return tooltip;
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class DPPSumFormulaPredictionTask method getIsotopeSimilarityScore.
private double getIsotopeSimilarityScore(IMolecularFormula cdkFormula, IsotopePattern detectedPattern) {
IsotopePattern predictedIsotopePattern = null;
Double isotopeScore = null;
String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
return isotopeScore;
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class PeakUtils method copyPeakProperties.
/**
* Copies properties such as isotope pattern and charge from the source peak to the target peak
*/
public static void copyPeakProperties(Feature source, Feature target) {
// Copy isotope pattern
IsotopePattern originalPattern = source.getIsotopePattern();
if (originalPattern != null)
target.setIsotopePattern(originalPattern);
// Copy charge
int charge = source.getCharge();
target.setCharge(charge);
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class ADAPInterface method getComponent.
public static Component getComponent(final PeakListRow row) {
if (row.getNumberOfPeaks() == 0)
throw new IllegalArgumentException("No peaks found");
NavigableMap<Double, Double> spectrum = new TreeMap<>();
// Read Spectrum information
IsotopePattern ip = row.getBestIsotopePattern();
if (ip != null) {
for (DataPoint dataPoint : ip.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
}
// Read Chromatogram
final Feature peak = row.getBestPeak();
final RawDataFile dataFile = peak.getDataFile();
NavigableMap<Double, Double> chromatogram = new TreeMap<>();
for (final int scan : peak.getScanNumbers()) {
final DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
}
return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Aggregations