## org.biojava.bio.alignment
Class SmithWaterman

    java.lang.Object
      org.biojava.bio.alignment.SequenceAlignment
          org.biojava.bio.alignment.NeedlemanWunsch
              org.biojava.bio.alignment.SmithWaterman

    public class SmithWaterman

extends NeedlemanWunsch

Smith and Waterman developed an efficient dynamic programing algorithm to perform local sequence alignments, which returns the most conserved region of two sequences (longes common substring with modifications). This algorithm is performed by the method `pairwiseAlignment` of this class. It uses affine gap penalties if and only if the expenses of a delete or insert operation are unequal to the expenses of gap extension. This uses significantly more memory (four times as much) and increases the runtime if swaping is performed.

Since:
  1.5
Author:
  Andreas Dräger, Gero Greiner

Field Summary

Fields inherited from class org.biojava.bio.alignment.NeedlemanWunsch
`alignment, CostMatrix, pairalign, subMatrix`

Constructor Summary
`SmithWaterman(double match, double replace, double insert, double delete, double gapExtend, SubstitutionMatrix matrix)` Constructs the new SmithWaterman alignment object.

Method Summary
`double` `pairwiseAlignment(Sequence query, Sequence subject)` Overrides the method inherited from the NeedlemanWunsch and performs only a local alignment.
`void` `setDelete(double del)` Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a delete operation to the specified value.
`void` `setGapExt(double ge)` Overrides the method inherited from the NeedlemanWunsch and sets the penalty for an extension of any gap (insert or delete) to the specified value.
`void` `setInsert(double ins)` Overrides the method inherited from the NeedlemanWunsch and sets the penalty for an insert operation to the specified value.
`void` `setMatch(double ma)` Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a match operation to the specified value.
`void` `setReplace(double rep)` Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a replace operation to the specified value.

Methods inherited from class org.biojava.bio.alignment.NeedlemanWunsch
`alignAll, getAlignment, getAlignmentString, getDelete, getEditDistance, getGapExt, getInsert, getMatch, getReplace, min, printAlignment, printCostMatrix, setSubstitutionMatrix`

Methods inherited from class org.biojava.bio.alignment.SequenceAlignment
`formatOutput`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SmithWaterman

    public SmithWaterman(double match,
                         double replace,
                         double insert,
                         double delete,
                         double gapExtend,
                         SubstitutionMatrix matrix)

  Constructs the new SmithWaterman alignment object. Alignments are only performed, if the alphabet of the given `SubstitutionMatrix` equals the alpabet of both the query and the target `Sequence`. The alignment parameters here are expenses and not scores as they are in the `NeedlemanWunsch` object. scores are just given by multipliing the expenses with `(-1)`. For example you could use parameters like "-2, 5, 3, 3, 0". If the expenses for gap extension are equal to the cost of starting a gap (delete or insert), no affine gap penalties are used, which saves memory.

  Parameters:
    `match` - expenses for a match
    `replace` - expenses for a replace operation
    `insert` - expenses for a gap opening in the query sequence
    `delete` - expenses for a gap opening in the target sequence
    `gapExtend` - expenses for the extension of a gap which was started earlier.
    `matrix` - the `SubstitutionMatrix` object to use.

Method Detail

### setInsert

    public void setInsert(double ins)

  Overrides the method inherited from the NeedlemanWunsch and sets the penalty for an insert operation to the specified value. Reason: internaly scores are used instead of penalties so that the value is muliplied with -1.

  Overrides:
    `setInsert` in class `NeedlemanWunsch`
  Parameters:
    `ins` - costs for a single insert operation

### setDelete

    public void setDelete(double del)

  Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a delete operation to the specified value. Reason: internaly scores are used instead of penalties so that the value is muliplied with -1.

  Overrides:
    `setDelete` in class `NeedlemanWunsch`
  Parameters:
    `del` - costs for a single deletion operation

### setGapExt

    public void setGapExt(double ge)

  Overrides the method inherited from the NeedlemanWunsch and sets the penalty for an extension of any gap (insert or delete) to the specified value. Reason: internaly scores are used instead of penalties so that the value is muliplied with -1.

  Overrides:
    `setGapExt` in class `NeedlemanWunsch`
  Parameters:
    `ge` - costs for any gap extension

### setMatch

    public void setMatch(double ma)

  Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a match operation to the specified value. Reason: internaly scores are used instead of penalties so that the value is muliplied with -1.

  Overrides:
    `setMatch` in class `NeedlemanWunsch`
  Parameters:
    `ma` - costs for a single match operation

### setReplace

    public void setReplace(double rep)

  Overrides the method inherited from the NeedlemanWunsch and sets the penalty for a replace operation to the specified value. Reason: internaly scores are used instead of penalties so that the value is muliplied with -1.

  Overrides:
    `setReplace` in class `NeedlemanWunsch`
  Parameters:
    `rep` - costs for a single replace operation

### pairwiseAlignment

    public double pairwiseAlignment(Sequence query,
                                    Sequence subject)
                             throws BioRuntimeException

  Overrides the method inherited from the NeedlemanWunsch and performs only a local alignment. It finds only the longest common subsequence. This is good for the beginning, but it might be better to have a system to find more than only one hit within the score matrix. Therfore one should only define the k-th best hit, where k is somehow related to the number of hits.

  Overrides:
    `pairwiseAlignment` in class `NeedlemanWunsch`
  Returns:
    score of the alignment or the distance.
  Throws:
    `BioRuntimeException`
  See Also:
    `SequenceAlignment.pairwiseAlignment(org.biojava.bio.seq.Sequence, org.biojava.bio.seq.Sequence)`