start from where and are
the last indices in 1st and 2nd dimension for NW
the indices for the matrix with the maximum score in SW
Check the score from
(cell to the left), a gap score
(cell above), a gap score
(cell from diagonal), a match or mismatch
If any match your current cell, push correct characters to alignments
push gap to seq1
, character at to seq2
push character at to seq1
, gap to seq2
push character at to seq1
, character at to =seq2=
update indices
Be mindful of what happens when you hit the first row or first column
or may throw bounds error
When should your loop stop?
It will be different for Needleman-Wunsch than for Smith-Waterman
@testset "Lab07" begin
@test nwalign("AATTGGCC", "AATTTGCC") == ("AATTGGCC", "AATTTGCC")
@test any(aln -> aln == nwalign("AATTGGCC", "AAGGTTCC"), [
("AA--TTGGCC", "AAGGTT--CC"),
("AATTGGCC", "AAGGTTCC")])
@test nwalign("AATTGGCC", "AAGGTTCC", gap=-2) == ("AATTGGCC", "AAGGTTCC")
@test nwalign("AATTGGCC", "AAGGTTCC", mismatch=-2) == ("AA--TTGGCC", "AAGGTT--CC")
@test swalign("AAT", "AA") == ("AA", "AA")
@test swalign("AAAAATTGGCCAAAAA", "ATTGGCCA") == ("ATTGGCCA", "ATTGGCCA")
@test swalign("AAAAATTGGCCAAAAA", "ATTGGCAAA") == ("ATTGGCCAAA", "ATTGGC-AAA")
end