+ /**
+ * Test generation of consensus annotation with options 'include gaps'
+ * (profile percentages are of all sequences, whether gapped or not), and
+ * 'show logo' (the full profile with all residue percentages is reported in
+ * the description for the tooltip)
+ */
+ @Test(groups = { "Functional" })
+ public void testCompleteConsensus_includeGaps_showLogo()
+ {
+ /*
+ * first compute the profiles
+ */
+ SequenceI seq1 = new Sequence("Seq1", "CAG-T");
+ SequenceI seq2 = new Sequence("Seq2", "CAC-T");
+ SequenceI seq3 = new Sequence("Seq3", "C---G");
+ SequenceI seq4 = new Sequence("Seq4", "CA--t");
+ SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
+ int width = seq1.getLength();
+ ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
+
+ AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
+ "PID", new Annotation[width]);
+ AAFrequency.completeConsensus(consensus, profiles, 0, 5, false, true,
+ 4);
+
+ Annotation ann = consensus.annotations[0];
+ assertEquals("C 100%", ann.description);
+ assertEquals("C", ann.displayCharacter);
+ ann = consensus.annotations[1];
+ assertEquals("A 75%", ann.description);
+ assertEquals("A", ann.displayCharacter);
+ ann = consensus.annotations[2];
+ assertEquals("C 25%; G 25%", ann.description);
+ assertEquals("+", ann.displayCharacter);
+ ann = consensus.annotations[3];
+ assertEquals("", ann.description);
+ assertEquals("-", ann.displayCharacter);
+ ann = consensus.annotations[4];
+ assertEquals("T 75%; G 25%", ann.description);
+ assertEquals("T", ann.displayCharacter);
+ }
+
+ /**
+ * Test generation of consensus annotation with options 'ignore gaps' (profile
+ * percentages are of the non-gapped sequences) and 'no logo' (only the modal
+ * residue[s] percentage is reported in the description for the tooltip)
+ */
+ @Test(groups = { "Functional" })
+ public void testCompleteConsensus_ignoreGaps_noLogo()
+ {
+ /*
+ * first compute the profiles
+ */
+ SequenceI seq1 = new Sequence("Seq1", "CAG-T");
+ SequenceI seq2 = new Sequence("Seq2", "CAC-T");
+ SequenceI seq3 = new Sequence("Seq3", "C---G");
+ SequenceI seq4 = new Sequence("Seq4", "CA--t");
+ SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
+ int width = seq1.getLength();
+ ProfilesI profiles = AAFrequency.calculate(seqs, width, 0, width, true);
+
+ AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
+ "PID", new Annotation[width]);
+ AAFrequency.completeConsensus(consensus, profiles, 0, 5, true, false,
+ 4);
+
+ Annotation ann = consensus.annotations[0];
+ assertEquals("C 100%", ann.description);
+ assertEquals("C", ann.displayCharacter);
+ ann = consensus.annotations[1];
+ assertEquals("A 100%", ann.description);
+ assertEquals("A", ann.displayCharacter);
+ ann = consensus.annotations[2];
+ assertEquals("[CG] 50%", ann.description);
+ assertEquals("+", ann.displayCharacter);
+ ann = consensus.annotations[3];
+ assertEquals("", ann.description);
+ assertEquals("-", ann.displayCharacter);
+ ann = consensus.annotations[4];
+ assertEquals("T 75%", ann.description);
+ assertEquals("T", ann.displayCharacter);
+ }
+
+ /**
+ * Test to include rounding down of a non-zero count to 0% (JAL-3202)
+ */
+ @Test(groups = { "Functional" })
+ public void testExtractProfile()
+ {
+ /*
+ * 200 sequences of which 30 gapped (170 ungapped)
+ * max count 70 for modal residue 'G'
+ */
+ ProfileI profile = new Profile(200, 30, 70, "G");
+ ResidueCount counts = new ResidueCount();
+ counts.put('G', 70);
+ counts.put('R', 60);
+ counts.put('L', 38);
+ counts.put('H', 2);
+ profile.setCounts(counts);
+
+ /*
+ * [0, noOfValues, totalPercent, char1, count1, ...]
+ * G: 70/170 = 41.2 = 41
+ * R: 60/170 = 35.3 = 35
+ * L: 38/170 = 22.3 = 22
+ * H: 2/170 = 1
+ * total (rounded) percentages = 99
+ */
+ int[] extracted = AAFrequency.extractProfile(profile, true);
+ int[] expected = new int[] { 0, 4, 99, 'G', 41, 'R', 35, 'L', 22, 'H',
+ 1 };
+ org.testng.Assert.assertEquals(extracted, expected);
+
+ /*
+ * add some counts of 1; these round down to 0% and should be discarded
+ */
+ counts.put('G', 68); // 68/170 = 40% exactly (percentages now total 98)
+ counts.put('Q', 1);
+ counts.put('K', 1);
+ extracted = AAFrequency.extractProfile(profile, true);
+ expected = new int[] { 0, 4, 98, 'G', 40, 'R', 35, 'L', 22, 'H', 1 };
+ org.testng.Assert.assertEquals(extracted, expected);
+
+ }
+
+ /**
+ * Tests for the profile calculation where gaps are included i.e. the
+ * denominator is the total number of sequences in the column
+ */