Wolfram Language

Core Language

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]:=
Click for copyable input
genes = RandomSample[GenomeData["ChromosomeYGenes"], 4]
Out[1]=

Group these genes by pairs.

In[2]:=
Click for copyable input
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]:=
Click for copyable input
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]:=
Click for copyable input
commonDNASubequence[pair[1]]
Out[4]=

Longest common subsequence of the second pair.

In[5]:=
Click for copyable input
commonDNASubequence[pair[2]]
Out[5]=

Longest common subsequence of the third pair.

In[6]:=
Click for copyable input
commonDNASubequence[pair[3]]
Out[6]=

Longest common subsequence of the fourth pair.

In[7]:=
Click for copyable input
commonDNASubequence[pair[4]]
Out[7]=

Longest common subsequence of the fifth pair.

In[8]:=
Click for copyable input
commonDNASubequence[pair[5]]
Out[8]=

Longest common subsequence of the sixth pair.

In[9]:=
Click for copyable input
commonDNASubequence[pair[6]]
Out[9]=

Related Examples

de es fr ja ko pt-br ru zh