gives a number representing the NeedlemanWunsch similarity between strings, vectors or biomolecular sequences u and v.

Details and Options

  • NeedlemanWunschSimilarity[u,v] finds an optimal global alignment between the elements of u and v, and returns the number of one-element matches.
  • For strings, setting the option IgnoreCase->True makes NeedlemanWunschSimilarity treat lowercase and uppercase letters as equivalent.
  • With the default setting SimilarityRules->Automatic, each match between two characters contributes to the total similarity score, while each mismatch, insertion, or deletion contributes .
  • The option GapPenalty specifies an additional cost to be subtracted from the similarity score for any run of insertions or deletions.


open allclose all

Basic Examples  (3)

NeedlemanWunsch similarity between two strings:

NeedlemanWunsch similarity between two vectors:

NeedlemanWunsch similarity between two biomolecular sequences:

Options  (1)

SimilarityRules  (1)

The "SimilarDegenerateBases" setting allows a higher similarity for matching degenerate terms in biomolecular sequences:

Wolfram Research (2008), NeedlemanWunschSimilarity, Wolfram Language function, (updated 2020).


Wolfram Research (2008), NeedlemanWunschSimilarity, Wolfram Language function, (updated 2020).


@misc{reference.wolfram_2020_needlemanwunschsimilarity, author="Wolfram Research", title="{NeedlemanWunschSimilarity}", year="2020", howpublished="\url{}", note=[Accessed: 01-December-2020 ]}


@online{reference.wolfram_2020_needlemanwunschsimilarity, organization={Wolfram Research}, title={NeedlemanWunschSimilarity}, year={2020}, url={}, note=[Accessed: 01-December-2020 ]}


Wolfram Language. 2008. "NeedlemanWunschSimilarity." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020.


Wolfram Language. (2008). NeedlemanWunschSimilarity. Wolfram Language & System Documentation Center. Retrieved from