Skip to content
A modification of MATLAB's nwalign function requiring linear (rather than quadratic) space
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Let sequences seq1 and seq2 have lengths n1 and n2 respectively, with n1<n2. To align these sequences, MATLAB's nwalign function requires O(n1.n2) space and O(n1.n2) time. nwalign2 requires O(n1) space and O(n1.n2) time.

nwalign2 takes the same input options as nwalign, and produces the same output. Note, however, that nwalign2 cannot produce the full score and path matrices for the alignment, as this would require O(n1.n2) space.

To use nwalign2, download nwalign2.m and simplegapmex2.cpp. In MATLAB, navigate to the folder where the files are located and run the command "mex simplegapmex2.cpp". Now use nwalign2 as you would nwalign.


  • nwalign2 is missing the 'ExtendGap' option from nwalign.
  • When the 'Glocal' option is chosen, nwalign2 sometimes produces a slightly different result to nwalign. This only occurs when attempting to perform unrealistically short or mismatched alignments.
You can’t perform that action at this time.