use of de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class SimulateSpectrumHDX method generateDeuteratedSpectrumNegative.
/**
* @param candidate
* @return
* @throws AtomTypeNotKnownFromInputListException
* @throws Exception
*/
public static double[][] generateDeuteratedSpectrumNegative(ICandidate candidate, int method) throws AtomTypeNotKnownFromInputListException, Exception {
int numberPositions = searchForDeuteriumExchangeablePositions((TopDownBitArrayPrecursor) candidate.getPrecursorMolecule()).length;
HDTopDownBitArrayPrecursor preHDX = new HDTopDownBitArrayPrecursor(candidate.getImplicitHydrogenAtomContainer(), (byte) numberPositions);
preHDX.preprocessPrecursor();
MatchList matchList = candidate.getMatchList();
double[][] spectrumHDX = null;
if (method == 3)
spectrumHDX = new double[matchList.getNumberElements() * 2][2];
else
spectrumHDX = new double[matchList.getNumberElements()][2];
for (int i = 0; i < matchList.getNumberElements(); i++) {
IFragment frag = matchList.getElement(i).getBestMatchedFragment();
IPeak peak = matchList.getElement(i).getMatchedPeak();
int[] setAtoms = ((DefaultBitArrayFragment) frag).getAtomsFastBitArray().getSetIndeces();
int numberDeuteriums = 0;
for (int k = 0; k < setAtoms.length; k++) {
numberDeuteriums += preHDX.getNumberDeuteriumsConnectedToAtomIndex(0, setAtoms[k]);
}
spectrumHDX[i][1] = peak.getAbsoluteIntensity();
// [M-D]-
if (method == 1) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[i][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // [M]-
if (method == 2) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
// nothing to do
} else // [M]- [M-D]-
if (method == 3) {
spectrumHDX[i * 2][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // predict based on deuteriums
if (method == 4) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (numberDeuteriums != 0)
spectrumHDX[i][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // predict based on adduct
if (method == 5) {
byte adductTypeIndex = ((DefaultFragmentToPeakMatch) matchList.getElement(i)).getBestMatchedFragmentAdductTypeIndex();
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (adductTypeIndex == 1)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
}
}
return spectrumHDX;
}
use of de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor 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.precursor.HDTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class MoleculeFunctions method getStructureAsIAtomContainerHD.
public static IAtomContainer getStructureAsIAtomContainerHD(IMolecularStructure precursorMolecule, IFragment fragment, int precursorIndexHD) throws CloneNotSupportedException {
HDTopDownBitArrayPrecursor precursor = (HDTopDownBitArrayPrecursor) precursorMolecule;
de.ipbhalle.metfraglib.FastBitArray atomsFastBitArray = ((de.ipbhalle.metfraglib.fragment.DefaultBitArrayFragment) fragment).getAtomsFastBitArray();
de.ipbhalle.metfraglib.FastBitArray bondsFastBitArray = ((de.ipbhalle.metfraglib.fragment.DefaultBitArrayFragment) fragment).getBondsFastBitArray();
IAtomContainer mol = precursor.getStructureAsIAtomContainer().clone();
prepareAtomContainer(mol, false);
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
IAtomContainer fragmentStructure = builder.newInstance(IAtomContainer.class);
if (atomsFastBitArray.cardinality() == 1) {
int firstSetBit = atomsFastBitArray.getFirstSetBit();
IAtom atom = (IAtom) mol.getAtom(firstSetBit).clone();
fragmentStructure.addAtom(atom);
int numberDeuteriums = precursor.getNumberDeuteriumsConnectedToAtomIndex(precursorIndexHD, firstSetBit);
for (int i = 0; i < numberDeuteriums; i++) {
IAtom hydrogen = new Atom("H");
fragmentStructure.addAtom(hydrogen);
atom.setImplicitHydrogenCount(atom.getImplicitHydrogenCount() - 1);
IBond bond = new org.openscience.cdk.Bond(hydrogen, atom);
fragmentStructure.addBond(bond);
}
return fragmentStructure;
}
for (int i = 0; i < atomsFastBitArray.getSize(); i++) {
if (atomsFastBitArray.get(i)) {
int numberDeuteriums = precursor.getNumberDeuteriumsConnectedToAtomIndex(precursorIndexHD, i);
IAtom atom = mol.getAtom(i);
for (int k = 0; k < numberDeuteriums; k++) {
IAtom hydrogen = new Atom("H");
fragmentStructure.addAtom(hydrogen);
atom.setImplicitHydrogenCount(atom.getImplicitHydrogenCount() - 1);
IBond bond = new org.openscience.cdk.Bond(hydrogen, atom);
fragmentStructure.addBond(bond);
}
}
}
for (int i = 0; i < bondsFastBitArray.getSize(); i++) {
if (bondsFastBitArray.get(i)) {
IBond curBond = mol.getBond(i);
for (IAtom atom : curBond.atoms()) {
fragmentStructure.addAtom(atom);
}
fragmentStructure.addBond(curBond);
}
}
// loss of hydrogens
MoleculeFunctions.prepareAtomContainer(fragmentStructure, false);
return fragmentStructure;
}
use of de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class HDPrecursorCandidateWrapper method initialisePrecursorCandidate.
public void initialisePrecursorCandidate() throws Exception {
this.candidate.setPrecursorMolecule(new HDTopDownBitArrayPrecursor(this.candidate.getImplicitHydrogenAtomContainer(), this.candidate.getProperty(VariableNames.HD_NUMBER_EXCHANGED_HYDROGENS) != null ? (Byte) this.candidate.getProperty(VariableNames.HD_NUMBER_EXCHANGED_HYDROGENS) : (byte) 0));
this.candidate.getPrecursorMolecule().preprocessPrecursor();
}
use of de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class SimulateSpectrumHDX method generateDeuteratedSpectrumPositive.
/**
* @param candidate
* @return
* @throws AtomTypeNotKnownFromInputListException
* @throws Exception
*/
public static double[][] generateDeuteratedSpectrumPositive(ICandidate candidate, int method) throws AtomTypeNotKnownFromInputListException, Exception {
int numberPositions = searchForDeuteriumExchangeablePositions((TopDownBitArrayPrecursor) candidate.getPrecursorMolecule()).length;
HDTopDownBitArrayPrecursor preHDX = new HDTopDownBitArrayPrecursor(candidate.getImplicitHydrogenAtomContainer(), (byte) numberPositions);
preHDX.preprocessPrecursor();
MatchList matchList = candidate.getMatchList();
double[][] spectrumHDX = null;
if (method == 3)
spectrumHDX = new double[matchList.getNumberElements() * 2][2];
else
spectrumHDX = new double[matchList.getNumberElements()][2];
for (int i = 0; i < matchList.getNumberElements(); i++) {
IFragment frag = matchList.getElement(i).getBestMatchedFragment();
IPeak peak = matchList.getElement(i).getMatchedPeak();
int[] setAtoms = ((DefaultBitArrayFragment) frag).getAtomsFastBitArray().getSetIndeces();
int numberDeuteriums = 0;
for (int k = 0; k < setAtoms.length; k++) {
numberDeuteriums += preHDX.getNumberDeuteriumsConnectedToAtomIndex(0, setAtoms[k]);
}
if (method != 3) {
spectrumHDX[i][1] = peak.getAbsoluteIntensity();
} else {
spectrumHDX[i * 2][1] = peak.getAbsoluteIntensity();
spectrumHDX[(i * 2) + 1][1] = peak.getAbsoluteIntensity();
}
// [M+D]+
if (method == 1) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // [M]+
if (method == 2) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
// nothing to do
} else // [M]+ [M+D]+
if (method == 3) {
spectrumHDX[i * 2][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // predict based on in silico added deuteriums
if (method == 4) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (numberDeuteriums != 0)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // predict based on adduct
if (method == 5) {
byte adductTypeIndex = ((DefaultFragmentToPeakMatch) matchList.getElement(i)).getBestMatchedFragmentAdductTypeIndex();
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (adductTypeIndex == 2)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
}
if (method != 3) {
spectrumHDX[i][0] = MathTools.round(spectrumHDX[i][0]);
} else {
spectrumHDX[i * 2][0] = MathTools.round(spectrumHDX[i * 2][0]);
spectrumHDX[(i * 2) + 1][0] = MathTools.round(spectrumHDX[(i * 2) + 1][0]);
}
}
return spectrumHDX;
}
Aggregations