| 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 test.dr.evomodel.alloppnet.speciation; |
| 27 |
|
| 28 |
import dr.evomodel.alloppnet.speciation.AlloppMulLabTree; |
| 29 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings; |
| 30 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings.ApSpInfo; |
| 31 |
import dr.math.MathUtils; |
| 32 |
import dr.math.distributions.GammaDistribution; |
| 33 |
import org.junit.Before; |
| 34 |
import org.junit.Test; |
| 35 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings.Individual; |
| 36 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesNetworkModel; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
import static org.junit.Assert.assertEquals; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public class AlloppSpeciesNetworkModelTEST { |
| 51 |
|
| 52 |
@Before |
| 53 |
public void setUp() throws Exception { |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
@Test |
| 60 |
public void testAlloppSpeciesNetworkModel() { |
| 61 |
|
| 62 |
|
| 63 |
testNetworkToMulLabTree(); |
| 64 |
testLhoodMulLabTree(); |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public void testGammaQuantile() { |
| 77 |
MathUtils.setSeed(42); |
| 78 |
for (int i = 0; i < 1000000; i++) { |
| 79 |
double s = MathUtils.uniform(.999, 1.001); |
| 80 |
double b = MathUtils.uniform(6e-5, 7e-5); |
| 81 |
final GammaDistribution gamma = new GammaDistribution(s,b); |
| 82 |
double q = MathUtils.uniform(3e-7, 4e-7); |
| 83 |
double x = gamma.quantile(q); |
| 84 |
assert x > 1e-20; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
public void testNetworkToMulLabTree() { |
| 90 |
ApSpInfo[] apspecies = new ApSpInfo[5]; |
| 91 |
apspecies[0] = new ApSpInfo("a", 2, new Individual[0]); |
| 92 |
apspecies[1] = new ApSpInfo("b", 4, new Individual[0]); |
| 93 |
apspecies[2] = new ApSpInfo("c", 4, new Individual[0]); |
| 94 |
apspecies[3] = new ApSpInfo("d", 4, new Individual[0]); |
| 95 |
apspecies[4] = new ApSpInfo("e", 2, new Individual[0]); |
| 96 |
|
| 97 |
AlloppSpeciesBindings testASB = new AlloppSpeciesBindings(apspecies); |
| 98 |
AlloppSpeciesNetworkModel testASNM = new AlloppSpeciesNetworkModel(testASB); |
| 99 |
|
| 100 |
System.out.println("Tests of Network To MulLabTree conversion with dips a,e and tets b,c,d"); |
| 101 |
String newick; |
| 102 |
newick = testASNM.testExampleNetworkToMulLabTree(1); |
| 103 |
System.out.println(newick + "\n\n"); |
| 104 |
assertEquals(0, newick.compareTo("((((b0,c0),d0),a),(((b1,c1),d1),e))")); |
| 105 |
newick = testASNM.testExampleNetworkToMulLabTree(2); |
| 106 |
System.out.println(newick + "\n\n"); |
| 107 |
assertEquals(0, newick.compareTo("(((((b0,c0),d0),a),((b1,c1),d1)),e)")); |
| 108 |
newick = testASNM.testExampleNetworkToMulLabTree(3); |
| 109 |
System.out.println(newick + "\n\n"); |
| 110 |
assertEquals(0, newick.compareTo("(((((b0,c0),d0),((b1,c1),d1)),a),e)")); |
| 111 |
newick = testASNM.testExampleNetworkToMulLabTree(4); |
| 112 |
System.out.println(newick + "\n\n"); |
| 113 |
assertEquals(0, newick.compareTo("((((b0,c0),a),(d0,d1)),((b1,c1),e))")); |
| 114 |
newick = testASNM.testExampleNetworkToMulLabTree(5); |
| 115 |
System.out.println(newick + "\n\n"); |
| 116 |
assertEquals(0, newick.compareTo("(((((a,b0),c0),c1),(d0,d1)),(b1,e))")); |
| 117 |
System.out.println(""); |
| 118 |
System.out.println(""); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
public void testLhoodMulLabTree() { |
| 123 |
ApSpInfo[] apspecies = new ApSpInfo[3]; |
| 124 |
apspecies[0] = new ApSpInfo("a", 2, new Individual[0]); |
| 125 |
apspecies[1] = new ApSpInfo("b", 2, new Individual[0]); |
| 126 |
apspecies[2] = new ApSpInfo("z", 4, new Individual[0]); |
| 127 |
|
| 128 |
AlloppSpeciesBindings testASB = new AlloppSpeciesBindings(apspecies); |
| 129 |
AlloppMulLabTree testamlt = new AlloppMulLabTree(testASB); |
| 130 |
double llhood = testamlt.testGeneTreeInMULTreeLogLikelihood(); |
| 131 |
assertEquals(llhood, -13.562218135041552713, 1e-10); |
| 132 |
System.out.println(llhood); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
} |
| 252 |
|