Debian Codegraph @

src/dr/evoxml/HypermutantAlignmentParser.java

raw symbols SCIP
1 /*
2 * HypermutantAlignmentParser.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.HypermutantAlignment;
30 import dr.evolution.datatype.*;
31 import dr.xml.*;
32
33 import java.util.logging.Logger;
34
35 /**
36 * This converts 'A's that are at specific APOBEC targeted contexts into an A/G ambiguity code for
37 * later recognition by the HypermutantErrorModel.
38 *
39 * @author Andrew Rambaut
40 *
41 * @version $Id$
42 */
43 public class HypermutantAlignmentParser extends AbstractXMLObjectParser {
44 public final static String HYPERMUTANT_ALIGNMENT = "hypermutantAlignment";
45 public final static String CONTEXT_TYPE = "type";
46
47 public String getParserName() { return HYPERMUTANT_ALIGNMENT; }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 Alignment alignment = (Alignment)xo.getChild(Alignment.class);
52
53 if (alignment.getDataType().getType() != DataType.NUCLEOTIDES) {
54 throw new XMLParseException("HypermutantAlignment can only convert nucleotide alignments");
55 }
56
57 String typeName = xo.getStringAttribute(CONTEXT_TYPE);
58 HypermutantAlignment.APOBECType type = null;
59 try {
60 type = HypermutantAlignment.APOBECType.valueOf(typeName.toUpperCase());
61 } catch(IllegalArgumentException iae) {
62 throw new XMLParseException("Unrecognised hypermutation type: " + typeName);
63 }
64
65 HypermutantAlignment convert = new HypermutantAlignment(type, alignment);
66 int mutatedCount = convert.getMutatedContextCount();
67 int totalCount = mutatedCount + convert.getUnmutatedContextCount();
68
69 Logger.getLogger("dr.evoxml").info("Converted alignment, '" + xo.getId() + "' to a hypermutant alignment targeting " + type.toString() + " contexts.\r" +
70 "\tPotentially mutated contexts: " + mutatedCount + " out of a total of " + totalCount + " contexts");
71
72 return convert;
73 }
74
75 public String getParserDescription() {
76 return "Converts an alignment so that 'A's at specific APOBEC targeted contexts are set to an A/G ambiguity code.";
77 }
78
79 public Class getReturnType() { return Alignment.class; }
80
81 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
82
83 private XMLSyntaxRule[] rules = new XMLSyntaxRule[] {
84 new ElementRule(Alignment.class),
85 new StringAttributeRule(CONTEXT_TYPE,
86 "The type of APOBEC molecule being modelled",
87 new String[] {HypermutantAlignment.APOBECType.ALL.toString(), HypermutantAlignment.APOBECType.BOTH.toString(), HypermutantAlignment.APOBECType.HA3G.toString(), HypermutantAlignment.APOBECType.HA3F.toString()},
88 false )
89 };
90 }