Debian Codegraph @

src/dr/evoxml/DistanceMatrixParser.java

raw symbols SCIP
1 /*
2 * DistanceMatrixParser.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.datatype.Nucleotides;
30 import dr.evolution.distance.DistanceMatrix;
31 import dr.evolution.distance.F84DistanceMatrix;
32 import dr.evolution.distance.JukesCantorDistanceMatrix;
33 import dr.evolution.distance.SMMDistanceMatrix;
34 import dr.xml.*;
35
36 import java.util.logging.Logger;
37
38 /**
39 * @author Alexei Drummond
40 * @author Andrew Rambaut
41 *
42 * @version $Id: DistanceMatrixParser.java,v 1.3 2005/07/11 14:06:25 rambaut Exp $
43 */
44 public class DistanceMatrixParser extends AbstractXMLObjectParser {
45
46 public static final String DISTANCE_MATRIX = "distanceMatrix";
47 public static final String CORRECTION = "correction";
48
49 public String getParserName() { return DISTANCE_MATRIX; }
50
51 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
52
53 PatternList patterns = (PatternList)xo.getChild(PatternList.class);
54
55 DistanceMatrix matrix = null;
56
57 String type = xo.getStringAttribute(CORRECTION);
58 if (type.equals(Nucleotides.JC)) {
59 Logger.getLogger("dr.evoxml").info("Creating Jukes-Cantor distance matrix");
60 matrix = new JukesCantorDistanceMatrix(patterns);
61 } else if (type.equals(Nucleotides.F84)) {
62 Logger.getLogger("dr.evoxml").info("Creating F84 distance matrix");
63 matrix = new F84DistanceMatrix(patterns);
64 } else if (type.equals("SMM")){
65 Logger.getLogger("dr.evoxml").info("Creating SMM distance matrix");
66 matrix = new SMMDistanceMatrix(patterns);
67 } else {
68 matrix = new DistanceMatrix(patterns);
69 }
70
71 return matrix;
72 }
73
74 public XMLSyntaxRule[] getSyntaxRules() {
75 return rules;
76 }
77
78 private final XMLSyntaxRule[] rules = {
79 new StringAttributeRule(CORRECTION,
80 "The type of distance correction used",
81 new String[] { "none", Nucleotides.JC, Nucleotides.F84, "SMM" }, false),
82 new ElementRule(PatternList.class)
83 };
84
85 public String getParserDescription() {
86 return "Constructs a distance matrix from a pattern list or alignment";
87 }
88
89 public Class getReturnType() { return DistanceMatrix.class; }
90 }