From: gmungoc Date: Tue, 6 Sep 2016 13:46:45 +0000 (+0100) Subject: JAL-2147 additional test coverage for findMappingsForSequenceAndOthers X-Git-Tag: Release_2_10_0~47^2~4^2~10 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ef72c714cc7edbc26c4518e0c84a15b110bc6e3d;p=jalview.git JAL-2147 additional test coverage for findMappingsForSequenceAndOthers --- diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 515ff51..da83338 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -757,9 +757,19 @@ public final class MappingUtils return findMappingsForSequenceAndOthers(sequence, mappings, null); } + /** + * Returns a list of any mappings that are from or to the given (aligned or + * dataset) sequence, optionally limited to mappings involving one of a given + * list of sequences. + * + * @param sequence + * @param mappings + * @param filterList + * @return + */ public static List findMappingsForSequenceAndOthers( SequenceI sequence, List mappings, - AlignmentI alignment) + List filterList) { List result = new ArrayList(); if (sequence == null || mappings == null) @@ -770,14 +780,14 @@ public final class MappingUtils { if (mapping.involvesSequence(sequence)) { - if (alignment != null) + if (filterList != null) { - for (SequenceI otherseq : alignment.getSequences()) + for (SequenceI otherseq : filterList) { + SequenceI otherDataset = otherseq.getDatasetSequence(); if (otherseq == sequence - || (otherseq.getDatasetSequence() != null && (otherseq - .getDatasetSequence() == sequence || otherseq - .getDatasetSequence() == sequence + || otherseq == sequence.getDatasetSequence() + || (otherDataset != null && (otherDataset == sequence || otherDataset == sequence .getDatasetSequence()))) { // skip sequences in subset which directly relate to sequence diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 19ebf45..a954a83 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -2730,7 +2730,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } seqMappings = MappingUtils .findMappingsForSequenceAndOthers(sequence, mappings, - getCodingComplement().getAlignment()); + getCodingComplement().getAlignment().getSequences()); if (!seqMappings.isEmpty()) { break; diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 7e28579..d131ed2 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -708,7 +708,7 @@ public class MappingUtilsTest * subselect the mapping search */ @Test(groups = { "Functional" }) - public void testFindMappingsBetweenSequenceAndOthers() + public void testFindMappingsForSequenceAndOthers() { SequenceI seq1 = new Sequence("Seq1", "ABC"); SequenceI seq2 = new Sequence("Seq2", "ABC"); @@ -720,7 +720,7 @@ public class MappingUtilsTest seq4.createDatasetSequence(); /* - * Create mappings from seq1 to seq2, seq2 to seq1, seq3 to seq1 + * Create mappings from seq1 to seq2, seq2 to seq1, seq3 to seq1, seq3 to seq4 */ AlignedCodonFrame acf1 = new AlignedCodonFrame(); MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1); @@ -729,23 +729,54 @@ public class MappingUtilsTest acf2.addMap(seq2.getDatasetSequence(), seq1.getDatasetSequence(), map); AlignedCodonFrame acf3 = new AlignedCodonFrame(); acf3.addMap(seq3.getDatasetSequence(), seq1.getDatasetSequence(), map); + AlignedCodonFrame acf4 = new AlignedCodonFrame(); + acf4.addMap(seq3.getDatasetSequence(), seq4.getDatasetSequence(), map); List mappings = new ArrayList(); mappings.add(acf1); mappings.add(acf2); mappings.add(acf3); + mappings.add(acf4); /* - * Seq1 has three mappings + * test for null args */ List result = MappingUtils - .findMappingsForSequenceAndOthers(seq1, mappings, - new Alignment(new SequenceI[] { seq1, seq2 })); + .findMappingsForSequenceAndOthers(null, mappings, + Arrays.asList(new SequenceI[] { seq1, seq2 })); + assertTrue(result.isEmpty()); + + result = MappingUtils.findMappingsForSequenceAndOthers(seq1, null, + Arrays.asList(new SequenceI[] { seq1, seq2 })); + assertTrue(result.isEmpty()); + + /* + * Seq1 has three mappings, but filter argument will only accept + * those to seq2 + */ + result = MappingUtils.findMappingsForSequenceAndOthers( + seq1, + mappings, + Arrays.asList(new SequenceI[] { seq1, seq2, + seq1.getDatasetSequence() })); + assertEquals(2, result.size()); assertTrue(result.contains(acf1)); assertTrue(result.contains(acf2)); assertFalse("Did not expect to find mapping acf3 - subselect failed", result.contains(acf3)); - assertEquals(2, result.size()); + assertFalse( + "Did not expect to find mapping acf4 - doesn't involve sequence", + result.contains(acf4)); + + /* + * and verify the no filter case + */ + result = MappingUtils.findMappingsForSequenceAndOthers(seq1, mappings, + null); + assertEquals(3, result.size()); + assertTrue(result.contains(acf1)); + assertTrue(result.contains(acf2)); + assertTrue(result.contains(acf3)); } @Test(groups = { "Functional" })