| 1 |
package dr.evomodelxml.operators; |
| 2 |
|
| 3 |
import dr.evolution.util.Taxa; |
| 4 |
import dr.evomodel.operators.TipLeapOperator; |
| 5 |
import dr.evomodel.tree.TreeModel; |
| 6 |
import dr.inference.operators.AdaptableMCMCOperator; |
| 7 |
import dr.inference.operators.AdaptationMode; |
| 8 |
import dr.inference.operators.MCMCOperator; |
| 9 |
import dr.xml.*; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public class TipLeapOperatorParser extends AbstractXMLObjectParser { |
| 14 |
|
| 15 |
public static final String TIP_LEAP = "tipLeap"; |
| 16 |
|
| 17 |
public static final String SIZE = "size"; |
| 18 |
public static final String TARGET_ACCEPTANCE = "targetAcceptance"; |
| 19 |
public static final String TAXA = "taxa"; |
| 20 |
|
| 21 |
public String getParserName() { |
| 22 |
return TIP_LEAP; |
| 23 |
} |
| 24 |
|
| 25 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 26 |
|
| 27 |
AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 28 |
|
| 29 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 30 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 31 |
|
| 32 |
Taxa taxa = (Taxa) xo.getChild(Taxa.class); |
| 33 |
|
| 34 |
|
| 35 |
final double size = xo.getAttribute(SIZE, Double.NaN); |
| 36 |
final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234); |
| 37 |
|
| 38 |
if (size <= 0.0) { |
| 39 |
throw new XMLParseException("The TipLeap size attribute must be positive and non-zero."); |
| 40 |
} |
| 41 |
|
| 42 |
if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) { |
| 43 |
throw new XMLParseException("Target acceptance probability has to lie in (0, 1)"); |
| 44 |
} |
| 45 |
TipLeapOperator operator = new TipLeapOperator(treeModel, taxa, weight, size, targetAcceptance, mode); |
| 46 |
|
| 47 |
return operator; |
| 48 |
} |
| 49 |
|
| 50 |
public String getParserDescription() { |
| 51 |
return "An operator that moves a tip a certain patristic distance."; |
| 52 |
} |
| 53 |
|
| 54 |
public Class getReturnType() { |
| 55 |
return TipLeapOperator.class; |
| 56 |
} |
| 57 |
|
| 58 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 59 |
return rules; |
| 60 |
} |
| 61 |
|
| 62 |
private final XMLSyntaxRule[] rules = { |
| 63 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 64 |
AttributeRule.newDoubleRule(SIZE, false), |
| 65 |
AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true), |
| 66 |
AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 67 |
new ElementRule(TreeModel.class), |
| 68 |
new ElementRule(Taxa.class) |
| 69 |
}; |
| 70 |
|
| 71 |
} |