| 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.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 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
|
| 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 |
} |