Debian Codegraph @

src/dr/evoxml/PatternSubSetParser.java

raw symbols SCIP
1 /*
2 * PatternSubSetParser.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.PatternList;
29 import dr.evolution.alignment.Patterns;
30 import dr.evolution.alignment.SiteList;
31 import dr.xml.*;
32
33 import java.util.logging.Logger;
34
35 /**
36 * @author Alexei Drummond
37 * @author Andrew Rambaut
38 * @version $Id: PatternsParser.java,v 1.2 2005/05/24 20:25:59 rambaut Exp $
39 */
40 public class PatternSubSetParser extends AbstractXMLObjectParser {
41
42 public static final String PATTERNS_SUB_SET = "patternSubSet";
43 public static final String SUB_SET = "subSet";
44 public static final String SUB_SET_COUNT = "subSetCount";
45
46 public String getParserName() {
47 return PATTERNS_SUB_SET;
48 }
49
50 /**
51 * Parses a patterns element and returns a patterns object.
52 */
53 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
54
55 SiteList patterns = (SiteList) xo.getChild(SiteList.class);
56
57 int subSet = 0;
58 int subSetCount = 0;
59
60 if (xo.hasAttribute(SUB_SET)) {
61 subSet = xo.getIntegerAttribute(SUB_SET) - 1;
62 if (subSet < 0)
63 throw new XMLParseException("illegal 'subSet' attribute in patterns element");
64 }
65
66 if (xo.hasAttribute(SUB_SET_COUNT)) {
67 subSetCount = xo.getIntegerAttribute(SUB_SET_COUNT);
68 if (subSetCount < 0)
69 throw new XMLParseException("illegal 'subSetCount' attribute in patterns element");
70 }
71
72 Patterns subPatterns = new Patterns(patterns, 0, 0, 1, subSet, subSetCount);
73
74 if (xo.hasAttribute(XMLParser.ID)) {
75 final Logger logger = Logger.getLogger("dr.evoxml");
76 logger.info("Pattern subset '" + xo.getId() + "' created from '" + patterns.getId() +"' ("+(subSet+1)+"/"+subSetCount+")");
77 logger.info(" pattern count = " + subPatterns.getPatternCount());
78 }
79
80 return subPatterns;
81 }
82
83 public XMLSyntaxRule[] getSyntaxRules() {
84 return rules;
85 }
86
87 private final XMLSyntaxRule[] rules = {
88 AttributeRule.newIntegerRule(SUB_SET, true, "Which subset of patterns to use (out of subSetCount)"),
89 AttributeRule.newIntegerRule(SUB_SET_COUNT, true, "The number of subsets"),
90
91 new ElementRule(SiteList.class)
92 };
93
94 public String getParserDescription() {
95 return "A weighted list of the unique site patterns (unique columns) in an alignment.";
96 }
97
98 public Class getReturnType() {
99 return PatternList.class;
100 }
101
102 }