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 * Created on June 24, 2010 021 * Author: Mark Chapman 022 */ 023 024package org.biojava.nbio.alignment; 025 026import org.biojava.nbio.core.alignment.SimpleSequencePair; 027import org.biojava.nbio.alignment.template.AbstractPairwiseSequenceAligner; 028import org.biojava.nbio.core.alignment.template.AlignedSequence; 029import org.biojava.nbio.core.alignment.template.AlignedSequence.Step; 030import org.biojava.nbio.alignment.template.GapPenalty; 031import org.biojava.nbio.core.alignment.template.SubstitutionMatrix; 032import org.biojava.nbio.core.sequence.template.Compound; 033import org.biojava.nbio.core.sequence.template.Sequence; 034 035import java.util.List; 036 037/** 038 * Smith and Waterman defined an algorithm for pairwise local sequence alignments (best match of sections from each 039 * {@link Sequence}). This class performs such local sequence comparisons efficiently by dynamic programming. 040 * 041 * @author Mark Chapman 042 * @param <S> each {@link Sequence} of the alignment pair is of type S 043 * @param <C> each element of an {@link AlignedSequence} is a {@link Compound} of type C 044 */ 045public class SmithWaterman<S extends Sequence<C>, C extends Compound> extends AbstractPairwiseSequenceAligner<S, C> { 046 047 /** 048 * Before running a pairwise local sequence alignment, data must be sent in via calls to 049 * {@link #setQuery(Sequence)}, {@link #setTarget(Sequence)}, {@link #setGapPenalty(GapPenalty)}, and 050 * {@link #setSubstitutionMatrix(SubstitutionMatrix)}. 051 */ 052 public SmithWaterman() { 053 super(null, null, null, null, true); 054 } 055 056 /** 057 * Prepares for a pairwise local sequence alignment. 058 * 059 * @param query the first {@link Sequence} of the pair to align 060 * @param target the second {@link Sequence} of the pair to align 061 * @param gapPenalty the gap penalties used during alignment 062 * @param subMatrix the set of substitution scores used during alignment 063 */ 064 public SmithWaterman(S query, S target, GapPenalty gapPenalty, SubstitutionMatrix<C> subMatrix) { 065 super(query, target, gapPenalty, subMatrix, true); 066 } 067 068 // method for AbstractMatrixAligner 069 070 @Override 071 protected void setProfile(List<Step> sx, List<Step> sy) { 072 profile = pair = new SimpleSequencePair<S, C>(getQuery(), getTarget(), sx, xyStart[0], 073 getQuery().getLength() - xyMax[0], sy, xyStart[1], getTarget().getLength() - xyMax[1]); 074 } 075 076}