| 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.branchratemodel; |
| 27 |
|
| 28 |
import dr.evomodel.branchratemodel.BranchRateModel; |
| 29 |
import dr.evomodel.branchratemodel.CompoundBranchRateModel; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
import java.util.ArrayList; |
| 33 |
import java.util.List; |
| 34 |
import java.util.logging.Logger; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class CompoundBranchRateModelParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String COMPOUND_BRANCH_RATE_MODEL = "compoundBranchRateModel"; |
| 41 |
|
| 42 |
public String getParserName() { |
| 43 |
return COMPOUND_BRANCH_RATE_MODEL; |
| 44 |
} |
| 45 |
|
| 46 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 47 |
|
| 48 |
List<BranchRateModel> branchRateModels = new ArrayList<BranchRateModel>(); |
| 49 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 50 |
if (xo.getChild(i) instanceof BranchRateModel) { |
| 51 |
branchRateModels.add((BranchRateModel) xo.getChild(i)); |
| 52 |
} else { |
| 53 |
|
| 54 |
Object rogueElement = xo.getChild(i); |
| 55 |
|
| 56 |
throw new XMLParseException("An element (" + rogueElement |
| 57 |
+ ") which is not a branchRateModel has been added to a " + COMPOUND_BRANCH_RATE_MODEL + " element"); |
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
Logger.getLogger("dr.evomodel").info("Creating a compound branch rate model of " + branchRateModels.size() + " sub-models"); |
| 63 |
|
| 64 |
return new CompoundBranchRateModel(branchRateModels); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public String getParserDescription() { |
| 72 |
return "This element provides a strict clock model. " + |
| 73 |
"All branches have the same rate of molecular evolution."; |
| 74 |
} |
| 75 |
|
| 76 |
public Class getReturnType() { |
| 77 |
return CompoundBranchRateModel.class; |
| 78 |
} |
| 79 |
|
| 80 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 81 |
return rules; |
| 82 |
} |
| 83 |
|
| 84 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 85 |
new ElementRule(BranchRateModel.class, "The component branch rate models", 1, Integer.MAX_VALUE), |
| 86 |
}; |
| 87 |
|
| 88 |
} |