use of de.ipbhalle.metfraglib.match.HDFragmentMassToPeakMatch in project MetFragRelaunched by ipb-halle.
the class NewFragmenterLipidScore method calculateSingleMatch.
/**
*/
public Double[] calculateSingleMatch(IMatch currentMatch) {
if (currentMatch instanceof HDFragmentMassToPeakMatch)
return new Double[] { 0.0, null };
FragmentList currentFragmentList = currentMatch.getMatchedFragmentList();
double minimumEnergyPerMatch = (double) Integer.MAX_VALUE;
double peakScore = 0.0;
try {
peakScore = Math.pow((currentMatch.getMatchedPeak().getMass() / this.measuredPrecursorMass) * 10.0, this.ALPHA) * Math.pow(currentMatch.getMatchedPeak().getIntensity(), this.BETA);
} catch (RelativeIntensityNotDefinedException e) {
e.printStackTrace();
}
int indexOfBestFragment = -1;
double overallMatchScore = 0.0;
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 = ((AbstractTopDownBitArrayFragment) currentFragment).getBrokenBondsFastBitArray().getSetIndeces();
double energyOfFragment = 0.0;
for (int bondIndex : brokenBondIndeces) {
energyOfFragment += this.bondEnergies[bondIndex];
}
energyOfFragment += Math.abs(currentMatch.getNumberOfOverallHydrogensDifferToPeakMass(ii)) * this.WEIGHT_HYDROGEN_PENALTY;
/*
* assign optimal bondenergy and store best fragment
*/
overallMatchScore += peakScore / Math.pow(energyOfFragment, this.GAMMA);
if (energyOfFragment < minimumEnergyPerMatch) {
minimumEnergyPerMatch = energyOfFragment;
indexOfBestFragment = ii;
}
/*
if(((AbstractTopDownBitArrayFragment)currentFragment).getAtomsFastBitArray().toString().equals("111110001100010001")) {
System.out.println(((AbstractTopDownBitArrayFragment)currentFragment).getAtomsFastBitArray().toString() + " " +
((AbstractTopDownBitArrayFragment)currentFragment).getBondsFastBitArray().toString() + " " +
((AbstractTopDownBitArrayFragment)currentFragment).getBrokenBondsFastBitArray().toString() + " " + currentFragment.getID()
+ " " + energyOfFragment);
}
*/
}
this.calculationFinished = true;
if (indexOfBestFragment != -1)
currentMatch.initialiseBestMatchedFragment(indexOfBestFragment);
return new Double[] { overallMatchScore, minimumEnergyPerMatch };
}
use of de.ipbhalle.metfraglib.match.HDFragmentMassToPeakMatch in project MetFragRelaunched by ipb-halle.
the class HDNewFragmenterScore method calculateSingleMatch.
/**
*/
public Double[] calculateSingleMatch(IMatch currentMatch) {
if (!(currentMatch instanceof HDFragmentMassToPeakMatch))
return new Double[] { 0.0, null };
FragmentList currentFragmentList = currentMatch.getMatchedFragmentList();
double minimumEnergyPerMatch = (double) Integer.MAX_VALUE;
double peakScore = 0.0;
try {
peakScore = Math.pow((currentMatch.getMatchedPeak().getMass() / this.measuredPrecursorMass) * 10.0, this.ALPHA) * Math.pow(currentMatch.getMatchedPeak().getIntensity(), this.BETA);
} catch (RelativeIntensityNotDefinedException e) {
e.printStackTrace();
}
int indexOfBestFragment = -1;
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 = ((AbstractTopDownBitArrayFragment) currentFragment).getBrokenBondsFastBitArray().getSetIndeces();
double energyOfFragment = 0.0;
for (int bondIndex : brokenBondIndeces) {
energyOfFragment += this.bondEnergies[bondIndex];
}
energyOfFragment += Math.abs(currentMatch.getNumberOfOverallHydrogensDifferToPeakMass(ii)) * this.WEIGHT_HYDROGEN_PENALTY;
/*
* assign optimal bondenergy and store best fragment
*/
if (energyOfFragment < minimumEnergyPerMatch) {
minimumEnergyPerMatch = energyOfFragment;
indexOfBestFragment = ii;
}
}
if (indexOfBestFragment != -1)
currentMatch.initialiseBestMatchedFragment(indexOfBestFragment);
return new Double[] { peakScore / Math.pow(minimumEnergyPerMatch, this.GAMMA), minimumEnergyPerMatch };
}
use of de.ipbhalle.metfraglib.match.HDFragmentMassToPeakMatch in project MetFragRelaunched by ipb-halle.
the class HDTopDownBitArrayFragmentWrapper method matchToPeak.
/**
* check math for HD fragment
*
* @param peak
* @param precursorIonTypeIndex
* @param isPositive
* @param fragmentPeakMatch
* @return
*/
public byte matchToPeak(IMolecularStructure precursorMolecule, IPeak peak, int precursorIonTypeIndex, boolean isPositive, IMatch[] fragmentPeakMatch) {
if (fragmentPeakMatch == null || fragmentPeakMatch.length != 1)
return -1;
double[] ionisationTypeMassCorrection = new double[] { Constants.getIonisationTypeMassCorrection(precursorIonTypeIndex, isPositive), Constants.getIonisationTypeMassCorrection(0, isPositive) };
// count number deuteriums of current fragment
byte numberDeuteriums = 0;
// get current precursor
HDTopDownBitArrayPrecursor currentPrecursor = (HDTopDownBitArrayPrecursor) precursorMolecule;
for (int i = 0; i < this.wrappedFragment.getAtomsFastBitArray().getSize(); i++) if (this.wrappedFragment.getAtomsFastBitArray().get(i))
numberDeuteriums += currentPrecursor.getNumberDeuteriumsConnectedToAtomIndex(this.precursorIndex, i);
// correct ionisation type in case no deuterium is attached to fragment
if (numberDeuteriums == 0 && Constants.ADDUCT_NOMINAL_MASSES.get(precursorIonTypeIndex) == -2)
ionisationTypeMassCorrection[0] = Constants.getIonisationTypeMassCorrection(Constants.ADDUCT_NOMINAL_MASSES.indexOf(-1), isPositive);
// number variable deuteriums are equal over all fragments
byte variableDeuteriums = (byte) currentPrecursor.getNumberVariableDeuteriums();
double[] shifts = new double[(this.wrappedFragment.getTreeDepth() * 2) + 1];
shifts[0] = 0.0;
int index = 1;
// hydrogen/deuterium shift array
boolean[] toUseForHydrogen = new boolean[(this.wrappedFragment.getTreeDepth() * 2) + 1];
boolean[] toUseForDeuterium = new boolean[(this.wrappedFragment.getTreeDepth() * 2) + 1];
/*
* set all shifts as possible
*/
for (int i = 0; i < toUseForHydrogen.length; i++) {
toUseForHydrogen[i] = true;
toUseForDeuterium[i] = true;
}
for (int i = 1; i <= this.wrappedFragment.getTreeDepth(); i++) {
shifts[index++] = i;
shifts[index++] = -1.0 * (double) i;
}
/*
* find shifts that are not possible
*/
for (int i = 1; i <= this.wrappedFragment.getTreeDepth(); i++) if (i + (this.wrappedFragment.getNumberHydrogens() - variableDeuteriums) > currentPrecursor.getNumberHydrogens()) {
toUseForHydrogen[2 * i - 1] = false;
toUseForHydrogen[2 * i] = false;
}
for (int i = 1; i <= this.wrappedFragment.getTreeDepth(); i++) {
if (i + numberDeuteriums > currentPrecursor.getNumberOverallDeuteriums()) {
toUseForDeuterium[2 * i - 1] = false;
toUseForDeuterium[2 * i] = false;
}
}
byte numberCompareResultsEqualPlusOne = 0;
byte numberCompareResultsEqualMinusOne = 0;
byte numberComparisons = 0;
boolean matched = false;
short numberDeuteriumsPrecusor = currentPrecursor.getNumberOverallDeuteriums();
short numberHydrogensPrecusor = currentPrecursor.getNumberHydrogens();
for (int p = 0; p < ionisationTypeMassCorrection.length; p++) {
int substractDeuteriumFromCharge = 0;
int substractHydrogenFromCharge = 0;
if (p == 0 && precursorIonTypeIndex == 1)
substractHydrogenFromCharge = 1;
if (p == 0 && precursorIonTypeIndex == 3)
substractDeuteriumFromCharge = 1;
for (int i = 0; i < toUseForDeuterium.length; i++) {
if (!toUseForDeuterium[i])
continue;
for (int j = 0; j < toUseForHydrogen.length; j++) {
// loop for variable deuteriums
for (byte k = 0; k <= variableDeuteriums; k++) {
if (!toUseForHydrogen[i]) {
continue;
}
if (Math.abs(shifts[i]) + Math.abs(shifts[j]) > this.wrappedFragment.getTreeDepth()) {
continue;
}
// check number overall hydrogens smaller zero
if (shifts[i] + shifts[j] + this.wrappedFragment.getNumberHydrogens() - substractHydrogenFromCharge < 0) {
continue;
}
// check number normal hydrogens smaller zero (shifts[j] -> number shifted hydrogens)
if (shifts[j] + (this.wrappedFragment.getNumberHydrogens() - numberDeuteriums) - substractHydrogenFromCharge < 0) {
continue;
}
// check number overall hydrogens greater than hydrogens available
if ((int) (shifts[i] + shifts[j] + this.wrappedFragment.getNumberHydrogens()) > numberHydrogensPrecusor) {
continue;
}
// number of overall deuteriums of fragment must not be smaller than 0
if (shifts[i] + k + numberDeuteriums - substractDeuteriumFromCharge < 0) {
continue;
}
// of deuteriums of the precursor
if (shifts[i] + k + numberDeuteriums > numberDeuteriumsPrecusor) {
continue;
}
numberComparisons++;
// calculate corrected fragment mass
// includes hydrogen/deuterium shift
double monoisotopicFragmentMass = this.wrappedFragment.getMonoisotopicMass(precursorMolecule);
// correct fragment mass by number of exchanged hydrogens
monoisotopicFragmentMass += Constants.getMonoisotopicMassOfAtom("D") * (double) numberDeuteriums - Constants.getMonoisotopicMassOfAtom("H") * (double) numberDeuteriums;
double currentFragmentMass = monoisotopicFragmentMass + ionisationTypeMassCorrection[p] + (shifts[j]) * Constants.getMonoisotopicMassOfAtom("H") + (Constants.getMonoisotopicMassOfAtom("D") * (double) k - Constants.getMonoisotopicMassOfAtom("H") * (double) k) + (shifts[i] * Constants.getMonoisotopicMassOfAtom("D"));
byte compareResult = ((TandemMassPeak) peak).matchesToMass(currentFragmentMass);
if (compareResult == 0) {
if (fragmentPeakMatch[0] != null) {
((HDFragmentMassToPeakMatch) fragmentPeakMatch[0]).addMatchedFragment(this.wrappedFragment, (byte) shifts[j], (byte) shifts[i], currentFragmentMass, p == 0 ? (byte) precursorIonTypeIndex : (byte) 0, k, numberDeuteriums);
} else {
fragmentPeakMatch[0] = new HDFragmentMassToPeakMatch(peak);
fragmentPeakMatch[0].setIsPositiveCharge(isPositive);
((HDFragmentMassToPeakMatch) fragmentPeakMatch[0]).addMatchedFragment(this.wrappedFragment, (byte) shifts[j], (byte) shifts[i], currentFragmentMass, p == 0 ? (byte) precursorIonTypeIndex : (byte) 0, k, numberDeuteriums);
}
matched = true;
((HDFragmentMassToPeakMatch) fragmentPeakMatch[0]).setIsPositiveCharge(isPositive);
} else if (compareResult == 1)
numberCompareResultsEqualPlusOne++;
else if (compareResult == -1)
numberCompareResultsEqualMinusOne++;
}
}
}
}
if (matched) {
this.wrappedFragment.setHasMatched();
return 0;
}
if (numberCompareResultsEqualPlusOne == numberComparisons)
return 1;
if (numberCompareResultsEqualMinusOne == numberComparisons)
return -1;
return -1;
}
use of de.ipbhalle.metfraglib.match.HDFragmentMassToPeakMatch in project MetFragRelaunched by ipb-halle.
the class HDFragmentPairScore method checkForMatchingFragments.
/**
* @param fragmentList
* @param fragmentListHD
* @param deuteriumShift
* @return
*/
private boolean checkForMatchingFragments(MatchFragmentList fragmentList, MatchFragmentList fragmentListHD, int deuteriumShift) {
MatchFragmentNode node = fragmentList.getRootNode();
MatchFragmentNode nodeHD = fragmentListHD.getRootNode();
while (node != null) {
while (nodeHD != null) {
for (int i = 0; i < node.getMatch().getMatchedFragmentsSize(); i++) {
HDFragmentMassToPeakMatch matchHD = ((HDFragmentMassToPeakMatch) nodeHD.getMatch());
int numberMatchedFragmentsHD = matchHD.getMatchedFragmentsSize();
for (int j = 0; j < numberMatchedFragmentsHD; j++) {
int numberDeuteriumsOfMatchedFragment = 0;
int deuteriumsOfMatchedFragment = matchHD.getNumberOfDeuteriumsOfMatchedFragment(j);
int deuteriumDifferenceOfMatchedFragment = matchHD.getNumberOfDeuteriumDifferToPeakMass(j);
int deuteriumFromCharge = 0;
if (Constants.ADDUCT_NOMINAL_MASSES.get(matchHD.getFragmentsAdductTypeIndex(j)) == 2)
deuteriumFromCharge = 1;
else if (Constants.ADDUCT_NOMINAL_MASSES.get(matchHD.getFragmentsAdductTypeIndex(j)) == -2)
deuteriumFromCharge = -1;
numberDeuteriumsOfMatchedFragment = deuteriumsOfMatchedFragment + deuteriumDifferenceOfMatchedFragment + deuteriumFromCharge;
IFragment fragment = node.getMatch().getMatchedFragmentList().getElement(i);
IFragment fragmentHD = nodeHD.getMatch().getMatchedFragmentList().getElement(j);
if (fragment.equals(fragmentHD) && numberDeuteriumsOfMatchedFragment == deuteriumShift)
return true;
}
}
nodeHD = nodeHD.getNext();
}
node = node.getNext();
}
return false;
}
use of de.ipbhalle.metfraglib.match.HDFragmentMassToPeakMatch in project MetFragRelaunched by ipb-halle.
the class HDFragmentPairScore2 method checkForMatchingFragments.
/**
* @param fragmentList
* @param fragmentListHD
* @param deuteriumShift
* @return
*/
private boolean checkForMatchingFragments(MatchFragmentList fragmentList, MatchFragmentList fragmentListHD, int deuteriumShift) {
MatchFragmentNode node = fragmentList.getRootNode();
MatchFragmentNode nodeHD = fragmentListHD.getRootNode();
while (node != null) {
while (nodeHD != null) {
for (int i = 0; i < node.getMatch().getMatchedFragmentsSize(); i++) {
HDFragmentMassToPeakMatch matchHD = ((HDFragmentMassToPeakMatch) nodeHD.getMatch());
int numberMatchedFragmentsHD = matchHD.getMatchedFragmentsSize();
for (int j = 0; j < numberMatchedFragmentsHD; j++) {
int numberDeuteriumsOfMatchedFragment = 0;
int deuteriumsOfMatchedFragment = matchHD.getNumberOfDeuteriumsOfMatchedFragment(j);
int deuteriumDifferenceOfMatchedFragment = matchHD.getNumberOfDeuteriumDifferToPeakMass(j);
int deuteriumFromCharge = 0;
if (Constants.ADDUCT_NOMINAL_MASSES.get(matchHD.getFragmentsAdductTypeIndex(j)) == 2)
deuteriumFromCharge = 1;
else if (Constants.ADDUCT_NOMINAL_MASSES.get(matchHD.getFragmentsAdductTypeIndex(j)) == -2)
deuteriumFromCharge = -1;
numberDeuteriumsOfMatchedFragment = deuteriumsOfMatchedFragment + deuteriumDifferenceOfMatchedFragment + deuteriumFromCharge;
IFragment fragment = node.getMatch().getMatchedFragmentList().getElement(i);
IFragment fragmentHD = nodeHD.getMatch().getMatchedFragmentList().getElement(j);
// if(fragment.equals(fragmentHD) && numberDeuteriumsOfMatchedFragment == deuteriumShift) return true;
if (fragment.equals(fragmentHD)) {
if (numberDeuteriumsOfMatchedFragment == deuteriumShift)
return true;
else if ((numberDeuteriumsOfMatchedFragment - deuteriumFromCharge) == deuteriumShift)
return true;
}
}
}
nodeHD = nodeHD.getNext();
}
node = node.getNext();
}
return false;
}
Aggregations