}
/**
- * Test percentage identity calculation for two sequences.
+ * Test the percentage identity calculation for two sequences
*/
@Test(groups = { "Functional" })
- public void testPID_matchGaps()
+ public void testPID()
{
String seq1 = "ABCDEF";
String seq2 = "abcdef";
seq2 = "abcdefghijklmnopqrstuvwxyz";
assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);
- seq2 = "a---bcdef";
+ // 5 identical, 2 gap-gap, 2 gap-residue, 1 mismatch
+ seq1 = "a--b-cdefh";
+ seq2 = "a---bcdefg";
+ int length = seq1.length();
+
+ // match gap-residue, match gap-gap: 9/10 identical
+ assertEquals(90f, Comparison.PID(seq1, seq2, 0, length, true, false),
+ 0.001f);
+ // overloaded version of the method signature above:
+ assertEquals(90f, Comparison.PID(seq1, seq2), 0.001f);
+
+ // don't match gap-residue, match gap-gap: 7/10 identical
+ assertEquals(70f,
+ Comparison.PID(seq1, seq2, 0, seq1.length(), false, false),
+ 0.001f);
+
+ // match gap-residue, match gap-gap: 7/8 identical
+ assertEquals(87.5f,
+ Comparison.PID(seq1, seq2, 0, seq1.length(), true, true),
+ 0.001f);
+
+ // don't match gap-residue with 'ungapped only' - same as above
+ assertEquals(87.5f,
+ Comparison.PID(seq1, seq2, 0, seq1.length(), false, true),
+ 0.001f);
}
}