How do I make a CrossProductAlphabet such as a codon Alphabet? - Cookbook - BioSharp
CrossProductAlphabets result from the multiplication of other IAlphabets. CrossProductAlphabets are used to wrap up 2 or more Symbols into a single "cross product" ISymbol. For example using a 3 way cross of the DNA alphabet you could wrap a codon as a ISymbol. You could then count those codon ISymbols in a Count or you could used them in a Distribution.
CrossProductAlphabets can be created by name (if the component IAlphabets are registered in the AlphabetManager) or by making a list of the desired IAlphabets and creating the IAlphabet from the list. Both approaches are shown in the example below.
- using System;
- using BioSharp.Core.Utils;
- using BioSharp.Core.Bio.Symbol;
- using BioSharp.Core.Bio.Seq;
- namespace Cookbook.Alphabets
- {
- class CrossProduct
- {
- public static void Main(string[] args)
- {
- // Make a CrossProductAlphabet from a List
- EquatableList<IAlphabet> l = new EquatableList<IAlphabet>();
- l.Add(DNATools.DNA);
- l.Add(DNATools.DNA);
- l.Add(DNATools.DNA);
- IAlphabet codon = AlphabetManager.GetCrossProductAlphabet(l);
- // Get the same Alphabet by name
- IAlphabet codon2 = AlphabetManager.GenerateCrossProductAlphaFromName("(DNA x DNA x DNA)");
- // Show that the two Alphabets are canonical
- Console.WriteLine(codon == codon2);
- }
- }
- }