From: Jim Procter Date: Thu, 14 Jul 2016 13:49:35 +0000 (+0100) Subject: JAL-2147 findMappingsBetweenSequenceAndOthers for scoping search to sequences in... X-Git-Tag: Release_2_10_0~140^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=81dc9ebd9bd93355897a9c5c87733c0bdb3e5f3b;p=jalview.git JAL-2147 findMappingsBetweenSequenceAndOthers for scoping search to sequences in an alignment --- diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index ae4e55d..515ff51 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -754,6 +754,13 @@ public final class MappingUtils public static List findMappingsForSequence( SequenceI sequence, List mappings) { + return findMappingsForSequenceAndOthers(sequence, mappings, null); + } + + public static List findMappingsForSequenceAndOthers( + SequenceI sequence, List mappings, + AlignmentI alignment) + { List result = new ArrayList(); if (sequence == null || mappings == null) { @@ -763,7 +770,31 @@ public final class MappingUtils { if (mapping.involvesSequence(sequence)) { - result.add(mapping); + if (alignment != null) + { + for (SequenceI otherseq : alignment.getSequences()) + { + if (otherseq == sequence + || (otherseq.getDatasetSequence() != null && (otherseq + .getDatasetSequence() == sequence || otherseq + .getDatasetSequence() == sequence + .getDatasetSequence()))) + { + // skip sequences in subset which directly relate to sequence + continue; + } + if (mapping.involvesSequence(otherseq)) + { + // selected a mapping contained in subselect alignment + result.add(mapping); + break; + } + } + } + else + { + result.add(mapping); + } } } return result; diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index 3c417c3..7e28579 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -703,6 +703,51 @@ public class MappingUtilsTest assertEquals(0, result.size()); } + /** + * just like the one above, but this time, we provide a set of sequences to + * subselect the mapping search + */ + @Test(groups = { "Functional" }) + public void testFindMappingsBetweenSequenceAndOthers() + { + SequenceI seq1 = new Sequence("Seq1", "ABC"); + SequenceI seq2 = new Sequence("Seq2", "ABC"); + SequenceI seq3 = new Sequence("Seq3", "ABC"); + SequenceI seq4 = new Sequence("Seq4", "ABC"); + seq1.createDatasetSequence(); + seq2.createDatasetSequence(); + seq3.createDatasetSequence(); + seq4.createDatasetSequence(); + + /* + * Create mappings from seq1 to seq2, seq2 to seq1, seq3 to seq1 + */ + AlignedCodonFrame acf1 = new AlignedCodonFrame(); + MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1); + acf1.addMap(seq1.getDatasetSequence(), seq2.getDatasetSequence(), map); + AlignedCodonFrame acf2 = new AlignedCodonFrame(); + acf2.addMap(seq2.getDatasetSequence(), seq1.getDatasetSequence(), map); + AlignedCodonFrame acf3 = new AlignedCodonFrame(); + acf3.addMap(seq3.getDatasetSequence(), seq1.getDatasetSequence(), map); + + List mappings = new ArrayList(); + mappings.add(acf1); + mappings.add(acf2); + mappings.add(acf3); + + /* + * Seq1 has three mappings + */ + List result = MappingUtils + .findMappingsForSequenceAndOthers(seq1, mappings, + new Alignment(new SequenceI[] { seq1, seq2 })); + 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()); + } + @Test(groups = { "Functional" }) public void testMapEditCommand() {