diff --git a/lphybeast/src/main/java/lphybeast/tobeast/generators/PhyloCTMCToBEAST.java b/lphybeast/src/main/java/lphybeast/tobeast/generators/PhyloCTMCToBEAST.java index f651e73..ccdcb0a 100644 --- a/lphybeast/src/main/java/lphybeast/tobeast/generators/PhyloCTMCToBEAST.java +++ b/lphybeast/src/main/java/lphybeast/tobeast/generators/PhyloCTMCToBEAST.java @@ -11,7 +11,6 @@ import beast.base.evolution.substitutionmodel.SubstitutionModel; import beast.base.evolution.tree.Tree; import beast.base.inference.distribution.Prior; -import beast.base.inference.operator.kernel.BactrianUpDownOperator; import beast.base.inference.parameter.RealParameter; import beastclassic.evolution.alignment.AlignmentFromTrait; import beastclassic.evolution.likelihood.AncestralStateTreeLikelihood; @@ -33,6 +32,7 @@ import lphybeast.BEASTContext; import lphybeast.GeneratorToBEAST; import lphybeast.tobeast.loggers.TraitTreeLogger; +import lphybeast.tobeast.operators.DefaultOperatorStrategy; import java.util.Map; @@ -215,7 +215,7 @@ public static void constructTreeAndBranchRate(PhyloCTMC phyloCTMC, GenericTreeLi treeLikelihood.setInputValue("branchRateModel", clockModel); if (clockRate instanceof RandomVariable && timeTreeValue instanceof RandomVariable && skipBranchOperators == false) { - addUpDownOperator(tree, clockRatePara, context); + DefaultOperatorStrategy.addUpDownOperator(tree, clockRatePara, context); } } } @@ -323,21 +323,6 @@ private static void addRelaxedClockOperators(Tree tree, UCRelaxedClockModel rela context.addExtraOperator(smallPulley); } - // when both mu and tree are random var - private static void addUpDownOperator(Tree tree, RealParameter clockRate, BEASTContext context) { - String idStr = clockRate.getID() + "Up" + tree.getID() + "DownOperator"; - // avoid to duplicate updown ops from the same pair of rate and tree - if (!context.hasExtraOperator(idStr)) { - BactrianUpDownOperator upDownOperator = new BactrianUpDownOperator(); - upDownOperator.setID(idStr); - upDownOperator.setInputValue("up", clockRate); - upDownOperator.setInputValue("down", tree); - upDownOperator.setInputValue("scaleFactor", 0.9); - upDownOperator.setInputValue("weight", BEASTContext.getOperatorWeight(tree.getInternalNodeCount()+1)); - context.addExtraOperator(upDownOperator); - } - } - @Override public Class getGeneratorClass() { return PhyloCTMC.class; diff --git a/lphybeast/src/main/java/lphybeast/tobeast/operators/DefaultOperatorStrategy.java b/lphybeast/src/main/java/lphybeast/tobeast/operators/DefaultOperatorStrategy.java index d6ac019..81b56be 100644 --- a/lphybeast/src/main/java/lphybeast/tobeast/operators/DefaultOperatorStrategy.java +++ b/lphybeast/src/main/java/lphybeast/tobeast/operators/DefaultOperatorStrategy.java @@ -10,6 +10,7 @@ import beast.base.inference.operator.IntRandomWalkOperator; import beast.base.inference.operator.kernel.BactrianDeltaExchangeOperator; import beast.base.inference.operator.kernel.BactrianRandomWalkOperator; +import beast.base.inference.operator.kernel.BactrianUpDownOperator; import beast.base.inference.parameter.BooleanParameter; import beast.base.inference.parameter.IntegerParameter; import beast.base.inference.parameter.RealParameter; @@ -187,5 +188,20 @@ private Operator createBitFlipOperator(BooleanParameter parameter) { return operator; } - + //*** static methods ***// + + // when both mu and tree are random var + public static void addUpDownOperator(Tree tree, RealParameter clockRate, BEASTContext context) { + String idStr = clockRate.getID() + "Up" + tree.getID() + "DownOperator"; + // avoid to duplicate updown ops from the same pair of rate and tree + if (!context.hasExtraOperator(idStr)) { + BactrianUpDownOperator upDownOperator = new BactrianUpDownOperator(); + upDownOperator.setID(idStr); + upDownOperator.setInputValue("up", clockRate); + upDownOperator.setInputValue("down", tree); + upDownOperator.setInputValue("scaleFactor", 0.9); + upDownOperator.setInputValue("weight", BEASTContext.getOperatorWeight(tree.getInternalNodeCount()+1)); + context.addExtraOperator(upDownOperator); + } + } }