| 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.evomodel.alloppnet.parsers; |
| 27 |
|
| 28 |
import dr.evolution.tree.Tree; |
| 29 |
import dr.evomodel.alloppnet.speciation.MulSpeciesBindings; |
| 30 |
import dr.evomodel.alloppnet.speciation.MulSpeciesTreeModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.inference.model.ParameterParser; |
| 33 |
import dr.util.Attributable; |
| 34 |
import dr.xml.*; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class MulSpeciesTreeModelParser extends AbstractXMLObjectParser { |
| 44 |
public static final String MUL_SPECIES_TREE = "mulSpeciesTree"; |
| 45 |
|
| 46 |
public static final String SPP_SPLIT_POPULATIONS = "sppSplitPopulations"; |
| 47 |
|
| 48 |
public static final String CONST_ROOT_POPULATION = "constantRoot"; |
| 49 |
public static final String CONSTANT_POPULATION = "constantPopulation"; |
| 50 |
|
| 51 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 52 |
MulSpeciesBindings spb = (MulSpeciesBindings) xo.getChild(MulSpeciesBindings.class); |
| 53 |
|
| 54 |
final Boolean cr = xo.getAttribute(CONST_ROOT_POPULATION, false); |
| 55 |
final Boolean cp = xo.getAttribute(CONSTANT_POPULATION, false); |
| 56 |
|
| 57 |
final XMLObject cxo = xo.getChild(SPP_SPLIT_POPULATIONS); |
| 58 |
|
| 59 |
final double value = cxo.getAttribute(Attributable.VALUE, 1.0); |
| 60 |
final boolean nonConstRootPopulation = !cr; |
| 61 |
final Parameter sppSplitPopulations = MulSpeciesTreeModel.createSplitPopulationsParameter(spb, value, nonConstRootPopulation, cp); |
| 62 |
ParameterParser.replaceParameter(cxo, sppSplitPopulations); |
| 63 |
|
| 64 |
final Parameter.DefaultBounds bounds = |
| 65 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, sppSplitPopulations.getDimension()); |
| 66 |
sppSplitPopulations.addBounds(bounds); |
| 67 |
|
| 68 |
final Tree startTree = null; |
| 69 |
|
| 70 |
return new MulSpeciesTreeModel(spb, sppSplitPopulations, null, null, startTree, false, nonConstRootPopulation, cp); |
| 71 |
} |
| 72 |
|
| 73 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 74 |
return new XMLSyntaxRule[]{ |
| 75 |
AttributeRule.newBooleanRule(CONST_ROOT_POPULATION, true), |
| 76 |
AttributeRule.newBooleanRule(CONSTANT_POPULATION, true), |
| 77 |
new ElementRule(MulSpeciesBindings.class), |
| 78 |
|
| 79 |
new ElementRule(Tree.class, true), |
| 80 |
new ElementRule(SPP_SPLIT_POPULATIONS, new XMLSyntaxRule[]{ |
| 81 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 82 |
new ElementRule(Parameter.class)}) |
| 83 |
}; |
| 84 |
} |
| 85 |
|
| 86 |
public String getParserDescription() { |
| 87 |
return "Multiply-labelled species tree which includes demographic function per branch."; |
| 88 |
} |
| 89 |
|
| 90 |
public Class getReturnType() { |
| 91 |
return MulSpeciesTreeModel.class; |
| 92 |
} |
| 93 |
|
| 94 |
public String getParserName() { |
| 95 |
return MUL_SPECIES_TREE; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
} |
| 100 |
|