From: Jim Procter Date: Wed, 26 Jan 2022 19:36:23 +0000 (+0000) Subject: Merge branch 'task/JAL-3763_newDatasetForCds' into merge/develop_task/JAL-3763_newDat... X-Git-Tag: Release_2_11_2_0~15^2~1^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=27aed96d1aeae689818bd0a0028553186e3c3839;p=jalview.git Merge branch 'task/JAL-3763_newDatasetForCds' into merge/develop_task/JAL-3763_newDatasetForCds Conflicts: src/jalview/analysis/AlignmentUtils.java src/jalview/util/MapList.java test/jalview/util/MapListTest.java test/jalview/util/MappingUtilsTest.java --- 27aed96d1aeae689818bd0a0028553186e3c3839 diff --cc src/jalview/analysis/AlignmentUtils.java index 23c5d64,9a63eb1..f95ff73 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@@ -20,8 -20,23 +20,25 @@@ */ package jalview.analysis; +import java.util.Locale; + + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Collection; + import java.util.Collections; + import java.util.HashMap; + import java.util.HashSet; + import java.util.Iterator; + import java.util.LinkedHashMap; + import java.util.List; + import java.util.Map; + import java.util.Map.Entry; + import java.util.NoSuchElementException; + import java.util.Set; + import java.util.SortedMap; + import java.util.TreeMap; + + import jalview.bin.Cache; import jalview.commands.RemoveGapColCommand; import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; diff --cc src/jalview/util/MappingUtils.java index 4e07a08,1e8c8d7..c8b5190 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@@ -20,15 -20,9 +20,16 @@@ */ package jalview.util; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import jalview.analysis.AlignmentSorter; import jalview.api.AlignViewportI; + import jalview.bin.Cache; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; diff --cc test/jalview/util/MapListTest.java index cf10aba,71fbdfd..3f1f7f3 --- a/test/jalview/util/MapListTest.java +++ b/test/jalview/util/MapListTest.java @@@ -831,7 -783,7 +831,8 @@@ public class MapListTes // 'subsumed' ranges are preserved ranges.clear(); ranges.add(new int[] { 10, 30 }); - ranges.add(new int[] { 15, 25 }); + ranges.add(new int[] { 15, 25 }); ++ merged = MapList.coalesceRanges(ranges); assertEquals(2, merged.size()); assertArrayEquals(new int[] { 10, 30 }, merged.get(0)); diff --cc test/jalview/util/MappingUtilsTest.java index 3418f3c,f149cf9..bd81d30 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@@ -24,18 -24,17 +24,28 @@@ import static org.testng.AssertJUnit.as import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import static org.testng.AssertJUnit.fail; + +import java.awt.Color; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + import java.awt.Color; + import java.io.IOException; + import java.util.ArrayList; + import java.util.Arrays; + import java.util.Iterator; + import java.util.List; + + import org.testng.annotations.BeforeClass; + import org.testng.annotations.Test; + import jalview.api.AlignViewportI; import jalview.bin.Cache; import jalview.commands.EditCommand; @@@ -1328,32 -1329,104 +1339,133 @@@ public class MappingUtilsTes assertEquals(9, ranges.get(0)[1]); } + @Test(groups = "Functional") + public void testListToArray() + { + List ranges = new ArrayList<>(); + + int[] result = MappingUtils.rangeListToArray(ranges); + assertEquals(result.length, 0); + ranges.add(new int[] { 24, 12 }); + result = MappingUtils.rangeListToArray(ranges); + assertEquals(result.length, 2); + assertEquals(result[0], 24); + assertEquals(result[1], 12); + ranges.add(new int[] { -7, 30 }); + result = MappingUtils.rangeListToArray(ranges); + assertEquals(result.length, 4); + assertEquals(result[0], 24); + assertEquals(result[1], 12); + assertEquals(result[2], -7); + assertEquals(result[3], 30); + try + { + MappingUtils.rangeListToArray(null); + fail("Expected exception"); + } catch (NullPointerException e) + { + // expected + } + } ++ + /** + * 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 + * @throws IOException + */ + @Test(groups = { "Functional" }) + public void testMapSequenceGroup_sharedDataset() throws IOException + { + /* + * Set up dna and protein Seq1/2/3 with mappings (held on the protein + * viewport). CDS sequences share the same 'gene' dataset sequence. + */ + SequenceI dna = new Sequence("dna", "aaatttgggcccaaatttgggccc"); + SequenceI cds1 = new Sequence("cds1/1-6", "aaattt"); + SequenceI cds2 = new Sequence("cds1/4-9", "tttggg"); + SequenceI cds3 = new Sequence("cds1/19-24", "gggccc"); + + cds1.setDatasetSequence(dna); + cds2.setDatasetSequence(dna); + cds3.setDatasetSequence(dna); + + SequenceI pep1 = new Sequence("pep1", "KF"); + SequenceI pep2 = new Sequence("pep2", "FG"); + SequenceI pep3 = new Sequence("pep3", "GP"); + pep1.createDatasetSequence(); + pep2.createDatasetSequence(); + pep3.createDatasetSequence(); + + /* + * add mappings from coding positions of dna to respective peptides + */ + AlignedCodonFrame acf = new AlignedCodonFrame(); + acf.addMap(dna, pep1, + new MapList(new int[] + { 1, 6 }, new int[] { 1, 2 }, 3, 1)); + acf.addMap(dna, pep2, + new MapList(new int[] + { 4, 9 }, new int[] { 1, 2 }, 3, 1)); + acf.addMap(dna, pep3, + new MapList(new int[] + { 19, 24 }, new int[] { 1, 2 }, 3, 1)); + + List acfList = Arrays + .asList(new AlignedCodonFrame[] + { acf }); + + AlignmentI cdna = new Alignment(new SequenceI[] { cds1, cds2, cds3 }); + AlignmentI protein = new Alignment( + new SequenceI[] + { pep1, pep2, pep3 }); + AlignViewportI cdnaView = new AlignViewport(cdna); + AlignViewportI peptideView = new AlignViewport(protein); + protein.setCodonFrames(acfList); + + /* + * Select pep1 and pep3 in the protein alignment + */ + SequenceGroup sg = new SequenceGroup(); + sg.setColourText(true); + sg.setIdColour(Color.GREEN); + sg.setOutlineColour(Color.LIGHT_GRAY); + sg.addSequence(pep1, false); + sg.addSequence(pep3, false); + sg.setEndRes(protein.getWidth() - 1); + + /* + * Verify the mapped sequence group in dna is cds1 and cds3 + */ + SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, + peptideView, cdnaView); + assertTrue(mappedGroup.getColourText()); + assertSame(sg.getIdColour(), mappedGroup.getIdColour()); + assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); + assertEquals(2, mappedGroup.getSequences().size()); + assertSame(cds1, mappedGroup.getSequences().get(0)); + assertSame(cds3, mappedGroup.getSequences().get(1)); + // columns 1-6 selected (0-5 base zero) + assertEquals(0, mappedGroup.getStartRes()); + assertEquals(5, mappedGroup.getEndRes()); + + /* + * Select mapping sequence group from dna to protein + */ + sg.clear(); + sg.addSequence(cds2, false); + sg.addSequence(cds1, false); + sg.setStartRes(0); + sg.setEndRes(cdna.getWidth() - 1); + mappedGroup = MappingUtils.mapSequenceGroup(sg, cdnaView, peptideView); + assertTrue(mappedGroup.getColourText()); + assertSame(sg.getIdColour(), mappedGroup.getIdColour()); + assertSame(sg.getOutlineColour(), mappedGroup.getOutlineColour()); + assertEquals(2, mappedGroup.getSequences().size()); + assertSame(protein.getSequenceAt(1), mappedGroup.getSequences().get(0)); + assertSame(protein.getSequenceAt(0), mappedGroup.getSequences().get(1)); + assertEquals(0, mappedGroup.getStartRes()); + assertEquals(1, mappedGroup.getEndRes()); // two columns + } }