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 9aeaa24 commit c010595
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/beast/evolution/likelihood/MixtureTreeLikelihood.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public class MixtureTreeLikelihood extends TreeLikelihood {


@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
// sanity check: alignment should have same #taxa as tree
if (dataInput.get().getNrTaxa() != treeInput.get().getLeafNodeCount()) {
throw new Exception("The number of nodes in the tree does not match the number of sequences");
throw new IllegalArgumentException("The number of nodes in the tree does not match the number of sequences");
}
// No Beagle instance was found, so we use the good old java likelihood core
beagle = null;

int nodeCount = treeInput.get().getNodeCount();
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();
m_siteModel.setDataType(dataInput.get().getDataType());
Expand Down Expand Up @@ -92,7 +92,7 @@ public void initAndValidate() throws Exception {

/* Assumes there IS a branch rate model as opposed to traverse() */
@Override
int traverse(final Node node) throws Exception {
int traverse(final Node node) {

int update = (node.isDirty() | hasDirt);

Expand Down Expand Up @@ -139,7 +139,7 @@ int traverse(final Node node) throws Exception {
if (siteModel.integrateAcrossCategories()) {
mixtureLikelihoodCore.calculatePartials(childNum1, childNum2, iNode, classes);
} else {
throw new Exception("Error TreeLikelihood 201: Site categories not supported");
throw new IllegalArgumentException("Error TreeLikelihood 201: Site categories not supported");
//m_pLikelihoodCore->calculatePartials(childNum1, childNum2, nodeNum, siteCategories);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PartitionPositionLogger extends BEASTObject implements Loggable {
IntegerParameter partitionLengths;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
partitionLengths = partitionLengthsInput.get();
}

Expand Down
12 changes: 6 additions & 6 deletions src/beast/evolution/likelihood/PartitionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PartitionProvider extends CalculationNode implements StateNodeIniti
boolean needsInitilising = false;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
if (numPartitions.get() > 0) {
/** we have to wait to initialise till everything is parsed,
* so that the outputs of all plug-ins are properly set up */
Expand Down Expand Up @@ -203,7 +203,7 @@ public boolean delayInitialisation() {
* The StateNodeInitialiser interface can be abused for this purpose
*/
@Override
public void initStateNodes() throws Exception {
public void initStateNodes() {
System.err.println(Randomizer.getSeed());
PartitionedTreeLikelihood likelihood = null;
for (BEASTInterface plugin : getOutputs()) {
Expand All @@ -212,7 +212,7 @@ public void initStateNodes() throws Exception {
}
}
if (likelihood == null) {
throw new Exception("PartitionProvider must have PartitionedTreeLikelihood as output");
throw new IllegalArgumentException("PartitionProvider must have PartitionedTreeLikelihood as output");
}
SiteModel.Base siteModel = (SiteModel.Base) likelihood.siteModelInput.get();

Expand Down Expand Up @@ -255,7 +255,7 @@ public void initStateNodes() throws Exception {
initAndValidate();

Set<BEASTInterface> plugins = new HashSet<BEASTInterface>();
for (BEASTInterface plugin : mcmc.listActivePlugins()) {
for (BEASTInterface plugin : mcmc.listActiveBEASTObjects()) {
reinitialise(plugin, plugins);
}
//
Expand All @@ -267,8 +267,8 @@ public void initStateNodes() throws Exception {
// }
}

private void reinitialise(BEASTInterface plugin, Set<BEASTInterface> plugins) throws Exception {
for (BEASTInterface plugin2 : plugin.listActivePlugins()) {
private void reinitialise(BEASTInterface plugin, Set<BEASTInterface> plugins) {
for (BEASTInterface plugin2 : plugin.listActiveBEASTObjects()) {
if (!plugins.contains(plugin2)) {
plugins.add(plugin2);
reinitialise(plugin2, plugins);
Expand Down
6 changes: 3 additions & 3 deletions src/beast/evolution/likelihood/PartitionProviderByCodon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
public class PartitionProviderByCodon extends PartitionProvider {


public void initAndValidate() throws Exception {
public void initAndValidate() {
partitionLengths = partitionLengthsInput.get();
if (partitionLengths.getDimension() * 3 != m_pSiteModel.get().size()) {
throw new Exception("nr of site models must be 3 times nr of partitions defined trough partitionLengths");
throw new IllegalArgumentException("nr of site models must be 3 times nr of partitions defined trough partitionLengths");
}

siteCount = alignment.get().getSiteCount();
Expand All @@ -34,7 +34,7 @@ public void initAndValidate() throws Exception {
sum += partitionLengths.getValue(i);
}
if (sum * 3 != siteCount + (siteCount % 3 == 0? 0 : 3-siteCount % 3)) {
throw new Exception("nr of sites does not match partitions lengths (sum=" + sum + "*3 != siteCount=" + siteCount+")");
throw new IllegalArgumentException("nr of sites does not match partitions lengths (sum=" + sum + "*3 != siteCount=" + siteCount+")");
}

// weights = new int[patternIndicators.length][patternCount];
Expand Down
16 changes: 8 additions & 8 deletions src/beast/evolution/likelihood/PartitionedTreeLikelihood.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public PartitionedTreeLikelihood() {


@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
// sanity check: alignment should have same #taxa as tree
if (dataInput.get().getNrTaxa() != treeInput.get().getLeafNodeCount()) {
throw new Exception("The number of nodes in the tree does not match the number of sequences");
throw new IllegalArgumentException("The number of nodes in the tree does not match the number of sequences");
}
m_beagle = null;
// m_beagle = new BeagleTreeLikelihood();
Expand Down Expand Up @@ -293,7 +293,7 @@ void setPartials(int partition, Node node, int patternCount) {
int X = 100;

@Override
public double calculateLogP() throws Exception {
public double calculateLogP() {
if (m_beagle != null) {
logP = m_beagle.calculateLogP();
return logP;
Expand Down Expand Up @@ -342,7 +342,7 @@ public double calculateLogP() throws Exception {
return logP;
}

void calcLogP() throws Exception {
void calcLogP() {
logP = 0.0;
if (m_bAscertainedSitePatterns) {
for (int k = 0; k < partitionCount; k++) {
Expand Down Expand Up @@ -391,7 +391,7 @@ public void run() {

CountDownLatch m_nCountDown;

void threadedTraverse(Node root) throws Exception {
void threadedTraverse(Node root) {
try {
int nPatterns = m_fPatternLogLikelihoods.length;
if (partitionCount >= 1) {
Expand All @@ -407,7 +407,7 @@ void threadedTraverse(Node root) throws Exception {
traverse(iThread, partitionProvider.getPatternIndicators(iThread), root);
}
}
} catch (RejectedExecutionException e) {
} catch (RejectedExecutionException | InterruptedException e) {
System.err.println("Reducing nr of threads to 1 because " + e.getMessage());
// refresh thread pool
for (int iThread = 0; iThread < partitionCount; iThread++) {
Expand All @@ -418,7 +418,7 @@ void threadedTraverse(Node root) throws Exception {


/* Assumes there IS a branch rate model as opposed to traverse() */
int traverse(int partition, List<Integer> patternIndicator, Node node) throws Exception {
int traverse(int partition, List<Integer> patternIndicator, Node node) {

int update = (node.isDirty() | m_nHasDirt);

Expand Down Expand Up @@ -467,7 +467,7 @@ int traverse(int partition, List<Integer> patternIndicator, Node node) throws Ex
if (m_siteModel[partition].integrateAcrossCategories()) {
m_likelihoodCore[partition].calculatePartials(childNum1, childNum2, iNode, patternIndicator);
} else {
throw new Exception("Error TreeLikelihood 201: Site categories not supported");
throw new IllegalArgumentException("Error TreeLikelihood 201: Site categories not supported");
//m_pLikelihoodCore->calculatePartials(childNum1, childNum2, nodeNum, siteCategories);
}

Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/operators/FreeRateOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FreeRateOperator extends Operator {


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

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/operators/RBOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RBOperator extends Operator {
ParametricDistribution distr;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
rates = rateInput.get();
distr = new Exponential();
for (Object plugin : rates.getOutputs()) {
Expand Down
4 changes: 2 additions & 2 deletions src/beast/evolution/operators/RBScaleOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class RBScaleOperator extends ScaleOperator {
Parameter count;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
count = countInput.get();
if (treeInput.get() != null) {
throw new Exception("A parameter (not a tree) should not be specified");
throw new IllegalArgumentException("A parameter (not a tree) should not be specified");
}
super.initAndValidate();
}
Expand Down
4 changes: 2 additions & 2 deletions src/beast/evolution/sitemodel/FreeRateModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FreeRateModel extends SiteModel.Base {
RealParameter invarParameter;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
muParameter = muParameterInput.get();
if (muParameter == null) {
muParameter = new RealParameter("1.0");
Expand Down Expand Up @@ -62,7 +62,7 @@ public void initAndValidate() throws Exception {


if (/*invarParameter != null && */(invarParameter.getValue() < 0 || invarParameter.getValue() > 1)) {
throw new Exception("proportion invariant should be between 0 and 1");
throw new IllegalArgumentException("proportion invariant should be between 0 and 1");
}
refresh();

Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/sitemodel/MixtureSiteModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MixtureSiteModel extends DefaultMixtureSiteModel {
boolean [] isDirtySiteModel;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
components = componentInput.get();
weights = new double[components.size()];
updateWeights = true;
Expand Down
2 changes: 1 addition & 1 deletion src/beast/evolution/sitemodel/MixtureSubstModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MixtureSubstModel extends CalculationNode {
SubstitutionModel.Base substitutionModel;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
weight = weightInput.get();
rate = rateInput.get();
substitutionModel = substModelInput.get();
Expand Down
14 changes: 10 additions & 4 deletions src/beast/evolution/substitutionmodel/RB.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package beast.evolution.substitutionmodel;


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

import beast.core.Citation;
Expand All @@ -25,21 +26,26 @@ public class RB extends GeneralSubstitutionModel {
IntegerParameter m_count;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
m_count = m_countInput.get();
m_rate = ratesInput.get();
if (m_rate.getDimension() != 5) {
throw new Exception("rate input must have dimension 5");
throw new IllegalArgumentException("rate input must have dimension 5");
}

frequencies = frequenciesInput.get();
updateMatrix = true;
nrOfStates = frequencies.getFreqs().length;
if (nrOfStates != 4) {
throw new Exception("Frequencies has wrong size. Expected 4, but got " + nrOfStates);
throw new IllegalArgumentException("Frequencies has wrong size. Expected 4, but got " + nrOfStates);
}

eigenSystem = createEigenSystem();
try {
eigenSystem = createEigenSystem();
} catch (SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new IllegalArgumentException(e);
}
rateMatrix = new double[nrOfStates][nrOfStates];
relativeRates = new double[nrOfStates * (nrOfStates - 1)];
storedRelativeRates = new double[nrOfStates * (nrOfStates - 1)];
Expand Down
14 changes: 10 additions & 4 deletions src/beast/evolution/substitutionmodel/VS.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package beast.evolution.substitutionmodel;

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

import beast.core.Citation;
Expand All @@ -21,21 +22,26 @@ public class VS extends GeneralSubstitutionModel {
IntegerParameter count;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
count = countInput.get();
rate = ratesInput.get();
if (rate.getDimension() != 5) {
throw new Exception("rate input must have dimension 5");
throw new IllegalArgumentException("rate input must have dimension 5");
}

frequencies = frequenciesInput.get();
updateMatrix = true;
nrOfStates = frequencies.getFreqs().length;
if (nrOfStates != 4) {
throw new Exception("Frequencies has wrong size. Expected 4, but got " + nrOfStates);
throw new IllegalArgumentException("Frequencies has wrong size. Expected 4, but got " + nrOfStates);
}

eigenSystem = createEigenSystem();
try {
eigenSystem = createEigenSystem();
} catch (SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new IllegalArgumentException(e);
}
rateMatrix = new double[nrOfStates][nrOfStates];
relativeRates = new double[nrOfStates * (nrOfStates - 1)];
storedRelativeRates = new double[nrOfStates * (nrOfStates - 1)];
Expand Down
4 changes: 2 additions & 2 deletions src/beast/math/distributions/RBPrior.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class RBPrior extends Prior {
private Parameter counts;

@Override
public void initAndValidate() throws Exception {
public void initAndValidate() {
counts = countInput.get();
super.initAndValidate();
}

@Override
public double calculateLogP() throws Exception {
public double calculateLogP() {
Function x = m_x.get();
int dim = (int) counts.getArrayValue();
double fOffset = dist.offsetInput.get();
Expand Down

0 comments on commit c010595

Please sign in to comment.