Skip to content

Commit

Permalink
sync with beast2 exception overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Feb 22, 2016
1 parent 15b467e commit 04c0e63
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/beast/app/beauti/BeautiDiscreteTraitProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class BeautiDiscreteTraitProvider extends BeautiAlignmentProvider {

@Override
List<BEASTInterface> getAlignments(BeautiDoc doc) {
protected List<BEASTInterface> getAlignments(BeautiDoc doc) {
try {
List<String> trees = new ArrayList<String>();
doc.scrubAll(true, false);
Expand Down
2 changes: 1 addition & 1 deletion src/beast/app/beauti/BeautiLocationTraitProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class BeautiLocationTraitProvider extends BeautiAlignmentProvider {

@Override
List<BEASTInterface> getAlignments(BeautiDoc doc) {
protected List<BEASTInterface> getAlignments(BeautiDoc doc) {
try {
List<String> trees = new ArrayList<String>();
doc.scrubAll(true, false);
Expand Down
6 changes: 3 additions & 3 deletions src/beast/continuous/AbstractMultivariateTraitLikelihood.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public abstract class AbstractMultivariateTraitLikelihood extends GenericTreeLik
protected double[] m_StoredBranchLengths;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
//super.initAndValidate();
m_branchLengths = new double[0];
m_StoredBranchLengths = new double[0];
Expand Down Expand Up @@ -125,7 +125,7 @@ public void initAndValidate() throws Exception {
if (dataInput.get() instanceof AlignmentFromTraitMap) {
traitMap = ((AlignmentFromTraitMap) dataInput.get()).getTraitMap();
} else {
throw new Exception ("Expected that data input is AlignmentFromTraitMap");
throw new IllegalArgumentException ("Expected that data input is AlignmentFromTraitMap");
}
recalculateTreeLength();
// printInformtion();
Expand Down Expand Up @@ -492,7 +492,7 @@ public final double getLogLikelihood() {
}

@Override
public double calculateLogP() throws Exception {
public double calculateLogP() {
logP = getLogLikelihood();
return logP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public abstract class IntegratedMultivariateTraitLikelihood extends AbstractMult
// super(traitName, treeModel, diffusionModel, traitParameter, deltaParameter, missingIndices, cacheBranches, scaleByTime,
// useTreeLength, rateModel, driftModels, samplingDensity, reportAsMultivariate, reciprocalRates);

public void initAndValidate() throws Exception {
public void initAndValidate() {
super.initAndValidate();

// Delegate caches to helper
Expand Down
4 changes: 2 additions & 2 deletions src/beast/continuous/MultivariateDiffusionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class MultivariateDiffusionModel extends ContinuousSubstitutionModel {
int dimension;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
//diffusionPrecisionMatrix =
this.diffusionPrecisionMatrixParameter = diffusionPrecisionMatrixInput.get();
dimension = (int) Math.sqrt(diffusionPrecisionMatrixParameter.getDimension());
if (dimension * dimension != diffusionPrecisionMatrixParameter.getDimension()) {
throw new Exception ("Dimension of diffusion matrix should be a square");
throw new IllegalArgumentException ("Dimension of diffusion matrix should be a square");
}
calculatePrecisionInfo();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SampledMultivariateTraitLikelihood extends AbstractMultivariateTrai
public Input<Boolean> initFromTree = new Input<Boolean>("initFromTree","initiliase initial state from tree", false);

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
super.initAndValidate();
if (initFromTree.get()) {
Node [] nodes = treeModel.getNodesAsArray();
Expand Down
13 changes: 9 additions & 4 deletions src/beast/evolution/alignment/AlignmentFromTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AlignmentFromTrait() {
}

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
traitSet = traitInput.get();
patternIndex = new int[0];
counts = new ArrayList<List<Integer>>();
Expand All @@ -37,12 +37,17 @@ public void initAndValidate() throws Exception {
m_dataType = userDataTypeInput.get();
} else {
if (types.indexOf(dataTypeInput.get()) < 0) {
throw new Exception("data type + '" + dataTypeInput.get() + "' cannot be found. " +
throw new IllegalArgumentException("data type + '" + dataTypeInput.get() + "' cannot be found. " +
"Choose one of " + Arrays.toString(types.toArray(new String[0])));
}
List<String> sDataTypes = AddOnManager.find(beast.evolution.datatype.DataType.class, IMPLEMENTATION_DIR);
for (String sDataType : sDataTypes) {
DataType dataType = (DataType) Class.forName(sDataType).newInstance();
DataType dataType = null;
try {
dataType = (DataType) Class.forName(sDataType).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
if (dataTypeInput.get().equals(dataType.getTypeDescription())) {
m_dataType = dataType;
break;
Expand All @@ -61,7 +66,7 @@ public void initAndValidate() throws Exception {
for (int i = 0; i < taxaNames.size(); i++) {
String sValue = traitSet.getStringValue(i);
if (sValue == null) {
throw new Exception("Trait not specified for " + i);
throw new IllegalArgumentException("Trait not specified for " + i);
}
List<Integer> iStates = m_dataType.string2state(sValue);
counts.add(iStates);
Expand Down
4 changes: 2 additions & 2 deletions src/beast/evolution/alignment/AlignmentFromTraitMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AlignmentFromTraitMap() {
}

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
traitMap = traitInput.get();
patternIndex = new int[0];
counts = new ArrayList<List<Integer>>();
Expand All @@ -36,7 +36,7 @@ public void initAndValidate() throws Exception {
}
m_dataType = userDataTypeInput.get();
if (!(m_dataType instanceof ContinuousDataType)) {
throw new Exception("Data type must be a ContinuousDataType, not " + m_dataType.getClass().getName());
throw new IllegalArgumentException("Data type must be a ContinuousDataType, not " + m_dataType.getClass().getName());
}

taxaNames = new ArrayList<String>();
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/datatype/ContinuousDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public int getStateCount() {
}

@Override
public List<Integer> string2state(String sSequence) throws Exception {
public List<Integer> string2state(String sSequence) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/datatype/LocationDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class LocationDataType extends ContinuousDataType {

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
// nothing to do
}

Expand Down
10 changes: 5 additions & 5 deletions src/beast/evolution/likelihood/AncestralStateTreeLikelihood.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class AncestralStateTreeLikelihood extends TreeLikelihood implements Tree
int[][] tipStates; // used to store tip states when using beagle

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
if (dataInput.get().getSiteCount() == 0) {
return;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public String getTraitString(TreeInterface tree, Node node) {
// }
if (beagle != null) {
if (!(siteModelInput.get() instanceof SiteModel.Base)) {
throw new Exception ("siteModel input should be of type SiteModel.Base");
throw new IllegalArgumentException ("siteModel input should be of type SiteModel.Base");
}
m_siteModel = (SiteModel.Base) siteModelInput.get();
substitutionModel = (SubstitutionModel.Base) m_siteModel.substModelInput.get();
Expand Down Expand Up @@ -179,7 +179,7 @@ public String getTraitString(TreeInterface tree, Node node) {
parameters[i] = leafTrait.parameter.get();
// sanity check
if (parameters[i].getDimension() != traitDimension) {
throw new Exception("Expected parameter dimension to be " + traitDimension + ", not "
throw new IllegalArgumentException("Expected parameter dimension to be " + traitDimension + ", not "
+ parameters[i].getDimension());
}
// identify node
Expand All @@ -191,7 +191,7 @@ public String getTraitString(TreeInterface tree, Node node) {
leafNr[i] = k;
// sanity check
if (k == taxaNames.size()) {
throw new Exception("Could not find taxon '" + taxon + "' in tree");
throw new IllegalArgumentException("Could not find taxon '" + taxon + "' in tree");
}
// initialise parameter value from states
Integer[] values = new Integer[tipStates[k].length];
Expand Down Expand Up @@ -334,7 +334,7 @@ public void redrawAncestralStates() {


@Override
public double calculateLogP() throws Exception {
public double calculateLogP() {
areStatesRedrawn = false;
double marginalLogLikelihood = super.calculateLogP();
if (returnMarginalLogLikelihood) {
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/likelihood/LeafTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class LeafTrait extends CalculationNode {
public Input<String> taxonName = new Input<String>("taxon", "taxon name identifying the leaf", Validate.REQUIRED);
public Input<IntegerParameter> parameter = new Input<IntegerParameter>("parameter", "parameter associated with the leaf", Validate.REQUIRED);

public void initAndValidate() throws Exception {
public void initAndValidate() {
// nothing to do
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class GMRFSkyrideBlockUpdateOperator extends Operator {
private double[] zeros;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
gmrfField = GMRFSkyrideLikelihoodInput .get();
popSizeParameter = gmrfField.getPopSizeParameter();
precisionParameter = gmrfField.getPrecisionParameter();
Expand Down Expand Up @@ -385,7 +385,7 @@ public void optimize(double logAlpha) {
}

@Override
public List<StateNode> listStateNodes() throws Exception {
public List<StateNode> listStateNodes() {
List<StateNode> list = new ArrayList<StateNode>();
list.add(precisionParameter);
if (lambdaParameter.isEstimatedInput.get()) {
Expand Down
6 changes: 3 additions & 3 deletions src/beast/evolution/operators/GeneralIntegerOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GeneralIntegerOperator extends Operator {
IntegerParameter parameter;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
howMany = howManyyInput.get();

parameter = parameterInput.get();
Expand Down Expand Up @@ -61,7 +61,7 @@ public void initAndValidate() throws Exception {
RealParameter probsParam = probsInput.get();
IntegerParameter indexParam = indexInput.get();
if (probsParam.getDimension() != indexParam.getDimension()) {
throw new Exception("probs and index must be of the same length");
throw new IllegalArgumentException("probs and index must be of the same length");
}
Integer [] indices = indexParam.getValues();
int max = 0;
Expand All @@ -80,7 +80,7 @@ public void initAndValidate() throws Exception {
sum += f;
}
if (Math.abs(sum - 1.0) > 1e-6) {
throw new Exception("Probabilities must sum to one (instead of " + sum + ")");
throw new IllegalArgumentException("Probabilities must sum to one (instead of " + sum + ")");
}

// convert to cumulative pdf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class PrecisionMatrixGibbsOperator extends Operator {
TreeTraitMap traitMap;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
traitMap = mapInput.get();
treeModel = treeInput.get();
precisionParam = precisionParamInput.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class RegressionGibbsEffectOperator extends Operator {
private double[][] precision = null;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
this.linearModel = linearModelInput.get();
this.effect = effectInput.get();
this.indicators = indicatorsInput.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RegressionGibbsPrecisionOperator extends Operator {
private Gamma prior;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
//if (!(prior instanceof GammaDistribution))
// throw new RuntimeException("Precision prior must be Gamma");
this.prior = priorInput.get();
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/operators/SphereRandomWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SphereRandomWalker extends Operator {
boolean optimise = false;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
location = locationInput.get();
windowSize = windowSizeInput.get();
range = 1 + location.getDimension()/2;
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/operators/TraitGibbsOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class TraitGibbsOperator extends Operator {
TreeTraitMap traitMap;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
traitMap = mapInput.get();

this.traitModel = traitModelInput.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@



import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

import beast.core.Function;
Expand Down Expand Up @@ -36,14 +37,14 @@ public class SVSGeneralSubstitutionModel extends GeneralSubstitutionModel implem
private BooleanParameter rateIndicator;

@Override
public void initAndValidate() throws Exception{
public void initAndValidate(){

frequencies = frequenciesInput.get();

updateMatrix = true;
nrOfStates = frequencies.getFreqs().length;
if (isSymmetricInput.get() && ratesInput.get().getDimension() != nrOfStates * (nrOfStates-1)/2) {
throw new Exception("Dimension of input 'rates' is " + ratesInput.get().getDimension() + " but a " +
throw new IllegalArgumentException("Dimension of input 'rates' is " + ratesInput.get().getDimension() + " but a " +
"rate matrix of dimension " + nrOfStates + "x" + (nrOfStates -1) + "/2" + "=" + nrOfStates * (nrOfStates -1) / 2 + " was " +
"expected");
}
Expand All @@ -62,7 +63,12 @@ public void initAndValidate() throws Exception{
Log.warning.println("WARNING: eigenSystemClass is DefautlEigneSystem, which may cause trouble with asymtric analysis. "
+ "You may want to consider eigensystem='beast.evolution.substitutionmodel.RobustEigenSystem' instead.");
}
eigenSystem = createEigenSystem();
try {
eigenSystem = createEigenSystem();
} catch (SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new IllegalArgumentException(e);
}

// if (robust.get()){
// eigenSystem = new RobustEigenSystem(m_nStates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SVSGeneralSubstitutionModelLogger extends BEASTObject implements Lo
public SVSGeneralSubstitutionModelLogger() { }

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
model = modelInput.get();
}

Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/tree/RootTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RootTrait extends CalculationNode implements Function, Loggable {
RealParameter parameter;
int dim;

public void initAndValidate() throws Exception {
public void initAndValidate() {
map = mapInput.get();
tree = map.tree;
parameter = map.parameterInput.get();
Expand Down
8 changes: 4 additions & 4 deletions src/beast/evolution/tree/TreeTraitMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TreeTraitMap extends CalculationNode implements TreeTrait<double[]>

double [] traitvalues;
@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
tree = treeInput.get();
int nNodes = tree.getNodeCount();
parameter = parameterInput.get();
Expand Down Expand Up @@ -111,12 +111,12 @@ public void initAndValidate() throws Exception {
}
String[] sStrs = sTrait.split("=");
if (sStrs.length != 2) {
throw new Exception("could not parse trait: " + sTrait);
throw new IllegalArgumentException("could not parse trait: " + sTrait);
}
String sTaxonID = normalize(sStrs[0]);
int iTaxon = sTaxa.indexOf(sTaxonID);
if (iTaxon < 0) {
throw new Exception("Trait (" + sTaxonID + ") is not a known taxon. Spelling error perhaps?");
throw new IllegalArgumentException("Trait (" + sTaxonID + ") is not a known taxon. Spelling error perhaps?");
}
String sTraitValue = normalize(sStrs[1]);
String [] sTraitValues = sTraitValue.split("\\s");
Expand All @@ -129,7 +129,7 @@ public void initAndValidate() throws Exception {
}
}
if (bDone[iTaxon]) {
throw new Exception("Trait for taxon " + sTaxa.get(iTaxon)+ " defined twice");
throw new IllegalArgumentException("Trait for taxon " + sTaxa.get(iTaxon)+ " defined twice");
}
bDone[iTaxon] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/tree/TreeTraitProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public TreeTrait<?> getTreeTrait(String key) {
private Map<String, TreeTrait<?>> traits = new HashMap<String, TreeTrait<?>>();

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
// nothing to do
}
}
Expand Down
Loading

0 comments on commit 04c0e63

Please sign in to comment.