jpayne@68: package icecream; jpayne@68: jpayne@68: import aligner.AlignmentResult; jpayne@68: import shared.KillSwitch; jpayne@68: import shared.Shared; jpayne@68: jpayne@68: public final class IceCreamAlignerJNI extends IceCreamAligner { jpayne@68: jpayne@68: static { jpayne@68: Shared.loadJNI(); jpayne@68: } jpayne@68: jpayne@68: IceCreamAlignerJNI(){} jpayne@68: jpayne@68: /** jpayne@68: * @param query jpayne@68: * @param ref jpayne@68: * @param qstart 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: jpayne@68: final int qlen=query.length; jpayne@68: final int rlen=rstop-rstart+1; jpayne@68: final int[] retVec=KillSwitch.allocInt1D(4); jpayne@68: jpayne@68: // alignForwardJNI(qInt, rInt, retVec, qlen, rlen, minScore, minRatio); jpayne@68: // alignForwardPseudo(qInt, rInt, retVec, qlen, rlen, minScore, minRatio); jpayne@68: jpayne@68: if((qlen+rlen+32)*2>Short.MAX_VALUE) { jpayne@68: final int[] qInt=new int[query.length]; jpayne@68: final int[] rInt=new int[rlen]; jpayne@68: for(int i=0; iShort.MAX_VALUE) { jpayne@68: final int[] qInt=new int[query.length]; jpayne@68: final int[] rInt=new int[rlen]; jpayne@68: for(int i=0; i=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: jpayne@68: for(int rpos=0, apos=1; rpos=vScore ? dScore : vScore); jpayne@68: next[apos]=score; jpayne@68: } jpayne@68: jpayne@68: for(int apos=1; aposscore ? hScore : score); jpayne@68: next[apos]=score; jpayne@68: maxScoreThisPass=(score>maxScoreThisPass ? score : maxScoreThisPass); jpayne@68: } jpayne@68: iters+=arrayLength; jpayne@68: jpayne@68: //Aggressive early exit jpayne@68: if(maxScoreThisPass=maxScore){ jpayne@68: maxScore=score; jpayne@68: maxQpos=qlen; jpayne@68: maxRpos=apos-1; jpayne@68: } jpayne@68: } jpayne@68: retArray[0]=maxScore; jpayne@68: retArray[1]=maxQpos; jpayne@68: retArray[2]=maxRpos; jpayne@68: retArray[3]=iters; jpayne@68: } jpayne@68: jpayne@68: private static void alignForwardShortPseudo(int[] query, int[] ref, int[] retArray, int qlen, int rlen) { jpayne@68: jpayne@68: final int arrayLength=qlen; jpayne@68: final int arrayLength2=qlen+1; jpayne@68: jpayne@68: //Stack allocated; faster. jpayne@68: int[] array1=new int[arrayLength2]; jpayne@68: int[] array2=new int[arrayLength2]; jpayne@68: jpayne@68: int[] prev=array1; jpayne@68: int[] next=array2; jpayne@68: int maxScore=-999999; jpayne@68: int maxQpos=-1; jpayne@68: int maxRpos=-1; jpayne@68: int itersShort=0; jpayne@68: jpayne@68: for(int i=0; i=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: retArray[0]=maxScore; jpayne@68: retArray[1]=maxQpos; jpayne@68: retArray[2]=maxRpos; jpayne@68: retArray[3]=itersShort; jpayne@68: } jpayne@68: jpayne@68: private static native void alignForwardJNI(int[] query, int[] ref, int[] retArray, int qlen, int rlen, int minScore, float minRatio); jpayne@68: private static native void alignForward16JNI(short[] query, short[] ref, int[] retArray, short qlen, short rlen, short minScore, float minRatio); jpayne@68: private static native void alignForwardShortJNI(int[] query, int[] ref, int[] retArray, int qlen, int rlen); jpayne@68: private static native void alignForwardShort16JNI(short[] query, short[] ref, int[] retArray, short qlen, short rlen); jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Getters ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: @Override jpayne@68: long iters(){return iters;} jpayne@68: jpayne@68: @Override jpayne@68: long itersShort(){return itersShort;} jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Fields ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: long iters = 0; jpayne@68: long itersShort = 0; jpayne@68: jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: /*---------------- Constants ----------------*/ jpayne@68: /*--------------------------------------------------------------*/ jpayne@68: jpayne@68: public static final int pointsMatch = 1; jpayne@68: public static final int pointsSub = -1; jpayne@68: public static final int pointsDel = -2; jpayne@68: public static final int pointsIns = -2; jpayne@68: jpayne@68: }