From: gmungoc Date: Tue, 25 Oct 2016 15:21:17 +0000 (+0100) Subject: JAL-98 minor fixes to / tests for annotation derivation X-Git-Tag: Release_2_10_1^2~22^2~3^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d94db336381e48d9155736ca4ea058d9f747439c;p=jalview.git JAL-98 minor fixes to / tests for annotation derivation --- diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 569b036..61e11c4 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -47,18 +47,8 @@ import java.util.List; */ public class AAFrequency { - public static final String MAXCOUNT = "C"; - - public static final String MAXRESIDUE = "R"; - - public static final String PID_GAPS = "G"; - - public static final String PID_NOGAPS = "N"; - public static final String PROFILE = "P"; - public static final String ENCODED_CHARS = "E"; - /* * Quick look-up of String value of char 'A' to 'Z' */ @@ -275,7 +265,16 @@ public class AAFrequency String description = getTooltip(profile, value, showSequenceLogo, ignoreGaps, dp); - consensus.annotations[i] = new Annotation(profile.getModalResidue(), + String modalResidue = profile.getModalResidue(); + if ("".equals(modalResidue)) + { + modalResidue = "-"; + } + else if (modalResidue.length() > 1) + { + modalResidue = "+"; + } + consensus.annotations[i] = new Annotation(modalResidue, description, ' ', value); } // long elapsed = System.currentTimeMillis() - now; @@ -318,15 +317,18 @@ public class AAFrequency String maxRes = profile.getModalResidue(); if (maxRes.length() > 1) { - sb.append("[").append(maxRes).append("] "); - maxRes = "+"; + sb.append("[").append(maxRes).append("]"); } else { - sb.append(maxRes).append(" "); + sb.append(maxRes); + } + if (maxRes.length() > 0) + { + sb.append(" "); + Format.appendPercentage(sb, pid, dp); + sb.append("%"); } - Format.appendPercentage(sb, pid, dp); - sb.append("%"); description = sb.toString(); } return description; diff --git a/test/jalview/analysis/AAFrequencyTest.java b/test/jalview/analysis/AAFrequencyTest.java index ecddad1..0ddbddc 100644 --- a/test/jalview/analysis/AAFrequencyTest.java +++ b/test/jalview/analysis/AAFrequencyTest.java @@ -23,6 +23,8 @@ package jalview.analysis; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.Annotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; @@ -30,23 +32,13 @@ import org.testng.annotations.Test; public class AAFrequencyTest { - private static final String C = AAFrequency.MAXCOUNT; - - private static final String R = AAFrequency.MAXRESIDUE; - - private static final String G = AAFrequency.PID_GAPS; - - private static final String N = AAFrequency.PID_NOGAPS; - - private static final String P = AAFrequency.PROFILE; - @Test(groups = { "Functional" }) public void testCalculate_noProfile() { - SequenceI seq1 = new Sequence("Seq1", "CAGT"); - SequenceI seq2 = new Sequence("Seq2", "CACT"); - SequenceI seq3 = new Sequence("Seq3", "C--G"); - SequenceI seq4 = new Sequence("Seq4", "CA-t"); + 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 }; Profile[] result = new Profile[seq1.getLength()]; @@ -74,8 +66,15 @@ public class AAFrequencyTest assertEquals(1, col.getMaxCount()); assertEquals("CG", col.getModalResidue()); - // col 3 is 75% T 25% G + // col 3 is all gaps col = result[3]; + assertEquals(0f, col.getPercentageIdentity(false)); + assertEquals(0f, col.getPercentageIdentity(true)); + assertEquals(0, col.getMaxCount()); + assertEquals("", col.getModalResidue()); + + // col 4 is 75% T 25% G + col = result[4]; assertEquals(75f, col.getPercentageIdentity(false)); assertEquals(75f, col.getPercentageIdentity(true)); assertEquals(3, col.getMaxCount()); @@ -116,7 +115,7 @@ public class AAFrequencyTest assertEquals(4, profile.getNonGapped()); } - @Test(groups = { "Functional" }) + @Test(groups = { "Functional" }, enabled = false) public void testCalculate_withProfileTiming() { SequenceI seq1 = new Sequence("Seq1", "CAGT"); @@ -136,4 +135,87 @@ public class AAFrequencyTest } System.out.println(System.currentTimeMillis() - start); } + + /** + * 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 }; + Profile[] profiles = new Profile[seq1.getLength()]; + AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true); + + AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus", + "PID", new Annotation[seq1.getLength()]); + 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 }; + Profile[] profiles = new Profile[seq1.getLength()]; + AAFrequency.calculate(seqs, 0, seq1.getLength(), profiles, true); + + AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus", + "PID", new Annotation[seq1.getLength()]); + 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); + } }