| 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.ArrayList; |
| 29 |
import java.util.List; |
| 30 |
import java.util.logging.Logger; |
| 31 |
|
| 32 |
import dr.evomodel.branchmodel.RandomBranchAssignmentModel; |
| 33 |
import dr.evomodel.branchmodel.RandomBranchModel; |
| 34 |
import dr.evomodel.substmodel.SubstitutionModel; |
| 35 |
import dr.evomodel.tree.TreeModel; |
| 36 |
import dr.xml.AbstractXMLObjectParser; |
| 37 |
import dr.xml.ElementRule; |
| 38 |
import dr.xml.XMLObject; |
| 39 |
import dr.xml.XMLParseException; |
| 40 |
import dr.xml.XMLSyntaxRule; |
| 41 |
|
| 42 |
public class RandomBranchAssignmentModelParser extends AbstractXMLObjectParser { |
| 43 |
|
| 44 |
public static final String MODELS = "models"; |
| 45 |
|
| 46 |
@Override |
| 47 |
public String getParserName() { |
| 48 |
return RandomBranchAssignmentModel.RANDOM_BRANCH_ASSIGNMENT_MODEL; |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 53 |
|
| 54 |
Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model."); |
| 55 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 56 |
|
| 57 |
XMLObject cxo = xo.getChild(MODELS); |
| 58 |
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>(); |
| 59 |
for (int i = 0; i < cxo.getChildCount(); i++) { |
| 60 |
|
| 61 |
SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i); |
| 62 |
substitutionModels.add(substModel); |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
return new RandomBranchAssignmentModel(treeModel, substitutionModels); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 71 |
|
| 72 |
return new XMLSyntaxRule[]{ |
| 73 |
|
| 74 |
new ElementRule(TreeModel.class, false), |
| 75 |
new ElementRule(MODELS, |
| 76 |
new XMLSyntaxRule[] { |
| 77 |
new ElementRule(SubstitutionModel.class, 1, Integer.MAX_VALUE), |
| 78 |
} |
| 79 |
) |
| 80 |
|
| 81 |
}; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public String getParserDescription() { |
| 86 |
return "This element provides a branch model which randomly assigns " + |
| 87 |
"substitution models to branches on the tree by sampling " + |
| 88 |
"with replacement from the provided list of substitution models. "; |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public Class getReturnType() { |
| 93 |
return RandomBranchModel.class; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
} |