*/
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'
*/
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;
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;
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;
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()];
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());
assertEquals(4, profile.getNonGapped());
}
- @Test(groups = { "Functional" })
+ @Test(groups = { "Functional" }, enabled = false)
public void testCalculate_withProfileTiming()
{
SequenceI seq1 = new Sequence("Seq1", "CAGT");
}
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);
+ }
}