X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FComparisonTest.java;h=9aab66c93a4550d0ced4cf72cb05e4ed5a0b2ff4;hb=refs%2Fheads%2Freleases%2FRelease_2_10_0_Branch;hp=c52d52487c16620eec2caa3190f99209a27351a7;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/test/jalview/util/ComparisonTest.java b/test/jalview/util/ComparisonTest.java index c52d524..9aab66c 100644 --- a/test/jalview/util/ComparisonTest.java +++ b/test/jalview/util/ComparisonTest.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -49,7 +49,7 @@ public class ComparisonTest * AGCTU. Test is not case-sensitive and ignores gaps. */ @Test(groups = { "Functional" }) - public void testIsNucleotide() + public void testIsNucleotide_sequences() { SequenceI seq = new Sequence("eightypercent", "agctuAGCPV"); assertFalse(Comparison.isNucleotide(new SequenceI[] { seq })); @@ -101,10 +101,10 @@ public class ComparisonTest } /** - * 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_includingGaps() { String seq1 = "ABCDEF"; String seq2 = "abcdef"; @@ -114,6 +114,78 @@ public class ComparisonTest 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, length, false, false), + 0.001f); + } + + @Test(groups = { "Functional" }) + public void testIsNucleotide() + { + assertTrue(Comparison.isNucleotide('a')); + assertTrue(Comparison.isNucleotide('A')); + assertTrue(Comparison.isNucleotide('c')); + assertTrue(Comparison.isNucleotide('C')); + assertTrue(Comparison.isNucleotide('g')); + assertTrue(Comparison.isNucleotide('G')); + assertTrue(Comparison.isNucleotide('t')); + assertTrue(Comparison.isNucleotide('T')); + assertTrue(Comparison.isNucleotide('u')); + assertTrue(Comparison.isNucleotide('U')); + assertFalse(Comparison.isNucleotide('-')); + assertFalse(Comparison.isNucleotide('P')); + } + + /** + * Test the percentage identity calculation for two sequences + */ + @Test(groups = { "Functional" }) + public void testPID_ungappedOnly() + { + // 5 identical, 2 gap-gap, 2 gap-residue, 1 mismatch + String seq1 = "a--b-cdefh"; + String seq2 = "a---bcdefg"; + int length = seq1.length(); + + /* + * As currently coded, 'ungappedOnly' ignores gap-residue but counts + * gap-gap. Is this a bug - should gap-gap also be ignored, giving a PID of + * 5/6? + * + * Note also there is no variant of the calculation that penalises + * gap-residue i.e. counts it as a mismatch. This would give a score of 5/8 + * (if we ignore gap-gap) or 5/10 (if we count gap-gap as a match). + */ + // match gap-residue, match gap-gap: 7/8 identical + assertEquals(87.5f, Comparison.PID(seq1, seq2, 0, length, true, true), + 0.001f); + + // don't match gap-residue with 'ungapped only' - same as above + assertEquals(87.5f, Comparison.PID(seq1, seq2, 0, length, false, true), + 0.001f); + } + + @Test(groups = { "Functional" }) + public void testIsNucleotideSequence() + { + assertFalse(Comparison.isNucleotideSequence(null, true)); + assertTrue(Comparison.isNucleotideSequence("", true)); + assertTrue(Comparison.isNucleotideSequence("aAgGcCtTuU", true)); + assertTrue(Comparison.isNucleotideSequence("aAgGcCtTuU", false)); + assertFalse(Comparison.isNucleotideSequence("xAgGcCtTuU", false)); + assertFalse(Comparison.isNucleotideSequence("aAgGcCtTuUx", false)); + assertTrue(Comparison.isNucleotideSequence("a A-g.GcCtTuU", true)); + assertFalse(Comparison.isNucleotideSequence("a A-g.GcCtTuU", false)); } }