001 package calhoun.analysis.crf.test;
002
003 import calhoun.analysis.crf.features.supporting.LogProbLookup;
004 import calhoun.analysis.crf.io.InputSequenceCharacter;
005 import calhoun.seq.KmerHasher;
006 import calhoun.util.AbstractTestCase;
007
008 /** Tests that CRF is working with valid probabilities - the sum of all possible labelings is 1.
009 *
010 * Test that the code to walk through only the valid paths works correctly.
011 * Uses a two state model that disallows transitions to self. 010101... or 101010... are the only allowed paths. */
012 public class LogprobLookupTest extends AbstractTestCase {
013
014
015 public void testLogProbLookupRC() throws Exception {
016 String forward = "TGTTGGTACGCTTGCGGCTCTGCTGCAGCGAAAAAAAAGATCGAAATGACCAG";
017 String reverse = "CTGGTCATTTCGATCTTTTTTTTCGCTGCAGCAGAGCCGCAAGCGTACCAACA";
018 String computedReverse = KmerHasher.reverseComplement(forward);
019
020 int len = forward.length();
021 assertEquals(reverse,computedReverse);
022
023
024
025 InputSequenceCharacter forwardSeq = new InputSequenceCharacter(forward);
026 InputSequenceCharacter reverseSeq = new InputSequenceCharacter(reverse);
027
028 LogProbLookup lf = new LogProbLookup(2,1.0);
029
030 LogProbLookup lr = new LogProbLookup(2,1.0);
031
032 for (int j=0; j<len; j++) {
033 lf.increment(forwardSeq,j,true);
034 lr.increment(reverseSeq,j,false);
035 }
036
037 lf.finalize();
038 lr.finalize();
039
040 for (int j=0; j<len; j++) {
041 assertEquals(lf.lookup(forwardSeq,j,true),lr.lookup(forwardSeq,j,true),0.0001);
042 assertEquals(lf.lookup(forwardSeq,j,false),lr.lookup(forwardSeq,j,false),0.0001);
043 assertEquals(lf.lookup(forwardSeq,j,true),lr.lookup(reverseSeq,len-j-1,false),0.0001);
044 }
045
046
047 System.out.println("hello");
048
049 }
050
051 }