import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
+import jalview.datamodel.HiddenMarkovModel;
import jalview.datamodel.Profile;
import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.ResidueCount;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
+import jalview.io.HMMFile;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.Hashtable;
public class AAFrequencyTest
{
+ HiddenMarkovModel hmm;
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
}
+ @BeforeClass(alwaysRun = true)
+ public void setUp() throws IOException, MalformedURLException
+ {
+ /*
+ * load a dna (ACGT) HMM file to a HiddenMarkovModel
+ */
+ HMMFile hmmFile = new HMMFile(new FileParse(
+ "test/jalview/io/test_MADE1_hmm.txt", DataSourceType.FILE));
+ hmm = hmmFile.getHMM();
+ }
+
@Test(groups = { "Functional" })
public void testCalculate_noProfile()
{
SequenceI seq4 = new Sequence("Seq4", "CA--t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
int width = seq1.getLength();
- ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
- false);
+ ProfilesI result = AAFrequency.calculate(seqs, width, 0, width, false);
// col 0 is 100% C
ProfileI col = result.get(0);
SequenceI seq4 = new Sequence("Seq4", "CA-t");
SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4 };
int width = seq1.getLength();
- ProfilesI result = AAFrequency.calculate(seqs, width, 0, width,
- true);
+ ProfilesI result = AAFrequency.calculate(seqs, width, 0, width, true);
ProfileI profile = result.get(0);
assertEquals(4, profile.getCounts().getCount('C'));
AlignmentAnnotation consensus = new AlignmentAnnotation("Consensus",
"PID", new Annotation[width]);
- AAFrequency
- .completeConsensus(consensus, profiles, 0, 5, false, true, 4);
+ AAFrequency.completeConsensus(consensus, profiles, 0, 5, false, true,
+ 4);
Annotation ann = consensus.annotations[0];
assertEquals("C 100%", ann.description);
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);
-
+ AAFrequency.completeConsensus(consensus, profiles, 0, 5, true, false,
+ 4);
+
Annotation ann = consensus.annotations[0];
assertEquals("C 100%", ann.description);
assertEquals("C", ann.displayCharacter);
counts.put('L', 38);
counts.put('H', 2);
profile.setCounts(counts);
-
+
/*
* [0, noOfValues, totalPercent, char1, count1, ...]
* G: 70/200 = 35%
*/
int[] extracted = AAFrequency.extractProfile(profile, false);
int[] expected = new int[] { AlignmentAnnotation.SEQUENCE_PROFILE, 4,
- 85, 'G', 35, 'R', 30, 'L', 19, 'H',
- 1 };
+ 85, 'G', 35, 'R', 30, 'L', 19, 'H', 1 };
org.testng.Assert.assertEquals(extracted, expected);
-
+
/*
* add some counts of 1; these round down to 0% and should be discarded
*/
expected = new int[] { AlignmentAnnotation.SEQUENCE_PROFILE, 4, 84, 'G',
34, 'R', 30, 'L', 19, 'H', 1 };
org.testng.Assert.assertEquals(extracted, expected);
-
+
}
@Test(groups = { "Functional" })
codonCounts[0] = 120;
codonCounts[1] = 110;
profile.put(AAFrequency.PROFILE, codonCounts);
-
+
/*
* [0, noOfValues, totalPercent, char1, count1, ...]
* codon1: 30/110 = 27.2 = 27%
* max count 70 for modal residue 'G'
*/
Hashtable profile = new Hashtable();
-
+
/*
* cdna profile is {seqCount, ungappedCount, codonCount1, ...codonCount64}
* where 1..64 positions correspond to encoded codons
codonCounts[0] = 120;
codonCounts[1] = 110;
profile.put(AAFrequency.PROFILE, codonCounts);
-
+
/*
* [0, noOfValues, totalPercent, char1, count1, ...]
* codon1: 30/120 = 25%
encoded2, 58, encoded1, 25, encoded3, 7 };
org.testng.Assert.assertEquals(extracted, expected);
}
+
+ @Test(groups = { "Functional" })
+ public void testExtractHMMProfile()
+ throws MalformedURLException, IOException
+ {
+ int[] expected = { 0, 4, 100, 'T', 71, 'C', 12, 'G', 9, 'A', 9 };
+ int[] actual = AAFrequency.extractHMMProfile(hmm, 17, false, false);
+ for (int i = 0; i < actual.length; i++)
+ {
+ if (i == 2)
+ {
+ assertEquals(actual[i], expected[i]);
+ }
+ else
+ {
+ assertEquals(actual[i], expected[i]);
+ }
+ }
+
+ int[] expected2 = { 0, 4, 100, 'A', 85, 'C', 0, 'G', 0, 'T', 0 };
+ int[] actual2 = AAFrequency.extractHMMProfile(hmm, 2, true, false);
+ for (int i = 0; i < actual2.length; i++)
+ {
+ if (i == 2)
+ {
+ assertEquals(actual[i], expected[i]);
+ }
+ else
+ {
+ assertEquals(actual[i], expected[i]);
+ }
+ }
+
+ assertNull(AAFrequency.extractHMMProfile(null, 98978867, true, false));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetAnalogueCount()
+ {
+ /*
+ * 'T' in column 0 has emission probability 0.7859, scales to 7859
+ */
+ int count = AAFrequency.getAnalogueCount(hmm, 0, 'T', false, false);
+ assertEquals(7859, count);
+
+ /*
+ * same with 'use info height': value is multiplied by log ratio
+ * log(value / background) / log(2) = log(0.7859/0.25)/0.693
+ * = log(3.1)/0.693 = 1.145/0.693 = 1.66
+ * so value becomes 1.2987 and scales up to 12987
+ */
+ count = AAFrequency.getAnalogueCount(hmm, 0, 'T', false, true);
+ assertEquals(12987, count);
+
+ /*
+ * 'G' in column 20 has emission probability 0.75457, scales to 7546
+ */
+ count = AAFrequency.getAnalogueCount(hmm, 20, 'G', false, false);
+ assertEquals(7546, count);
+
+ /*
+ * 'G' in column 1077 has emission probability 0.0533, here
+ * ignored (set to 0) since below background of 0.25
+ */
+ count = AAFrequency.getAnalogueCount(hmm, 1077, 'G', true, false);
+ assertEquals(0, count);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCompleteInformation()
+ {
+ ProfileI prof1 = new Profile(1, 0, 100, "A");
+ ProfileI prof2 = new Profile(1, 0, 100, "-");
+
+ ProfilesI profs = new Profiles(new ProfileI[] { prof1, prof2 });
+ Annotation ann1 = new Annotation(6.5f);
+ Annotation ann2 = new Annotation(0f);
+ Annotation[] annots = new Annotation[] { ann1, ann2 };
+ SequenceI seq = new Sequence("", "AA", 0, 0);
+ seq.setHMM(hmm);
+ AlignmentAnnotation annot = new AlignmentAnnotation("", "", annots);
+ annot.setSequenceRef(seq);
+ AAFrequency.completeInformation(annot, profs, 0, 1);
+ float ic = annot.annotations[0].value;
+ assertEquals(0.91532f, ic, 0.0001f);
+ ic = annot.annotations[1].value;
+ assertEquals(0f, ic, 0.0001f);
+ int i = 0;
+ }
}