| 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.alloppnet.speciation; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
import java.util.Stack; |
| 31 |
|
| 32 |
import dr.evolution.tree.SimpleNode; |
| 33 |
import dr.evolution.util.Taxon; |
| 34 |
|
| 35 |
import jebl.util.FixedBitSet; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public interface AlloppNode { |
| 49 |
int nofChildren(); |
| 50 |
AlloppNode getChild(int ch); |
| 51 |
AlloppNode getAnc(); |
| 52 |
Taxon getTaxon(); |
| 53 |
double getHeight(); |
| 54 |
FixedBitSet getUnion(); |
| 55 |
|
| 56 |
void setChild(int ch, AlloppNode newchild); |
| 57 |
void setAnc(AlloppNode anc); |
| 58 |
void setTaxon(String name); |
| 59 |
void setHeight(double height); |
| 60 |
void setUnion(FixedBitSet union); |
| 61 |
void addChildren(AlloppNode c0, AlloppNode c1); |
| 62 |
|
| 63 |
String asText(int indentlen); |
| 64 |
|
| 65 |
void fillinUnionsInSubtree(int unionsize); |
| 66 |
AlloppNode nodeOfUnionInSubtree(FixedBitSet x); |
| 67 |
|
| 68 |
|
| 69 |
public abstract class Abstract implements AlloppNode { |
| 70 |
|
| 71 |
|
| 72 |
public void fillinUnionsInSubtree(int unionsize) { |
| 73 |
if (nofChildren() > 0) { |
| 74 |
getChild(0).fillinUnionsInSubtree(unionsize); |
| 75 |
getChild(1).fillinUnionsInSubtree(unionsize); |
| 76 |
FixedBitSet union = new FixedBitSet(unionsize); |
| 77 |
union.union(getChild(0).getUnion()); |
| 78 |
union.union(getChild(1).getUnion()); |
| 79 |
setUnion(union); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public AlloppNode nodeOfUnionInSubtree(FixedBitSet x) { |
| 91 |
if (nofChildren() == 0) { |
| 92 |
return this; |
| 93 |
} |
| 94 |
if (x.setInclusion(getChild(0).getUnion())) { |
| 95 |
return getChild(0).nodeOfUnionInSubtree(x); |
| 96 |
} else if (x.setInclusion(getChild(1).getUnion())) { |
| 97 |
return getChild(1).nodeOfUnionInSubtree(x); |
| 98 |
} else { |
| 99 |
return this; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
public static String subtreeAsText(AlloppNode node, String s, Stack<Integer> x, int depth, String b) { |
| 104 |
Integer[] y = x.toArray(new Integer[x.size()]); |
| 105 |
StringBuffer indent = new StringBuffer(); |
| 106 |
for (int i = 0; i < depth; i++) { |
| 107 |
indent.append(" "); |
| 108 |
} |
| 109 |
for (int i = 0; i < y.length; i++) { |
| 110 |
indent.replace(2*y[i], 2*y[i]+1, "|"); |
| 111 |
} |
| 112 |
if (b.length() > 0) { |
| 113 |
indent.replace(indent.length()-b.length(), indent.length(), b); |
| 114 |
} |
| 115 |
s += indent; |
| 116 |
s += node.asText(indent.length()); |
| 117 |
s += System.getProperty("line.separator"); |
| 118 |
String subs = ""; |
| 119 |
if (node.nofChildren() > 0) { |
| 120 |
x.push(depth); |
| 121 |
subs += subtreeAsText(node.getChild(0), "", x, depth+1, "-"); |
| 122 |
x.pop(); |
| 123 |
subs += subtreeAsText(node.getChild(1), "", x, depth+1, "`-"); |
| 124 |
} |
| 125 |
return s + subs; |
| 126 |
} |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
} |