From: James Procter Date: Thu, 22 Jun 2023 15:00:31 +0000 (+0200) Subject: JAL-2292 - ensure mapping is built for equal symbols with mismatched case X-Git-Tag: Release_2_11_3_0~12^2~13^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fpatch%2FJAL-2292_caseSensitivePAE;p=jalview.git JAL-2292 - ensure mapping is built for equal symbols with mismatched case --- diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index 65fd110..02b3f41 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -890,7 +890,8 @@ public class AlignSeq pdbpos++; } - if (allowmismatch || c1 == c2) + // ignore case differences + if (allowmismatch || (c1 == c2) || (Math.abs(c2-c1)==('a'-'A'))) { // extend mapping interval if (lp1 + 1 != alignpos || lp2 + 1 != pdbpos) diff --git a/test/jalview/analysis/TestAlignSeq.java b/test/jalview/analysis/TestAlignSeq.java index 5134511..62250eb 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 * @@ -83,16 +87,42 @@ 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); + checkMapping(s1tos2,s1,ns2); + } @Test(groups = { "Functional" }) public void testExtractGaps()