Talk:Needleman–Wunsch algorithm

message: 1) In the matrix calculation, the loop iterates from 1 to length(A) and length(B) where the sequences start from 0. Therefore, S(Ai,Bj) should be S(Ai-1, Bj-1) since S(Ai,Bj) would return an error.
==> I have made the suggested change here (and elsewhere) which corresponds to zero based indexing for the sequences.  The pseudo-code should now be self consistent. -- Kipton Barros, 4/18/2010
====> This is still not fixed, it is true that S(Ai,Bj) should be changed to S(Ai-1, Bj-1), as well as changing Ai and Bi to Ai-1 and Bi-1 respectively in the whole pseudo-code for it to work properly (I tried it in C with this fix and it now works fine). The whole problem is that the F matrix goes from [0][0] to [lengthA][lengthB], while the sequences go from [0] to [length-1]. So the pseudo code should be changed to this:
 for i=0 to length(A)
   F(i,0) ← d*i
 for j=0 to length(B)
   F(0,j) ← d*j
 for i=1 to length(A)
   for j=1 to length(B)
   {
     Match ← F(i-1,j-1) + S(Ai-1, Bj-1)
     Delete ← F(i-1, j) + d
     Insert ← F(i, j-1) + d
     F(i,j) ← max(Match, Insert, Delete)
   }
 AlignmentA ← ""
 AlignmentB ← ""
 i ← length(A)
 j ← length(B)
 while (i > 0 or j > 0)
 {
   if (i > 0 and j > 0 and F(i,j) == F(i-1,j-1) + S(Ai-1, Bj-1))
   {
     AlignmentA ← Ai-1 + AlignmentA
     AlignmentB ← Bj-1 + AlignmentB
     i ← i - 1
     j ← j - 1
   }
   else if (i > 0 and F(i,j) == F(i-1,j) + d)
   {
     AlignmentA ← Ai-1 + AlignmentA
     AlignmentB ← "-" + AlignmentB
     i ← i - 1
   }
   else (j > 0 and F(i,j) == F(i,j-1) + d)
   {
     AlignmentA ← "-" + AlignmentA
     AlignmentB ← Bj-1 + AlignmentB
     j ← j - 1
   }
 }
192.55.54.40 (talk) 23:19, 6 August 2013 (UTC)
thread_title: Errors with the algorithm as it is presented here:

message: Note that everyone so far has failed to define the variable d in all their formulas. What is this?
Also, I just backtracked up an edit distance matrix and the alignments generated definitely seemed fine to me (inserting "-" when you don't move diagonally). Is this formula a generalization of that? It seems like it. Should this be noted and explained in this page or the Levenshtein page?  —Preceding unsigned comment added by 65.88.178.10 (talk) 18:17, 17 September 2007 (UTC)
thread_title:  Defining <i>d</i> and edit distance 

message: I made an implementation of this algorithm in C. It seems there is some misstake : (well, I am not completly sure of me, but I did the following change in my source code to make it works correctly :
{
  i <- length(B) - 1
  j <- length(A) - 1
}
instead of
{
  i <- length(A) - 1
  j <- length(B) - 1
}
According we consider F(x,y) (x number of line, y number of column). Which has been the choice in my implementation, and seems to be the choice in this algorithm.
Thanks to confirm it
Valeuf (talk) 17:51, 17 May 2009 (UTC)
thread_title:  Error ? 

message: The following link gives a clear explanation of Needleman-Wunsch algorithm, and can be included in the external links.
http://technology66.blogspot.com/
--122.169.92.175 (talk) 21:11, 12 September 2008 (UTC)
thread_title:  Adding a link 

message: In the pseudo code, what does S mean? It's never mentioned in the text above
Match ← F(i-1,j-1) + S(Ai, Bj)
I suggest a short explaination.
Mcemperor (talk) 16:27, 30 November 2011 (UTC)
thread_title:  Wat is S? 

message: Why is the F(0,0) initialized two times?
for i=0 to length(A)
  F(i,0) ← d*i
for j=0 to length(B)
  F(0,j) ← d*j
Either initialize the F(0,0) in a separate statement or adjust the start index of the second loop:
F(0,0) ← 0
for i=1 to length(A)
  F(i,0) ← d*i
for j=1 to length(B)
  F(0,j) ← d*j
for i=0 to length(A)
  F(i,0) ← d*i
for j=1 to length(B)
  F(0,j) ← d*j
--Hubalu (talk) 09:00, 16 July 2013 (UTC)
thread_title: Code optimization?

message: I think there's an issue with the indexes in the verbal description of the algorithm. There are i rows, one for each element of sequence B. We then index i over A rather than B. Likewise there are j columns based on the number of elements in A and then we index j over B. In a square matrix, this should result in the transpose of the desired match matrix and in a non-square matrix this will result in an index going out of bounds.  — Preceding unsigned comment added by 107.191.32.203 (talk) 14:48, 14 August 2014 (UTC)
thread_title: Indexing problem

message: Hi! I've just noticed a mistake in one of the example sequences. The last base in the first sequence is ″U″ (GCATGCU). As it is DNA it should only contain A, T, C and G, shouldn't it?--Zlir'a (talk) 09:52, 30 December 2014 (UTC)
thread_title:  The ″U″ in DNA sequence 

message: Hello fellow Wikipedians,
I have just modified one external link on Needleman–Wunsch algorithm. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
*Added archive https://web.archive.org/web/20140729133238/http://www.science.marshall.edu/murraye/Clearer%20Matrix%20slide%20show.pdf to http://www.science.marshall.edu/murraye/Clearer%20Matrix%20slide%20show.pdf
*Added  tag to http://svitsrv25.epfl.ch/R-doc/library/Biostrings/html/00Index.html
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
Cheers.—InternetArchiveBot (Report bug) 09:29, 15 February 2018 (UTC)
thread_title:  External links modified (February 2018) 

message: Note that this algorithm was later used for the Unix diff command. It used to be mentioned on the man page for diff, but it seems not anymore. It might be useful to say that, as that is where more people will actually use it. Gah4 (talk) 09:02, 18 June 2021 (UTC)
thread_title:  diff 

message: In the "Basic Scoring" section, two alternate example scoring schemes are discussed... but they are in fact identical.
I think the edit "15:19, 5 April 2023‎ 106.205.216.93 →‎Basic scoring schemes" introduced a mistake. Previous to this edit, the schemes were different. 136.38.95.121 (talk) 18:08, 10 May 2024 (UTC)
thread_title:  Mistake/Typo/Redundancy in Basic Scoring Section