| 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.branchmodel; |
| 27 |
|
| 28 |
import java.util.logging.Logger; |
| 29 |
|
| 30 |
import dr.evomodel.branchmodel.RandomBranchModel; |
| 31 |
import dr.evomodel.substmodel.codon.GY94CodonModel; |
| 32 |
import dr.evomodel.substmodel.SubstitutionModel; |
| 33 |
import dr.evomodel.tree.TreeModel; |
| 34 |
import dr.xml.AbstractXMLObjectParser; |
| 35 |
import dr.xml.AttributeRule; |
| 36 |
import dr.xml.ElementRule; |
| 37 |
import dr.xml.XMLObject; |
| 38 |
import dr.xml.XMLParseException; |
| 39 |
import dr.xml.XMLSyntaxRule; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class RandomBranchModelParser extends AbstractXMLObjectParser { |
| 48 |
|
| 49 |
public static final String BASE_MODEL = "baseSubstitutionModel"; |
| 50 |
public static final String SEED = "seed"; |
| 51 |
|
| 52 |
public static final String RATE = "rate"; |
| 53 |
|
| 54 |
@Override |
| 55 |
public String getParserName() { |
| 56 |
return RandomBranchModel.RANDOM_BRANCH_MODEL; |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 61 |
|
| 62 |
Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model."); |
| 63 |
|
| 64 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 65 |
GY94CodonModel baseSubstitutionModel = (GY94CodonModel) xo .getElementFirstChild(BASE_MODEL); |
| 66 |
|
| 67 |
|
| 68 |
long seed = -1; |
| 69 |
boolean hasSeed = false; |
| 70 |
if (xo.hasAttribute(SEED)) { |
| 71 |
seed = xo.getLongIntegerAttribute(SEED); |
| 72 |
hasSeed = true; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
double rate = 1; |
| 77 |
if (xo.hasAttribute(RATE)) { |
| 78 |
rate = xo.getDoubleAttribute(RATE); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
return new RandomBranchModel(treeModel, baseSubstitutionModel, rate, hasSeed, seed); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 87 |
|
| 88 |
return new XMLSyntaxRule[] { |
| 89 |
|
| 90 |
AttributeRule.newDoubleRule(RATE, true, "Rate of the exponentially distributed random component."), |
| 91 |
new ElementRule(TreeModel.class, false), |
| 92 |
new ElementRule(BASE_MODEL, |
| 93 |
new XMLSyntaxRule[]{ new ElementRule(SubstitutionModel.class, 1, 1) }) |
| 94 |
|
| 95 |
}; |
| 96 |
} |
| 97 |
|
| 98 |
@Override |
| 99 |
public String getParserDescription() { |
| 100 |
return RandomBranchModel.RANDOM_BRANCH_MODEL; |
| 101 |
} |
| 102 |
|
| 103 |
@Override |
| 104 |
public Class getReturnType() { |
| 105 |
return RandomBranchModel.class; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
} |