Question: Biojava HMM error
gravatar for Jamand
5.1 years ago by
European Union
Jamand110 wrote:


Biojava is a framework bugged also in the most simple functions and it is very hard to think to use it for solving complex questions.

I've recently used it to make an alignment using HMM adn I try to execute the eample in the cookbook

Here is the example

ProfileHMM hmm = new ProfileHMM(DNATools.getDNA(),
                         "my profilehmm");
    //create the Dynamic Programming matrix for the model.
    dp = DPFactory.DEFAULT.createDP(hmm);


    //Database to hold the training set
    SequenceDB db = new HashSequenceDB();
    //code here to load the training set

Now initialize all of the model parameters to a uniform value. Alternatively parameters could be set randomly or set to represent a guess at what the best model might be. Then use the Baum-Welch Algorithm to optimise the parameters.

    //train the model to have uniform parameters
    ModelTrainer mt = new SimpleModelTrainer();
    //register the model to train
    //as no other counts are being used the null weight will cause everything to be uniform
    //create a BW trainer for the dp matrix generated from the HMM
    BaumWelchTrainer bwt = new BaumWelchTrainer(dp);
    //anonymous implementation of the stopping criteria interface to stop after 20 iterations
    StoppingCriteria stopper = new StoppingCriteria(){
      public boolean isTrainingComplete(TrainingAlgorithm ta){
        return (ta.getCycle() > 20);
     * optimize the dp matrix to reflect the training set in db using a null model
     * weight of 1.0 and the Stopping criteria defined above.

Below is an example of scoring a sequence and outputting the state path.

    SymbolList test = null;
    //code here to initialize the test sequence
     * put the test sequence in an array, an array is used because for pairwise
     * alignments using an HMM there would need to be two SymbolLists in the 
     * array
    SymbolList[] sla = {test};
    //decode the most likely state path and produce an 'odds' score
    StatePath path = dp.viterbi(sla, ScoreType.ODDS);
    System.out.println("Log Odds = "+path.getScore());
    //print state path
    for(int i = 1; i <= path.length(); i++){
      System.out.println(path.symbolAt(StatePath.STATES, i).getName());


Everything seemed to go right up to the following line when I got an Exception(and it is not the first time since I use biojava):

StatePath path = dp.viterbi(sla, ScoreType.ODDS);

java.lang.ClassCastException: cannot be cast to java.lang.String
    at it.multimedia.hmm.TestHMM.main(

I pass as parameter a file with fasta sequences

Could you help me to solve this problem?

If someone who wrote Biojava should read this post I'd like to ask him how can be published a so "bugged" framework of which not even can be excuted correctly examples reported in the official documentation.

Thank you very much


software error • 1.3k views
ADD COMMENTlink modified 5.1 years ago by eric.kern13190 • written 5.1 years ago by Jamand110
gravatar for eric.kern13
5.1 years ago by
United States
eric.kern13190 wrote:

You could consider opening this as an issue on their GitHub. Sorry I can't address the error itself.

ADD COMMENTlink written 5.1 years ago by eric.kern13190
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1525 users visited in the last hour