# 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[1]:=
`genes = RandomSample[GenomeData["ChromosomeYGenes"], 4]`
Out[1]=

Group these genes by pairs.

In[2]:=
```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[3]:=
```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[4]:=
`commonDNASubequence[pair[1]]`
Out[4]=

Longest common subsequence of the second pair.

In[5]:=
`commonDNASubequence[pair[2]]`
Out[5]=

Longest common subsequence of the third pair.

In[6]:=
`commonDNASubequence[pair[3]]`
Out[6]=

Longest common subsequence of the fourth pair.

In[7]:=
`commonDNASubequence[pair[4]]`
Out[7]=

Longest common subsequence of the fifth pair.

In[8]:=
`commonDNASubequence[pair[5]]`
Out[8]=

Longest common subsequence of the sixth pair.

In[9]:=
`commonDNASubequence[pair[6]]`
Out[9]=