VectorAlignments

Compare and align vectors with contents of any type: find longest common subsequence, shortest common supersequence, and align elements in parallel sequences.

Overview

using VectorAlignments

Longest common subsequence:

lcs("abc", "abd")
2-element Vector{Any}:
 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
 'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)

Shortest common supersequence:

scs("abc", "abd")
4-element Vector{Any}:
 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
 'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)
 'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)
 'd': ASCII/Unicode U+0064 (category Ll: Letter, lowercase)

Align elements in parallel sequences (return value is a Vector of Vectors):

align("abc", "abd")
2-element Vector{Any}:
 Any['a', 'b', 'c', nothing]
 Any['a', 'b', nothing, 'd']

Align elements in parallel sequences (return value is a two-dimensional matrix):

featurematrix("abc", "abd")
4×2 Matrix{Any}:
 'a'      'a'
 'b'      'b'
 'c'      nothing
 nothing  'd'

Types

The vectors to compare can contain elements of any type.

scs([1,3,5], [1,2,3])
4-element Vector{Any}:
 1
 2
 3
 5

Since strings are treated as vectors of characters, the return values of scs and lcs will be vectors of characters: you'll have to turn them into strings yourself if you want a String value.

scs("bc", "abc") |> join
"abc"