| 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.tree.LineageCountThroughTime; |
| 29 |
import dr.stats.Variate; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class LineageCountThroughTimeParser extends AbstractXMLObjectParser { |
| 37 |
|
| 38 |
public static final String TREE_FILE = "treeFile"; |
| 39 |
public static final String MIN_TIME = "minTime"; |
| 40 |
public static final String MAX_TIME = "maxTime"; |
| 41 |
public static final String BIN_COUNT = "binCount"; |
| 42 |
public static final String SKIP = "skip"; |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return "lineageCountThroughTime"; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
if (xo.getChildCount() > 0) { |
| 51 |
throw new XMLParseException("No child elements allowed in location element."); |
| 52 |
} |
| 53 |
|
| 54 |
int binCount = xo.getAttribute(BIN_COUNT, 100); |
| 55 |
int skip = xo.getAttribute(SKIP, 0); |
| 56 |
double minTime = xo.getAttribute(MIN_TIME, 0.0); |
| 57 |
double maxTime = xo.getAttribute(MAX_TIME, 1.0); |
| 58 |
|
| 59 |
String treeFile = xo.getAttribute(TREE_FILE, ""); |
| 60 |
|
| 61 |
try { |
| 62 |
Variate[] ltt = LineageCountThroughTime.getLTT(treeFile, minTime, maxTime, binCount, skip); |
| 63 |
|
| 64 |
StringBuilder builder = new StringBuilder(); |
| 65 |
builder.append("Time\tLineage_Count\n"); |
| 66 |
for (int i = 0; i < ltt[0].getCount(); i++) { |
| 67 |
builder.append(ltt[0].get(i)); |
| 68 |
builder.append("\t"); |
| 69 |
builder.append(ltt[1].get(i)); |
| 70 |
builder.append("\n"); |
| 71 |
} |
| 72 |
String lttString = builder.toString(); |
| 73 |
|
| 74 |
System.out.println(); |
| 75 |
System.out.println(lttString); |
| 76 |
return lttString; |
| 77 |
|
| 78 |
} catch (Exception e) { |
| 79 |
|
| 80 |
return e.getMessage(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
public String getParserDescription() { |
| 86 |
return "Specifies a location with an optional longitude and latitude"; |
| 87 |
} |
| 88 |
|
| 89 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 90 |
return rules; |
| 91 |
} |
| 92 |
|
| 93 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 94 |
AttributeRule.newStringRule(TREE_FILE, false, |
| 95 |
"A tree file to calculate the average lineage count through time plot."), |
| 96 |
AttributeRule.newIntegerRule(SKIP, true, |
| 97 |
"The number of trees to skip at start of file."), |
| 98 |
AttributeRule.newIntegerRule(BIN_COUNT, true, |
| 99 |
"The number of bins to use in lineage count through time plot."), |
| 100 |
AttributeRule.newDoubleRule(MIN_TIME, true, |
| 101 |
"The min time to compute lineage count from."), |
| 102 |
AttributeRule.newDoubleRule(MAX_TIME, false, |
| 103 |
"The max time to compute lineage count to."), |
| 104 |
}; |
| 105 |
|
| 106 |
public Class getReturnType() { |
| 107 |
return String.class; |
| 108 |
} |
| 109 |
} |