package org.biojava.bio.symbol;

import java.util.*;

import org.biojava.utils.*;
import org.biojava.bio.seq.*;
  
public class DNAAmbPack
  implements
    Packing,
    java.io.Serializable
{
  private final Symbol[] syms;
  
  public DNAAmbPack() {
    this.syms = new Symbol[16];
    for(byte i = 0; i < 16; i++) {
      syms[i] = _unpack(i);
    }
  }
  
  public FiniteAlphabet getAlphabet() {
    return DNATools.getDNA();
  }
  
  public byte pack(Symbol sym) {
    if(false) {
    } else if(sym == DNATools.a()) {
      return 1;
    } else if(sym == DNATools.g()) {
      return 2;
    } else if(sym == DNATools.c()) {
      return 4;
    } else if(sym == DNATools.t()) {
      return 8;
    } else if(sym == DNATools.n()) {
      return 15;
    }
    
    byte p = 0;
    for(Iterator i = DNATools.getDNA().iterator(); i.hasNext(); ) {
      p |= pack((AtomicSymbol) i.next());
    }
    return p;
  }
  
  public Symbol unpack(byte b) {
    return syms[b];
  }
  
  private Symbol _unpack(byte b) {
    Set syms = new SmallSet();
/*    if(false) {
    } else if(0 != (b & 1)) {
      syms.add(DNATools.a());
    } else if(0 != (b & 2)) {
      syms.add(DNATools.g());
    } else if(0 != (b & 4)) {
      syms.add(DNATools.c());
    } else if(0 != (b & 8)) {
      syms.add(DNATools.t());
    }*/
    if(0 != (b & 1)) {
      syms.add(DNATools.a());
    }
    if(0 != (b & 2)) {
      syms.add(DNATools.g());
    }
    if(0 != (b & 4)) {
      syms.add(DNATools.c());
    }
    if(0 != (b & 8)) {
      syms.add(DNATools.t());
    }
    try {
      return DNATools.getDNA().getAmbiguity(syms);
    } catch (IllegalSymbolException ise) {
      throw new NestedError(ise, "Assertion failure: couldn't get DNA ambiguity from DNA: " + syms);
    }
  }
  
  public byte wordSize() {
    return 4;
  }
  
  public boolean handlesAmbiguity() {
    return true;
  }
}


@@ -1,116 +1,849 @@
-package org.biojava.bio.symbol;%0A%0Aimport java.util.*;%0A%0Aimport org.biojava.utils.*;%0Aimport org.biojava.bio.seq.*;%0A
+/*%0A *                    BioJava development code%0A *%0A * This code may be freely distributed and modified under the%0A * terms of the GNU Lesser General Public Licence.  This should%0A * be distributed with the code.  If you do not have a copy,%0A * see:%0A *%0A *      http://www.gnu.org/copyleft/lesser.html%0A *%0A * Copyright for this code is held jointly by the individual%0A * authors.  These should be listed in @author doc comments.%0A *%0A * For more information on the BioJava project and its aims,%0A * or to join the biojava-l mailing list, visit the home page%0A * at:%0A *%0A *      http://www.biojava.org/%0A *%0A */%0A%0Apackage org.biojava.bio.symbol;%0A%0Aimport java.util.*;%0A%0Aimport org.biojava.utils.*;%0Aimport org.biojava.bio.seq.*;%0A%0A/**%0A * Packing utility class for DNA.  Also represents%0A * ambiguity.%0A *%0A * @author Matthew Pocock%0A * @author David Huen (bugfix)%0A */
   %0Ap
@@ -1770,274 +1770,8 @@
 ();%0A
-/*    if(false) %7B%0A    %7D else if(0 != (b & 1)) %7B%0A      syms.add(DNATools.a());%0A    %7D else if(0 != (b & 2)) %7B%0A      syms.add(DNATools.g());%0A    %7D else if(0 != (b & 4)) %7B%0A      syms.add(DNATools.c());%0A    %7D else if(0 != (b & 8)) %7B%0A      syms.add(DNATools.t());%0A    %7D*/%0A
     

add boilerplate and clean up