| 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 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
package dr.evomodel.coalescent; |
| 31 |
|
| 32 |
import dr.evolution.coalescent.TreeIntervals; |
| 33 |
import dr.evolution.tree.Tree; |
| 34 |
import dr.inference.model.Statistic; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class CoalescentTreeIntervalStatistic extends Statistic.Abstract { |
| 40 |
|
| 41 |
private Tree tree; |
| 42 |
private TreeIntervals intervals; |
| 43 |
private int dimension; |
| 44 |
private double[] nonZeroIntervals; |
| 45 |
private int[] lineageCounts; |
| 46 |
|
| 47 |
public CoalescentTreeIntervalStatistic(Tree tree) { |
| 48 |
this.tree = tree; |
| 49 |
this.intervals = new TreeIntervals(tree); |
| 50 |
|
| 51 |
setDimension(intervals); |
| 52 |
this.lineageCounts = new int[this.dimension]; |
| 53 |
this.nonZeroIntervals = new double[this.dimension]; |
| 54 |
removeZeroLengthIntervals(intervals); |
| 55 |
} |
| 56 |
|
| 57 |
public int getDimension() { |
| 58 |
return this.dimension; |
| 59 |
} |
| 60 |
|
| 61 |
public double getStatisticValue(int i) { |
| 62 |
|
| 63 |
if (i == 0) { |
| 64 |
intervals.setIntervalsUnknown(); |
| 65 |
removeZeroLengthIntervals(intervals); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
return this.nonZeroIntervals[i]; |
| 72 |
} |
| 73 |
|
| 74 |
public double getLineageCount(int i) { |
| 75 |
|
| 76 |
if (i == 0) { |
| 77 |
intervals.setIntervalsUnknown(); |
| 78 |
removeZeroLengthIntervals(intervals); |
| 79 |
} |
| 80 |
|
| 81 |
return this.lineageCounts[i]; |
| 82 |
} |
| 83 |
|
| 84 |
public String getStatisticName() { |
| 85 |
return "coalescentTreeIntervalStatistic"; |
| 86 |
} |
| 87 |
|
| 88 |
private void setDimension(TreeIntervals intervals) { |
| 89 |
int dim = intervals.getIntervalCount(); |
| 90 |
for (int i = 0; i < intervals.getIntervalCount(); i++) { |
| 91 |
if (intervals.getInterval(i) == 0.0) { |
| 92 |
dim--; |
| 93 |
} |
| 94 |
} |
| 95 |
this.dimension = dim; |
| 96 |
} |
| 97 |
|
| 98 |
private void removeZeroLengthIntervals(TreeIntervals intervals) { |
| 99 |
int dim = 0; |
| 100 |
for (int i = 0; i < intervals.getIntervalCount(); i++) { |
| 101 |
double intervalLength = intervals.getInterval(i); |
| 102 |
if (intervalLength != 0.0) { |
| 103 |
this.nonZeroIntervals[dim] = intervalLength; |
| 104 |
this.lineageCounts[dim] = intervals.getLineageCount(i); |
| 105 |
dim++; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} |