[Biojava-l] NPE from FlatModel.<init> with SimpleModelInState

Douglas Hoen douglas.hoen at mail.mcgill.ca
Thu Mar 4 13:33:18 EST 2004


Hi,

I want to put a two-headed markov model in a SimpleModelInState.
But when I attempt to call DPFactory.DEFAULT.createDP, I get a
NullPointerException from inside the org.biojava.bio.dp.FlatModel
constructor. 

I get the same problem from the biojava-1.30-jdk13.jar,
biojava-1.30-jdk14.jar, and biojava-1.3.1.jar distributions.

Also, I turned up a similar thread in Dec. 2002 biojava-l archive
entitled "SimpleModelInState Problem?". Matthew Pocock responded to the
query saying he was about to work on the issue, but there is no
followup.

My questions: Is this a real bug? If so, should I expect this API
(ModelInState for two-headed models) to be supported in the near future,
or should I simply build a flat model?

The stack trace, possible problem biojava code, and snippets of my test
code are below. 

Thanks very much for any help.
Doug


Here is the stack trace:
------------------------

Exception in thread "main" java.lang.NullPointerException
        at org.biojava.bio.dp.FlatModel.<init>(FlatModel.java:251)
        at org.biojava.bio.dp.DP.flatView(DP.java:168)
        at
org.biojava.bio.dp.DPFactory$DefaultFactory.createDP(DPFactory.java:52)
        at ltr.ModelInStateExample.main(ModelInStateExample.java:124)
rethrown as org.biojava.utils.NestedError: Can't align.
        at ltr.ModelInStateExample.main(ModelInStateExample.java:133)


The NPE seems to be coming from the following FlatModel code:
-------------------------------------------------------------

//
// FIXME -- [SOMEONE (ed.)] broked this...
//

TranslatedDistribution dist = null;
// TranslatedDistribution dist TranslatedDistribution.getDistribution(
//  delegate.transitionsFrom(s),
//  sModel.getWeights(sOrig)
// );
SimpleReversibleTranslationTable table =
	(SimpleReversibleTranslationTable) dist.getTable();


Here is the model creation code:
--------------------------------

...
FiniteAlphabet singleAlphabet = DNATools.getDNA();
FiniteAlphabet doubleAlphabet = 
    ( FiniteAlphabet ) AlphabetManager.getCrossProductAlphabet( 
        Collections.nCopies( 2, singleAlphabet ) );

State matchState = new SimpleEmissionState(
        "match",
        Annotation.EMPTY_ANNOTATION,
        new int[] { 1, 1 },
        new UniformDistribution( doubleAlphabet )
        );
State insertState = new SimpleEmissionState(
        "insert",
        Annotation.EMPTY_ANNOTATION,
        new int[] { 0, 1 },
        new PairDistribution( 
            new GapDistribution( singleAlphabet ),
            new UniformDistribution( singleAlphabet )
        ) );
State deleteState = new SimpleEmissionState(
        "delete",
        Annotation.EMPTY_ANNOTATION,
        new int[] { 1, 0 },
        new PairDistribution(                     
            new UniformDistribution( singleAlphabet ),
            new GapDistribution( singleAlphabet )
        ) );

SimpleMarkovModel innerModel = 
    new SimpleMarkovModel( 2, doubleAlphabet, "inner");
innerModel.addState( matchState );
innerModel.addState( insertState );
innerModel.addState( deleteState );

innerModel.createTransition( innerModel.magicalState(), matchState );
innerModel.createTransition( matchState, insertState );
innerModel.createTransition( matchState, deleteState );
innerModel.createTransition( matchState, matchState );
innerModel.createTransition( matchState, innerModel.magicalState() );
innerModel.createTransition( insertState, matchState );
innerModel.createTransition( insertState, insertState );
innerModel.createTransition( deleteState, matchState );
innerModel.createTransition( deleteState, deleteState );

double d = 0.1;
double e = 0.1;
double t = 0.1;

innerModel.getWeights( innerModel.magicalState() )
            .setWeight( matchState,  1.0 );

Distribution fromMatch = innerModel.getWeights( matchState );
fromMatch.setWeight( insertState, d );
fromMatch.setWeight( deleteState, d );
fromMatch.setWeight( matchState, 1-2*d-t );
fromMatch.setWeight( innerModel.magicalState(), t );

Distribution fromInsert = innerModel.getWeights( insertState );
fromInsert.setWeight( matchState, 1-e );
fromInsert.setWeight( insertState, e );

Distribution fromDelete = innerModel.getWeights( deleteState );
fromDelete.setWeight( matchState, 1-e );
fromDelete.setWeight( deleteState, e );

State innerModelInState = 
    new SimpleModelInState( innerModel, "modelInState" );

SimpleMarkovModel outerModel = 
    new SimpleMarkovModel( 2, doubleAlphabet, "outer" );

outerModel.addState( innerModelInState );

outerModel.createTransition( 
    outerModel.magicalState(), innerModelInState );
outerModel.createTransition( 
    innerModelInState, outerModel.magicalState() );

outerModel.getWeights( outerModel.magicalState() )
            .setWeight( innerModelInState, 1.0 );
outerModel.getWeights( innerModelInState )
            .setWeight( outerModel.magicalState(), 1.0 );

...

DPFactory.DEFAULT.createDP( outerModel );  <==================== NPE




More information about the Biojava-l mailing list