<p>There are many implementations of the Smith-Waterman algorithm. However, they are not all guaranteed to give the same output because although it's an optimal local alignment algorithm, it still depends on the chosen scoring scheme (i.e. substitution matrix and gap penalties).</p>

<p>With this in mind, you could try EMBOSS Water online:
<a href="https://www.ebi.ac.uk/Tools/psa/emboss_water/" rel="nofollow noreferrer">https://www.ebi.ac.uk/Tools/psa/emboss_water/</a></p>

<p>Or in Biopython, the <code>Align.PairwiseAligner()</code> (which uses SW by default when <code>aligner.mode</code> is set to <code>local</code>):
<a href="https://biopython.org/DIST/docs/api/Bio.Align.PairwiseAligner-class.html" rel="nofollow noreferrer">https://biopython.org/DIST/docs/api/Bio.Align.PairwiseAligner-class.html</a></p>

CC BY-SA 4.0
2019-10-12T20:52:31.400Z
2019-10-12T20:52:31.400Z
Chris_Rands
<p>In R, you can use <a href="https://www.rdocumentation.org/packages/Biostrings/versions/2.40.2/topics/pairwiseAlignment" rel="nofollow noreferrer">pairwise Alignment in Biostrings</a>. </p>

<pre><code>## Nucleotide global, local, and overlap alignments
library(Biostrings)
s1 &lt;- DNAString("ACTTCACCAGCTCCCTGGCGGTAAGTTGAT")
s2 &lt;- DNAString("GTTTCACTACTTCCTTTCGGGTAAGTAAAT")
# needleman
pairwiseAlignment(s1,s2,type="global")
# smith-waterman
pairwiseAlignment(s1,s2,type="local")
</code></pre>

<p>I am not very sure how to implement it from scratch. If you face more problems with this example, I can have a go at it.</p>

CC BY-SA 4.0
2020-09-05T17:59:03.307Z
are there faster methods to do this than the Biostrings implementation in R? Using R, are there hash or FFT methods?
Vass
CC BY-SA 4.0
2020-09-05T19:22:30.070Z
it's not related to this question (which does smith-waterman) maybe you can try https://rdrr.io/rforge/NameNeedle/man/needles.html
StupidWolf
CC BY-SA 4.0
2019-10-13T14:07:53.443Z
2019-10-13T14:07:53.443Z
StupidWolf
<p>I have written a R code for Smith-Waterman (SW) algorithm. </p>

<p>I wanted to check the results of my code with online examples. In all cases -except one- I found the same alignment. So there is this one example -let's say example A*- for which I found a quite different alignment result: in the example they give three equivally good alignments whereas I found only one that corresponds to no none of those three alignments (we have the same score, though).</p>

<p>I am now trying to understand whether example A is wrong or if my code is not working properly.</p>

<p>Therefore, I have two requests:</p>

<ul>
<li>Does anyone have a dataset of the result of SW used on two sequences? 
I could then compare these results with the output of my code.</li>
<li>Does anyone have whatever way to compute SW algorithm? Then, I could give that person the example A, which could then try this example A, and give me the output.</li>
</ul>

<p>This would be very helpful if someone could help, I have already spent so much time on my code, without finding anything that could explain those different outputs.</p>

<p>Thank you!</p>

<ul>
<li>Example A: Sequence A = "TGCTCTGT" and Sequence B = "TACTATCAT"</li>
</ul>

<phylogenetics>
Smith-Waterman Pairwise Local Alignment Algorithm
# Smith-Waterman Pairwise Local Alignment Algorithm

(Asked by: username_0 on 2019-10-12)

I have written a R code for Smith-Waterman (SW) algorithm.

I wanted to check the results of my code with online examples. In all cases -except one- I found the same alignment. So there is this one example -let's say example A\*- for which I found a quite different alignment result: in the example they give three equivally good alignments whereas I found only one that corresponds to no none of those three alignments (we have the same score, though).

I am now trying to understand whether example A is wrong or if my code is not working properly.

Therefore, I have two requests:

* Does anyone have a dataset of the result of SW used on two sequences?
  I could then compare these results with the output of my code.
* Does anyone have whatever way to compute SW algorithm? Then, I could give that person the example A, which could then try this example A, and give me the output.

This would be very helpful if someone could help, I have already spent so much time on my code, without finding anything that could explain those different outputs.

Thank you!

* Example A: Sequence A = "TGCTCTGT" and Sequence B = "TACTATCAT"

**Tags:** phylogenetics

---

## 2 answers

### Answer by username_1 on 2019-10-12. Score: 3

There are many implementations of the Smith-Waterman algorithm. However, they are not all guaranteed to give the same output because although it's an optimal local alignment algorithm, it still depends on the chosen scoring scheme (i.e. substitution matrix and gap penalties).

With this in mind, you could try EMBOSS Water online:
<https://www.ebi.ac.uk/Tools/psa/emboss_water/>

Or in Biopython, the `Align.PairwiseAligner()` (which uses SW by default when `aligner.mode` is set to `local`):
<https://biopython.org/DIST/docs/api/Bio.Align.PairwiseAligner-class.html>


---

### Answer by username_2 on 2019-10-13. Score: 2

In R, you can use pairwise Alignment in Biostrings. 
## Nucleotide global, local, and overlap alignments
library(Biostrings)
s1 <- DNAString("ACTTCACCAGCTCCCTGGCGGTAAGTTGAT")
s2 <- DNAString("GTTTCACTACTTCCTTTCGGGTAAGTAAAT")
# needleman
pairwiseAlignment(s1,s2,type="global")
# smith-waterman
pairwiseAlignment(s1,s2,type="local")

I am not very sure how to implement it from scratch. If you face more problems with this example, I can have a go at it.

> **Comments:**
> **username_3**: are there faster methods to do this than the Biostrings implementation in R? Using R, are there hash or FFT methods?  
> **username_2**: it's not related to this question (which does smith-waterman) maybe you can try https://rdrr.io/rforge/NameNeedle/man/needles.html  

---

