| 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.evomodel.arg; |
| 27 |
|
| 28 |
import dr.evomodel.arg.ARGModel.Node; |
| 29 |
import dr.inference.model.Statistic; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
public class ARGTotalLengthStatistic extends Statistic.Abstract{ |
| 33 |
|
| 34 |
public static final String ARG_TOTAL_LENGTH = "argTotalLengthStatistic"; |
| 35 |
private ARGModel arg; |
| 36 |
|
| 37 |
public ARGTotalLengthStatistic(String id, ARGModel arg){ |
| 38 |
super(id); |
| 39 |
|
| 40 |
this.arg = arg; |
| 41 |
} |
| 42 |
|
| 43 |
public int getDimension() { |
| 44 |
return 1; |
| 45 |
} |
| 46 |
|
| 47 |
public double getStatisticValue(int dim) { |
| 48 |
|
| 49 |
double length = 0; |
| 50 |
|
| 51 |
for(int i = 0; i < arg.getNodeCount(); i++){ |
| 52 |
Node x = (Node) arg.getNode(i); |
| 53 |
|
| 54 |
if(!x.isRoot()){ |
| 55 |
length += x.getParent(ARGModel.LEFT).getHeight() - x.getHeight(); |
| 56 |
if(x.isReassortment()){ |
| 57 |
length += x.getParent(ARGModel.RIGHT).getHeight() - x.getHeight(); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
return length; |
| 63 |
} |
| 64 |
|
| 65 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser(){ |
| 66 |
|
| 67 |
@Override |
| 68 |
public String getParserDescription() { |
| 69 |
|
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public Class getReturnType() { |
| 75 |
|
| 76 |
return ARGTotalLengthStatistic.class; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 81 |
|
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 87 |
String id = xo.getId(); |
| 88 |
|
| 89 |
ARGModel a = (ARGModel) xo.getChild(ARGModel.class); |
| 90 |
|
| 91 |
return new ARGTotalLengthStatistic(id,a); |
| 92 |
} |
| 93 |
|
| 94 |
public String getParserName() { |
| 95 |
|
| 96 |
return ARG_TOTAL_LENGTH; |
| 97 |
} |
| 98 |
|
| 99 |
}; |
| 100 |
|
| 101 |
} |