[Biojava-l] SimpleModelInState problem?

Russell Smithies russell_smithies@hotmail.com
Fri, 06 Dec 2002 03:58:29 +0000


I'm trying to create a reasonably complex markov model so have split it into 
bits to make it a little easier to handle.
I'm then trying to re-assemble the bits into another model by creating 
SimpleModelInState's from the sub-models.
The problem is that I keep getting errors and not sure why.
heres some code I did as a test, the top portion creates a sub-model (which 
compiles correctly) but when I try to add them to create the DP for, I get 
null pointer errors and was getting errors about null back pointers?

heres some testy code :
(sorry if HotMail munges it)  :-)



import java.util.*;

import org.biojava.bio.*;
import org.biojava.bio.dist.*;
import org.biojava.bio.dp.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.symbol.*;

public class modelInStateTest {
  public static void main(String[] args) throws Exception {

    // sequence to test
    SymbolList sl  = DNATools.createDNA("actgatcgactgtacgatgagatgcgactga"+
                                        
"tcgactgactgctgcgtatcgatcgatcgatgactgacg");
    int[] advance = { 1 };

    //create order n alphabet
    Alphabet orderNAlpha = AlphabetManager.getCrossProductAlphabet(
                                            Collections.nCopies(3, 
DNATools.getDNA()));

    //create uniform distribution for emission states
    Distribution uni_dist = new UniformDistribution(DNATools.getDNA());

    // create simple markov model
    SimpleMarkovModel mm = new SimpleMarkovModel(1, DNATools.getDNA(), 
"mm");

    //create emission states
    EmissionState es1 = new SimpleEmissionState("1_es", 
Annotation.EMPTY_ANNOTATION, advance, uni_dist);
    EmissionState es2 = new SimpleEmissionState("2_es", 
Annotation.EMPTY_ANNOTATION, advance, uni_dist);


    //  add states to model
    mm.addState(es1);
    mm.addState(es2);

    //  create transitions between all states
    mm.createTransition(mm.magicalState(), es1);
    mm.createTransition(mm.magicalState(), es2);
    mm.createTransition(es1, es1);
    mm.createTransition(es1, es2);
    mm.createTransition(es2, es2);
    mm.createTransition(es2, es1);
    mm.createTransition(es2, mm.magicalState());
    mm.createTransition(es1, mm.magicalState());

    //set weights on transitions
    mm.setWeights(mm.magicalState(), new 
UniformDistribution(mm.transitionsFrom(mm.magicalState())));
    mm.setWeights(es1, new UniformDistribution(mm.transitionsFrom(es1)));
    mm.setWeights(es2, new UniformDistribution(mm.transitionsFrom(es2)));

    sl = SymbolListViews.orderNSymbolList(sl, 3);

    SymbolList[] sla = { sl };

    //  create the dynamic programming object
    DP dp = DPFactory.DEFAULT.createDP(mm);

    //create statepath
    StatePath sp = dp.viterbi(sla, ScoreType.PROBABILITY);

    /////////     TRY TO CREATE SUB MODELS AND INTEGRATE THEM  
///////////////////////////

    SimpleMarkovModel mm2 = new SimpleMarkovModel(1, DNATools.getDNA(), 
"2_mm");

    //create states
    SimpleModelInState smis1 = new SimpleModelInState(mm, "1_smis");
    SimpleModelInState smis2 = new SimpleModelInState(mm, "2_smis");

    mm2.addState(smis1);
    mm2.addState(smis2);

    //  create transitions between all states
    mm2.createTransition(mm2.magicalState(), smis1);
    mm2.createTransition(mm2.magicalState(), smis2);
    mm2.createTransition(smis1, smis1);
    mm2.createTransition(smis1, smis2);
    mm2.createTransition(smis2, smis2);
    mm2.createTransition(smis2, smis1);
    mm2.createTransition(smis2, mm2.magicalState());
    mm2.createTransition(smis1, mm2.magicalState());

    //set weights on transitions
    mm2.setWeights(mm2.magicalState(), new 
UniformDistribution(mm2.transitionsFrom(mm2.magicalState())));
    mm2.setWeights(smis1, new 
UniformDistribution(mm2.transitionsFrom(smis1)));
    mm2.setWeights(smis2, new 
UniformDistribution(mm2.transitionsFrom(smis2)));

    //  create the dynamic programming object
    DP dp2 = DPFactory.DEFAULT.createDP(mm2);   //<<<<-----------------

    //create statepath
    StatePath sp2 = dp2.viterbi(sla, ScoreType.PROBABILITY);

    /*
    java.lang.NullPointerException
        at org.biojava.bio.dp.FlatModel.<init>(FlatModel.java:229)
        at org.biojava.bio.dp.DP.flatView(DP.java:96)
        at 
org.biojava.bio.dp.DPFactory$DefaultFactory.createDP(DPFactory.java:51)
        at markov.modelInStateTest.main(modelInStateTest.java:89)
    Exception in thread "main"
    */

  }
}




_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail