From: Jim Procter Date: Sun, 18 Jan 2015 15:21:00 +0000 (+0000) Subject: JAL-1628 new method to get a list of insertions in a SequenceI X-Git-Tag: Jalview_2_9~108^2~24 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=393d4a79542f70fd6975e2a5250b819d5023f590;p=jalview.git JAL-1628 new method to get a list of insertions in a SequenceI --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index cf1c983..96e469a 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -682,6 +682,42 @@ public class Sequence implements SequenceI } @Override + public List getInsertions() + { + ArrayList map = new ArrayList(); + int lastj = -1, j = 0; + int pos = start; + int seqlen = sequence.length; + while ((j < seqlen)) + { + if (jalview.util.Comparison.isGap(sequence[j])) + { + if (lastj == -1) + { + lastj = j; + } + } + else + { + if (lastj != -1) + { + map.add(new int[] + { lastj, j - 1 }); + lastj = -1; + } + } + j++; + } + if (lastj != -1) + { + map.add(new int[] + { lastj, j - 1 }); + lastj = -1; + } + return map; + } + + @Override public void deleteChars(int i, int j) { int newstart = start, newend = end; diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 46669ae..e8c1d71 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -414,4 +414,10 @@ public interface SequenceI */ public void setRNA(RNA rna); + /** + * + * @return list of insertions (gap characters) in sequence + */ + public List getInsertions(); + } diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index d9a4573..40476a0 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -20,6 +20,21 @@ public class SequenceTest seq = new Sequence("FER1", "AKPNGVL"); } @Test + public void testInsertGapsAndGapmaps() + { + SequenceI aseq = seq.deriveSequence(); + aseq.insertCharAt(2, 3, '-'); + aseq.insertCharAt(6, 3, '-'); + assertEquals("Gap insertions not correct", "AK---P---NGVL", + aseq.getSequenceAsString()); + List gapInt = aseq.getInsertions(); + assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]); + assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]); + assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]); + assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]); + } + + @Test public void testGetAnnotation() { // initial state returns null not an empty array