| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 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 |
} |