BioJava:Cookbook:Alphabets:CrossProduct

How do I make a CrossProductAlphabet such as a codon Alphabet

CrossProductAlphabets result from the multiplication of other Alphabets. CrossProductAlphabets are used to wrap up 2 or more Symbolsinto a single “cross product” Symbol. For example using a 3 way cross of the DNA alphabet you could wrap a codon as a Symbol. You could then count those codon Symbols in a Count or you could used them in a Distribution.

CrossProductAlphabets can be created by name (if the component Alphabets are registered in the AlphabetManager) or by making a list of the desired Alphabets and creating the Alphabet from the List. Both approaches are shown in the example below.

```java package biojava_in_anger;

import java.util.*; import org.biojava.bio.seq.*; import org.biojava.bio.symbol.*;

public class CrossProduct {

 public static void main(String[] args) {

   //make a CrossProductAlphabet from a List
   List l = Collections.nCopies(3, DNATools.getDNA());
   Alphabet codon = AlphabetManager.getCrossProductAlphabet(l);

   //get the same Alphabet by name
   Alphabet codon2 =
       AlphabetManager.generateCrossProductAlphaFromName("(DNA x DNA x DNA)");

   //show that the two Alphabets are canonical
   System.out.println(codon == codon2);
 }

} ```