001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022
023package org.biojava.bio.dist;
024
025import java.io.Serializable;
026
027import org.biojava.bio.symbol.Alphabet;
028import org.biojava.bio.symbol.IllegalAlphabetException;
029import org.biojava.bio.symbol.IllegalSymbolException;
030import org.biojava.bio.symbol.Symbol;
031import org.biojava.utils.ChangeVetoException;
032import org.biojava.utils.Unchangeable;
033
034/**
035 * This distribution emits gap symbols.
036 * <p>
037 * It is a useful thing to have around for pair-wise alignment, as you can
038 * build a PairDistribution that emits gaps in one sequence and Symbols in the
039 * other. The GapDistriution will always emit with a probability of 1, as every
040 * symbol has a matches alphabet that contains the empty set. Or is this so?
041 *
042 * @author Matthew Pocock
043 * @since 1.0
044 */
045public class GapDistribution
046  extends
047    Unchangeable
048  implements
049    Distribution,
050    Serializable
051{
052  private final Alphabet alpha;
053    private static final long serialVersionUID = 88622317;
054    
055  public double getWeight(Symbol sym) throws IllegalSymbolException {
056    return 1.0;
057  }
058
059  public void setWeight(Symbol s, double w) throws IllegalSymbolException,
060  UnsupportedOperationException {
061    getAlphabet().validate(s);
062    throw new UnsupportedOperationException(
063      "The weights are immutable: " + s.getName() + " -> " + w
064    );
065  }
066
067  public Alphabet getAlphabet() {
068    return alpha;
069  }
070    
071  public Symbol sampleSymbol() {
072    return getAlphabet().getGapSymbol();
073  }
074  
075  public Distribution getNullModel() {
076    return this;
077  }
078
079  public void setNullModel(Distribution nullModel)
080  throws IllegalAlphabetException, ChangeVetoException {
081    throw new ChangeVetoException("Can't change null model for GapDistribution");
082  }
083  
084  public void registerWithTrainer(DistributionTrainerContext dtc) {
085    dtc.registerTrainer(this, IgnoreCountsTrainer.getInstance());
086  }
087
088  /**
089   * Get a GapDistribution for an alphabet.
090   *
091   * @param alpha  the Alphabet that this distribution is over
092   */
093  public GapDistribution(Alphabet alpha) {
094    this.alpha = alpha;
095  }
096}
097  
098