VBA for comparing sequences of characters.
Actually, the code that I've already written is the following, and it
works really good :-)
The only thing that is missing is the code to rewrite sequence1 in the
same cell but with the characters different from sequence2 in
bold/underlined/whatever :-)
Function SEQALIGN(sequence1 As String, sequence2 As String) As String
'It gives the consensus sequence comparing two different starting
sequences
'The repeated characters are shown as "-"
'The characters which are different in the second sequence compared
to the first one are listed
Dim length1 As Integer
Dim length2 As Integer
Dim i As Integer
Dim finalresult As String
Dim letter As String
length1 = Len(sequence1)
length2 = Len(sequence2)
If length1 < length2 Then
MsgBox "ERROR! The two sequences MUST have the same length.
Check and make corrections."
End If
finalresult = letter
For i = 1 To length1
letter = IIf(Mid(sequence1, i, 1) = Mid(sequence2, i, 1), "-",
Mid(sequence2, i, 1))
finalresult = finalresult + letter
Next i
SEQALIGN = finalresult
'By Antonio Riva - 2006
End Function
|