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.AtomicSymbol;
029import org.biojava.bio.symbol.FiniteAlphabet;
030import org.biojava.bio.symbol.IllegalAlphabetException;
031import org.biojava.bio.symbol.IllegalSymbolException;
032import org.biojava.utils.ChangeVetoException;
033
034/**
035 * An implementation of an uniform distribution
036 * @serial WARNING serialized versions of this class may be incompatible with future versions of BioJava
037 * @author Matthew Pocock
038 * @author Mark Schreiber
039 * @author Thomas Down
040 * @since 1.0
041 */
042
043public class UniformDistribution
044  extends
045    AbstractDistribution
046  implements
047    Serializable
048{
049  private final FiniteAlphabet alphabet;
050  private Distribution nullModel;
051  private static final long serialVersionUID = 88454038;
052
053  public Alphabet getAlphabet() {
054    return alphabet;
055  }
056
057  public Distribution getNullModel() {
058    return nullModel;
059  }
060
061  /**
062   * Assign a background distribution.
063   *
064   * @param nullModel the background distribution to assign
065   * @throws IllegalAlphabetException if nullModel is over an incompattible
066   *    alphabet
067   */
068  protected void setNullModelImpl(Distribution nullModel)
069  throws IllegalAlphabetException {
070    this.nullModel = nullModel;
071  }
072
073  protected double getWeightImpl(AtomicSymbol s)
074  throws IllegalSymbolException {
075    return (1.0 / alphabet.size());
076  }
077
078  protected void setWeightImpl(AtomicSymbol sym, double weight)
079  throws ChangeVetoException {
080    throw new ChangeVetoException(
081      "Can't change the weights in a UniformDistribution"
082    );
083  }
084
085  public void registerWithTrainer(DistributionTrainerContext dtc) {
086    dtc.registerTrainer(this, IgnoreCountsTrainer.getInstance());
087  }
088
089  /**
090   * Create a new UniformDistribution.
091   *
092   * @param alphabet  the finite alphabet to be over
093   */
094  public UniformDistribution(FiniteAlphabet alphabet) {
095    this.alphabet = alphabet;
096    this.nullModel = this;
097  }
098}