diff --git a/src/beast/evolution/likelihood/MixtureTreeLikelihood.java b/src/beast/evolution/likelihood/MixtureTreeLikelihood.java index 8c4688c..e3ba0fc 100644 --- a/src/beast/evolution/likelihood/MixtureTreeLikelihood.java +++ b/src/beast/evolution/likelihood/MixtureTreeLikelihood.java @@ -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()); @@ -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); @@ -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); } diff --git a/src/beast/evolution/likelihood/PartitionPositionLogger.java b/src/beast/evolution/likelihood/PartitionPositionLogger.java index 03c0ffc..3add413 100644 --- a/src/beast/evolution/likelihood/PartitionPositionLogger.java +++ b/src/beast/evolution/likelihood/PartitionPositionLogger.java @@ -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(); } diff --git a/src/beast/evolution/likelihood/PartitionProvider.java b/src/beast/evolution/likelihood/PartitionProvider.java index 3c9effc..267c370 100644 --- a/src/beast/evolution/likelihood/PartitionProvider.java +++ b/src/beast/evolution/likelihood/PartitionProvider.java @@ -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 */ @@ -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()) { @@ -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(); @@ -255,7 +255,7 @@ public void initStateNodes() throws Exception { initAndValidate(); Set plugins = new HashSet(); - for (BEASTInterface plugin : mcmc.listActivePlugins()) { + for (BEASTInterface plugin : mcmc.listActiveBEASTObjects()) { reinitialise(plugin, plugins); } // @@ -267,8 +267,8 @@ public void initStateNodes() throws Exception { // } } - private void reinitialise(BEASTInterface plugin, Set plugins) throws Exception { - for (BEASTInterface plugin2 : plugin.listActivePlugins()) { + private void reinitialise(BEASTInterface plugin, Set plugins) { + for (BEASTInterface plugin2 : plugin.listActiveBEASTObjects()) { if (!plugins.contains(plugin2)) { plugins.add(plugin2); reinitialise(plugin2, plugins); diff --git a/src/beast/evolution/likelihood/PartitionProviderByCodon.java b/src/beast/evolution/likelihood/PartitionProviderByCodon.java index 092f8aa..747c222 100644 --- a/src/beast/evolution/likelihood/PartitionProviderByCodon.java +++ b/src/beast/evolution/likelihood/PartitionProviderByCodon.java @@ -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(); @@ -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]; diff --git a/src/beast/evolution/likelihood/PartitionedTreeLikelihood.java b/src/beast/evolution/likelihood/PartitionedTreeLikelihood.java index 0900394..4dd3b43 100644 --- a/src/beast/evolution/likelihood/PartitionedTreeLikelihood.java +++ b/src/beast/evolution/likelihood/PartitionedTreeLikelihood.java @@ -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(); @@ -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; @@ -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++) { @@ -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) { @@ -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++) { @@ -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 patternIndicator, Node node) throws Exception { + int traverse(int partition, List patternIndicator, Node node) { int update = (node.isDirty() | m_nHasDirt); @@ -467,7 +467,7 @@ int traverse(int partition, List 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); } diff --git a/src/beast/evolution/operators/FreeRateOperator.java b/src/beast/evolution/operators/FreeRateOperator.java index c8338dd..c5dfb52 100644 --- a/src/beast/evolution/operators/FreeRateOperator.java +++ b/src/beast/evolution/operators/FreeRateOperator.java @@ -17,7 +17,7 @@ public class FreeRateOperator extends Operator { @Override - public void initAndValidate() throws Exception { + public void initAndValidate() { } @Override diff --git a/src/beast/evolution/operators/RBOperator.java b/src/beast/evolution/operators/RBOperator.java index 6d664d6..ff84dd6 100644 --- a/src/beast/evolution/operators/RBOperator.java +++ b/src/beast/evolution/operators/RBOperator.java @@ -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()) { diff --git a/src/beast/evolution/operators/RBScaleOperator.java b/src/beast/evolution/operators/RBScaleOperator.java index 9b427d2..32516c9 100644 --- a/src/beast/evolution/operators/RBScaleOperator.java +++ b/src/beast/evolution/operators/RBScaleOperator.java @@ -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(); } diff --git a/src/beast/evolution/sitemodel/FreeRateModel.java b/src/beast/evolution/sitemodel/FreeRateModel.java index 86c9623..ab204bd 100644 --- a/src/beast/evolution/sitemodel/FreeRateModel.java +++ b/src/beast/evolution/sitemodel/FreeRateModel.java @@ -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"); @@ -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(); diff --git a/src/beast/evolution/sitemodel/MixtureSiteModel.java b/src/beast/evolution/sitemodel/MixtureSiteModel.java index 61c7806..9b6f761 100644 --- a/src/beast/evolution/sitemodel/MixtureSiteModel.java +++ b/src/beast/evolution/sitemodel/MixtureSiteModel.java @@ -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; diff --git a/src/beast/evolution/sitemodel/MixtureSubstModel.java b/src/beast/evolution/sitemodel/MixtureSubstModel.java index 7a15021..528adc5 100644 --- a/src/beast/evolution/sitemodel/MixtureSubstModel.java +++ b/src/beast/evolution/sitemodel/MixtureSubstModel.java @@ -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(); diff --git a/src/beast/evolution/substitutionmodel/RB.java b/src/beast/evolution/substitutionmodel/RB.java index 748bef1..9ff9d97 100644 --- a/src/beast/evolution/substitutionmodel/RB.java +++ b/src/beast/evolution/substitutionmodel/RB.java @@ -1,6 +1,7 @@ package beast.evolution.substitutionmodel; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import beast.core.Citation; @@ -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)]; diff --git a/src/beast/evolution/substitutionmodel/VS.java b/src/beast/evolution/substitutionmodel/VS.java index 0b13517..23866e7 100644 --- a/src/beast/evolution/substitutionmodel/VS.java +++ b/src/beast/evolution/substitutionmodel/VS.java @@ -1,5 +1,6 @@ package beast.evolution.substitutionmodel; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import beast.core.Citation; @@ -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)]; diff --git a/src/beast/math/distributions/RBPrior.java b/src/beast/math/distributions/RBPrior.java index 12e87a6..f52cd06 100644 --- a/src/beast/math/distributions/RBPrior.java +++ b/src/beast/math/distributions/RBPrior.java @@ -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();