jpayne@68: package icecream; jpayne@68: jpayne@68: import aligner.AlignmentResult; jpayne@68: jpayne@68: public final class IceCreamAlignerJava extends IceCreamAligner { jpayne@68: jpayne@68: IceCreamAlignerJava(){} jpayne@68: jpayne@68: /** jpayne@68: * @param query jpayne@68: * @param ref jpayne@68: * @param rstart jpayne@68: * @param rstop jpayne@68: * @param minScore Quit early if score drops below this jpayne@68: * @param minRatio Don't return results if max score is less than this fraction of max possible score jpayne@68: * @return jpayne@68: */ jpayne@68: @Override jpayne@68: public AlignmentResult alignForward(final byte[] query, final byte[] ref, final int rstart, final int rstop, final int minScore, jpayne@68: final float minRatio) { jpayne@68: final int arrayLength=rstop-rstart+1; jpayne@68: jpayne@68: //Stack allocated; faster. jpayne@68: final int[] array1=new int[arrayLength+1], array2=new int[arrayLength+1]; jpayne@68: jpayne@68: final int minPassingScore=(int)(query.length*minRatio*pointsMatch); jpayne@68: final int minPassingScore3=minPassingScore-query.length*pointsMatch; jpayne@68: jpayne@68: int[] prev=array1, next=array2; jpayne@68: int maxScore=-999999; jpayne@68: int maxQpos=-1; jpayne@68: int maxRpos=-1; jpayne@68: jpayne@68: for(int i=0; i<=arrayLength-query.length; i++){prev[i]=0;} jpayne@68: for(int i=arrayLength-query.length, score=0; i<=arrayLength; i++, score+=pointsDel) { jpayne@68: prev[i]=score; jpayne@68: } jpayne@68: jpayne@68: int currentRstart=rstart; jpayne@68: for(int qpos=0; qpos=maxScoreThisPass){ jpayne@68: // maxScoreThisPass=score; jpayne@68: // if(score>=maxScore){ jpayne@68: // maxScore=score; jpayne@68: // maxQpos=qpos; jpayne@68: // maxRpos=rpos; jpayne@68: // } jpayne@68: // } jpayne@68: jpayne@68: //Should be branchless conditional moves jpayne@68: int score=(dScore>=vScore ? dScore : vScore); jpayne@68: score=(hScore>score ? hScore : score); jpayne@68: next[apos]=score; jpayne@68: maxScoreThisPass=(score>maxScoreThisPass ? score : maxScoreThisPass); jpayne@68: jpayne@68: // minViableRstart=((scoreminViableRstart) ? minViableRstart : rpos); jpayne@68: } jpayne@68: iters+=arrayLength; jpayne@68: if(maxScoreThisPass=maxScore){ jpayne@68: maxScore=score; jpayne@68: maxQpos=query.length; jpayne@68: maxRpos=rpos; jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: maxScore=(maxScore-pointsSub*query.length)/(pointsMatch-pointsSub);//Rescale 0 to length jpayne@68: final float ratio=maxScore/(float)query.length; jpayne@68: jpayne@68: if(ratio=vScore ? dScore : vScore); jpayne@68: score=(hScore>score ? hScore : score); jpayne@68: jpayne@68: next[apos]=score; jpayne@68: } jpayne@68: jpayne@68: // //Inner DV loop jpayne@68: // for(int qpos=0, apos=1; qpos=vScore ? dScore : vScore); jpayne@68: // jpayne@68: // next[apos]=score; jpayne@68: // } jpayne@68: // jpayne@68: // //Inner I loop jpayne@68: // for(int qpos=0, apos=1; qposscore ? hScore : score); jpayne@68: // jpayne@68: // next[apos]=score; jpayne@68: // } jpayne@68: jpayne@68: itersShort+=arrayLength; jpayne@68: jpayne@68: if(score>=maxScore){ jpayne@68: maxScore=score; jpayne@68: maxQpos=arrayLength-1; jpayne@68: maxRpos=rpos; jpayne@68: } jpayne@68: jpayne@68: int[] temp=prev; jpayne@68: prev=next; jpayne@68: next=temp; jpayne@68: } jpayne@68: jpayne@68: maxScore=(maxScore-pointsSub*query.length)/(pointsMatch-pointsSub);//Rescale 0 to length jpayne@68: final float ratio=maxScore/(float)query.length; jpayne@68: jpayne@68: if(ratio