| 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.coalescent; |
| 27 |
|
| 28 |
import dr.evolution.tree.Tree; |
| 29 |
import dr.evolution.coalescent.TreeIntervals; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.inference.model.Model; |
| 32 |
import dr.inference.model.ModelListener; |
| 33 |
|
| 34 |
import java.util.Arrays; |
| 35 |
import java.util.List; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public interface MultiLociTreeSet { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
int nLoci(); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
Tree getTree(int nt); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
TreeIntervals getTreeIntervals(int nt); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
double getPopulationFactor(int nt); |
| 68 |
|
| 69 |
void storeTheState(); |
| 70 |
|
| 71 |
void restoreTheState(); |
| 72 |
|
| 73 |
public class Default implements MultiLociTreeSet, ModelListener { |
| 74 |
private final List<TreeModel> trees; |
| 75 |
private final List<Double> factors; |
| 76 |
private final boolean[] dirty; |
| 77 |
private final boolean[] gotDirty; |
| 78 |
|
| 79 |
private final TreeIntervals[] intervals; |
| 80 |
|
| 81 |
public Default(List<TreeModel> trees, List<Double> popFactors) { |
| 82 |
this.trees = trees; |
| 83 |
this.factors = popFactors; |
| 84 |
|
| 85 |
for(TreeModel t : trees ) { |
| 86 |
t.addModelListener(this); |
| 87 |
} |
| 88 |
|
| 89 |
final int nt = trees.size(); |
| 90 |
dirty = new boolean[nt]; |
| 91 |
gotDirty = new boolean[nt]; |
| 92 |
intervals = new TreeIntervals[nt]; |
| 93 |
Arrays.fill(dirty, true); |
| 94 |
Arrays.fill(intervals, null); |
| 95 |
} |
| 96 |
|
| 97 |
public int nLoci() { |
| 98 |
return trees.size(); |
| 99 |
} |
| 100 |
|
| 101 |
public Tree getTree(int nt) { |
| 102 |
return trees.get(nt); |
| 103 |
} |
| 104 |
|
| 105 |
public TreeIntervals getTreeIntervals(int nt) { |
| 106 |
if( dirty[nt] ) { |
| 107 |
intervals[nt] = new TreeIntervals(trees.get(nt)); |
| 108 |
intervals[nt].setMultifurcationLimit(0); |
| 109 |
dirty[nt] = false; |
| 110 |
} |
| 111 |
return intervals[nt]; |
| 112 |
} |
| 113 |
|
| 114 |
public double getPopulationFactor(int nt) { |
| 115 |
return factors.get(nt); |
| 116 |
} |
| 117 |
|
| 118 |
public void storeTheState() { |
| 119 |
Arrays.fill(gotDirty, false); |
| 120 |
} |
| 121 |
|
| 122 |
public void restoreTheState() { |
| 123 |
for(int nt = 0; nt < gotDirty.length; ++nt) { |
| 124 |
if( gotDirty[nt] ) { |
| 125 |
dirty[nt] = true; |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
public void modelChangedEvent(Model model, Object object, int index) { |
| 131 |
assert model instanceof TreeModel; |
| 132 |
final int k = trees.indexOf((TreeModel)model); |
| 133 |
dirty[k] = gotDirty[k] = true; |
| 134 |
} |
| 135 |
|
| 136 |
public void modelRestored(Model model) {} |
| 137 |
} |
| 138 |
} |