JAL-1466 improved test and patched off by one that deleted one dataset residue from...
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 18 Apr 2014 09:08:57 +0000 (10:08 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Mon, 21 Apr 2014 13:09:17 +0000 (14:09 +0100)
src/jalview/analysis/AlignmentUtils.java
test/jalview/analysis/AlignmentUtilsTests.java

index 2e607c0..5bbdc4a 100644 (file)
@@ -44,8 +44,9 @@ public class AlignmentUtils
       while (ds.getDatasetSequence()!=null) {
         ds=ds.getDatasetSequence();
       }
+      int s_end = s.findPosition(s.getStart()+s.getLength());
       // find available flanking residues for sequence
-      int ustream_ds=s.getStart()-ds.getStart(),dstream_ds=ds.getEnd()-s.getEnd();
+      int ustream_ds=s.getStart()-ds.getStart(),dstream_ds=ds.getEnd()-s_end;
       
       // build new flanked sequence
       
@@ -66,7 +67,7 @@ public class AlignmentUtils
         }
       }
       char[] upstream = new String(ds.getSequence(s.getStart()-1-ustream_ds, s.getStart()-1)).toLowerCase().toCharArray();
-      char[] downstream = new String(ds.getSequence(s.getEnd()+1,s.getEnd()+1+dstream_ds)).toLowerCase().toCharArray();
+      char[] downstream = new String(ds.getSequence(s_end-1,s_end+1+dstream_ds)).toLowerCase().toCharArray();
       char[] coreseq=s.getSequence();
       char[] nseq = new char[offset+upstream.length+downstream.length+coreseq.length]; 
       char c = core.getGapCharacter();
@@ -82,7 +83,7 @@ public class AlignmentUtils
       System.arraycopy(downstream, 0, nseq, p+coreseq.length+upstream.length, downstream.length);
       s.setSequence(new String(nseq));
       s.setStart(s.getStart()-ustream_ds);
-      s.setEnd(s.getEnd()+downstream.length);
+      s.setEnd(s_end+downstream.length);
     }
     AlignmentI newAl = new jalview.datamodel.Alignment(sq.toArray(new SequenceI[0]));
     newAl.setDataset(core.getDataset());
index 5039deb..2104d4a 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.analysis;
 
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 
 import jalview.datamodel.Alignment;
@@ -23,8 +25,16 @@ public class AlignmentUtilsTests
     System.out.println(new AppletFormatAdapter().formatSequences("Clustal", al, true));
     for (int flnk=-1;flnk<25; flnk++)
     {
+      AlignmentI exp;
       System.out.println("\nFlank size: "+flnk);
-      System.out.println(new AppletFormatAdapter().formatSequences("Clustal", AlignmentUtils.expandContext(al, flnk), true));
+      System.out.println(new AppletFormatAdapter().formatSequences("Clustal", exp=AlignmentUtils.expandContext(al, flnk), true));
+      if (flnk==-1) {
+        for (SequenceI sq:exp.getSequences())
+      {
+          String ung = sq.getSequenceAsString().replaceAll("-+", "");
+          assertTrue("Flanking sequence not the same as original dataset sequence.\n"+ung+"\n"+sq.getDatasetSequence().getSequenceAsString(),ung.equalsIgnoreCase(sq.getDatasetSequence().getSequenceAsString()));
+      }
+      }
     }    
   }
 }