| 1 |
|
| 2 |
package dr.evomodel.antigenic.phyloclustering.statistics; |
| 3 |
|
| 4 |
import dr.evomodel.antigenic.phyloclustering.TreeClusteringVirusesPrior; |
| 5 |
import dr.evomodel.tree.TreeModel; |
| 6 |
import dr.inference.model.*; |
| 7 |
import dr.xml.*; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class DriverCountStatistic extends Statistic.Abstract implements VariableListener { |
| 16 |
|
| 17 |
|
| 18 |
public static final String DRIVERCOUNT_STATISTIC = "driverCountStatistic"; |
| 19 |
|
| 20 |
private TreeModel treeModel; |
| 21 |
private TreeClusteringVirusesPrior clusterPrior; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public DriverCountStatistic(TreeModel tree, TreeClusteringVirusesPrior clusterPrior_in) { |
| 26 |
this.treeModel = tree; |
| 27 |
this.clusterPrior = clusterPrior_in; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public int getDimension() { |
| 33 |
int[] causalCount = clusterPrior.getCausalCount(); |
| 34 |
int numdata = causalCount.length *2; |
| 35 |
return numdata; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public double getStatisticValue(int dim) { |
| 43 |
|
| 44 |
int[] causalCount = clusterPrior.getCausalCount(); |
| 45 |
int[] nonCausalCount = clusterPrior.getNonCausalCount(); |
| 46 |
|
| 47 |
int index = dim/2; |
| 48 |
double value = -1; |
| 49 |
if(dim%2==0){ |
| 50 |
value = causalCount[index]; |
| 51 |
} |
| 52 |
else{ |
| 53 |
value = nonCausalCount[index]; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
return ( value); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public String getDimensionName(int dim) { |
| 63 |
String name = ""; |
| 64 |
if(dim%2==0){ |
| 65 |
name += "C"; |
| 66 |
} |
| 67 |
else{ |
| 68 |
name += "N"; |
| 69 |
} |
| 70 |
name += ""+ (dim/2 +1); |
| 71 |
return name; |
| 72 |
} |
| 73 |
|
| 74 |
public void variableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 75 |
|
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public String getParserName() { |
| 84 |
return DRIVERCOUNT_STATISTIC; |
| 85 |
} |
| 86 |
|
| 87 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 88 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 89 |
TreeClusteringVirusesPrior clusterPrior = (TreeClusteringVirusesPrior) xo.getChild(TreeClusteringVirusesPrior.class); |
| 90 |
|
| 91 |
return new DriverCountStatistic( treeModel, clusterPrior); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public String getParserDescription() { |
| 100 |
return "."; |
| 101 |
} |
| 102 |
|
| 103 |
public Class getReturnType() { |
| 104 |
return DriverCountStatistic.class; |
| 105 |
} |
| 106 |
|
| 107 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 108 |
return rules; |
| 109 |
} |
| 110 |
|
| 111 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 112 |
new ElementRule(TreeModel.class), |
| 113 |
new ElementRule(TreeClusteringVirusesPrior.class), |
| 114 |
}; |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
} |