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$
2
  • 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
    Commented Oct 22, 2015 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
    Commented Oct 22, 2015 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.