use of de.ipbhalle.metfraglib.peak.MergedTandemMassPeak in project MetFragRelaunched by ipb-halle.
the class NewMergedPeakFragmenterScore method calculate.
public void calculate() {
this.matchList = (MatchList) settings.get(VariableNames.MATCH_LIST_NAME);
this.value = Double.valueOf(0);
this.bestFragmentIndeces = new int[this.matchList.getNumberElements()];
this.optimalValues = new double[this.matchList.getNumberElements()];
for (int i = 0; i < this.matchList.getNumberElements(); i++) {
DefaultFragmentToPeakMatch currentMatch = null;
boolean isMatchOfQuerySpectrum = true;
if (this.matchList.getElement(i) instanceof FragmentMassToPeakMatch)
currentMatch = (FragmentMassToPeakMatch) this.matchList.getElement(i);
else
currentMatch = (FragmentFormulaToPeakMatch) this.matchList.getElement(i);
double intensity = 0.0;
try {
intensity = currentMatch.getMatchedPeak().getIntensity();
} catch (RelativeIntensityNotDefinedException e) {
// if the match is not caused by a peak of the query spectrum
isMatchOfQuerySpectrum = false;
intensity = 0.0;
}
MergedTandemMassPeak matchedPeak = (MergedTandemMassPeak) currentMatch.getMatchedPeak();
FragmentList currentFragmentList = currentMatch.getMatchedFragmentList();
double minimumEnergyPerMatch = (double) Integer.MAX_VALUE;
/*
* get all intensities of random spectra of this peak
*/
java.util.ArrayList<Double> intensities = matchedPeak.getIntensities();
java.util.ArrayList<Integer> spectraIDs = matchedPeak.getSpectraIDs();
double peakScore = Math.pow((matchedPeak.getMass() / this.measuredPrecursorMass) * 10.0, this.ALPHA) * Math.pow(intensity, this.BETA);
double[] peakScores = new double[intensities.size()];
for (int k = 0; k < intensities.size(); k++) {
peakScores[k] = Math.pow((matchedPeak.getMass() / this.measuredPrecursorMass) * 10.0, this.ALPHA) * Math.pow(intensities.get(k), this.BETA);
}
for (int ii = 0; ii < currentFragmentList.getNumberElements(); ii++) {
IFragment currentFragment = currentFragmentList.getElement(ii);
/*
* check if current fragment is valid based on the tree depth
*/
// if(currentFragment.getTreeDepth() > this.maximumTreeDepth) continue;
int[] brokenBondIndeces = currentFragment.getBrokenBondIndeces();
double energyOfFragment = 0.0;
for (int bondIndex : brokenBondIndeces) {
energyOfFragment += this.bondEnergies[bondIndex];
}
energyOfFragment += Math.abs(currentMatch.getNumberOfHydrogensDifferToPeakMass(ii)) * this.WEIGHT_HYDROGEN_PENALTY;
/*
* assign optimal bondenergy and store best fragment
*/
if (energyOfFragment < minimumEnergyPerMatch) {
minimumEnergyPerMatch = energyOfFragment;
if (isMatchOfQuerySpectrum)
this.bestFragmentIndeces[i] = ii;
}
}
if (isMatchOfQuerySpectrum) {
currentMatch.initialiseBestMatchedFragment(this.bestFragmentIndeces[i]);
this.value += peakScore / Math.pow(minimumEnergyPerMatch, this.GAMMA);
this.optimalValues[i] = minimumEnergyPerMatch;
}
for (int k = 0; k < spectraIDs.size(); k++) {
this.scoresRandomSpectra[spectraIDs.get(k)] += peakScores[k] / Math.pow(minimumEnergyPerMatch, this.GAMMA);
}
}
int betterEqualScores = 0;
for (int i = 0; i < this.scoresRandomSpectra.length; i++) {
if (this.scoresRandomSpectra[i] >= this.value)
betterEqualScores++;
}
this.scoredCandidate.setProperty("p-value", (double) betterEqualScores / (double) this.scoresRandomSpectra.length);
this.calculationFinished = true;
}
use of de.ipbhalle.metfraglib.peak.MergedTandemMassPeak in project MetFragRelaunched by ipb-halle.
the class FilteredMergedRandomTandemMassPeakListReader method read.
@Override
public DefaultPeakList read() {
/*
* reading the query peak list
*/
SortedTandemMassPeakList peakList = (SortedTandemMassPeakList) super.read();
/*
* generating randomised spectra queried from massbank
*/
Double exactMass = (Double) this.settings.get(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME);
java.util.ArrayList<MergedTandemMassPeak> mergedTandemMassPeaks = new java.util.ArrayList<MergedTandemMassPeak>();
for (int i = 0; i < peakList.getNumberElements(); i++) {
MergedTandemMassPeak newMergedTandemMassPeak = new MergedTandemMassPeak(peakList.getElement(i).getMass(), peakList.getElement(i).getAbsoluteIntensity());
newMergedTandemMassPeak.setRelativeIntensity(peakList.getElement(i).getRelativeIntensity());
mergedTandemMassPeaks.add(newMergedTandemMassPeak);
}
int index = 0;
for (int i = 0; i < this.numberRandomSpectra; i++) {
double[][] currentRandomSpectrum = this.generateRandomSpectrum(exactMass, peakList);
for (int k = 0; k < currentRandomSpectrum.length; k++) {
index = 0;
boolean found = false;
while (index < mergedTandemMassPeaks.size()) {
if (mergedTandemMassPeaks.get(index).getMass() == currentRandomSpectrum[k][0]) {
found = true;
break;
} else if (mergedTandemMassPeaks.get(index).getMass() > currentRandomSpectrum[k][0]) {
break;
}
index++;
}
if (found) {
mergedTandemMassPeaks.get(index).getIntensities().add(currentRandomSpectrum[k][1]);
mergedTandemMassPeaks.get(index).getSpectraIDs().add(i);
} else {
MergedTandemMassPeak newMergedTandemMassPeak = new MergedTandemMassPeak(currentRandomSpectrum[k][0], -1.0);
newMergedTandemMassPeak.getIntensities().add(currentRandomSpectrum[k][1]);
newMergedTandemMassPeak.getSpectraIDs().add(i);
mergedTandemMassPeaks.add(index, newMergedTandemMassPeak);
}
}
}
SortedMergedTandemMassPeakList sortedMergedTandemMassPeakList = new SortedMergedTandemMassPeakList(exactMass);
for (int i = 0; i < mergedTandemMassPeaks.size(); i++) {
sortedMergedTandemMassPeakList.addElement(mergedTandemMassPeaks.get(i));
}
return sortedMergedTandemMassPeakList;
}
Aggregations