Main Links
Documentation
Source Code

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.

  1. using System;
  2. using BioSharp.Core.Utils;
  3. using BioSharp.Core.Bio.Symbol;
  4. using BioSharp.Core.Bio.Seq;
  5. namespace Cookbook.Alphabets
  6. {
  7. class CrossProduct
  8. {
  9. public static void Main(string[] args)
  10. {
  11. // Make a CrossProductAlphabet from a List
  12. EquatableList<IAlphabet> l = new EquatableList<IAlphabet>();
  13. l.Add(DNATools.DNA);
  14. l.Add(DNATools.DNA);
  15. l.Add(DNATools.DNA);
  16. IAlphabet codon = AlphabetManager.GetCrossProductAlphabet(l);
  17. // Get the same Alphabet by name
  18. IAlphabet codon2 = AlphabetManager.GenerateCrossProductAlphaFromName("(DNA x DNA x DNA)");
  19. // Show that the two Alphabets are canonical
  20. Console.WriteLine(codon == codon2);
  21. }
  22. }
  23. }