Debian Codegraph @

src/dr/evoxml/LineageCountThroughTimeParser.java

raw symbols SCIP
1 /*
2 * LineageCountThroughTimeParser.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.tree.LineageCountThroughTime;
29 import dr.stats.Variate;
30 import dr.xml.*;
31
32 /**
33 * @author Andrew Rambaut
34 * @version $Id: DateParser.java,v 1.2 2005/05/24 20:25:59 rambaut Exp $
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 }