use of de.ipbhalle.metfraglib.precursor.AbstractTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class TopDownNeutralLossFragmenter method generateFragments.
public FragmentList generateFragments() {
FragmentList generatedFragments = new FragmentList();
java.util.Queue<AbstractTopDownBitArrayFragment> temporaryFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragment>();
java.util.Queue<Byte> numberOfFragmentAddedToQueue = new java.util.LinkedList<Byte>();
java.util.Queue<de.ipbhalle.metfraglib.FastBitArray> nextBondIndecesToRemove = new java.util.LinkedList<de.ipbhalle.metfraglib.FastBitArray>();
/*
* set first fragment as root for fragment generation (precursor)
*/
AbstractTopDownBitArrayFragment root = ((AbstractTopDownBitArrayPrecursor) this.scoredCandidate.getPrecursorMolecule()).toFragment();
root.setID(++this.numberOfGeneratedFragments);
root.setWasRingCleavedFragment(false);
generatedFragments.addElement(root);
temporaryFragments.add(root);
numberOfFragmentAddedToQueue.add((byte) 1);
nextBondIndecesToRemove.add(root.getBondsFastBitArray());
for (int k = 1; k <= this.maximumTreeDepth; k++) {
java.util.Queue<AbstractTopDownBitArrayFragment> newTemporaryFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragment>();
java.util.Queue<Byte> newNumberOfFragmentAddedToQueue = new java.util.LinkedList<Byte>();
java.util.Queue<de.ipbhalle.metfraglib.FastBitArray> newNextBondIndecesToRemove = new java.util.LinkedList<de.ipbhalle.metfraglib.FastBitArray>();
while (!temporaryFragments.isEmpty()) {
AbstractTopDownBitArrayFragment nextTopDownFragmentForFragmentation = temporaryFragments.poll();
byte numberOfNextTopDownFragmentForFragmentationAddedToQueue = numberOfFragmentAddedToQueue.poll();
int[] indecesOfSetBondsOfNextTopDownFragment = nextBondIndecesToRemove.poll().getSetIndeces();
for (int i = 0; i < indecesOfSetBondsOfNextTopDownFragment.length; i++) {
short nextBondIndexToRemove = (short) indecesOfSetBondsOfNextTopDownFragment[i];
/*
* if index of selected bond is smaller than the maximum
* index of a cleaved bond of the fragment then select
* another bond prevents generating fragments redundantly
*/
if (nextBondIndexToRemove < nextTopDownFragmentForFragmentation.getMaximalIndexOfRemovedBond() || !nextTopDownFragmentForFragmentation.getBondsFastBitArray().get(nextBondIndexToRemove)) {
continue;
}
short[] indecesOfBondConnectedAtoms = ((AbstractTopDownBitArrayPrecursor) this.scoredCandidate.getPrecursorMolecule()).getConnectedAtomIndecesOfBondIndex(nextBondIndexToRemove);
/*
* getting fragment generated by cleavage of the current
* bond "nextBondIndexToRemove"
*/
AbstractTopDownBitArrayFragment[] newGeneratedTopDownFragments = nextTopDownFragmentForFragmentation.traverseMolecule(this.scoredCandidate.getPrecursorMolecule(), nextBondIndexToRemove, indecesOfBondConnectedAtoms);
/*
* if we got two fragments then save these as valid ones
*/
if (newGeneratedTopDownFragments.length == 2) {
this.checkForNeutralLossesAdaptMolecularFormulas(newGeneratedTopDownFragments, nextBondIndexToRemove);
if (newGeneratedTopDownFragments[0].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
newGeneratedTopDownFragments[0].setID(++this.numberOfGeneratedFragments);
generatedFragments.addElement(newGeneratedTopDownFragments[0]);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
newNumberOfFragmentAddedToQueue.add((byte) 1);
newTemporaryFragments.add(newGeneratedTopDownFragments[0]);
}
if (newGeneratedTopDownFragments[1].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
newGeneratedTopDownFragments[1].setID(++this.numberOfGeneratedFragments);
generatedFragments.addElement(newGeneratedTopDownFragments[1]);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[1].getBondsFastBitArray());
newNumberOfFragmentAddedToQueue.add((byte) 1);
newTemporaryFragments.add(newGeneratedTopDownFragments[1]);
}
} else /*
* if just one fragment then we have to cleave once again
*/
{
if (newGeneratedTopDownFragments[0].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
if (numberOfNextTopDownFragmentForFragmentationAddedToQueue < this.maximumNumberOfAFragmentAddedToQueue) {
temporaryFragments.add(newGeneratedTopDownFragments[0]);
numberOfFragmentAddedToQueue.add((byte) (numberOfNextTopDownFragmentForFragmentationAddedToQueue + 1));
// nextBondIndecesToRemove.add(this.precursorMolecule.getFastBitArrayOfBondsBelongingtoRingLikeBondIndex(nextBondIndexToRemove));
nextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
} else {
newTemporaryFragments.add(newGeneratedTopDownFragments[0]);
newNumberOfFragmentAddedToQueue.add((byte) 1);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
}
}
}
}
}
temporaryFragments = newTemporaryFragments;
numberOfFragmentAddedToQueue = newNumberOfFragmentAddedToQueue;
nextBondIndecesToRemove = newNextBondIndecesToRemove;
}
temporaryFragments = null;
numberOfFragmentAddedToQueue = null;
nextBondIndecesToRemove = null;
return generatedFragments;
}
use of de.ipbhalle.metfraglib.precursor.AbstractTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class PFAS method getSplitResult.
public FragmentPFAS getSplitResult(List<Integer> bondIndexes, int[] endChainCarbonIndexes) {
LinkedList<AbstractTopDownBitArrayFragment> abstractTopDownBitArrayFragments = new LinkedList<AbstractTopDownBitArrayFragment>();
LinkedList<AbstractTopDownBitArrayFragment> newAbstractTopDownBitArrayFragments = null;
AbstractTopDownBitArrayFragment root = ((AbstractTopDownBitArrayPrecursor) this.pfasStructure.getPrecursorMolecule()).toFragment();
abstractTopDownBitArrayFragments.add(root);
int bondsBroken = 0;
List<AbstractTopDownBitArrayFragment> createdFragments = new ArrayList<AbstractTopDownBitArrayFragment>();
// store atoms
List<short[]> indecesOfBondConnectedAtomsList = new ArrayList<short[]>();
for (int i = 0; i < bondIndexes.size(); i++) {
int bondIndex = bondIndexes.get(i);
newAbstractTopDownBitArrayFragments = new LinkedList<AbstractTopDownBitArrayFragment>();
while (!abstractTopDownBitArrayFragments.isEmpty()) {
AbstractTopDownBitArrayFragment currentFragment = abstractTopDownBitArrayFragments.remove();
if (currentFragment.getBondsFastBitArray().get(bondIndex)) {
short[] indecesOfBondConnectedAtoms = new short[2];
AbstractTopDownBitArrayFragment[] fragments = this.split((short) bondIndex, currentFragment, indecesOfBondConnectedAtoms);
if (fragments.length != 1)
bondsBroken++;
for (int ii = 0; ii < fragments.length; ii++) {
newAbstractTopDownBitArrayFragments.add(fragments[ii]);
createdFragments.add(fragments[ii]);
indecesOfBondConnectedAtomsList.add(indecesOfBondConnectedAtoms);
}
}
}
abstractTopDownBitArrayFragments = newAbstractTopDownBitArrayFragments;
}
List<short[]> cleanedIndecesOfBondConnectedAtomsList = new ArrayList<short[]>();
List<AbstractTopDownBitArrayFragment> cleanedCreatedFragments = new ArrayList<AbstractTopDownBitArrayFragment>();
for (int i = 0; i < createdFragments.size(); i++) {
boolean bondFound = false;
for (int j = 0; j < bondIndexes.size(); j++) {
if (createdFragments.get(i).getBondsFastBitArray().get(bondIndexes.get(j))) {
bondFound = true;
}
}
if (!bondFound) {
cleanedCreatedFragments.add(createdFragments.get(i));
cleanedIndecesOfBondConnectedAtomsList.add(indecesOfBondConnectedAtomsList.get(i));
}
}
boolean[] containsEndChainCarbon = new boolean[cleanedCreatedFragments.size()];
for (int i = 0; i < cleanedCreatedFragments.size(); i++) {
for (int ii = 0; ii < endChainCarbonIndexes.length; ii++) {
if (cleanedCreatedFragments.get(i).getAtomsFastBitArray().get(endChainCarbonIndexes[ii]))
containsEndChainCarbon[i] = true;
}
}
int fragmentsWithEndChainCarbonCount = 0;
for (boolean fragmentsWithEndChainCarbon : containsEndChainCarbon) if (fragmentsWithEndChainCarbon)
fragmentsWithEndChainCarbonCount++;
if (fragmentsWithEndChainCarbonCount == 0) {
System.err.println("Error: Problem occured. Check input molecule. No PFAS left after split.");
return null;
}
for (int i = 0; i < containsEndChainCarbon.length; i++) if (!containsEndChainCarbon[i])
return new FragmentPFAS(cleanedCreatedFragments, cleanedIndecesOfBondConnectedAtomsList, containsEndChainCarbon, bondsBroken, this.pfasStructure);
return null;
}
use of de.ipbhalle.metfraglib.precursor.AbstractTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class TopDownFragmenter method generateFragments.
public FragmentList generateFragments() {
FragmentList generatedFragments = new FragmentList();
java.util.Queue<AbstractTopDownBitArrayFragment> temporaryFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragment>();
java.util.Queue<Byte> numberOfFragmentAddedToQueue = new java.util.LinkedList<Byte>();
java.util.Queue<de.ipbhalle.metfraglib.FastBitArray> nextBondIndecesToRemove = new java.util.LinkedList<de.ipbhalle.metfraglib.FastBitArray>();
/*
* set first fragment as root for fragment generation (precursor)
*/
AbstractTopDownBitArrayFragment root = ((AbstractTopDownBitArrayPrecursor) this.scoredCandidate.getPrecursorMolecule()).toFragment();
root.setID(++this.numberOfGeneratedFragments);
temporaryFragments.add(root);
generatedFragments.addElement(root);
numberOfFragmentAddedToQueue.add((byte) 1);
nextBondIndecesToRemove.add(root.getBondsFastBitArray());
for (int k = 1; k <= this.maximumTreeDepth; k++) {
java.util.Queue<AbstractTopDownBitArrayFragment> newTemporaryFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragment>();
java.util.Queue<Byte> newNumberOfFragmentAddedToQueue = new java.util.LinkedList<Byte>();
java.util.Queue<de.ipbhalle.metfraglib.FastBitArray> newNextBondIndecesToRemove = new java.util.LinkedList<de.ipbhalle.metfraglib.FastBitArray>();
while (!temporaryFragments.isEmpty()) {
AbstractTopDownBitArrayFragment nextTopDownFragmentForFragmentation = temporaryFragments.poll();
byte numberOfNextTopDownFragmentForFragmentationAddedToQueue = numberOfFragmentAddedToQueue.poll();
int[] indecesOfSetBondsOfNextTopDownFragment = nextBondIndecesToRemove.poll().getSetIndeces();
for (int i = 0; i < indecesOfSetBondsOfNextTopDownFragment.length; i++) {
short nextBondIndexToRemove = (short) indecesOfSetBondsOfNextTopDownFragment[i];
/*
* if index of selected bond is smaller than the maximum index of a cleaved bond of the
* fragment then select another bond
* prevents generating fragments redundantly
*/
if (nextBondIndexToRemove < nextTopDownFragmentForFragmentation.getMaximalIndexOfRemovedBond() || !nextTopDownFragmentForFragmentation.getBondsFastBitArray().get(nextBondIndexToRemove)) {
continue;
}
short[] indecesOfBondConnectedAtoms = ((BitArrayPrecursor) this.scoredCandidate.getPrecursorMolecule()).getConnectedAtomIndecesOfBondIndex(nextBondIndexToRemove);
/*
* getting fragment generated by cleavage of the current bond "nextBondIndexToRemove"
*/
AbstractTopDownBitArrayFragment[] newGeneratedTopDownFragments = nextTopDownFragmentForFragmentation.traverseMolecule(this.scoredCandidate.getPrecursorMolecule(), nextBondIndexToRemove, indecesOfBondConnectedAtoms);
/*
* if we got two fragments then save these as valid ones
*/
if (newGeneratedTopDownFragments.length == 2) {
if (newGeneratedTopDownFragments[0].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
newGeneratedTopDownFragments[0].setID(++this.numberOfGeneratedFragments);
generatedFragments.addElement(newGeneratedTopDownFragments[0]);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
newNumberOfFragmentAddedToQueue.add((byte) 1);
newTemporaryFragments.add(newGeneratedTopDownFragments[0]);
}
if (newGeneratedTopDownFragments[1].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
newGeneratedTopDownFragments[1].setID(++this.numberOfGeneratedFragments);
generatedFragments.addElement(newGeneratedTopDownFragments[1]);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[1].getBondsFastBitArray());
newNumberOfFragmentAddedToQueue.add((byte) 1);
newTemporaryFragments.add(newGeneratedTopDownFragments[1]);
}
} else /*
* if just one fragment then we have to cleave once again
*/
{
if (newGeneratedTopDownFragments[0].getMonoisotopicMass(this.scoredCandidate.getPrecursorMolecule()) > this.minimumFragmentMassLimit - this.minimumMassDeviationForFragmentGeneration) {
if (numberOfNextTopDownFragmentForFragmentationAddedToQueue < this.maximumNumberOfAFragmentAddedToQueue) {
temporaryFragments.add(newGeneratedTopDownFragments[0]);
numberOfFragmentAddedToQueue.add((byte) (numberOfNextTopDownFragmentForFragmentationAddedToQueue + 1));
// nextBondIndecesToRemove.add(this.precursorMolecule.getFastBitArrayOfBondsBelongingtoRingLikeBondIndex(nextBondIndexToRemove));
nextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
} else {
newTemporaryFragments.add(newGeneratedTopDownFragments[0]);
newNumberOfFragmentAddedToQueue.add((byte) 1);
newNextBondIndecesToRemove.add(newGeneratedTopDownFragments[0].getBondsFastBitArray());
}
}
}
}
}
temporaryFragments = newTemporaryFragments;
numberOfFragmentAddedToQueue = newNumberOfFragmentAddedToQueue;
nextBondIndecesToRemove = newNextBondIndecesToRemove;
}
temporaryFragments = null;
numberOfFragmentAddedToQueue = null;
nextBondIndecesToRemove = null;
return generatedFragments;
}
use of de.ipbhalle.metfraglib.precursor.AbstractTopDownBitArrayPrecursor in project MetFragRelaunched by ipb-halle.
the class TopDownFragmenterAssignerScorer method calculate.
@Override
public void calculate() {
AbstractTopDownBitArrayPrecursor candidatePrecursor = (AbstractTopDownBitArrayPrecursor) (this.candidates[0]).getPrecursorMolecule();
// generate root fragment to start fragmentation
AbstractTopDownBitArrayFragment root = candidatePrecursor.toFragment();
Byte maximumTreeDepth = (Byte) settings.get(VariableNames.MAXIMUM_TREE_DEPTH_NAME);
if (maximumTreeDepth == 0) {
maximumTreeDepth = candidatePrecursor.getNumNodeDegreeOne() >= 4 ? (byte) 3 : (byte) 2;
}
this.candidates[0].setProperty(VariableNames.MAXIMUM_TREE_DEPTH_NAME, maximumTreeDepth);
// read peaklist
SortedTandemMassPeakList tandemMassPeakList = (SortedTandemMassPeakList) settings.get(VariableNames.PEAK_LIST_NAME);
tandemMassPeakList.initialiseMassLimits((Double) this.settings.get(VariableNames.RELATIVE_MASS_DEVIATION_NAME), (Double) settings.get(VariableNames.ABSOLUTE_MASS_DEVIATION_NAME));
Integer precursorIonType = (Integer) this.settings.get(VariableNames.PRECURSOR_ION_MODE_NAME);
Boolean positiveMode = (Boolean) this.settings.get(VariableNames.IS_POSITIVE_ION_MODE_NAME);
int precursorIonTypeIndex = Constants.ADDUCT_NOMINAL_MASSES.indexOf(precursorIonType);
this.fragmenter.setMinimumFragmentMassLimit(this.fragmenter.getMinimumFragmentMassLimit() - Constants.ADDUCT_MASSES.get(precursorIonTypeIndex));
/*
* prepare the processing
*/
java.util.Queue<AbstractTopDownBitArrayFragmentWrapper> toProcessFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragmentWrapper>();
/*
* wrap the root fragment
*/
AbstractTopDownBitArrayFragmentWrapper rootFragmentWrapper = new AbstractTopDownBitArrayFragmentWrapper(root, tandemMassPeakList.getNumberElements() - 1);
toProcessFragments.add(rootFragmentWrapper);
java.util.HashMap<Integer, MatchFragmentList> peakIndexToPeakMatch = new java.util.HashMap<Integer, MatchFragmentList>();
java.util.HashMap<Integer, MatchPeakList> fragmentIndexToPeakMatch = new java.util.HashMap<Integer, MatchPeakList>();
/*
* iterate over the maximal allowed tree depth
*/
for (int k = 1; k <= maximumTreeDepth; k++) {
java.util.Queue<AbstractTopDownBitArrayFragmentWrapper> newToProcessFragments = new java.util.LinkedList<AbstractTopDownBitArrayFragmentWrapper>();
/*
* use each fragment that is marked as to be processed
*/
while (!toProcessFragments.isEmpty()) {
/*
* generate fragments of new tree depth
*/
AbstractTopDownBitArrayFragmentWrapper wrappedPrecursorFragment = toProcessFragments.poll();
if (wrappedPrecursorFragment.getWrappedFragment().isDiscardedForFragmentation()) {
AbstractTopDownBitArrayFragment clonedFragment = (AbstractTopDownBitArrayFragment) wrappedPrecursorFragment.getWrappedFragment().clone(candidatePrecursor);
clonedFragment.setAsDiscardedForFragmentation();
if (clonedFragment.getTreeDepth() < maximumTreeDepth)
newToProcessFragments.add(new AbstractTopDownBitArrayFragmentWrapper(clonedFragment, wrappedPrecursorFragment.getCurrentPeakIndexPointer()));
continue;
}
/*
* generate fragments of next tree depth
*/
java.util.ArrayList<AbstractTopDownBitArrayFragment> fragmentsOfCurrentTreeDepth = this.fragmenter.getFragmentsOfNextTreeDepth(wrappedPrecursorFragment.getWrappedFragment());
/*
* get peak pointer of current precursor fragment
*/
int currentPeakPointer = wrappedPrecursorFragment.getCurrentPeakIndexPointer();
/*
* start loop over all child fragments from precursor fragment
* to try assigning them to the current peak
*/
for (int l = 0; l < fragmentsOfCurrentTreeDepth.size(); l++) {
AbstractTopDownBitArrayFragment currentFragment = fragmentsOfCurrentTreeDepth.get(l);
if (!fragmentsOfCurrentTreeDepth.get(l).isValidFragment()) {
if (currentFragment.getTreeDepth() < maximumTreeDepth)
newToProcessFragments.add(new AbstractTopDownBitArrayFragmentWrapper(fragmentsOfCurrentTreeDepth.get(l), currentPeakPointer));
continue;
}
if (this.wasAlreadyGeneratedByHashtable(currentFragment)) {
currentFragment.setAsDiscardedForFragmentation();
if (currentFragment.getTreeDepth() < maximumTreeDepth)
newToProcessFragments.add(new AbstractTopDownBitArrayFragmentWrapper(currentFragment, currentPeakPointer));
continue;
}
byte matched = -1;
int tempPeakPointer = currentPeakPointer;
while (matched != 1 && tempPeakPointer >= 0) {
IMatch[] match = new IMatch[1];
/*
* calculate match
*/
matched = currentFragment.matchToPeak(candidatePrecursor, tandemMassPeakList.getElement(tempPeakPointer), precursorIonTypeIndex, positiveMode, match);
/*
* check whether match has occurred
*/
if (matched == 0) {
currentFragment.setPrecursorFragments(true);
Double[][] currentScores = this.scoreCollection.calculateSingleMatch(match[0]);
/*
* insert fragment into peak's fragment list
*/
/*
* first generate the new fragment node and set the score values
*/
MatchFragmentNode newNode = new MatchFragmentNode(match[0]);
newNode.setScore(currentScores[0][0]);
newNode.setFragmentScores(currentScores[0]);
newNode.setOptimalValues(currentScores[1]);
/*
* find correct location in the fragment list
*/
boolean similarFragmentFound = false;
if (peakIndexToPeakMatch.containsKey(tempPeakPointer)) {
Double[] values = peakIndexToPeakMatch.get(tempPeakPointer).containsByFingerprint(currentFragment.getAtomsFastBitArray());
if (values == null) {
peakIndexToPeakMatch.get(tempPeakPointer).insert(newNode);
} else {
if (values[0] < currentScores[0][0]) {
peakIndexToPeakMatch.get(tempPeakPointer).removeElementByID((int) Math.floor(values[1]));
fragmentIndexToPeakMatch.get((int) Math.floor(values[1])).removeElementByID(tempPeakPointer);
if (fragmentIndexToPeakMatch.get((int) Math.floor(values[1])).getRootNode() == null) {
fragmentIndexToPeakMatch.remove((int) Math.floor(values[1]));
}
peakIndexToPeakMatch.get(tempPeakPointer).insert(newNode);
} else
similarFragmentFound = true;
}
} else {
MatchFragmentList newFragmentList = new MatchFragmentList(newNode);
peakIndexToPeakMatch.put(tempPeakPointer, newFragmentList);
}
/*
* insert peak into fragment's peak list
*/
if (!similarFragmentFound) {
if (fragmentIndexToPeakMatch.containsKey(currentFragment.getID())) {
fragmentIndexToPeakMatch.get(currentFragment.getID()).insert(tandemMassPeakList.getElement(tempPeakPointer), currentScores[0][0], tempPeakPointer);
} else {
MatchPeakList newPeakList = new MatchPeakList(tandemMassPeakList.getElement(tempPeakPointer), currentScores[0][0], tempPeakPointer);
fragmentIndexToPeakMatch.put(currentFragment.getID(), newPeakList);
}
}
}
/*
* if the mass of the current fragment was greater than the peak mass then assign the current peak ID to the peak IDs of the
* child fragments as they have smaller masses
*/
if (matched == 1 || tempPeakPointer == 0) {
/*
* mark current fragment for further fragmentation
*/
if (currentFragment.getTreeDepth() < maximumTreeDepth)
newToProcessFragments.add(new AbstractTopDownBitArrayFragmentWrapper(currentFragment, tempPeakPointer));
}
/*
* if the current fragment has matched to the current peak then set the current peak index to the next peak as the current fragment can
* also match to the next peak
* if the current fragment mass was smaller than that of the current peak then set the current peak index to the next peak (reduce the index)
* as the next peak mass is smaller and could match the current smaller fragment mass
*/
if (matched == 0 || matched == -1)
tempPeakPointer--;
}
}
}
toProcessFragments = newToProcessFragments;
}
toProcessFragments.clear();
this.matchList = new MatchList();
/*
* collect score of all scores over all matches
*/
double[][] singleScores = new double[this.scoreCollection.getNumberScores()][peakIndexToPeakMatch.size()];
/*
* collect the sum of all scores over all matches
*/
double[] summedScores = new double[this.scoreCollection.getNumberScores()];
java.util.Iterator<Integer> it = peakIndexToPeakMatch.keySet().iterator();
int index = 0;
/*
* go over peak matches
*/
while (it.hasNext()) {
int key = it.next();
MatchFragmentList matchFragmentList = peakIndexToPeakMatch.get(key);
MatchFragmentNode bestFragment = matchFragmentList.getRootNode();
IMatch match = bestFragment.getMatch();
Double[] scoreValuesSingleMatch = null;
try {
scoreValuesSingleMatch = bestFragment.getFragmentScores();
} catch (Exception e) {
matchFragmentList.printElements(this.candidates[0].getPrecursorMolecule());
System.out.println(this.candidates[0].getIdentifier() + " " + key);
System.exit(1);
}
Double[] optimalValuesSingleMatch = bestFragment.getOptimalValues();
for (int k = 1; k < scoreValuesSingleMatch.length; k++) {
if (optimalValuesSingleMatch[k] != null)
singleScores[k - 1][index] = optimalValuesSingleMatch[k];
summedScores[k - 1] += scoreValuesSingleMatch[k];
}
if (bestFragment != null) {
bestFragment.getFragment().setIsBestMatchedFragment(true);
// match.initialiseBestMatchedFragmentByFragmentID(bestFragment.getFragment().getID());
this.matchList.addElementSorted(match);
MatchFragmentNode currentFragment = bestFragment;
while (currentFragment.hasNext()) {
MatchFragmentNode node = currentFragment.getNext();
match.addToMatch(node.getMatch());
currentFragment = currentFragment.getNext();
}
}
index++;
}
for (int i = 0; i < this.matchList.getNumberElements(); i++) this.matchList.getElement(i).shallowNullify();
this.settings.set(VariableNames.MATCH_LIST_NAME, this.matchList);
this.candidates[0].setMatchList(this.matchList);
if (this.scoreCollection == null)
return;
try {
for (int i = 0; i < this.scoreCollection.getNumberScores(); i++) {
if (!this.scoreCollection.getScore(i).calculationFinished()) {
this.scoreCollection.getScore(i).calculate();
} else
this.scoreCollection.getScore(i).setValue(summedScores[i]);
if (singleScores[i].length != 0 && this.scoreCollection.getScore(i).hasInterimResults() && !this.scoreCollection.getScore(i).isInterimResultsCalculated()) {
this.scoreCollection.getScore(i).setOptimalValues(singleScores[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.warn("candidate score calculation interrupted");
return;
}
}
Aggregations