Debian Codegraph @

src/dr/evoxml/ConvertAlignmentParser.java

raw symbols SCIP
1 /*
2 * ConvertAlignmentParser.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.Alignment;
29 import dr.evolution.alignment.ConvertAlignment;
30 import dr.evolution.datatype.*;
31 import dr.evoxml.util.DataTypeUtils;
32 import dr.xml.*;
33
34 import java.util.logging.Logger;
35
36 /**
37 * @author Alexei Drummond
38 * @author Andrew Rambaut
39 *
40 * @version $Id: ConvertAlignmentParser.java,v 1.3 2005/07/11 14:06:25 rambaut Exp $
41 */
42 public class ConvertAlignmentParser extends AbstractXMLObjectParser {
43
44 public final static String CONVERT = "convert";
45
46 public String getParserName() { return CONVERT; }
47
48 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
49
50 Alignment alignment = (Alignment)xo.getChild(Alignment.class);
51
52 // Old parser always returned UNIVERSAL type for codon conversion
53 DataType dataType = DataTypeUtils.getDataType(xo);
54
55 GeneticCode geneticCode = GeneticCode.UNIVERSAL;
56 if (dataType instanceof Codons) {
57 geneticCode = ((Codons)dataType).getGeneticCode();
58 }
59
60 ConvertAlignment convert = new ConvertAlignment(dataType, geneticCode, alignment);
61 Logger.getLogger("dr.evoxml").info("Converted alignment, '" + xo.getId() + "', from " +
62 alignment.getDataType().getDescription() + " to " + dataType.getDescription());
63
64
65 return convert;
66 }
67
68 public String getParserDescription() {
69 return "Converts an alignment to the given data type.";
70 }
71
72 public Class getReturnType() { return Alignment.class; }
73
74 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
75
76 private XMLSyntaxRule[] rules = new XMLSyntaxRule[] {
77 new ElementRule(Alignment.class),
78 new StringAttributeRule(DataType.DATA_TYPE,
79 "The type of sequence data",
80 new String[] {Nucleotides.DESCRIPTION, AminoAcids.DESCRIPTION, Codons.DESCRIPTION, TwoStates.DESCRIPTION,
81 HiddenCodons.DESCRIPTION+"2",HiddenCodons.DESCRIPTION+"3"},
82 false )
83 };
84 }