| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodelxml.operators; |
| 27 |
|
| 28 |
import dr.util.FileHelpers; |
| 29 |
import dr.xml.*; |
| 30 |
import dr.evolution.io.NexusImporter; |
| 31 |
import dr.evolution.io.Importer; |
| 32 |
import dr.evolution.tree.Tree; |
| 33 |
import dr.evolution.util.TaxonList; |
| 34 |
import dr.evomodel.tree.EmpiricalTreeDistributionModel; |
| 35 |
import dr.evomodel.tree.TreeModel; |
| 36 |
import dr.evomodel.operators.WilsonBalding; |
| 37 |
import dr.evomodel.operators.EmpiricalTreeDistributionOperator; |
| 38 |
import dr.inference.operators.MCMCOperator; |
| 39 |
|
| 40 |
import java.io.*; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class EmpiricalTreeDistributionOperatorParser extends AbstractXMLObjectParser { |
| 48 |
|
| 49 |
public String getParserName() { |
| 50 |
return EmpiricalTreeDistributionOperator.EMPIRICAL_TREE_DISTRIBUTION_OPERATOR; |
| 51 |
} |
| 52 |
|
| 53 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 54 |
|
| 55 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 56 |
boolean metropolisHastings = false; |
| 57 |
|
| 58 |
if (xo.hasAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS)) { |
| 59 |
metropolisHastings = xo.getBooleanAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS); |
| 60 |
} |
| 61 |
|
| 62 |
final EmpiricalTreeDistributionModel treeModel = (EmpiricalTreeDistributionModel) xo.getChild(EmpiricalTreeDistributionModel.class); |
| 63 |
|
| 64 |
return new EmpiricalTreeDistributionOperator(treeModel, metropolisHastings, weight); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 72 |
return rules; |
| 73 |
} |
| 74 |
|
| 75 |
private final XMLSyntaxRule[] rules = { |
| 76 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 77 |
AttributeRule.newBooleanRule(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS, true), |
| 78 |
new ElementRule(EmpiricalTreeDistributionModel.class) |
| 79 |
}; |
| 80 |
|
| 81 |
public String getParserDescription() { |
| 82 |
return "Operator which switches between trees in an empirical distribution."; |
| 83 |
} |
| 84 |
|
| 85 |
public Class getReturnType() { |
| 86 |
return EmpiricalTreeDistributionOperator.class; |
| 87 |
} |
| 88 |
} |