Skip to content

Commit

Permalink
Avoid attempting to access beyond the end of the 2 bit reference array.
Browse files Browse the repository at this point in the history
  • Loading branch information
mozack committed Mar 6, 2015
1 parent f58700a commit b0a2e67
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/abra/CompareToReference2.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public String getSequence(String chromosome, int position, int length) {
if (is2Bit) {
StringBuffer buf = new StringBuffer(length);
int start = Math.max(position, 0);
int stop = Math.min(position+length, ref.length*4+1);
int stop = Math.min(position+length, ref.length*4);

for (int i=start; i<stop; i++) {
buf.append(getBaseAsChar(i, ref));
Expand Down Expand Up @@ -451,9 +451,14 @@ public static void main(String[] args) throws Exception {

public static void main(String[] args) throws Exception {
CompareToReference2 c2r = new CompareToReference2();
c2r.init("/home/lmose/reference/chr3/chr3.fa");
c2r.init("/home/lmose/reference/chrM/MT.fa");
// c2r.init("/home/lmose/reference/test/test.fa");
System.out.println(c2r.getSequence("chr3", 178948013, 100));

for (int i=16400; i<16600; i++) {
System.out.println("" + i + " : " + c2r.getSequence("MT", i, 100));
}

// System.out.println(c2r.getSequence("MT", 16474, 100));

// c2r.init("/home/lmose/reference/t2/t2.fa");
// System.out.println(c2r.getSequence("x1", 1, 12));
Expand Down

0 comments on commit b0a2e67

Please sign in to comment.