From: Jim Procter Date: Fri, 26 Feb 2021 14:02:27 +0000 (+0000) Subject: Merge branch 'bug/JAL-3806_mappingCoversSequence' into releases/Release_2_11_1_Branch X-Git-Tag: Release_2_11_1_4~6 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=cb628aab46f9027e71b71203b322f96710e09990;hp=a40669b2eeb34a6c760b63c172a31a194b456f24 Merge branch 'bug/JAL-3806_mappingCoversSequence' into releases/Release_2_11_1_Branch --- diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index 6faf7a6..6ccc0fc 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -171,8 +171,8 @@ public class AlignedCodonFrame if (length != -1) { - // add 1 to mapped length to allow for a mapped stop codon - if (length + 1 >= (mend - mstart + 1)) + // add 3 to mapped length to allow for a mapped stop codon + if (length + 3 >= (mend - mstart + 1)) { return true; } diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 177c54d..c9113ae 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -408,7 +408,6 @@ public final class MappingUtils int mappedEndCol = seq.findIndex(mappedEndResidue) - 1; maxEndCol = maxEndCol == -1 ? mappedEndCol : Math.max(maxEndCol, mappedEndCol); - break; } } } diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 08673ae..204d803 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -67,7 +67,7 @@ public class MappingUtilsTest { Cache.initLogger(); } - + @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() { @@ -277,7 +277,8 @@ public class MappingUtilsTest sg.addSequence(cdna.getSequenceAt(0), false); sg.setStartRes(0); sg.setEndRes(2); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, theProteinView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); assertTrue(mappedGroup.getColourText()); assertSame(sg.getIdColour(), mappedGroup.getIdColour()); assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); @@ -573,7 +574,8 @@ public class MappingUtilsTest // select columns 2 and 3 in DNA which span protein columns 0 and 1 sg.setStartRes(2); sg.setEndRes(3); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, theProteinView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); assertTrue(mappedGroup.getColourText()); assertSame(sg.getIdColour(), mappedGroup.getIdColour()); assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); @@ -656,7 +658,8 @@ public class MappingUtilsTest */ sg.setStartRes(2); sg.setEndRes(4); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theProteinView, theDnaView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theProteinView, + theDnaView); assertEquals(1, mappedGroup.getStartRes()); assertEquals(13, mappedGroup.getEndRes()); @@ -669,19 +672,22 @@ public class MappingUtilsTest // select columns 4,5 - includes Seq1:codon2 (A) only sg.setStartRes(4); sg.setEndRes(5); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, theProteinView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); assertEquals(2, mappedGroup.getStartRes()); assertEquals(2, mappedGroup.getEndRes()); // add Seq2 to dna selection cols 4-5 include codons 1 and 2 (LQ) sg.addSequence(cdna.getSequenceAt(1), false); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, theProteinView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); assertEquals(2, mappedGroup.getStartRes()); assertEquals(4, mappedGroup.getEndRes()); // add Seq3 to dna selection cols 4-5 include codon 1 (Q) sg.addSequence(cdna.getSequenceAt(2), false); - mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, theProteinView); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); assertEquals(0, mappedGroup.getStartRes()); assertEquals(4, mappedGroup.getEndRes()); } @@ -1330,20 +1336,20 @@ public class MappingUtilsTest assertEquals(1, ranges.size()); assertEquals(9, ranges.get(0)[1]); } - + @Test(groups = "Functional") public void testListToArray() { List ranges = new ArrayList<>(); - + int[] result = MappingUtils.listToArray(ranges); assertEquals(result.length, 0); - ranges.add(new int[] {24, 12}); + ranges.add(new int[] { 24, 12 }); result = MappingUtils.listToArray(ranges); assertEquals(result.length, 2); assertEquals(result[0], 24); assertEquals(result[1], 12); - ranges.add(new int[] {-7, 30}); + ranges.add(new int[] { -7, 30 }); result = MappingUtils.listToArray(ranges); assertEquals(result.length, 4); assertEquals(result[0], 24); @@ -1364,7 +1370,9 @@ public class MappingUtilsTest * Test mapping a sequence group where sequences in and outside the group * share a dataset sequence (e.g. alternative CDS for the same gene) *

- * This scenario doesn't arise after JAL-3763 changes, but test left as still valid + * This scenario doesn't arise after JAL-3763 changes, but test left as still + * valid + * * @throws IOException */ @Test(groups = { "Functional" }) @@ -1465,17 +1473,100 @@ public class MappingUtilsTest public void testFindOverlap() { List ranges = new ArrayList<>(); - ranges.add(new int[] {4, 8}); - ranges.add(new int[] {10, 12}); - ranges.add(new int[] {16, 19}); - - int[] overlap = MappingUtils.findOverlap(ranges, 5, 13); - assertArrayEquals(overlap, new int[] {5, 12}); + ranges.add(new int[] { 4, 8 }); + ranges.add(new int[] { 10, 12 }); + ranges.add(new int[] { 16, 19 }); + + int[] overlap = MappingUtils.findOverlap(ranges, 5, 13); + assertArrayEquals(overlap, new int[] { 5, 12 }); overlap = MappingUtils.findOverlap(ranges, -100, 100); - assertArrayEquals(overlap, new int[] {4, 19}); + assertArrayEquals(overlap, new int[] { 4, 19 }); overlap = MappingUtils.findOverlap(ranges, 7, 17); - assertArrayEquals(overlap, new int[] {7, 17}); + assertArrayEquals(overlap, new int[] { 7, 17 }); overlap = MappingUtils.findOverlap(ranges, 13, 15); assertNull(overlap); } + + /** + * Test mapping a sequence group including a sequence which maps to more than + * one other sequence + * + * @throws IOException + */ + @Test(groups = { "Functional" }) + public void testMapSequenceGroup_oneToMany() throws IOException + { + /* + * Uniprot:FER2_ARATH has cross-refs to 10 EMBLCDS sequences; + * we'll just mimic 3 of them here (abbreviated) + * From EMBLCDS|BAE98526 [ [1, 444] ] 3:1 to [ [1, 148] ] FER2_ARATH + * From EMBLCDS|AAM91336 same + * From EMBLCDS|AAM13033 same + */ + String coding = "atggcttccactgctctctca"; + AlignmentI cds = loadAlignment(">BAE98526\n" + coding + "\n>AAM91336\n" + + coding + "\n>AAM13033\n" + coding + "\n", + FileFormat.Fasta); + cds.setDataset(null); + AlignmentI protein = loadAlignment(">FER2_ARATH\nMASTALS\n", + FileFormat.Fasta); + protein.setDataset(null); + AlignedCodonFrame acf = new AlignedCodonFrame(); + MapList map = new MapList(new int[] { 1, 21 }, new int[] { 1, 7 }, 3, 1); + for (int seq = 0; seq < 3; seq++) + { + acf.addMap(cds.getSequenceAt(seq).getDatasetSequence(), + protein.getSequenceAt(0).getDatasetSequence(), map); + } + List acfList = Arrays + .asList(new AlignedCodonFrame[] + { acf }); + + AlignViewportI theDnaView = new AlignViewport(cds); + AlignViewportI theProteinView = new AlignViewport(protein); + protein.setCodonFrames(acfList); + + /* + * Select FER2_ARATH in the protein + */ + SequenceGroup sg = new SequenceGroup(); + sg.setColourText(true); + sg.setIdColour(Color.GREEN); + sg.setOutlineColour(Color.LIGHT_GRAY); + sg.addSequence(protein.getSequenceAt(0), false); + sg.setEndRes(protein.getWidth() - 1); + + /* + * Verify the mapped sequence group in dna + */ + SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, + theProteinView, theDnaView); + assertTrue(mappedGroup.getColourText()); + assertSame(sg.getIdColour(), mappedGroup.getIdColour()); + assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); + assertEquals(3, mappedGroup.getSequences().size()); + assertSame(cds.getSequenceAt(0), mappedGroup.getSequences().get(0)); + assertSame(cds.getSequenceAt(1), mappedGroup.getSequences().get(1)); + assertSame(cds.getSequenceAt(2), mappedGroup.getSequences().get(2)); + assertEquals(0, mappedGroup.getStartRes()); + assertEquals(20, mappedGroup.getEndRes()); // 21 columns (7 codons) + + /* + * Select 2 CDS, verify peptide is mapped + */ + sg.clear(); + sg.addSequence(cds.getSequenceAt(1), false); + sg.addSequence(cds.getSequenceAt(0), false); + sg.setStartRes(0); + sg.setEndRes(20); + mappedGroup = MappingUtils.mapSequenceGroup(sg, theDnaView, + theProteinView); + assertTrue(mappedGroup.getColourText()); + assertSame(sg.getIdColour(), mappedGroup.getIdColour()); + assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); + assertEquals(1, mappedGroup.getSequences().size()); + assertSame(protein.getSequenceAt(0), mappedGroup.getSequences().get(0)); + assertEquals(0, mappedGroup.getStartRes()); + assertEquals(6, mappedGroup.getEndRes()); + } }