static void comparePaths_local(Node * destination, Node * origin) { IDnum slowLength, fastLength; Node *fastNode, *slowNode; IDnum i; PassageMarkerI marker; //Measure lengths slowLength = fastLength = 0; fastNode = destination; slowNode = origin; //velvetLog("Looking into separate paths\n"); while (fastNode != slowNode) { //velvetLog("Fast node %li Slow node %li\n", getNodeID(fastNode), getNodeID(slowNode)); if (getNodeTime(fastNode) > getNodeTime(slowNode)) { fastLength++; fastNode = getNodePrevious(fastNode); } else if (getNodeTime(fastNode) < getNodeTime(slowNode)) { slowLength++; slowNode = getNodePrevious(slowNode); } else if (isPreviousToNode(slowNode, fastNode)) { while (fastNode != slowNode) { fastLength++; fastNode = getNodePrevious(fastNode); } } else if (isPreviousToNode(fastNode, slowNode)) { while (slowNode != fastNode) { slowLength++; slowNode = getNodePrevious(slowNode); } } else { fastLength++; fastNode = getNodePrevious(fastNode); slowLength++; slowNode = getNodePrevious(slowNode); } if (slowLength > MAXNODELENGTH || fastLength > MAXNODELENGTH) { //velvetLog("Paths too fragmented %li %li\n", slowLength, fastLength); return; } } if (fastLength == 0) return; //Backtracking to record actual paths fastPath = addUncertainPassageMarker(1, destination); setPassageMarkerStatus(fastPath, true); for (i = 0; i < fastLength; i++) { marker = addUncertainPassageMarker(1, getNodePrevious(getNode (fastPath))); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, fastPath, graph); fastPath = marker; } slowPath = addUncertainPassageMarker(2, destination); setPassageMarkerStatus(slowPath, true); marker = addUncertainPassageMarker(2, origin); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, slowPath, graph); slowPath = marker; for (i = 0; i < slowLength; i++) { marker = addUncertainPassageMarker(2, getNodePrevious(getNode (slowPath))); setPassageMarkerStatus(marker, true); connectPassageMarkers(marker, slowPath, graph); slowPath = marker; } //Extract sequences if (!extractSequence(fastPath, fastSequence) || !extractSequence(slowPath, slowSequence)) { //velvetLog("Paths too long\n"); destroyPaths(); return; } //Compare sequences if (compareSequences(fastSequence, slowSequence)) { //velvetLog("Correcting discrepancy\n"); cleanUpRedundancy_local(); return; } //velvetLog("\tFinished comparing paths, changes made\n"); destroyPaths(); }
int findTarget(HashMMData *mmData, unsigned char *target, int targetLen, unsigned char *extract, unsigned char *originalTarget, int eAllowed, int eAdded, unsigned int id, int outputP) { int count; int hash; int i; unsigned int leftHigh, leftLow; int offset; unsigned int *offsetTable = mmData->offsetTable; unsigned int *posTable = mmData->posTable; unsigned int rightHigh, rightLow; unsigned char *stop = target + targetLen - MerSize; count = 0; hash = 0; for (i = 0; i < MerSize; ++i) { int code = codings[target[i]]; hash = ((hash << 2) | code) & MerHashMask; } leftLow = offsetTable[hash]; leftHigh = offsetTable[hash+1]; if (leftLow == leftHigh) return 0; offset = targetLen - MerSize; if (offset) { hash = 0; for (i = offset; i < (offset+MerSize); ++i) { int code = codings[target[i]]; if (code < 0) return 0; hash = ((hash << 2) | code) & MerHashMask; } rightLow = offsetTable[hash]; rightHigh = offsetTable[hash+1]; if (rightLow == rightHigh) return 0; while (1) { if (posTable[leftLow]+offset > posTable[rightLow]) { ++rightLow; } else if (posTable[leftLow]+offset < posTable[rightLow]) { ++leftLow; } else { int eSeen = 0; // We know that the ends of extract and target agree for MerSize nts. unsigned char *ep = extract+MerSize; unsigned char *tp = target+MerSize; if ((tp < stop) || outputP) extractSequence(mmData, posTable[leftLow], targetLen, extract); while (tp < stop) { // Ignore case by mapping to lower. if (((*tp++)|32) != ((*ep++)|32)) if (++eSeen > eAllowed) break; } if (eSeen <= eAllowed) { ++count; if (outputP) { printf("%u\t%d\t%d\t%.*s\t%.*s\n", id, eSeen+eAdded, posTable[leftLow], targetLen, originalTarget, targetLen, extract); } } ++leftLow; ++rightLow; } if (rightLow == rightHigh) break; if (leftLow == leftHigh) break; } } else { for (i = leftLow; i < leftHigh; ++i) { ++count; if (outputP) { extractSequence(mmData, posTable[i], targetLen, extract); printf("%u\t%d\t%d\t%.*s\t%.*s\n", id, eAdded, posTable[i], targetLen, originalTarget, targetLen, extract); } } } return count; }