5
$\begingroup$

I am trying to use the SimilarityRules option of SequenceAlignment to customize its output. This works perfectly for strings, but I cannot get it to work for lists.

Compare the following outputs:

SequenceAlignment["abcba","abdcba"]
{"ab", {"", "d"}, "cba"}
SequenceAlignment[{a, b, c, b, a}, {a, b, d, c, b, a}]
{{a, b}, {{}, {d}}, {c, b, a}}
SequenceAlignment["abcba", "abdcba", 
  SimilarityRules -> {{a_, a_} -> 1, {a_, b_} -> -1}]
{"ab", {"", "d"}, "cba"}
SequenceAlignment[{a, b, c, b, a}, {a, b, d, c, b, a}, 
  SimilarityRules -> {{a_, a_} -> 1, {a_, b_} -> -1}]
SequenceAlignment[{a, b, c, b, a}, {a, b, d, c, b, a}, 
  SimilarityRules -> {{a_, a_} -> 1, {a_, b_} -> -1}]

So SequenceAlignment seems to work for lists, but not with the SimilarityRules option. Does anyone have a workaround for this?

$\endgroup$
  • 1
    $\begingroup$ I think you have got it right, and I can't see any work-around. SequenceAlignment given list arguments will accept SimilarityRules -> Automatic which makes me suspect it is checking for Automatic internally in this case. I would call this a documentation bug. The documentation totally fails to discuss SequenceAlignment with respect to list arguments, so we are left adrift where the issue you raise is concerned. What kind similarity rules were you thinking of using for lists? $\endgroup$ – m_goldberg Oct 22 '15 at 16:49
  • $\begingroup$ In my situation, I have two strings, a and b, where a was generated from b by removing some chunks. I want to align a to b. Therefore, my similarity rule would discount substitutions in favour of insertions, to get the best alignment. ({{a_, a_} -> 1, {a_, ""} -> -1, {a_, b_} -> -2}) I also use the option GapPenalty->1. This works for strings, but now I am trying to speed up by splitting the string into atomic parts (words), and putting those in lists. $\endgroup$ – Thijs Oct 22 '15 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.