示例#1
0
vector<uNumber> Aligner::alignReadGreedy(const string& read, bool& overlapFound, uint errors, bool r){
	vector<pair<kmer,uint>> listOverlap(getNOverlap(read,tryNumber));
	if(listOverlap.empty()){++noOverlapRead;++readNumber;return {};}
	overlapFound=true;
	vector<uNumber> pathBegin,pathEnd;
	for(uint start(0); start<(uint)listOverlap.size(); ++start){
		pathBegin={};
		uint errorBegin(checkBeginGreedy(read,listOverlap[start],pathBegin,errors));
		if(errorBegin<=errors){
			pathEnd={};
			uint errorsEnd(checkEndGreedy(read,listOverlap[start],pathEnd,errors-errorBegin));
			if(errorsEnd+errorBegin<=errors){
				alignedRead++;
				readNumber++;
				pathBegin.insert(pathBegin.end(), pathEnd.begin(),pathEnd.end());
				return pathBegin;
			}
		}
	}
	//TODO TEST this
	//if(!rc){return alignReadGreedy(reverseComplements(read), overlapFound,errors, true);}
	notAligned++;
	readNumber++;
	return {};
}
示例#2
0
int DynamicObject::checkForCollision(StaticObject** objects, int numObjects,double* xShift, double* yShift, int* objCollidedWith, int* numCollided){
	if(objects == NULL || numObjects == 0) return 0;
	
	int i;	
	int retVal = 0;
	int hitNE = -1;
	int hitSE = -1;
	int hitNW = -1;
	int hitSW = -1;
	
	//loop through the blocks and find any blocks that intercept a corner of the ball
	//it can be assumed that a particular corner will not intersect more than 1 block
	for(i = 0; i < numObjects; i++){
		if(objects[i] == this) continue;
		if(nwOverlap(objects[i])) hitNW = i;
		if(swOverlap(objects[i])) hitSW = i;
		if(neOverlap(objects[i])) hitNE = i;
		if(seOverlap(objects[i])) hitSE = i;
	}
	
	
	if(hitNE != -1 && hitSW != -1){		//if hit directly at intersection of 2 blocks
		
		if(movingSE()){
			if(xShift != NULL) *xShift = getEOverlap(objects[hitNE]);
			if(yShift != NULL) *yShift = getSOverlap(objects[hitSW]);
		}
		else if(movingNW()){
			if(xShift != NULL) *xShift = getWOverlap(objects[hitSW]);
			if(yShift != NULL) *yShift = getNOverlap(objects[hitNE]);
		}
		else{	//hope for the best
			if(xShift != NULL) *xShift = 0;
			if(yShift != NULL) *yShift = 0;
		}
		retVal = (X_AXIS | Y_AXIS);
	}
	else if(hitNW != -1 && hitSE != -1){
		if(movingSW()){
			if(xShift != NULL) *xShift = getWOverlap(objects[hitNW]);
			if(yShift != NULL) *yShift = getSOverlap(objects[hitSE]);
		}
		else if(movingNE()){
			if(xShift != NULL) *xShift = getEOverlap(objects[hitSE]);
			if(yShift != NULL) *yShift = getNOverlap(objects[hitNW]);
		}
		else{	//hope for the best
			if(xShift != NULL) *xShift = 0;
			if(yShift != NULL) *yShift = 0;
		}
		
		retVal = (X_AXIS | Y_AXIS);
	}
	else if(hitNW != -1 && hitSW != -1){
		if(xShift != NULL) *xShift = getWOverlap(objects[hitNW]);
		retVal = X_AXIS;
	}
	else if(hitNW != -1 && hitNE != -1){
		if(yShift != NULL) *yShift = getNOverlap(objects[hitNW]);
		retVal = Y_AXIS;
	}
	else if(hitSE != -1 && hitNE != -1){
		if(xShift != NULL) *xShift = getEOverlap(objects[hitNE]);
		retVal = X_AXIS;
	}
	else if(hitSE != -1 && hitSW != -1){
		if(yShift != NULL) *yShift = getSOverlap(objects[hitSE]);
		retVal = Y_AXIS;
	}
	else if(hitSE != -1){
		double x = getEOverlap(objects[hitSE]);
		double y = getSOverlap(objects[hitSE]);

		if(movingSE()){
			
			if(-1*x > -1*y){	//impact on south side of ball
				retVal = Y_AXIS;
				if(yShift != NULL) *yShift = y;
			}
			else if(-1*x < -1*y){	//impact on East side of ball
				retVal = X_AXIS;
				if(xShift != NULL) *xShift = x;
			}
			else{
				retVal = X_AXIS | Y_AXIS;
				if(xShift != NULL) *xShift = x;
				if(yShift != NULL) *yShift = y;
			}
		}
		else if(movingSW()){
			retVal = Y_AXIS;
			if(yShift != NULL) *yShift = y;
		}
		else if(movingNE()){
			retVal = X_AXIS;
			if(xShift != NULL) *xShift = x;
		}
		else{
//			printf("Level: Something wrong in SE\n");
		}
	}
	else if(hitSW != -1){
		
		double x = getWOverlap(objects[hitSW]);
		double y = getSOverlap(objects[hitSW]);
		
		if(movingSW()){
			
			if(x > -1*y){	//impact on south side of ball
				retVal = Y_AXIS;
				if(yShift != NULL) *yShift = y;
			}
			else if(x < -1*y){		//impact on west side of ball
				retVal = X_AXIS;
				if(xShift != NULL) *xShift = x;
			}
			else{
				retVal = X_AXIS | Y_AXIS;
				if(xShift != NULL) *xShift = x;
				if(yShift != NULL) *yShift = y;
			}
		}
		else if(movingSE()){
			retVal = Y_AXIS;
			if(yShift != NULL) *yShift = y;
		}
		else if(movingNW()){
			retVal = X_AXIS;
			if(xShift != NULL) *xShift = x;
		}
		else{
//			printf("Level: Something wrong in SW\n");
		}
	}
	else if(hitNE != -1){
		double x = getEOverlap(objects[hitNE]);
		double y = getNOverlap(objects[hitNE]);
		
		if(movingNE()){
			
			if(-1*x > y){	//impact on North side of ball
				retVal = Y_AXIS;
				if(yShift != NULL) *yShift = y;
			}
			else if(-1*x < y){	//impact on East side of ball
				retVal = X_AXIS;
				if(xShift != NULL) *xShift = x;
			}
			else{
				retVal = X_AXIS | Y_AXIS;
				if(xShift != NULL) *xShift = x;
				if(yShift != NULL) *yShift = y;
			}
		}
		else if(movingNW()){
			retVal = Y_AXIS;
			if(yShift != NULL) *yShift = y;
		}
		else if(movingSE()){
			retVal = X_AXIS;
			if(xShift != NULL) *xShift = x;
		}
		else{
//			printf("Level: Something wrong in SE\n");
		}
		
	}
	else if(hitNW != -1){
		double x = getWOverlap(objects[hitNW]);
		double y = getNOverlap(objects[hitNW]);
		
		if(movingNW()){
			
			if(x > y){	//impact on North side of ball
				retVal = Y_AXIS;
				if(yShift != NULL) *yShift = y;
			}
			else if(x < y){	//impact on West side of ball
				retVal = X_AXIS;
				if(xShift != NULL) *xShift = x;
			}
			else{
				retVal = X_AXIS | Y_AXIS;
				if(xShift != NULL) *xShift = x;
				if(yShift != NULL) *yShift = y;
			}
		}
		else if(movingNE()){
			retVal = Y_AXIS;
			if(yShift != NULL) *yShift = y;
		}
		else if(movingSW()){
			retVal = X_AXIS;
			if(xShift != NULL) *xShift = x;
		}
		else{
//			printf("Level: Something wrong in SE\n");
		}
	}
	else retVal = 0;
	
	if(objCollidedWith != NULL){
		i = 0;
		
		if(hitNE != -1){
			objCollidedWith[i] = hitNE;
			i++;
		}
		if(hitSE != -1){
			objCollidedWith[i] = hitSE;
			i++;
		}
		if(hitNW != -1){
			objCollidedWith[i] = hitNW;
			i++;
		}
		if(hitSW != -1){
			objCollidedWith[i] = hitSW;
			i++;
		}
		
		if(numCollided != NULL) *numCollided = i;
	}
	return retVal;
}