LongestCommonSequencePositions

LongestCommonSequencePositions[s1,s2]

finds the longest sequence of contiguous or disjoint elements common to the strings, lists or biomolecular sequences s1 and s2 and returns their positions.

Details and Options

  • LongestCommonSequencePositions[s1,s2] returns an expression of the form {pos1,pos2} where the posi specify the positions of the longest common sequence in the strings or lists si.
  • For lists si, Take[si,posi] returns the longest common sequence. For strings si, StringTake[si,posi] returns the longest common contiguous or disjoint substring.
  • If there are several common sequences of the same length, LongestCommonSequencePositions returns the one that begins earliest in s1.
  • For strings, setting the option IgnoreCase->True makes LongestCommonSequencePositions treat lowercase and uppercase letters as equivalent, and returns the form of common sequence that occurs in s1.

Examples

open allclose all

Basic Examples  (3)

Find the longest noncontiguous sequence common to two strings:

Find the longest noncontiguous sequence common to two lists:

Find the longest noncontiguous sequence common to two biomolecular sequences:

Scope  (2)

Act on two strings:

Act on two lists of expressions:

Options  (1)

IgnoreCase  (1)

By default, LongestCommonSequencePositions distinguishes lower and upper case:

Ignore case:

Properties & Relations  (1)

Take two strings:

Find the positions of the longest common sequence of characters:

The corresponding strings coincide:

LongestCommonSequence returns those strings joined:

SequenceAlignment returns a complete representation of the common and uncommon parts:

Wolfram Research (2015), LongestCommonSequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html (updated 2020).

Text

Wolfram Research (2015), LongestCommonSequencePositions, Wolfram Language function, https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html (updated 2020).

CMS

Wolfram Language. 2015. "LongestCommonSequencePositions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html.

APA

Wolfram Language. (2015). LongestCommonSequencePositions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html

BibTeX

@misc{reference.wolfram_2024_longestcommonsequencepositions, author="Wolfram Research", title="{LongestCommonSequencePositions}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html}", note=[Accessed: 18-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_longestcommonsequencepositions, organization={Wolfram Research}, title={LongestCommonSequencePositions}, year={2020}, url={https://reference.wolfram.com/language/ref/LongestCommonSequencePositions.html}, note=[Accessed: 18-November-2024 ]}