use of de.ipbhalle.metfraglib.interfaces.IFragment in project MetFragRelaunched by ipb-halle.
the class CandidateListWriterLossFragmentSmilesPSV method createLossAnnotations.
/**
* @param matchList
* @param settings
* @throws Exception
*/
private String createLossAnnotations(IMolecularStructure precursorMolecule, MatchList matchList, Settings settings, double[] correctedMasses, Fingerprint fingerprint) throws Exception {
java.util.ArrayList<String> lossFingerprint = new java.util.ArrayList<String>();
java.util.ArrayList<Double> lossMassDiff = new java.util.ArrayList<Double>();
// for the precursor ion
int ionmode = (Integer) settings.get(VariableNames.PRECURSOR_ION_MODE_NAME);
boolean ispositive = (Boolean) settings.get(VariableNames.IS_POSITIVE_ION_MODE_NAME);
double adductMass = Constants.getIonisationTypeMassCorrection(Constants.ADDUCT_NOMINAL_MASSES.indexOf(ionmode), ispositive);
double precursorMass = (Double) settings.get(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME);
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
precursorMass = precursorMolecule.getNeutralMonoisotopicMass();
double ionmass = MathTools.round(precursorMass + adductMass);
// check all matches
for (int i = 0; i < matchList.getNumberElements(); i++) {
IMatch matchI = matchList.getElement(i);
IFragment fragmentI = matchI.getBestMatchedFragment();
double peakMassI = matchI.getMatchedPeak().getMass();
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
peakMassI = correctedMasses[i];
// compare with matches having greater mass than the current one
for (int j = i + 1; j < matchList.getNumberElements(); j++) {
IMatch matchJ = matchList.getElement(j);
double peakMassJ = matchJ.getMatchedPeak().getMass();
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
peakMassJ = correctedMasses[j];
IFragment fragmentJ = matchJ.getBestMatchedFragment();
if (fragmentJ.isRealSubStructure(fragmentI)) {
double diff = MathTools.round(peakMassJ - peakMassI);
IFragment diffFragment = fragmentJ.getDifferenceFragment(precursorMolecule, fragmentI);
if (diffFragment == null)
continue;
IAtomContainer con = fingerprint.getNormalizedAtomContainer(precursorMolecule, diffFragment);
lossFingerprint.add(fingerprint.getNormalizedFingerprint(con));
lossMassDiff.add(diff);
}
}
// do the same for the precursor ion
double diff = MathTools.round(ionmass - peakMassI);
IFragment diffFragment = fragmentI.getDifferenceFragment(precursorMolecule);
if (diffFragment == null)
continue;
IAtomContainer con = fingerprint.getNormalizedAtomContainer(precursorMolecule, diffFragment);
lossFingerprint.add(fingerprint.getNormalizedFingerprint(con));
lossMassDiff.add(diff);
}
StringBuilder diffFingerPrint = new StringBuilder();
if (lossMassDiff.size() >= 1) {
diffFingerPrint.append(lossMassDiff.get(0));
diffFingerPrint.append(":");
diffFingerPrint.append(lossFingerprint.get(0));
}
for (int i = 1; i < lossMassDiff.size(); i++) {
diffFingerPrint.append(";");
diffFingerPrint.append(lossMassDiff.get(i));
diffFingerPrint.append(":");
diffFingerPrint.append(lossFingerprint.get(i));
}
return diffFingerPrint.length() == 0 ? "NA" : diffFingerPrint.toString();
}
use of de.ipbhalle.metfraglib.interfaces.IFragment in project MetFragRelaunched by ipb-halle.
the class AutomatedPeakFingerprintAnnotationScoreInitialiser method postProcessScoreParameters.
public void postProcessScoreParameters(Settings settings) throws Exception {
CombinedSingleCandidateMetFragProcess[] processes = (CombinedSingleCandidateMetFragProcess[]) settings.get(VariableNames.METFRAG_PROCESSES_NAME);
// to determine F_u
MassToFingerprintsHashMap peakMassToFingerprints = new MassToFingerprintsHashMap();
MassToFingerprintGroupListCollection peakToFingerprintGroupListCollection = (MassToFingerprintGroupListCollection) settings.get(VariableNames.PEAK_TO_FINGERPRINT_GROUP_LIST_COLLECTION_NAME);
Fingerprint fingerprint = new Fingerprint((String) settings.get(VariableNames.FINGERPRINT_TYPE_NAME));
DefaultPeakList peakList = (DefaultPeakList) settings.get(VariableNames.PEAK_LIST_NAME);
for (CombinedSingleCandidateMetFragProcess scmfp : processes) {
/*
* check whether the single run was successful
*/
if (scmfp.wasSuccessful()) {
ICandidate candidate = scmfp.getScoredPrecursorCandidates()[0];
MatchList matchlist = candidate.getMatchList();
java.util.LinkedList<Double> nonExplainedPeaks = this.getNonExplainedPeaks(peakList, matchlist);
java.util.ArrayList<MassFingerprintMatch> peakMatchlist = new java.util.ArrayList<MassFingerprintMatch>();
int numberMatchedPeaks = matchlist == null ? 0 : matchlist.getNumberElements();
candidate.initialisePrecursorCandidate();
for (int j = 0; j < numberMatchedPeaks + nonExplainedPeaks.size(); j++) {
FastBitArray currentFingerprint = null;
Double mass = null;
// check if it's a valid match (peak-fragment assignment)
if (j < matchlist.getNumberElements()) {
IMatch match = matchlist.getElement(j);
mass = match.getMatchedPeak().getMass();
IFragment frag = match.getBestMatchedFragment();
try {
IAtomContainer conPre = fingerprint.getNormalizedAtomContainer(candidate.getPrecursorMolecule(), frag);
// IAtomContainer con = MoleculeFunctions.convertImplicitToExplicitHydrogens(conPre);
currentFingerprint = fingerprint.getNormalizedFastBitArrayFingerprint(conPre);
} catch (InvalidSmilesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CDKException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// else it must be a non-matched peak
mass = nonExplainedPeaks.get(j - matchlist.getNumberElements());
currentFingerprint = new FastBitArray("0");
}
MassToFingerprintGroupList peakToFingerprintGroupList = peakToFingerprintGroupListCollection.getElementByPeak(mass);
if (peakToFingerprintGroupList == null)
continue;
peakMatchlist.add(new MassFingerprintMatch(mass, currentFingerprint));
// check whether fingerprint was observed for current peak mass in the training data
if (!peakToFingerprintGroupList.containsFingerprint(currentFingerprint)) {
// if not add the fingerprint to background by addFingerprint function
// addFingerprint checks also whether fingerprint was already added
peakMassToFingerprints.addFingerprint(mass, currentFingerprint);
}
}
candidate.setProperty("PeakMatchList", peakMatchlist);
}
}
// f_s
double f_seen_matched = (double) settings.get(VariableNames.PEAK_FINGERPRINT_MATCHED_TUPLE_COUNT_NAME);
// f_s
double f_seen_non_matched = (double) settings.get(VariableNames.PEAK_FINGERPRINT_NON_MATCHED_TUPLE_COUNT_NAME);
// f_u
double f_unseen_matched = peakMassToFingerprints.getOverallMatchedSize();
// f_u
double f_unseen_non_matched = peakMassToFingerprints.getOverallNonMatchedSize();
// alpha
double alpha = (double) settings.get(VariableNames.PEAK_FINGERPRINT_ANNOTATION_ALPHA_VALUE_NAME);
// beta
double beta = (double) settings.get(VariableNames.PEAK_FINGERPRINT_ANNOTATION_BETA_VALUE_NAME);
// \sum_N \sum_Ln 1
double sumFingerprintFrequencies = (double) settings.get(VariableNames.PEAK_FINGERPRINT_DENOMINATOR_COUNT_NAME);
// set value for denominator of P(f,m)
double denominatorValue = sumFingerprintFrequencies + alpha * (f_seen_matched + f_unseen_matched) + beta * (f_seen_non_matched + f_unseen_non_matched);
settings.set(VariableNames.PEAK_FINGERPRINT_DENOMINATOR_VALUE_NAME, denominatorValue);
// P(f,m) F_u
double alphaProbability = alpha / denominatorValue;
// p(f,m) not annotated
double betaProbability = beta / denominatorValue;
for (int i = 0; i < peakToFingerprintGroupListCollection.getNumberElements(); i++) {
MassToFingerprintGroupList groupList = peakToFingerprintGroupListCollection.getElement(i);
// sum_f P(f,m)
// calculate sum of MF_s (including the alpha count) and the joint probabilities
// at this stage getProbability() returns the absolute counts from the annotation files
double sum_f = 0.0;
double sumFsProbabilities = 0.0;
for (int ii = 0; ii < groupList.getNumberElements(); ii++) {
// first calculate P(f,m)
if (groupList.getElement(ii).getFingerprint().getSize() != 1)
groupList.getElement(ii).setJointProbability((groupList.getElement(ii).getProbability() + alpha) / denominatorValue);
else
groupList.getElement(ii).setJointProbability((groupList.getElement(ii).getProbability() + beta) / denominatorValue);
// sum_f P(f,m) -> for F_s
sumFsProbabilities += groupList.getElement(ii).getJointProbability();
}
// calculate the sum of probabilities for un-observed fingerprints for the current mass
double sumFuProbabilities = alphaProbability * peakMassToFingerprints.getSizeMatched(groupList.getPeakmz());
sumFuProbabilities += betaProbability;
sum_f += sumFsProbabilities;
sum_f += sumFuProbabilities;
for (int ii = 0; ii < groupList.getNumberElements(); ii++) {
// second calculate P(f|m)
groupList.getElement(ii).setConditionalProbability_sp(groupList.getElement(ii).getJointProbability() / sum_f);
}
groupList.setAlphaProb(alphaProbability / sum_f);
groupList.setBetaProb(betaProbability / sum_f);
groupList.setProbabilityToConditionalProbability_sp();
groupList.calculateSumProbabilites();
}
return;
}
use of de.ipbhalle.metfraglib.interfaces.IFragment in project MetFragRelaunched by ipb-halle.
the class CandidateListWriterLossFragmentSmilesCompletePSV method createLossAnnotations.
/**
* @param matchList
* @param settings
* @throws Exception
*/
private String[][] createLossAnnotations(IMolecularStructure precursorMolecule, MatchList matchList, Settings settings, double[] correctedMasses, FingerprintCollection fingerprintCollection, java.util.ArrayList<Double> uncorrectedMassDiff) throws Exception {
java.util.ArrayList<String[]> lossFingerprint = new java.util.ArrayList<String[]>();
java.util.ArrayList<Double> lossMassDiff = new java.util.ArrayList<Double>();
// for the precursor ion
int ionmode = (Integer) settings.get(VariableNames.PRECURSOR_ION_MODE_NAME);
boolean ispositive = (Boolean) settings.get(VariableNames.IS_POSITIVE_ION_MODE_NAME);
double adductMass = Constants.getIonisationTypeMassCorrection(Constants.ADDUCT_NOMINAL_MASSES.indexOf(ionmode), ispositive);
double precursorMass = (Double) settings.get(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME);
double uncorrectedPrecursorMass = precursorMass;
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
precursorMass = precursorMolecule.getNeutralMonoisotopicMass();
double ionmass = MathTools.round(precursorMass + adductMass);
double uncorrectedIonmass = MathTools.round(uncorrectedPrecursorMass + adductMass);
// check all matches
for (int i = 0; i < matchList.getNumberElements(); i++) {
IMatch matchI = matchList.getElement(i);
IFragment fragmentI = matchI.getBestMatchedFragment();
double peakMassI = matchI.getMatchedPeak().getMass();
double uncorrectedPeakMassI = peakMassI;
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
peakMassI = correctedMasses[i];
// compare with matches with greater mass than the current one
for (int j = i + 1; j < matchList.getNumberElements(); j++) {
IMatch matchJ = matchList.getElement(j);
double peakMassJ = matchJ.getMatchedPeak().getMass();
double uncorrectedPeakMassJ = peakMassJ;
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME))
peakMassJ = correctedMasses[j];
IFragment fragmentJ = matchJ.getBestMatchedFragment();
if (fragmentJ.isRealSubStructure(fragmentI)) {
double diff = MathTools.round(peakMassJ - peakMassI);
double uncorrectedDiff = MathTools.round(uncorrectedPeakMassJ - uncorrectedPeakMassI);
IFragment diffFragment = fragmentJ.getDifferenceFragment(precursorMolecule, fragmentI);
if (diffFragment == null)
continue;
IAtomContainer con = fingerprintCollection.getNormalizedAtomContainer(precursorMolecule, diffFragment);
lossFingerprint.add(fingerprintCollection.getNormalizedFingerprint(con));
lossMassDiff.add(diff);
uncorrectedMassDiff.add(uncorrectedDiff);
}
}
// do the same for the precursor ion
double diff = MathTools.round(ionmass - peakMassI);
double uncorrectedDiff = MathTools.round(uncorrectedIonmass - uncorrectedPeakMassI);
IFragment diffFragment = fragmentI.getDifferenceFragment(precursorMolecule);
if (diffFragment == null)
continue;
IAtomContainer con = fingerprintCollection.getNormalizedAtomContainer(precursorMolecule, diffFragment);
lossFingerprint.add(fingerprintCollection.getNormalizedFingerprint(con));
lossMassDiff.add(diff);
uncorrectedMassDiff.add(uncorrectedDiff);
}
StringBuilder[] diffFingerPrints = new StringBuilder[fingerprintCollection.getNumberFingerprinters()];
for (int i = 0; i < diffFingerPrints.length; i++) diffFingerPrints[i] = new StringBuilder();
if (lossMassDiff.size() >= 1) {
for (int ii = 0; ii < diffFingerPrints.length; ii++) {
diffFingerPrints[ii].append(lossMassDiff.get(0));
diffFingerPrints[ii].append(":");
diffFingerPrints[ii].append(lossFingerprint.get(0)[ii]);
}
}
for (int i = 1; i < lossMassDiff.size(); i++) {
for (int ii = 0; ii < diffFingerPrints.length; ii++) {
diffFingerPrints[ii].append(";");
diffFingerPrints[ii].append(lossMassDiff.get(i));
diffFingerPrints[ii].append(":");
diffFingerPrints[ii].append(lossFingerprint.get(i)[ii]);
}
}
String[][] fps_return = new String[fingerprintCollection.getNumberFingerprinters()][3];
for (int i = 0; i < fingerprintCollection.getNumberFingerprinters(); i++) {
if (diffFingerPrints[i].toString().equals(""))
fps_return[i] = new String[] { "NA", "NA", "NA" };
else
fps_return[i] = new String[] { diffFingerPrints[i].toString() };
}
return fps_return;
}
use of de.ipbhalle.metfraglib.interfaces.IFragment in project MetFragRelaunched by ipb-halle.
the class CandidateListWriterLossFragmentSmilesCompletePSV method writeFile.
public boolean writeFile(File file, IList list, Settings settings) throws Exception {
CandidateList candidateList = null;
int numberOfPeaksUsed = 0;
if (list instanceof ScoredCandidateList || list instanceof SortedScoredCandidateList) {
candidateList = (ScoredCandidateList) list;
numberOfPeaksUsed = ((ScoredCandidateList) list).getNumberPeaksUsed();
}
if (list instanceof CandidateList) {
candidateList = (CandidateList) list;
}
if (candidateList == null)
return false;
DefaultPeakList peakList = (DefaultPeakList) settings.get(VariableNames.PEAK_LIST_NAME);
java.io.BufferedWriter bwriter = new BufferedWriter(new FileWriter(file));
StringBuilder heading = new StringBuilder();
candidateList.getElement(0).removeProperty("ExplPeaks");
candidateList.getElement(0).removeProperty("FormulasOfExplPeaks");
candidateList.getElement(0).removeProperty("NumberPeaksUsed");
candidateList.getElement(0).removeProperty("NoExplPeaks");
String[] fpnames = ClassNames.getFingerprintNames();
for (int ii = 0; ii < fpnames.length; ii++) {
candidateList.getElement(0).removeProperty("FragmentFingerprintOfExplPeaks" + fpnames[ii]);
candidateList.getElement(0).removeProperty("LossFingerprintOfExplPeaks" + fpnames[ii]);
}
java.util.Enumeration<String> keys = candidateList.getElement(0).getProperties().keys();
if (keys.hasMoreElements()) {
String key = keys.nextElement();
heading.append(key);
}
while (keys.hasMoreElements()) {
String key = keys.nextElement();
heading.append("|");
heading.append(key);
}
heading.append("|");
heading.append("ExplPeaks");
heading.append("|");
heading.append("FormulasOfExplPeaks");
heading.append("|");
heading.append("NumberPeaksUsed");
heading.append("|");
heading.append("NoExplPeaks");
for (int i = 0; i < fpnames.length; i++) {
heading.append("|");
heading.append("FragmentFingerprintOfExplPeaks" + fpnames[i]);
heading.append("|");
heading.append("LossFingerprintOfExplPeaks" + fpnames[i]);
}
heading.append("|");
heading.append("NonExplainedPeaks");
heading.append("|");
heading.append("NonExplainedLosses");
bwriter.write(heading.toString());
bwriter.newLine();
FingerprintCollection fingerprintCollection = new FingerprintCollection();
int ionmode = (Integer) settings.get(VariableNames.PRECURSOR_ION_MODE_NAME);
boolean ispositive = (Boolean) settings.get(VariableNames.IS_POSITIVE_ION_MODE_NAME);
java.util.ArrayList<Double> nativeLossMasses = this.calculatePeakDifferences(peakList, (Double) settings.get(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME), Constants.getIonisationTypeMassCorrection(Constants.ADDUCT_NOMINAL_MASSES.indexOf(ionmode), ispositive));
for (int i = 0; i < candidateList.getNumberElements(); i++) {
StringBuilder line = new StringBuilder();
int countExplainedPeaks = 0;
ICandidate scoredCandidate = candidateList.getElement(i);
scoredCandidate.removeProperty("ExplPeaks");
scoredCandidate.removeProperty("FormulasOfExplPeaks");
scoredCandidate.removeProperty("NumberPeaksUsed");
scoredCandidate.removeProperty("NoExplPeaks");
for (int ii = 0; ii < fpnames.length; ii++) {
scoredCandidate.removeProperty("FragmentFingerprintOfExplPeaks" + fpnames[ii]);
scoredCandidate.removeProperty("LossFingerprintOfExplPeaks" + fpnames[ii]);
}
scoredCandidate.removeProperty("NonExplainedPeaks");
scoredCandidate.removeProperty("NonExplainedLosses");
if (settings != null)
scoredCandidate.setUseSmiles((Boolean) settings.get(VariableNames.USE_SMILES_NAME));
scoredCandidate.initialisePrecursorCandidate();
if (scoredCandidate.getMatchList() != null) {
MatchList matchList = scoredCandidate.getMatchList();
for (int l = 0; l < matchList.getNumberElements(); l++) {
try {
matchList.getElement(l).getMatchedPeak().getIntensity();
} catch (RelativeIntensityNotDefinedException e1) {
continue;
}
countExplainedPeaks++;
}
}
StringBuilder peaksExplained = new StringBuilder();
StringBuilder sumFormulasOfFragmentsExplainedPeaks = new StringBuilder();
StringBuilder[] fingerprintOfFragmentsExplainedPeaks = new StringBuilder[fingerprintCollection.getNumberFingerprinters()];
for (int ii = 0; ii < fingerprintOfFragmentsExplainedPeaks.length; ii++) fingerprintOfFragmentsExplainedPeaks[ii] = new StringBuilder();
keys = scoredCandidate.getProperties().keys();
if (keys.hasMoreElements()) {
String key = keys.nextElement();
line.append(scoredCandidate.getProperty(key));
}
while (keys.hasMoreElements()) {
String key = keys.nextElement();
line.append("|");
line.append(scoredCandidate.getProperty(key));
}
if (scoredCandidate.getMatchList() != null) {
String[] matchedFormulas = new String[scoredCandidate.getMatchList().getNumberElements()];
double[] correctedMasses = new double[scoredCandidate.getMatchList().getNumberElements()];
for (int ii = 0; ii < scoredCandidate.getMatchList().getNumberElements(); ii++) {
try {
double intensity = scoredCandidate.getMatchList().getElement(ii).getMatchedPeak().getIntensity();
peaksExplained.append(scoredCandidate.getMatchList().getElement(ii).getMatchedPeak().getMass());
peaksExplained.append("_");
peaksExplained.append(intensity);
peaksExplained.append(";");
} catch (RelativeIntensityNotDefinedException e1) {
continue;
}
String formula = scoredCandidate.getMatchList().getElement(ii).getModifiedFormulaStringOfBestMatchedFragment(scoredCandidate.getPrecursorMolecule());
double mass = scoredCandidate.getMatchList().getElement(ii).getMatchedPeak().getMass();
if ((Boolean) settings.get(VariableNames.CORRECT_MASSES_FOR_FINGERPRINT_ANNOTATION_NAME)) {
matchedFormulas[ii] = formula;
correctedMasses[ii] = MathTools.round(calculateMassOfFormula(formula));
mass = correctedMasses[ii];
}
sumFormulasOfFragmentsExplainedPeaks.append(scoredCandidate.getMatchList().getElement(ii).getMatchedPeak().getMass());
sumFormulasOfFragmentsExplainedPeaks.append(":");
sumFormulasOfFragmentsExplainedPeaks.append(formula);
sumFormulasOfFragmentsExplainedPeaks.append(";");
// get fragment of explained peak
IFragment frag = scoredCandidate.getMatchList().getElement(ii).getBestMatchedFragment();
String[] fps = null;
try {
IAtomContainer con = fingerprintCollection.getNormalizedAtomContainer(scoredCandidate.getPrecursorMolecule(), frag);
fps = fingerprintCollection.getNormalizedFingerprint(con);
} catch (Exception e) {
continue;
}
for (int iii = 0; iii < fps.length; iii++) {
fingerprintOfFragmentsExplainedPeaks[iii].append(mass);
fingerprintOfFragmentsExplainedPeaks[iii].append(":");
fingerprintOfFragmentsExplainedPeaks[iii].append(fps[iii]);
fingerprintOfFragmentsExplainedPeaks[iii].append(";");
}
}
line.append("|");
line.append(peaksExplained.length() == 0 ? "NA" : peaksExplained.substring(0, peaksExplained.length() - 1));
line.append("|");
line.append(sumFormulasOfFragmentsExplainedPeaks.length() == 0 ? "NA" : sumFormulasOfFragmentsExplainedPeaks.substring(0, sumFormulasOfFragmentsExplainedPeaks.length() - 1));
line.append("|");
line.append(numberOfPeaksUsed);
line.append("|");
line.append(countExplainedPeaks);
java.util.ArrayList<Double> uncorrectedLossMasses = new java.util.ArrayList<Double>();
// add loss information
if (settings != null) {
String[][] lossesInformation = createLossAnnotations(scoredCandidate.getPrecursorMolecule(), scoredCandidate.getMatchList(), settings, correctedMasses, fingerprintCollection, uncorrectedLossMasses);
for (int ii = 0; ii < fingerprintCollection.getNumberFingerprinters(); ii++) {
line.append("|");
line.append(fingerprintOfFragmentsExplainedPeaks[ii].length() == 0 ? "NA" : fingerprintOfFragmentsExplainedPeaks[ii].substring(0, fingerprintOfFragmentsExplainedPeaks[ii].length() - 1));
line.append("|");
line.append(lossesInformation[ii][0]);
}
}
line.append("|");
line.append(this.getNonExplainedPeakString(peakList, scoredCandidate.getMatchList()));
line.append("|");
line.append(this.getNonExplainedLossString(uncorrectedLossMasses, nativeLossMasses));
}
bwriter.write(line.toString());
bwriter.newLine();
}
bwriter.close();
return true;
}
use of de.ipbhalle.metfraglib.interfaces.IFragment 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