finds an optimal alignment of sequences of elements in the strings or lists s1 and s2, and yields a list of successive matching and differing sequences.

Details and Options

  • SequenceAlignment[s1,s2] gives a list of the form {seg1,seg2,} where each segi is either a single string or sequence of list elements u, representing a matching segment, or a pair {u1,u2}, representing segments that differ between the si.
  • SequenceAlignment by default finds a global NeedlemanWunsch alignment of the complete strings or lists s1 and s2.
  • With the option setting Method->"Local", it finds a local SmithWaterman alignment.
  • For sufficiently similar strings or lists, local and global alignment methods give the same result.
  • The following options can be given:
  • GapPenalty0additional cost for each alignment gap
    IgnoreCaseFalsewhether to ignore case of letters in strings
    MergeDifferencesTruewhether to combine adjacent differences
    Method"Global"alignment algorithm to be used
    SimilarityRulesAutomaticrules for similarities between elements
  • SequenceAlignment attempts to find an alignment that maximizes the total similarity score.
  • With the default setting SimilarityRules->Automatic, each match between two elements contributes 1 to the total similarity score, while each mismatch, insertion, or deletion contributes -1.
  • Various named similarity matrices are supported, as specified in the notes for SimilarityRules.


open all close all

Basic Examples  (2)

Globally align two similar strings:

Click for copyable input

Global alignment of two strings:

Click for copyable input

Local alignment of the same strings:

Click for copyable input

Options  (3)

Applications  (2)

Introduced in 2008