package abra;

import abra.SemiGlobalAligner.Result;

public class NativeSemiGlobalAligner {

	private native String align(String seq1, String seq2, int match, int mismatch, int gapOpen, int gapExtend);
	
	private int match = 8;
	private int mismatch = -32;
	private int gapOpen = -48;
	private int gapExtend = -1;
	
	public NativeSemiGlobalAligner(int match, int mismatch, int gapOpen, int gapExtend) {
		this.match = match;
		this.mismatch = mismatch;
		this.gapOpen = gapOpen;
		this.gapExtend = gapExtend;
	}
	
	public Result align(String seq1, String seq2) {
		
		// Result returned in format score:secondBest:pos:endPos:cigar
		// 789:741:611:734:52M108I71M
		String res = align(seq1, seq2, match, mismatch, gapOpen, gapExtend);
		
		String[] results = res.split(":");
		Result result = new Result(Integer.valueOf(results[0]), Integer.valueOf(results[1]),
				Integer.valueOf(results[2]), Integer.valueOf(results[3]), results[4]);
		
		return result;
	}
}

@@ -310,16 +310,113 @@
 = -1;%0A%09%0A
+%09private static final int MAX_CONTIG_LEN = 1998;%0A%09private static final int MAX_REF_LEN = 4998;%0A%09%0A
 %09public 
@@ -657,16 +657,220 @@
 2) %7B%0A%09%09%0A
+%09%09if (seq1.length() %3E MAX_CONTIG_LEN) %7B%0A%09%09%09throw new IllegalArgumentException(%22Contig too long%22);%0A%09%09%7D%0A%09%09%0A%09%09if (seq2.length() %3E MAX_REF_LEN) %7B%0A%09%09%09throw new IllegalArgumentException(%22Ref too long%22);%0A%09%09%7D%0A%09%09%0A
 %09%09// Res

Add length guard around native SG aligner input.