Package org.biojava.bio.dist
Class AbstractOrderNDistribution
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojava.bio.dist.AbstractDistribution
-
- org.biojava.bio.dist.AbstractOrderNDistribution
-
- All Implemented Interfaces:
Serializable
,Distribution
,OrderNDistribution
,Changeable
public abstract class AbstractOrderNDistribution extends AbstractDistribution implements OrderNDistribution, Serializable
Simple base class for OrderNDistributions.- Since:
- 1.2
- Author:
- Samiul Hasan, Matthew Pocock, Thomas Down
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.dist.Distribution
Distribution.NullModelForwarder
-
-
Field Summary
Fields Modifier and Type Field Description protected ChangeForwarder
weightForwarder
The listener that will forward events from the underlying distributions to listeners for this distribution.-
Fields inherited from class org.biojava.bio.dist.AbstractDistribution
nullModelForwarder
-
Fields inherited from interface org.biojava.bio.dist.Distribution
NULL_MODEL, WEIGHTS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractOrderNDistribution(Alphabet alpha)
Construct a new NthOrderDistribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Alphabet
getAlphabet()
The alphabet from which this spectrum emits symbols.protected ChangeSupport
getChangeSupport(ChangeType ct)
Called to retrieve the ChangeSupport for this object.Alphabet
getConditionedAlphabet()
Get the conditioned alphabet.Alphabet
getConditioningAlphabet()
Get the conditioning alphabet of this distribution.Distribution
getNullModel()
Retrieve the null model Distribution that this Distribution recognizes.protected double
getWeightImpl(AtomicSymbol sym)
Get a weight from one of the sub-distributions, conditioned on the first part of the symbol.void
registerWithTrainer(DistributionTrainerContext dtc)
Register an IgnoreCountsTrainer instance as the trainer for this distribution.void
setNullModelImpl(Distribution nullModel)
Implement this to set the null model.void
setWeightImpl(AtomicSymbol sym, double w)
Set a weight in one of the conditioned distributions.-
Methods inherited from class org.biojava.bio.dist.AbstractDistribution
equals, getWeight, hashCode, sampleSymbol, setNullModel, setWeight
-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Methods inherited from interface org.biojava.bio.dist.Distribution
getWeight, sampleSymbol, setNullModel, setWeight
-
Methods inherited from interface org.biojava.bio.dist.OrderNDistribution
conditionedDistributions, getDistribution, setDistribution
-
-
-
-
Field Detail
-
weightForwarder
protected transient ChangeForwarder weightForwarder
The listener that will forward events from the underlying distributions to listeners for this distribution.
-
-
Constructor Detail
-
AbstractOrderNDistribution
protected AbstractOrderNDistribution(Alphabet alpha) throws IllegalAlphabetException
Construct a new NthOrderDistribution.- Parameters:
alpha
- the Alpahbet this is over- Throws:
IllegalAlphabetException
-
-
Method Detail
-
getChangeSupport
protected ChangeSupport getChangeSupport(ChangeType ct)
Description copied from class:AbstractChangeable
Called to retrieve the ChangeSupport for this object.Your implementation of this method should have the following structure:
It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.ChangeSupport cs = super.getChangeSupport(ct); if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) { someForwarder = new ChangeForwarder(... this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange); } return cs;
- Overrides:
getChangeSupport
in classAbstractDistribution
-
getConditioningAlphabet
public Alphabet getConditioningAlphabet()
Get the conditioning alphabet of this distribution. If the `overall' alphabet is a cross-product of two alphabets, this will be the first of those alphabets. If it is a cross-product of more than two alphabets, the conditioning alphabet is the cross-product of all but the last alphabet.- Specified by:
getConditioningAlphabet
in interfaceOrderNDistribution
- Returns:
- the conditioning Alphabet
-
getConditionedAlphabet
public Alphabet getConditionedAlphabet()
Get the conditioned alphabet. This is the last alphabet in the distribution's overall cross-product. It will be the alphabet of all the sub-distributions contained within this OrderNDistribution.- Specified by:
getConditionedAlphabet
in interfaceOrderNDistribution
- Returns:
- the conditioned Alphabet
-
getAlphabet
public Alphabet getAlphabet()
Description copied from interface:Distribution
The alphabet from which this spectrum emits symbols.- Specified by:
getAlphabet
in interfaceDistribution
- Returns:
- the Alphabet associated with this spectrum
-
getWeightImpl
protected double getWeightImpl(AtomicSymbol sym) throws IllegalSymbolException
Get a weight from one of the sub-distributions, conditioned on the first part of the symbol.- Specified by:
getWeightImpl
in classAbstractDistribution
- Parameters:
sym
- the symbol to look up- Returns:
- the weight
- Throws:
IllegalSymbolException
- if sym is not recognised
-
setWeightImpl
public void setWeightImpl(AtomicSymbol sym, double w) throws IllegalSymbolException, ChangeVetoException
Set a weight in one of the conditioned distributions. It is the callers responsibility to ensure that all the conditioned distributions have total weights which sum to 1.0.- Specified by:
setWeightImpl
in classAbstractDistribution
- Parameters:
sym
- the symbol to set the weight forw
- the new weight- Throws:
IllegalSymbolException
- if the symbol is not knownChangeVetoException
- if the change is to be prevented
-
setNullModelImpl
public void setNullModelImpl(Distribution nullModel)
Description copied from class:AbstractDistribution
Implement this to set the null model.You should not inform any change listeners in this method. All of that work has been done for you.
- Specified by:
setNullModelImpl
in classAbstractDistribution
- Parameters:
nullModel
- the new null model Distribution
-
getNullModel
public Distribution getNullModel()
Description copied from interface:Distribution
Retrieve the null model Distribution that this Distribution recognizes.- Specified by:
getNullModel
in interfaceDistribution
- Returns:
- the apropriate null model
-
registerWithTrainer
public void registerWithTrainer(DistributionTrainerContext dtc)
Description copied from class:AbstractDistribution
Register an IgnoreCountsTrainer instance as the trainer for this distribution. Override this if you wish to implement a trainable distribution.- Specified by:
registerWithTrainer
in interfaceDistribution
- Overrides:
registerWithTrainer
in classAbstractDistribution
- Parameters:
dtc
- the context to register with
-
-