From efde43fab576590026bbe0ced39e13426aa6532f Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 18 Apr 2014 10:08:57 +0100 Subject: [PATCH] JAL-1466 improved test and patched off by one that deleted one dataset residue from flanking alignment --- src/jalview/analysis/AlignmentUtils.java | 7 ++++--- test/jalview/analysis/AlignmentUtilsTests.java | 12 +++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 2e607c0..5bbdc4a 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -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()); diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 5039deb..2104d4a 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -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())); + } + } } } } -- 1.7.10.2