use of net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance 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 net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance in project mzmine2 by mzmine.
the class MassListDeisotoper method filterIsotopes.
public static DataPoint[] filterIsotopes(DataPoint[] dataPoints, ParameterSet parameterSet) {
if (dataPoints == null || dataPoints.length == 0) {
return dataPoints;
}
MZTolerance mzTolerance = parameterSet.getParameter(MassListDeisotoperParameters.mzTolerance).getValue();
boolean monotonicShape = parameterSet.getParameter(MassListDeisotoperParameters.monotonicShape).getValue();
int maximumCharge = parameterSet.getParameter(MassListDeisotoperParameters.maximumCharge).getValue();
int[] charges = new int[maximumCharge];
for (int i = 0; i < maximumCharge; i++) charges[i] = i + 1;
// sort by intensity
dataPoints = dataPoints.clone();
Arrays.sort(dataPoints, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
List<DataPoint> deisotopedDataPoints = new ArrayList<>();
for (int i = 0; i < dataPoints.length; i++) {
DataPoint aPeak = dataPoints[i];
if (aPeak == null) {
continue;
}
// Check which charge state fits best around this peak
int bestFitCharge = 0;
int bestFitScore = -1;
List<DataPoint> bestFitPeaks = null;
for (int charge : charges) {
List<DataPoint> fittedPeaks = new ArrayList<>();
fittedPeaks.add(aPeak);
fitPattern(fittedPeaks, aPeak, charge, dataPoints, DELTA, monotonicShape, mzTolerance);
int score = fittedPeaks.size();
if ((score > bestFitScore) || ((score == bestFitScore) && (bestFitCharge > charge))) {
bestFitScore = score;
bestFitCharge = charge;
bestFitPeaks = fittedPeaks;
}
}
assert bestFitPeaks != null;
// add to deisotoped
deisotopedDataPoints.add(dataPoints[i]);
// remove all
for (int j = 0; j < dataPoints.length; j++) {
if (bestFitPeaks.contains(dataPoints[j]))
dataPoints[j] = null;
}
}
return deisotopedDataPoints.toArray(new DataPoint[deisotopedDataPoints.size()]);
}
Aggregations