Merge branch 'develop' into features/filetypeEnum
[jalview.git] / test / jalview / util / MappingUtilsTest.java
index 492cbb6..6ba69b0 100644 (file)
@@ -706,6 +706,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<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
+    mappings.add(acf1);
+    mappings.add(acf2);
+    mappings.add(acf3);
+
+    /*
+     * Seq1 has three mappings
+     */
+    List<AlignedCodonFrame> 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()
   {