// Path: src/main/java/jaligner/matrix/Matrix.java
// public class Matrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 3833742170619524400L;
// 	
// 	/**
// 	 * The size of the scoring matrix. It is the number of the characters in the
// 	 * ASCII table. It is more than the 20 amino acids just to save the
// 	 * processing time of the mapping.
// 	 */
// 	public static final int SIZE = 127;
// 
// 	/**
// 	 * Matrix id (or name)
// 	 */
// 	private final String id;
// 
// 	/**
// 	 * Scores
// 	 */
// 	private final float[][] scores;
// 
// 	public Matrix(String id, float[][] scores) {
// 		this.id = id;
// 		this.scores = scores;
// 	}
// 
// 	/**
// 	 * @return Returns the id.
// 	 */
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	/**
// 	 * @return Returns the scores.
// 	 */
// 	public float[][] getScores() {
// 		return this.scores;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param a
// 	 * @param b
// 	 * @return score
// 	 */
// 	public float getScore(char a, char b) {
// 		return this.scores[a][b];
// 	}
// }


import jaligner.matrix.Matrix;
import java.util.logging.Logger;
/*
 * $Id: SmithWatermanGotoh.java,v 1.10 2006/02/09 13:27:36 ahmed Exp $
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jaligner;



/**
 * An implementation of the Smith-Waterman algorithm with Gotoh's improvement
 * for biological local pairwise sequence alignment.
 *
 * <strong>Recursive definition:</strong>
 * <ul>
 * <li>
 * <strong>Base conditions:</strong>
 * <ul>
 * <li><code>V(0, 0) = 0</code></li>
 * <li><code>V(i, 0) = E(i, 0) = W<sub>g</sub> + iW<sub>s</sub></code></li>
 * <li><code>V(0, j) = F(0, j) = W<sub>g</sub> + jW<sub>s</sub></code></li>
 * </ul>
 * </li>
 * <li>
 * <strong>Recurrence relation:</strong>
 * <ul>
 * <li><code>V(i, j) = max{E(i, j), F(i, j), G(i, j)}</code>, where:</li>
 * <li><code>G(i, j) = V(i - 1, j - 1) + similarity(S<sub>i</sub>, T<sub>j</sub>)</code></li>
 * <li><code>E(i, j) = max{E(i, j - 1) + W<sub>s</sub>, V(i, j - 1) + W<sub>g</sub> + W<sub>s</sub>}</code></li>
 * <li><code>F(i, j) = max{F(i - 1, j) + W<sub>s</sub>, V(i - 1, j) + W<sub>g</sub> + W<sub>s</sub>}</code></li>
 * </ul>
 * </ul>
 *
 * @author Ahmed Moustafa (ahmed@users.sf.net)
 */
public final class SmithWatermanGotoh {

    /**
     * Hidden constructor
     */
    private SmithWatermanGotoh() {
        super();
    }

    /**
     * Aligns two sequences by Smith-Waterman (local)
     *
     * @param s1 sequene #1 ({@link Sequence})
     * @param s2 sequene #2 ({@link Sequence})
     * @param matrix scoring matrix ({@link Matrix})
     * @param o open gap penalty
     * @param e extend gap penalty
     * @return alignment object contains the two aligned sequences, the
     * alignment score and alignment statistics
     * @see Sequence
     * @see Matrix
     */
// Path: src/main/java/jaligner/matrix/Matrix.java
// public class Matrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 3833742170619524400L;
// 	
// 	/**
// 	 * The size of the scoring matrix. It is the number of the characters in the
// 	 * ASCII table. It is more than the 20 amino acids just to save the
// 	 * processing time of the mapping.
// 	 */
// 	public static final int SIZE = 127;
// 
// 	/**
// 	 * Matrix id (or name)
// 	 */
// 	private final String id;
// 
// 	/**
// 	 * Scores
// 	 */
// 	private final float[][] scores;
// 
// 	public Matrix(String id, float[][] scores) {
// 		this.id = id;
// 		this.scores = scores;
// 	}
// 
// 	/**
// 	 * @return Returns the id.
// 	 */
// 	public String getId() {
// 		return this.id;
// 	}
// 
// 	/**
// 	 * @return Returns the scores.
// 	 */
// 	public float[][] getScores() {
// 		return this.scores;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param a
// 	 * @param b
// 	 * @return score
// 	 */
// 	public float getScore(char a, char b) {
// 		return this.scores[a][b];
// 	}
// }


// Path: src/main/java/jaligner/SmithWatermanGotoh.java
import jaligner.matrix.Matrix;
import java.util.logging.Logger;

/*
 * $Id: SmithWatermanGotoh.java,v 1.10 2006/02/09 13:27:36 ahmed Exp $
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jaligner;



/**
 * An implementation of the Smith-Waterman algorithm with Gotoh's improvement
 * for biological local pairwise sequence alignment.
 *
 * <strong>Recursive definition:</strong>
 * <ul>
 * <li>
 * <strong>Base conditions:</strong>
 * <ul>
 * <li><code>V(0, 0) = 0</code></li>
 * <li><code>V(i, 0) = E(i, 0) = W<sub>g</sub> + iW<sub>s</sub></code></li>
 * <li><code>V(0, j) = F(0, j) = W<sub>g</sub> + jW<sub>s</sub></code></li>
 * </ul>
 * </li>
 * <li>
 * <strong>Recurrence relation:</strong>
 * <ul>
 * <li><code>V(i, j) = max{E(i, j), F(i, j), G(i, j)}</code>, where:</li>
 * <li><code>G(i, j) = V(i - 1, j - 1) + similarity(S<sub>i</sub>, T<sub>j</sub>)</code></li>
 * <li><code>E(i, j) = max{E(i, j - 1) + W<sub>s</sub>, V(i, j - 1) + W<sub>g</sub> + W<sub>s</sub>}</code></li>
 * <li><code>F(i, j) = max{F(i - 1, j) + W<sub>s</sub>, V(i - 1, j) + W<sub>g</sub> + W<sub>s</sub>}</code></li>
 * </ul>
 * </ul>
 *
 * @author Ahmed Moustafa (ahmed@users.sf.net)
 */
public final class SmithWatermanGotoh {

    /**
     * Hidden constructor
     */
    private SmithWatermanGotoh() {
        super();
    }

    /**
     * Aligns two sequences by Smith-Waterman (local)
     *
     * @param s1 sequene #1 ({@link Sequence})
     * @param s2 sequene #2 ({@link Sequence})
     * @param matrix scoring matrix ({@link Matrix})
     * @param o open gap penalty
     * @param e extend gap penalty
     * @return alignment object contains the two aligned sequences, the
     * alignment score and alignment statistics
     * @see Sequence
     * @see Matrix
     */
    public static Alignment align(Sequence s1, Sequence s2, Matrix matrix,