Debian Codegraph @

src/dr/evoxml/ConstantPatternsParser.java

raw symbols SCIP
1 /*
2 * ConstantPatternsParser.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * Creates a set of patterns for constant sites with weights as provided
38 * Can be merged with other pattern lists to pad out polymorphic sites
39 *
40 * @author Andrew Rambaut
41 * @version $Id: $
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 * Parses a patterns element and returns a patterns object.
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 }