X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fanalysis%2FTestAlignSeq.java;h=44bea811761f89441dd095ff44945226bf985eb5;hb=261d2ca1b0eef309cd9d178e023c6bfecbd62017;hp=9fc88ead7cf2ce865feac8c6fa0bc4557191e5b0;hpb=5f4e1e4c330b045e9c8bce28ee132a0fca3834d8;p=jalview.git diff --git a/test/jalview/analysis/TestAlignSeq.java b/test/jalview/analysis/TestAlignSeq.java index 9fc88ea..44bea81 100644 --- a/test/jalview/analysis/TestAlignSeq.java +++ b/test/jalview/analysis/TestAlignSeq.java @@ -29,11 +29,15 @@ import jalview.datamodel.SequenceI; import jalview.gui.JvOptionPane; import java.io.PrintStream; +import java.nio.charset.Charset; +import java.util.Locale; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import com.google.common.base.Charsets; + /** * Test the alignment -> Mapping routines * @@ -64,7 +68,7 @@ public class TestAlignSeq s2 = new Sequence("Seq2", "ASDFA"); s2.setStart(5); s2.setEnd(9); - s3 = new Sequence("Seq1", "SDFAQQQSSS"); + s3 = new Sequence("Seq3", "SDFAQQQSSS"); } @@ -83,16 +87,44 @@ public class TestAlignSeq assertEquals(as.getAStr1(), as.getAStr2()); Mapping s1tos2 = as.getMappingFromS1(false); + checkMapping(s1tos2,s1,s2); + } + + public void checkMapping(Mapping s1tos2,SequenceI _s1,SequenceI _s2) + { System.out.println(s1tos2.getMap().toString()); - for (int i = s2.getStart(); i < s2.getEnd(); i++) + for (int i = _s2.getStart(); i < _s2.getEnd(); i++) { - System.out.println("Position in s2: " + i - + " maps to position in s1: " + s1tos2.getPosition(i)); - // TODO fails: getCharAt doesn't allow for the start position?? - // assertEquals(String.valueOf(s2.getCharAt(i)), - // String.valueOf(s1.getCharAt(s1tos2.getPosition(i)))); + int p=s1tos2.getPosition(i); + char s2c=_s2.getCharAt(i-_s2.getStart()); + char s1c=_s1.getCharAt(p-_s1.getStart()); + System.out.println("Position in s2: " + i +s2c + + " maps to position in s1: " +p+s1c); + assertEquals(s1c,s2c); } } + @Test(groups = { "Functional" }) + /** + * simple test that mapping from alignment corresponds identical positions. + */ + public void testGetMappingForS1_withLowerCase() + { + // make one of the sequences lower case + SequenceI ns2 = new Sequence(s2); + ns2.replace('D', 'd'); + AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, ns2, AlignSeq.PEP); + System.out.println("s1: " + as.getAStr1()); + System.out.println("s2: " + as.getAStr2()); + + // aligned results match + assertEquals("ASDFA", as.getAStr1()); + assertEquals(as.getAStr1(), as.getAStr2().toUpperCase(Locale.ROOT)); + + Mapping s1tos2 = as.getMappingFromS1(false); + assertEquals("ASdFA",as.getAStr2()); + // verify mapping is consistent between original all-caps sequences + checkMapping(s1tos2,s1,s2); + } @Test(groups = { "Functional" }) public void testExtractGaps() @@ -125,10 +157,9 @@ public class TestAlignSeq }; as.printAlignment(ps); - String expected = "Score = 320\nLength of alignment = 10\nSequence Seq1 : 3 - 18 (Sequence length = 14)\nSequence Seq1 : 1 - 10 (Sequence length = 10)\n\n" - + "Seq1 SDFAQQQRRR\n" - + " ||||||| \n" - + "Seq1 SDFAQQQSSS\n\n" + "Percentage ID = 70.00\n"; + String expected = "Score = 320.0\nLength of alignment = 10\nSequence Seq1/4-13 (Sequence length = 14)\nSequence Seq3/1-10 (Sequence length = 10)\n\n" + + "Seq1/4-13 SDFAQQQRRR\n" + " ||||||| \n" + + "Seq3/1-10 SDFAQQQSSS\n\n" + "Percentage ID = 70.00\n\n"; assertEquals(expected, baos.toString()); } }