| 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.treelikelihood; |
| 27 |
|
| 28 |
import dr.evomodel.substmodel.CodonPartitionedRobustCounting; |
| 29 |
import dr.evomodel.treelikelihood.utilities.DnDsLogger; |
| 30 |
import dr.evolution.tree.Tree; |
| 31 |
import dr.evolution.tree.TreeTrait; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class DnDsLoggerParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String PARSER_NAME = "dNdSLogger"; |
| 41 |
public static final String USE_SMOOTHING = "smooth"; |
| 42 |
public static final String USE_DNMINUSDS = "dn-ds"; |
| 43 |
public static final String COUNTS = "counts"; |
| 44 |
public static final String SYNONYMOUS = "synonymous"; |
| 45 |
|
| 46 |
@Override |
| 47 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 48 |
|
| 49 |
String[] names = DnDsLogger.traitNames; |
| 50 |
TreeTrait[] foundTraits = new TreeTrait[names.length]; |
| 51 |
|
| 52 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 53 |
Object obj = xo.getChild(i); |
| 54 |
if (obj instanceof CodonPartitionedRobustCounting) { |
| 55 |
CodonPartitionedRobustCounting thisCount = (CodonPartitionedRobustCounting) obj; |
| 56 |
for (int j = 0; j < names.length; j++) { |
| 57 |
TreeTrait trait = thisCount.getTreeTrait(names[j]); |
| 58 |
if (trait != null) { |
| 59 |
foundTraits[j] = trait; |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
for (int i = 0; i < foundTraits.length; i++) { |
| 66 |
if (foundTraits[i] == null) { |
| 67 |
throw new XMLParseException("Unable to find trait '" + names[i] + "'"); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
Tree tree = (Tree) xo.getChild(Tree.class); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
boolean useSmoothing = xo.getAttribute(USE_SMOOTHING, true); |
| 76 |
boolean useDnMinusDs = xo.getAttribute(USE_DNMINUSDS, false); |
| 77 |
boolean conditionalCounts = xo.getAttribute(COUNTS, false); |
| 78 |
boolean synonymous = xo.getAttribute(SYNONYMOUS, false); |
| 79 |
|
| 80 |
return new DnDsLogger(xo.getId(), tree, foundTraits, useSmoothing, useDnMinusDs, conditionalCounts, synonymous); |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 85 |
return rules; |
| 86 |
} |
| 87 |
|
| 88 |
private static XMLSyntaxRule[] rules = { |
| 89 |
new ElementRule(CodonPartitionedRobustCounting.class, 2, 2), |
| 90 |
new ElementRule(Tree.class), |
| 91 |
AttributeRule.newBooleanRule(USE_SMOOTHING, true), |
| 92 |
AttributeRule.newBooleanRule(COUNTS, true), |
| 93 |
AttributeRule.newBooleanRule(SYNONYMOUS, true), |
| 94 |
AttributeRule.newBooleanRule(USE_DNMINUSDS, true), |
| 95 |
}; |
| 96 |
|
| 97 |
@Override |
| 98 |
public String getParserDescription() { |
| 99 |
return null; |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public Class getReturnType() { |
| 104 |
return DnDsLogger.class; |
| 105 |
} |
| 106 |
|
| 107 |
public String getParserName() { |
| 108 |
return PARSER_NAME; |
| 109 |
} |
| 110 |
} |