| 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.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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
} |