public static List<AlignedCodonFrame> findMappingsForSequence(
SequenceI sequence, List<AlignedCodonFrame> mappings)
{
+ return findMappingsForSequenceAndOthers(sequence, mappings, null);
+ }
+
+ public static List<AlignedCodonFrame> findMappingsForSequenceAndOthers(
+ SequenceI sequence, List<AlignedCodonFrame> mappings,
+ AlignmentI alignment)
+ {
List<AlignedCodonFrame> result = new ArrayList<AlignedCodonFrame>();
if (sequence == null || mappings == null)
{
{
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;
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()
{