# Wolfram Mathematica

## Common DNA Subsequence of Genes

The Version 7 functions LongestCommonSequence and LongestCommonSubsequence are now supplemented by their positional counterparts LongestCommonSequencePositions and LongestCommonSubsequencePositions.

Compare the DNA sequences of random genes of the Y chromosome.

In:= `genes = RandomSample[GenomeData["ChromosomeYGenes"], 4]`
Out= Group these genes by pairs.

In:= ```With[{subsets = Subsets[genes, {2}]}, Table[pair[i] = subsets[[i]], {i, 1, Length[subsets]}]];```

Define a function that will get the positions of the longest continuous DNA sequence common to each pair, together with the sequence itself.

In:= ```commonDNASubequence[{g1_, g2_}] := With[{d1 = GenomeData[g1], d2 = GenomeData[g2]}, {{g1, g2}, LongestCommonSubsequencePositions[d1, d2], LongestCommonSubsequence[d1, d2]}]```

Longest common subsequence of the first pair.

In:= `commonDNASubequence[pair]`
Out= Longest common subsequence of the second pair.

In:= `commonDNASubequence[pair]`
Out= Longest common subsequence of the third pair.

In:= `commonDNASubequence[pair]`
Out= Longest common subsequence of the fourth pair.

In:= `commonDNASubequence[pair]`
Out= Longest common subsequence of the fifth pair.

In:= `commonDNASubequence[pair]`
Out= Longest common subsequence of the sixth pair.

In:= `commonDNASubequence[pair]`
Out= 