Main Links
Documentation
Source Code

How do I make a CrossProductAlphabet such as a codon Alphabet? - Cookbook - BioSharp

CrossProductAlphabets are used to represent groups of Symbols as a single Symbol. This is very useful for treating things like codons as single Symbols. Sometimes however, you might want to covert the Symbols back into their component Symbols. The following recipe demonstrates how this can be done.

The Symbols from a CrossProductAlphabet are implementations of the AtomicSymbol interface. The prefix 'Atomic' suggests that the Symbols cannot be divided so one might ask, 'how can an indivisible Symbol be divided into it's component parts?'. The full definition of the AtomicSymbol is that it cannot be divided into a simpler Symbol that is still part of the same Alphabet. The component parts of an AtomicSymbol from a CrossProductAlphabet are not members of the same Alphabet so the 'Atomic' definition still stands. A codon would be from the (DNA x DNA x DNA) Alphabet whereas the components of the codon Symbol are from the DNA alphabet.

Contrast this with the definition of a BasisSymbol. A BasisSymbol can be validly divided into components that are still part of the same Alphabet. In this way a BasisSymbol can be ambiguous. For further discussion of BasisSymbol follow this link.

  1. using System;
  2. using System.Collections.Generic;
  3. using BioSharp.Core.Utils;
  4. using BioSharp.Core.Bio.Symbol;
  5. using BioSharp.Core.Bio.Seq;
  6. namespace Cookbook.Alphabets
  7. {
  8. class BreakingComponents
  9. {
  10. public static void Main(string[] args)
  11. {
  12. // Make the 'codon' alphabet
  13. EquatableList<IAlphabet> l = new EquatableList<IAlphabet>();
  14. l.Add(DNATools.DNA);
  15. l.Add(DNATools.DNA);
  16. l.Add(DNATools.DNA);
  17. IAlphabet alpha = AlphabetManager.GetCrossProductAlphabet(l);
  18. // Get the first symbol in the alphabet
  19. IEnumerator<ISymbol> iter = ((IFiniteAlphabet)alpha).GetEnumerator();
  20. iter.MoveNext();
  21. IAtomicSymbol codon = (IAtomicSymbol)iter.Current;
  22. Console.Write(codon.Name + " is made of:");
  23. // List out its components
  24. foreach (ISymbol sym in codon.Symbols)
  25. {
  26. Console.Write(" " + sym.Name);
  27. }
  28. Console.WriteLine();
  29. }
  30. }
  31. }