001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022
023package org.biojava.bio.dp.onehead;
024
025import java.io.Serializable;
026
027import org.biojava.bio.dp.DP;
028import org.biojava.bio.dp.DPMatrix;
029import org.biojava.bio.dp.MarkovModel;
030import org.biojava.bio.dp.State;
031import org.biojava.bio.symbol.SymbolList;
032
033/**
034 * The dynamic programming matrix for a single sequence.
035 *
036 * @author Matthew Pocock
037 * @author Lukas Kall
038 */
039public class SingleDPMatrix implements DPMatrix, Serializable {
040  protected final State [] states;
041  protected final MarkovModel model;
042  protected final SymbolList [] symList;
043  public final double [][] scores; // [symbol][state]
044  protected double score;
045 
046  public State [] states() {
047    return states;
048  }
049  
050  public MarkovModel model() {
051    return model;
052  }
053  
054  public SymbolList [] symList() {
055    return symList;
056  }
057  
058  public double getScore() {
059    return score;
060  }
061  
062  public void setScore(double score) {
063    this.score = score;
064  }
065  
066  public double getCell(int [] index)
067  throws IndexOutOfBoundsException {
068    if(index.length != 2) {
069      throw new IndexOutOfBoundsException("index must be two-dimensional");
070    }
071    return scores[index[1]][index[0]];
072  }
073  
074  public SingleDPMatrix(DP dp, SymbolList symList) {
075    this.model = dp.getModel();
076    this.states = dp.getStates();
077    this.symList = new SymbolList [] { symList };
078    this.score = Double.NaN;
079    this.scores = new double[symList.length() + 2][states.length];
080  }
081}