Debian Codegraph @

jni/BBMergeOverlapper.c

raw symbols SCIP
1 #include <jni.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "jgi_BBMergeOverlapper.h"
5
6 // C doesn't have min() or max() so we define our own
7 #define max(a,b) \
8 ({ __typeof__ (a) _a = (a); \
9 __typeof__ (b) _b = (b); \
10 _a > _b ? _a : _b; })
11
12 #define min(a,b) \
13 ({ __typeof__ (a) _a = (a); \
14 __typeof__ (b) _b = (b); \
15 _a < _b ? _a : _b; })
16
17 #define BAD_MULT 6
18 #define GOOD_MULT_1 8
19 #define GOOD_MULT_2 400
20
21 jint mid(int x, int y, int z){return x<y ? (x<z ? min(y, z) : x) : (y<z ? min(x, z) : y);}
22
23 //Looks fine on cursory inspection - BB Oct 27 2015
24 jint mateByOverlap(jbyte * a_bases, const jint a_bases_length, jbyte * b_bases, const jint b_bases_length, jbyte * a_quality, jbyte * b_quality, jfloat * aprob, jfloat * bprob, jint * rvector, jint minOverlap0, const jint minOverlap, const jint minInsert0, jint margin, const jint maxMismatches0, const jint maxMismatches, const jint minq) {
25
26 minOverlap0=min(max(1, minOverlap0), minOverlap);
27 margin=max(margin, 0);
28
29 const jbyte *abases=a_bases, *bbases=b_bases;
30 jbyte *aqual=NULL;
31 jbyte *bqual=NULL;
32 if(a_quality!=NULL){
33 aqual=a_quality;
34 }
35 if(b_quality!=NULL){
36 bqual=b_quality;
37 }
38 const jint alen=a_bases_length, blen=b_bases_length;
39
40 jint bestOverlap=-1;
41 jint bestGood=-1;
42 jint bestBad=maxMismatches0;
43
44 jboolean ambig=0;
45 const jint maxOverlap=alen+blen-max(minOverlap, minInsert0);
46
47 const jfloat probCorrect[71] =
48 {0.000f, 0.251f, 0.369f, 0.499f, 0.602f, 0.684f, 0.749f, 0.800f, 0.842f, 0.874f, 0.900f, 0.921f, 0.937f, 0.950f, 0.960f, 0.968f,
49 0.975f, 0.980f, 0.984f, 0.987f, 0.990f, 0.992f, 0.994f, 0.995f, 0.996f, 0.997f, 0.997f, 0.998f, 0.998f, 0.999f, 0.999f, 0.999f,
50 0.999f, 0.999f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
51
52 if(aqual!=NULL && bqual!=NULL){
53 for(jint i=0; i<alen; i++){aprob[i]=probCorrect[aqual[i]];}
54 for(jint i=0; i<blen; i++){bprob[i]=probCorrect[bqual[i]];}
55 }else{
56 for(jint i=0; i<alen; i++){aprob[i]=0.98f;}
57 for(jint i=0; i<blen; i++){bprob[i]=0.98f;}
58 }
59
60 const jfloat minprob=probCorrect[mid(1, minq, 41)];
61
62 for(jint overlap=max(minOverlap0, 0); overlap<maxOverlap; overlap++){
63 jint good=0, bad=0;
64 jint istart=(overlap<=alen ? 0 : overlap-alen);
65 jint jstart=(overlap<=alen ? alen-overlap : 0);
66 {
67 const jint iters=min(overlap-istart, min(blen-istart, alen-jstart));
68 const jint imax=istart+iters;
69 const jint badlim=bestBad+margin;
70
71 for(jint i=istart, j=jstart; i<imax && bad<=badlim; i++, j++){
72 const jbyte ca1=abases[j], cb1=bbases[i];
73 const jfloat pc=aprob[j]*bprob[j];
74
75 if(pc<=minprob){//do nothing
76 }else if(ca1==cb1){good++;}
77 else{bad++;}
78 }
79 }
80
81 if(bad*2<good){
82 if(good>minOverlap){//Candidate
83 if(bad<=bestBad){
84 if(bad<bestBad || (bad==bestBad && good>bestGood)){//Current winner
85 if(bestBad-bad<margin){ambig=1;}
86 bestOverlap=overlap;
87 bestBad=bad;
88 bestGood=good;
89 }else if(bad==bestBad){
90 ambig=1;
91 }
92
93 if(ambig && bestBad<margin){
94 rvector[2]=bestBad;
95 rvector[4]=(ambig ? 1 : 0);
96 return -1;
97 }
98 }
99 }else if(bad<margin){
100 ambig=1;
101 rvector[2]=bestBad;
102 rvector[4]=(ambig ? 1 : 0);
103 return -1;
104 }else{
105 }
106 }
107 }
108
109 if(!ambig && bestBad>maxMismatches-margin){bestOverlap=-1;}
110
111 rvector[2]=bestBad;
112 rvector[4]=(ambig ? 1 : 0);
113
114 return (bestOverlap<0 ? -1 : alen+blen-bestOverlap);
115 }
116 //Fixed - BB Oct 26 2015
117 jfloat findBestRatio(jbyte * a_bases, const jint a_bases_length, jbyte * b_bases, const jint b_bases_length,
118 const jint minOverlap0, const jint minOverlap, const jint minInsert, const jfloat maxRatio, const jfloat offset, const jfloat gIncr, const jfloat bIncr) {
119 const jbyte *abases=a_bases, *bbases=b_bases;
120 const jint alen=a_bases_length, blen=b_bases_length;
121
122 jfloat bestRatio=maxRatio+0.0001f;
123 const jint maxOverlap=alen+blen-max(minOverlap, minInsert);
124 // const jfloat altBadlimit=max(maxRatio, 0.07f)*2f*alen+1;
125 const jfloat halfmax=maxRatio*0.5f;
126 const jbyte N='N';
127
128 const jint largestInsertToTest=(alen+blen-minOverlap);
129 const jint smallestInsertToTest=minInsert;
130 for(jint insert=largestInsertToTest; insert>=smallestInsertToTest; insert--){
131 const jint istart=(insert<=blen ? 0 : insert-blen);
132 const jint jstart=(insert>=blen ? 0 : blen-insert);
133 const jint overlapLength=min(alen-istart, min(blen-jstart, insert));
134
135 // const jfloat badlimit=(min(altBadlimit, bestRatio*overlapLength));
136 const jfloat badlimit=bestRatio*overlapLength;
137 jfloat good=0, bad=0;
138
139 const jint imax=istart+overlapLength;
140 for(jint i=istart, j=jstart; i<imax && bad<=badlimit; i++, j++){
141 const jbyte ca=abases[i], cb=bbases[j];
142
143 if(ca==cb){
144 if(ca!=N){good+=gIncr;}
145 }else{bad+=bIncr;}
146 }
147
148 if(bad<=badlimit){
149 if(bad==0 && good>minOverlap0 && good<minOverlap){
150 return 100.0f;
151 }
152
153 jfloat ratio=(bad+offset)/overlapLength;
154
155 if(ratio<bestRatio){
156 bestRatio=ratio;
157 if(good>=minOverlap && ratio<halfmax){return bestRatio;}
158 }
159 }
160 }
161
162 return bestRatio;
163 }
164 //Fixed - BB Oct 27 2015
165 //TODO: remove a_quality and b_quality
166 jfloat findBestRatio_WithQualities(jbyte * a_bases, const jint a_bases_length, jbyte * b_bases, const jint b_bases_length,
167 jbyte * a_quality, jbyte * b_quality, //TODO: Not needed
168 jfloat * aprob, jfloat * bprob,
169 const jint minOverlap0, const jint minOverlap, const jint minInsert, const jfloat maxRatio, const jfloat offset) {
170 const jbyte *abases=a_bases, *bbases=b_bases;
171 const jint alen=a_bases_length, blen=b_bases_length;
172
173 jfloat bestRatio=maxRatio+0.0001f;
174 // const jfloat altBadlimit=max(maxRatio, 0.07f)*2f*alen+1;
175 const jfloat halfmax=maxRatio*0.5f;
176
177
178 const jint largestInsertToTest=(alen+blen-minOverlap); //TODO: test speed with minOverlap0
179 const jint smallestInsertToTest=minInsert;
180 for(jint insert=largestInsertToTest; insert>=smallestInsertToTest; insert--){
181
182
183 const jint istart=(insert<=blen ? 0 : insert-blen);
184 const jint jstart=(insert>=blen ? 0 : blen-insert);
185 const jint overlapLength=min(alen-istart, min(blen-jstart, insert));
186
187 // const jfloat badlimit=(min(altBadlimit, bestRatio*overlapLength));
188 const jfloat badlimit=bestRatio*overlapLength;
189 jfloat good=0, bad=0;
190
191 const jint imax=istart+overlapLength;
192 for(jint i=istart, j=jstart; i<imax && bad<=badlimit; i++, j++){
193 const jbyte ca=abases[i], cb=bbases[j];
194 const jfloat x=aprob[i]*bprob[j];
195
196 if(ca==cb){good+=x;}
197 else{bad+=x;}
198 }
199
200 if(bad<=badlimit){
201 if(bad==0 && good>minOverlap0 && good<minOverlap){
202 return 100.0f;
203 }
204
205 jfloat ratio=(bad+offset)/overlapLength;
206
207 if(ratio<bestRatio){
208 bestRatio=ratio;
209 if(good>=minOverlap && ratio<halfmax){return bestRatio;}
210 }
211 }
212 }
213
214 return bestRatio;
215 }
216 //Fixed - BB Oct 27 2015
217 jint mateByOverlapRatio_WithQualities(jbyte * a_bases, const jint a_bases_length, jbyte * b_bases, const jint b_bases_length,
218 jbyte * a_quality, jbyte * b_quality,
219 jfloat * aprob, jfloat * bprob,
220 jint * rvector, jint minOverlap0, jint minOverlap, jint minInsert0, jint minInsert, jfloat maxRatio, const jfloat margin, const jfloat offset) {
221 minOverlap=max(4, max(minOverlap0, minOverlap));
222 minOverlap0=mid(4, minOverlap0, minOverlap);
223
224 const jbyte *abases=a_bases, *bbases=b_bases, *aqual=a_quality, *bqual=b_quality;
225 const jint alen=a_bases_length, blen=b_bases_length;
226 const jint minLength=min(alen, blen);
227
228 {
229 const jfloat probCorrect[71] =
230 {0.000f, 0.251f, 0.369f, 0.499f, 0.602f, 0.684f, 0.749f, 0.800f, 0.842f, 0.874f, 0.900f, 0.921f, 0.937f, 0.950f, 0.960f, 0.968f,
231 0.975f, 0.980f, 0.984f, 0.987f, 0.990f, 0.992f, 0.994f, 0.995f, 0.996f, 0.997f, 0.997f, 0.998f, 0.998f, 0.999f, 0.999f, 0.999f,
232 0.999f, 0.999f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
233
234 for(jint i=0; i<alen; i++){aprob[i]=probCorrect[aqual[i]];}
235 for(jint i=0; i<blen; i++){bprob[i]=probCorrect[bqual[i]];}
236 }
237 {
238 jfloat x=findBestRatio_WithQualities(a_bases, a_bases_length, b_bases, b_bases_length, a_quality, b_quality, aprob, bprob, minOverlap0, minOverlap, minInsert, maxRatio, offset);
239 if(x>maxRatio){
240 rvector[2]=minLength;
241 rvector[4]=0;
242 return -1;
243 }
244 maxRatio=min(maxRatio, x);
245 }
246
247 const jfloat altBadlimit=max(maxRatio, 0.07f)*2.0f*alen+1;
248 const jfloat margin2=(margin+offset)/minLength;
249
250 jint bestInsert=-1;
251 jfloat bestBad=minLength;
252 jfloat bestRatio=1;
253 jboolean ambig=0;
254
255 const jint largestInsertToTest=(alen+blen-minOverlap0);
256 const jint smallestInsertToTest=minInsert0;
257 for(jint insert=largestInsertToTest; insert>=smallestInsertToTest; insert--){
258 jfloat good=0, bad=0;
259
260 const jint istart=(insert<=blen ? 0 : insert-blen);
261 const jint jstart=(insert>=blen ? 0 : blen-insert);
262
263 const jint overlapLength=min(alen-istart, min(blen-jstart, insert));
264 const jfloat badlimit=min(altBadlimit, min(bestRatio, maxRatio)*margin*overlapLength);
265
266 const jint imax=istart+overlapLength;
267 for(jint i=istart, j=jstart; i<imax && bad<=badlimit; i++, j++){
268 const jbyte ca=abases[i], cb=bbases[j];
269 const jfloat x=aprob[i]*bprob[j];
270
271 if(ca==cb){good+=x;}
272 else{bad+=x;}
273 }
274
275 if(bad<=badlimit){
276 if(bad==0 && good>minOverlap0 && good<minOverlap){
277 rvector[2]=(jint)bestBad;
278 rvector[4]=1;
279 return -1;
280 }
281
282 jfloat ratio=(bad+offset)/overlapLength;
283
284 if(ratio<bestRatio*margin){
285
286 ambig=(ratio*margin>=bestRatio || good<minOverlap);
287 if(ratio<bestRatio){
288 bestInsert=insert;
289 bestBad=bad;
290 bestRatio=ratio;
291 }
292 if(ambig && bestRatio<margin2){
293 rvector[2]=(jint)bestBad;
294 rvector[4]=1;
295 return -1;
296 }
297 }
298 }
299 }
300
301 if(!ambig && bestRatio>maxRatio){bestInsert=-1;}
302
303 rvector[2]=(jint)bestBad;
304 rvector[4]=(ambig ? 1 : 0);
305
306 return (bestInsert<0 ? -1 : bestInsert);
307 }
308 //Fixed - BB Oct 27 2015
309 jint mateByOverlapRatio(jbyte * a_bases, const jint a_bases_length, jbyte * b_bases, const jint b_bases_length, jint * rvector, jint minOverlap0, jint minOverlap, const jint minInsert0, const jint minInsert, jfloat maxRatio, const jfloat margin, const jfloat offset, const jfloat gIncr, const jfloat bIncr) {
310
311 minOverlap=max(4, max(minOverlap0, minOverlap));
312 minOverlap0=mid(4, minOverlap0, minOverlap);
313
314 const jbyte *abases=a_bases, *bbases=b_bases;
315 const jint alen=a_bases_length, blen=b_bases_length;
316 const jint minLength=min(alen, blen);
317 {
318 jfloat x=findBestRatio(a_bases, a_bases_length, b_bases, b_bases_length, minOverlap0, minOverlap, minInsert, maxRatio, offset, gIncr, bIncr);
319 if(x>=maxRatio){
320 rvector[2]=minLength;
321 rvector[4]=0;
322 return -1;
323 }
324 maxRatio=min(maxRatio, x);
325 }
326
327 const jfloat altBadlimit=max(maxRatio, 0.07f)*2.0f*alen+1;
328 const jfloat margin2=(margin+offset)/minLength;
329 const jbyte N='N';
330
331 jint bestInsert=-1;
332 jfloat bestBad=minLength;
333 jfloat bestRatio=1;
334 jboolean ambig=0;
335
336 const jint largestInsertToTest=(alen+blen-minOverlap0);
337 const jint smallestInsertToTest=minInsert0;
338 for(jint insert=largestInsertToTest; insert>=smallestInsertToTest; insert--){
339 const jint istart=(insert<=blen ? 0 : insert-blen);
340 const jint jstart=(insert>=blen ? 0 : blen-insert);
341 const jint overlapLength=min(alen-istart, min(blen-jstart, insert));
342
343 const jfloat badlimit=(min(altBadlimit, min(bestRatio, maxRatio)*margin*overlapLength));
344 jfloat good=0, bad=0;
345
346 const int imax=istart+overlapLength;
347 for(jint i=istart, j=jstart; i<imax && bad<=badlimit; i++, j++){
348 const jbyte ca=abases[i], cb=bbases[j];
349
350 if(ca==cb){
351 if(ca!=N){good+=gIncr;}
352 }else{bad+=bIncr;}
353 }
354
355 if(bad<=badlimit){
356 if(bad==0 && good>minOverlap0 && good<minOverlap){
357 rvector[2]=(jint)bestBad;
358 rvector[4]=1;
359 return -1;
360 }
361
362 jfloat ratio=(bad+offset)/overlapLength;
363
364 if(ratio<bestRatio*margin){
365
366 ambig=(ratio*margin>=bestRatio || good<minOverlap);
367 if(ratio<bestRatio){
368 bestInsert=insert;
369 bestBad=bad;
370 bestRatio=ratio;
371 }
372 if(ambig && bestRatio<margin2){
373 rvector[2]=(int)bestBad;
374 rvector[4]=1;
375 return -1;
376 }
377 }
378 }
379 }
380
381 if(!ambig && bestRatio>maxRatio){bestInsert=-1;}
382
383 rvector[2]=(jint)bestBad;
384 rvector[4]=(ambig ? 1 : 0);
385
386 return (bestInsert<0 ? -1 : bestInsert);
387 }
388
389 JNIEXPORT jint JNICALL Java_jgi_BBMergeOverlapper_mateByOverlapJNI_WithQualities(
390 JNIEnv *env,
391 jobject obj,
392 jbyteArray a_bases,
393 jbyteArray b_bases,
394 jbyteArray a_quality,
395 jbyteArray b_quality,
396 jfloatArray aprob,
397 jfloatArray bprob,
398 jintArray rvector,
399 jint minOverlap0,
400 jint minOverlap,
401 jint minInsert0,
402 jint minInsert,
403 jfloat maxRatio,
404 jfloat margin,
405 jfloat offset
406 ) {
407 jbyte * ja_quality = NULL;
408 jbyte * jb_quality = NULL;
409 jfloat * japrob = NULL;
410 jfloat * jbprob = NULL;
411
412 // Get the size of the read and the reference arrays
413 const jint a_bases_length = (*env)->GetArrayLength(env, a_bases);
414 const jint b_bases_length = (*env)->GetArrayLength(env, b_bases);
415
416 // Copy arrays from Java
417 jbyte * ja_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, a_bases, NULL);
418 jbyte * jb_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, b_bases, NULL);
419 if(a_quality!=NULL) {ja_quality = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, a_quality, NULL);}
420 if(b_quality!=NULL) {jb_quality = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, b_quality, NULL);}
421 if(aprob!=NULL) {japrob = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, aprob, NULL);}
422 if(bprob!=NULL) {jbprob = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, bprob, NULL);}
423 jint * jrvector = (jint*)(*env)->GetPrimitiveArrayCritical(env, rvector, NULL);
424
425 const jint returnVal = mateByOverlapRatio_WithQualities(ja_bases, a_bases_length, jb_bases, b_bases_length, ja_quality, jb_quality, japrob, jbprob, jrvector, minOverlap0, minOverlap, minInsert0, minInsert, maxRatio, margin, offset);
426
427 // Release Java arrays; 0 copies the array back to Java, JNI_ABORT does not copy the current array values to Java
428 (*env)->ReleasePrimitiveArrayCritical(env, a_bases, ja_bases, JNI_ABORT);
429 (*env)->ReleasePrimitiveArrayCritical(env, b_bases, jb_bases, JNI_ABORT);
430 if(ja_quality!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, a_quality, ja_quality, JNI_ABORT);}
431 if(jb_quality!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, b_quality, jb_quality, JNI_ABORT);}
432 if(japrob!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, aprob, japrob, JNI_ABORT);}
433 if(jbprob!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, bprob, jbprob, JNI_ABORT);}
434 (*env)->ReleasePrimitiveArrayCritical(env, rvector, jrvector, 0);
435
436 return returnVal;
437 }
438
439 JNIEXPORT jint JNICALL Java_jgi_BBMergeOverlapper_mateByOverlapJNI(
440 JNIEnv *env,
441 jobject obj,
442 jbyteArray a_bases,
443 jbyteArray b_bases,
444 jbyteArray a_quality,
445 jbyteArray b_quality,
446 jfloatArray aprob,
447 jfloatArray bprob,
448 jintArray rvector,
449 jint minOverlap0,
450 jint minOverlap,
451 jint minInsert0,
452 jint margin,
453 jint maxMismatches0,
454 jint maxMismatches,
455 jint minq
456 ) {
457 jbyte * ja_quality = NULL;
458 jbyte * jb_quality = NULL;
459 jfloat * japrob = NULL;
460 jfloat * jbprob = NULL;
461
462 // Get the size of the read and the reference arrays
463 const jint a_bases_length = (*env)->GetArrayLength(env, a_bases);
464 const jint b_bases_length = (*env)->GetArrayLength(env, b_bases);
465
466 // Copy arrays from Java
467 jbyte * ja_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, a_bases, NULL);
468 jbyte * jb_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, b_bases, NULL);
469 if(a_quality!=NULL) {ja_quality = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, a_quality, NULL);}
470 if(b_quality!=NULL) {jb_quality = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, b_quality, NULL);}
471 if(aprob!=NULL) {japrob = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, aprob, NULL);}
472 if(bprob!=NULL) {jbprob = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, bprob, NULL);}
473 jint * jrvector = (jint*)(*env)->GetPrimitiveArrayCritical(env, rvector, NULL);
474
475 const jint returnVal = mateByOverlap(ja_bases, a_bases_length, jb_bases, b_bases_length, ja_quality, jb_quality, japrob, jbprob, jrvector, minOverlap0, minOverlap, minInsert0, margin, maxMismatches0, maxMismatches, minq);
476
477 // Release Java arrays; 0 copies the array back to Java, JNI_ABORT does not copy the current array values to Java
478 (*env)->ReleasePrimitiveArrayCritical(env, a_bases, ja_bases, JNI_ABORT);
479 (*env)->ReleasePrimitiveArrayCritical(env, b_bases, jb_bases, JNI_ABORT);
480 if(ja_quality!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, a_quality, ja_quality, JNI_ABORT);}
481 if(jb_quality!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, b_quality, jb_quality, JNI_ABORT);}
482 if(japrob!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, aprob, japrob, JNI_ABORT);}
483 if(jbprob!=NULL) {(*env)->ReleasePrimitiveArrayCritical(env, bprob, jbprob, JNI_ABORT);}
484 (*env)->ReleasePrimitiveArrayCritical(env, rvector, jrvector, 0);
485
486 return returnVal;
487 }
488
489 JNIEXPORT jint JNICALL Java_jgi_BBMergeOverlapper_mateByOverlapRatioJNI(
490 JNIEnv *env,
491 jobject obj,
492 jbyteArray a_bases,
493 jbyteArray b_bases,
494 jintArray rvector,
495 jint minOverlap0,
496 jint minOverlap,
497 jint minInsert0,
498 jint minInsert,
499 jfloat maxRatio,
500 jfloat margin,
501 jfloat offset,
502 jfloat gIncr,
503 jfloat bIncr
504 ) {
505 // Get the size of the read and the reference arrays
506 const jint a_bases_length = (*env)->GetArrayLength(env, a_bases);
507 const jint b_bases_length = (*env)->GetArrayLength(env, b_bases);
508
509 // Copy arrays from Java
510 jbyte * ja_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, a_bases, NULL);
511 jbyte * jb_bases = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, b_bases, NULL);
512 jint * jrvector = (jint*)(*env)->GetPrimitiveArrayCritical(env, rvector, NULL);
513
514 const jint returnVal = mateByOverlapRatio(ja_bases, a_bases_length, jb_bases, b_bases_length, jrvector, minOverlap0, minOverlap, minInsert0, minInsert, maxRatio, margin, offset, gIncr, bIncr);
515
516 // Release Java arrays; 0 copies the array back to Java, JNI_ABORT does not copy the current array values to Java
517 (*env)->ReleasePrimitiveArrayCritical(env, a_bases, ja_bases, JNI_ABORT);
518 (*env)->ReleasePrimitiveArrayCritical(env, b_bases, jb_bases, JNI_ABORT);
519 (*env)->ReleasePrimitiveArrayCritical(env, rvector, jrvector, 0);
520
521 return returnVal;
522 }
523