3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
7 import jalview.datamodel.Sequence;
8 import jalview.datamodel.SequenceI;
10 import org.testng.annotations.Test;
12 public class ComparisonTest
15 @Test(groups ={ "Functional" })
16 public void testIsGap()
18 assertTrue(Comparison.isGap('-'));
19 assertTrue(Comparison.isGap('.'));
20 assertTrue(Comparison.isGap(' '));
21 assertFalse(Comparison.isGap('X'));
22 assertFalse(Comparison.isGap('x'));
23 assertFalse(Comparison.isGap('*'));
24 assertFalse(Comparison.isGap('G'));
28 * Test for isNucleotide is that sequences in a dataset are more than 85%
29 * AGCTU. Test is not case-sensitive and ignores gaps.
31 @Test(groups ={ "Functional" })
32 public void testIsNucleotide() {
33 SequenceI seq = new Sequence("eightypercent", "agctuAGCPV");
34 assertFalse(Comparison.isNucleotide(new SequenceI[]
36 assertFalse(Comparison.isNucleotide(new SequenceI[][]
40 seq = new Sequence("eightyfivepercent", "agctuAGCPVagctuAGCUV");
41 assertFalse(Comparison.isNucleotide(new SequenceI[]
44 seq = new Sequence("nineypercent", "agctuAGCgVagctuAGCUV");
45 assertTrue(Comparison.isNucleotide(new SequenceI[]
48 seq = new Sequence("eightyfivepercentgapped",
49 "--agc--tuA--GCPV-a---gct-uA-GC---UV");
50 assertFalse(Comparison.isNucleotide(new SequenceI[]
53 seq = new Sequence("nineypercentgapped",
54 "ag--ct-u-A---GC---g----Vag--c---tuAGCUV");
55 assertTrue(Comparison.isNucleotide(new SequenceI[]
58 seq = new Sequence("allgap", "---------");
59 assertFalse(Comparison.isNucleotide(new SequenceI[]
62 seq = new Sequence("DNA", "ACTugGCCAG");
63 SequenceI seq2 = new Sequence("Protein", "FLIMVSPTYW");
67 assertTrue(Comparison.isNucleotide(new SequenceI[]
68 { seq, seq, seq, seq, seq, seq, seq, seq, seq, seq2 }));
69 assertTrue(Comparison.isNucleotide(new SequenceI[][]
71 { seq }, new SequenceI[]
72 { seq, seq, seq }, new SequenceI[]
73 { seq, seq, seq, seq, seq, seq2 } }));
77 assertFalse(Comparison.isNucleotide(new SequenceI[]
78 { seq, seq, seq, seq, seq, seq, seq, seq, seq2, seq2 }));
79 assertFalse(Comparison.isNucleotide(new SequenceI[][]
81 { seq }, new SequenceI[]
82 { seq, seq, seq }, new SequenceI[]
83 { seq, seq, seq, seq, seq2, seq2, null } }));
85 seq = new Sequence("ProteinThatLooksLikeDNA", "WYATGCCTGAgtcgt");
87 assertTrue(Comparison.isNucleotide(new SequenceI[]
90 assertFalse(Comparison.isNucleotide((SequenceI[]) null));
91 assertFalse(Comparison.isNucleotide((SequenceI[][]) null));
95 * Test percentage identity calculation for two sequences.
97 @Test(groups ={ "Functional" })
98 public void testPID_matchGaps()
100 String seq1 = "ABCDEF";
101 String seq2 = "abcdef";
102 assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);
104 // comparison range defaults to length of first sequence
105 seq2 = "abcdefghijklmnopqrstuvwxyz";
106 assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);