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.twohead;
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 * Storage structure for intermediate values from a pairwise
035 * dynamic programming run.
036 *
037 * @author Thomas Down
038 */
039
040public class PairDPMatrix implements DPMatrix, Serializable {
041    private State[] states;
042    private SymbolList[] seqs;
043    private double[][][] scores;
044    private MarkovModel model;
045    private double finalScore;
046
047    public PairDPMatrix(DP dp, SymbolList seq0, SymbolList seq1) {
048        model = dp.getModel();
049        states = dp.getStates();
050        seqs = new SymbolList[2];
051        seqs[0] = seq0;
052        seqs[1] = seq1;
053        finalScore = Double.NaN;
054        scores = new double[seq0.length() + 2][seq1.length() + 2][states.length];
055    }
056
057    public State[] states() {
058        return states;
059    }
060
061    public MarkovModel model() {
062        return model;
063    }
064
065    public SymbolList[] symList() {
066        return seqs;
067    }
068
069    public double getScore() {
070        return finalScore;
071    }
072
073    public double getCell(int[] indxs) {
074        if (indxs.length != 3) {
075            throw new IndexOutOfBoundsException("Index array must be length 3");
076        }
077        return scores[indxs[1]][indxs[2]][indxs[0]];
078    }
079
080    double[][][] getScoreArray() {
081        return scores;
082    }
083
084    void setScore(double score) {
085        this.finalScore = score;
086    }
087}