| 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.evoxml; |
| 27 |
|
| 28 |
import dr.evolution.alignment.*; |
| 29 |
import dr.evolution.datatype.DataType; |
| 30 |
import dr.evolution.util.TaxonList; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
import java.util.logging.Logger; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class ConstantPatternsParser extends AbstractXMLObjectParser { |
| 44 |
|
| 45 |
public static final String CONSTANT_PATTERNS = "constantPatterns"; |
| 46 |
private static final String COUNTS = "counts"; |
| 47 |
|
| 48 |
public String getParserName() { |
| 49 |
return CONSTANT_PATTERNS; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 56 |
|
| 57 |
PatternList source = (PatternList)xo.getChild(PatternList.class); |
| 58 |
Parameter constantPatternCounts = (Parameter) xo.getElementFirstChild(COUNTS); |
| 59 |
|
| 60 |
Patterns patterns = new Patterns(source.getDataType(), source); |
| 61 |
|
| 62 |
for (int i = 0; i < source.getDataType().getStateCount(); i++) { |
| 63 |
int[] pattern = new int[patterns.getPatternLength()]; |
| 64 |
for (int j = 0; j < pattern.length; j++) { |
| 65 |
pattern[j] = i; |
| 66 |
} |
| 67 |
patterns.addPattern(pattern, constantPatternCounts.getParameterValue(i)); |
| 68 |
} |
| 69 |
|
| 70 |
return patterns; |
| 71 |
} |
| 72 |
|
| 73 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 74 |
return rules; |
| 75 |
} |
| 76 |
|
| 77 |
private final XMLSyntaxRule[] rules = { |
| 78 |
new ElementRule(PatternList.class), |
| 79 |
new ElementRule(COUNTS, |
| 80 |
new XMLSyntaxRule[]{ |
| 81 |
new ElementRule(Parameter.class) |
| 82 |
}) |
| 83 |
}; |
| 84 |
|
| 85 |
public String getParserDescription() { |
| 86 |
return "Creates a set of patterns for constant sites with weights as provided."; |
| 87 |
} |
| 88 |
|
| 89 |
public Class getReturnType() { |
| 90 |
return PatternList.class; |
| 91 |
} |
| 92 |
|
| 93 |
} |