| 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.app.bss.test; |
| 27 |
|
| 28 |
import java.io.File; |
| 29 |
import java.io.IOException; |
| 30 |
import java.text.NumberFormat; |
| 31 |
import java.util.ArrayList; |
| 32 |
import java.util.LinkedHashMap; |
| 33 |
import java.util.Locale; |
| 34 |
|
| 35 |
import dr.evolution.tree.TreeUtils; |
| 36 |
import dr.evomodel.branchmodel.HomogeneousBranchModel; |
| 37 |
import dr.evomodel.branchmodel.RandomBranchModel; |
| 38 |
import dr.evomodel.siteratemodel.GammaSiteRateModel; |
| 39 |
import dr.evomodel.substmodel.EmpiricalRateMatrix; |
| 40 |
import dr.evomodel.substmodel.FrequencyModel; |
| 41 |
import dr.evomodel.substmodel.aminoacid.Blosum62; |
| 42 |
import dr.evomodel.substmodel.aminoacid.EmpiricalAminoAcidModel; |
| 43 |
import dr.evomodel.substmodel.codon.GY94CodonModel; |
| 44 |
import dr.evomodel.substmodel.nucleotide.HKY; |
| 45 |
import dr.evomodel.substmodel.codon.MG94CodonModel; |
| 46 |
import dr.evomodel.treelikelihood.BeagleTreeLikelihood; |
| 47 |
import dr.evomodel.treelikelihood.PartialsRescalingScheme; |
| 48 |
import dr.app.beagle.tools.BeagleSequenceSimulator; |
| 49 |
import dr.app.beagle.tools.Partition; |
| 50 |
import dr.app.bss.Utils; |
| 51 |
import dr.evolution.alignment.Alignment; |
| 52 |
import dr.evolution.alignment.ConvertAlignment; |
| 53 |
import dr.evolution.alignment.SimpleAlignment; |
| 54 |
import dr.evolution.coalescent.CoalescentSimulator; |
| 55 |
import dr.evolution.coalescent.ExponentialGrowth; |
| 56 |
import dr.evolution.datatype.AminoAcids; |
| 57 |
import dr.evolution.datatype.Codons; |
| 58 |
import dr.evolution.datatype.DataType; |
| 59 |
import dr.evolution.datatype.GeneticCode; |
| 60 |
import dr.evolution.datatype.Nucleotides; |
| 61 |
import dr.evolution.io.Importer.ImportException; |
| 62 |
import dr.evolution.io.NewickImporter; |
| 63 |
import dr.evolution.sequence.Sequence; |
| 64 |
import dr.evolution.tree.NodeRef; |
| 65 |
import dr.evolution.tree.Tree; |
| 66 |
import dr.evolution.tree.TreeTraitProvider; |
| 67 |
import dr.evolution.util.Taxa; |
| 68 |
import dr.evolution.util.Taxon; |
| 69 |
import dr.evolution.util.Units; |
| 70 |
import dr.evomodel.branchratemodel.BranchRateModel; |
| 71 |
import dr.evomodel.branchratemodel.DefaultBranchRateModel; |
| 72 |
import dr.evomodel.tree.TreeModel; |
| 73 |
import dr.inference.model.Parameter; |
| 74 |
import dr.math.MathUtils; |
| 75 |
|
| 76 |
public class BeagleSeqSimTest { |
| 77 |
|
| 78 |
public static final boolean simulateInPar = true; |
| 79 |
|
| 80 |
public static void main(String[] args) { |
| 81 |
|
| 82 |
|
| 83 |
long tic = System.currentTimeMillis(); |
| 84 |
int N = 1; |
| 85 |
for (int i = 0; i < N; i++) { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
simulateRandomBranchAssignment(); |
| 94 |
|
| 95 |
} |
| 96 |
long toc = System.currentTimeMillis(); |
| 97 |
|
| 98 |
long time = toc - tic; |
| 99 |
System.out.println("Time: " + time + "milliseconds"); |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
static void simulateRandomBranchAssignment() { |
| 104 |
|
| 105 |
try { |
| 106 |
|
| 107 |
System.out.println("Test case I dunno which: simulate random branch assignments"); |
| 108 |
|
| 109 |
MathUtils.setSeed(666); |
| 110 |
|
| 111 |
int sequenceLength = 10; |
| 112 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 113 |
|
| 114 |
File treeFile = new File("/home/filip/Dropbox/BeagleSequenceSimulator/SimTree/SimTree.figtree"); |
| 115 |
Tree tree = Utils.importTreeFromFile(treeFile); |
| 116 |
TreeModel treeModel = new TreeModel(tree); |
| 117 |
|
| 118 |
|
| 119 |
Parameter freqs = new Parameter.Default(Utils.UNIFORM_CODON_FREQUENCIES); |
| 120 |
FrequencyModel freqModel = new FrequencyModel(Codons.UNIVERSAL, |
| 121 |
freqs); |
| 122 |
|
| 123 |
|
| 124 |
Parameter omegaParameter = new Parameter.Default("omega", 1, 1.0); |
| 125 |
Parameter kappaParameter = new Parameter.Default("kappa", 1, 1.0); |
| 126 |
GY94CodonModel baseSubModel = new GY94CodonModel(Codons.UNIVERSAL, omegaParameter, kappaParameter, freqModel); |
| 127 |
|
| 128 |
RandomBranchModel substitutionModel = new RandomBranchModel(treeModel, baseSubModel, 0.25, false, -1); |
| 129 |
|
| 130 |
|
| 131 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 132 |
"siteModel"); |
| 133 |
|
| 134 |
|
| 135 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 136 |
|
| 137 |
|
| 138 |
Partition partition1 = new Partition(treeModel, |
| 139 |
substitutionModel, |
| 140 |
siteRateModel, |
| 141 |
branchRateModel, |
| 142 |
freqModel, |
| 143 |
0, |
| 144 |
sequenceLength - 1, |
| 145 |
1 |
| 146 |
); |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
partitionsList.add(partition1); |
| 153 |
|
| 154 |
|
| 155 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 156 |
partitionsList); |
| 157 |
|
| 158 |
SimpleAlignment alignment = simulator.simulate(simulateInPar, true); |
| 159 |
|
| 160 |
|
| 161 |
alignment.setOutputType(SimpleAlignment.OutputType.XML); |
| 162 |
|
| 163 |
System.out.println(alignment.toString()); |
| 164 |
|
| 165 |
|
| 166 |
} catch (Exception e) { |
| 167 |
|
| 168 |
e.printStackTrace(); |
| 169 |
|
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
static void ancestralSequenceTree() { |
| 175 |
|
| 176 |
try { |
| 177 |
|
| 178 |
LinkedHashMap<NodeRef, int[]> sequenceMap = new LinkedHashMap<NodeRef, int[]>(); |
| 179 |
DataType dataType = Nucleotides.INSTANCE; |
| 180 |
|
| 181 |
|
| 182 |
NewickImporter importer = new NewickImporter( |
| 183 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 184 |
Tree tree = importer.importTree(null); |
| 185 |
TreeModel treeModel = new TreeModel(tree); |
| 186 |
|
| 187 |
for (NodeRef node : treeModel.getNodes()) { |
| 188 |
|
| 189 |
if (treeModel.isExternal(node)) { |
| 190 |
|
| 191 |
int[] seq = new int[] { 1, 1, 1 }; |
| 192 |
sequenceMap.put(node, seq); |
| 193 |
|
| 194 |
} else { |
| 195 |
|
| 196 |
int[] seq = new int[] { 2, 2, 2 }; |
| 197 |
sequenceMap.put(node, seq); |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
AncestralSequenceTrait ancestralSequence = new AncestralSequenceTrait(sequenceMap, dataType); |
| 204 |
TreeTraitProvider[] treeTraitProviders = new TreeTraitProvider[] { ancestralSequence }; |
| 205 |
|
| 206 |
StringBuffer buffer = new StringBuffer(); |
| 207 |
NumberFormat format = NumberFormat.getNumberInstance(Locale.ENGLISH); |
| 208 |
boolean useTipLabels = true; |
| 209 |
|
| 210 |
TreeUtils.newick(treeModel, |
| 211 |
treeModel.getRoot(), |
| 212 |
useTipLabels, |
| 213 |
TreeUtils.BranchLengthType.LENGTHS_AS_TIME, |
| 214 |
format, |
| 215 |
null, |
| 216 |
treeTraitProviders, |
| 217 |
null, buffer); |
| 218 |
|
| 219 |
System.out.println(buffer); |
| 220 |
|
| 221 |
} catch (IOException e) { |
| 222 |
|
| 223 |
e.printStackTrace(); |
| 224 |
|
| 225 |
} catch (ImportException e) { |
| 226 |
|
| 227 |
e.printStackTrace(); |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
} |
| 232 |
|
| 233 |
static void simulateTopology() { |
| 234 |
|
| 235 |
try { |
| 236 |
|
| 237 |
System.out.println("Test case 1: simulateTopology"); |
| 238 |
|
| 239 |
MathUtils.setSeed(666); |
| 240 |
|
| 241 |
int sequenceLength = 10; |
| 242 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 243 |
|
| 244 |
|
| 245 |
NewickImporter importer = new NewickImporter( |
| 246 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 247 |
Tree tree = importer.importTree(null); |
| 248 |
|
| 249 |
|
| 250 |
ExponentialGrowth exponentialGrowth = new ExponentialGrowth( |
| 251 |
Units.Type.YEARS); |
| 252 |
exponentialGrowth.setN0(10); |
| 253 |
exponentialGrowth.setGrowthRate(0.5); |
| 254 |
|
| 255 |
Taxa taxa = new Taxa(); |
| 256 |
for (Taxon taxon : tree.asList()) { |
| 257 |
|
| 258 |
double absoluteHeight = Utils.getAbsoluteTaxonHeight(taxon, |
| 259 |
tree); |
| 260 |
|
| 261 |
taxon.setAttribute(Utils.ABSOLUTE_HEIGHT, absoluteHeight); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
taxa.addTaxon(taxon); |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
CoalescentSimulator topologySimulator = new CoalescentSimulator(); |
| 271 |
|
| 272 |
TreeModel treeModel = new TreeModel(topologySimulator.simulateTree( |
| 273 |
taxa, exponentialGrowth)); |
| 274 |
|
| 275 |
System.out.println(treeModel.toString()); |
| 276 |
|
| 277 |
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, |
| 278 |
0.25, 0.25 }); |
| 279 |
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, |
| 280 |
freqs); |
| 281 |
|
| 282 |
|
| 283 |
Parameter kappa = new Parameter.Default(1, 10); |
| 284 |
HKY hky = new HKY(kappa, freqModel); |
| 285 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 286 |
hky); |
| 287 |
|
| 288 |
|
| 289 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 290 |
"siteModel"); |
| 291 |
|
| 292 |
|
| 293 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 294 |
|
| 295 |
|
| 296 |
Partition partition1 = new Partition(treeModel, |
| 297 |
substitutionModel, |
| 298 |
siteRateModel, |
| 299 |
branchRateModel, |
| 300 |
freqModel, |
| 301 |
0, |
| 302 |
sequenceLength - 1, |
| 303 |
1 |
| 304 |
); |
| 305 |
|
| 306 |
partitionsList.add(partition1); |
| 307 |
|
| 308 |
|
| 309 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 310 |
partitionsList); |
| 311 |
|
| 312 |
System.out.println(simulator.simulate(simulateInPar, false).toString()); |
| 313 |
|
| 314 |
} catch (Exception e) { |
| 315 |
e.printStackTrace(); |
| 316 |
System.exit(-1); |
| 317 |
} |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
static void simulateOnePartition() { |
| 322 |
|
| 323 |
try { |
| 324 |
|
| 325 |
MathUtils.setSeed(666); |
| 326 |
|
| 327 |
System.out.println("Test case 2: simulateOnePartition"); |
| 328 |
|
| 329 |
int sequenceLength = 10; |
| 330 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 331 |
|
| 332 |
|
| 333 |
NewickImporter importer = new NewickImporter( |
| 334 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 335 |
Tree tree = importer.importTree(null); |
| 336 |
TreeModel treeModel = new TreeModel(tree); |
| 337 |
|
| 338 |
|
| 339 |
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, |
| 340 |
0.25, 0.25 }); |
| 341 |
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, |
| 342 |
freqs); |
| 343 |
|
| 344 |
|
| 345 |
Parameter kappa = new Parameter.Default(1, 10); |
| 346 |
HKY hky = new HKY(kappa, freqModel); |
| 347 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 348 |
hky); |
| 349 |
|
| 350 |
|
| 351 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 352 |
"siteModel"); |
| 353 |
|
| 354 |
|
| 355 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 356 |
|
| 357 |
|
| 358 |
Partition partition1 = new Partition(treeModel, |
| 359 |
substitutionModel, |
| 360 |
siteRateModel, |
| 361 |
branchRateModel, |
| 362 |
freqModel, |
| 363 |
0, |
| 364 |
sequenceLength - 1, |
| 365 |
1 |
| 366 |
); |
| 367 |
|
| 368 |
Sequence ancestralSequence = new Sequence(); |
| 369 |
ancestralSequence.appendSequenceString("TCAAGTGAGG"); |
| 370 |
partition1.setRootSequence(ancestralSequence); |
| 371 |
|
| 372 |
partitionsList.add(partition1); |
| 373 |
|
| 374 |
|
| 375 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 376 |
partitionsList); |
| 377 |
|
| 378 |
SimpleAlignment alignment = simulator.simulate(simulateInPar, false); |
| 379 |
|
| 380 |
|
| 381 |
alignment.setOutputType(SimpleAlignment.OutputType.XML); |
| 382 |
|
| 383 |
System.out.println(alignment.toString()); |
| 384 |
|
| 385 |
} catch (Exception e) { |
| 386 |
e.printStackTrace(); |
| 387 |
System.exit(-1); |
| 388 |
} |
| 389 |
|
| 390 |
} |
| 391 |
|
| 392 |
static void simulateTwoPartitions() { |
| 393 |
|
| 394 |
try { |
| 395 |
|
| 396 |
System.out.println("Test case 3: simulateTwoPartitions"); |
| 397 |
|
| 398 |
MathUtils.setSeed(666); |
| 399 |
|
| 400 |
int sequenceLength = 11; |
| 401 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 402 |
|
| 403 |
|
| 404 |
NewickImporter importer = new NewickImporter( |
| 405 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 406 |
Tree tree = importer.importTree(null); |
| 407 |
TreeModel treeModel = new TreeModel(tree); |
| 408 |
|
| 409 |
|
| 410 |
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, |
| 411 |
0.25, 0.25 }); |
| 412 |
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, |
| 413 |
freqs); |
| 414 |
|
| 415 |
|
| 416 |
Parameter kappa = new Parameter.Default(1, 10); |
| 417 |
HKY hky = new HKY(kappa, freqModel); |
| 418 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 419 |
hky); |
| 420 |
|
| 421 |
|
| 422 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 423 |
"siteModel"); |
| 424 |
|
| 425 |
|
| 426 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 427 |
|
| 428 |
|
| 429 |
Partition partition1 = new Partition(treeModel, |
| 430 |
substitutionModel, |
| 431 |
siteRateModel, |
| 432 |
branchRateModel, |
| 433 |
freqModel, |
| 434 |
0, |
| 435 |
3, |
| 436 |
1 |
| 437 |
); |
| 438 |
|
| 439 |
|
| 440 |
Partition Partition = new Partition(treeModel, |
| 441 |
substitutionModel, |
| 442 |
siteRateModel, |
| 443 |
branchRateModel, |
| 444 |
freqModel, |
| 445 |
4, |
| 446 |
sequenceLength - 1, |
| 447 |
1 |
| 448 |
); |
| 449 |
|
| 450 |
Sequence ancestralSequence = new Sequence(); |
| 451 |
ancestralSequence.appendSequenceString("TCAAGTG"); |
| 452 |
Partition.setRootSequence(ancestralSequence); |
| 453 |
|
| 454 |
partitionsList.add(partition1); |
| 455 |
partitionsList.add(Partition); |
| 456 |
|
| 457 |
|
| 458 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 459 |
partitionsList); |
| 460 |
|
| 461 |
System.out.println(simulator.simulate(simulateInPar, false).toString()); |
| 462 |
|
| 463 |
} catch (Exception e) { |
| 464 |
e.printStackTrace(); |
| 465 |
System.exit(-1); |
| 466 |
} |
| 467 |
|
| 468 |
} |
| 469 |
|
| 470 |
static void simulateThreePartitions(int i, int N) { |
| 471 |
|
| 472 |
try { |
| 473 |
|
| 474 |
MathUtils.setSeed(666); |
| 475 |
|
| 476 |
System.out.println("Test case 3: simulateThreePartitions"); |
| 477 |
|
| 478 |
int sequenceLength = 100000; |
| 479 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 480 |
|
| 481 |
|
| 482 |
NewickImporter importer = new NewickImporter( |
| 483 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 484 |
Tree tree = importer.importTree(null); |
| 485 |
TreeModel treeModel = new TreeModel(tree); |
| 486 |
|
| 487 |
|
| 488 |
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, |
| 489 |
0.25, 0.25 }); |
| 490 |
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, |
| 491 |
freqs); |
| 492 |
|
| 493 |
|
| 494 |
Parameter kappa = new Parameter.Default(1, 10); |
| 495 |
HKY hky = new HKY(kappa, freqModel); |
| 496 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 497 |
hky); |
| 498 |
|
| 499 |
|
| 500 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 501 |
"siteModel"); |
| 502 |
|
| 503 |
|
| 504 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 505 |
|
| 506 |
|
| 507 |
Partition partition1 = new Partition(treeModel, |
| 508 |
substitutionModel, |
| 509 |
siteRateModel, |
| 510 |
branchRateModel, |
| 511 |
freqModel, |
| 512 |
0, |
| 513 |
sequenceLength - 1, |
| 514 |
3 |
| 515 |
); |
| 516 |
|
| 517 |
|
| 518 |
Partition Partition = new Partition(treeModel, |
| 519 |
substitutionModel, |
| 520 |
siteRateModel, |
| 521 |
branchRateModel, |
| 522 |
freqModel, |
| 523 |
1, |
| 524 |
sequenceLength - 1, |
| 525 |
3 |
| 526 |
); |
| 527 |
|
| 528 |
|
| 529 |
Partition partition3 = new Partition(treeModel, |
| 530 |
substitutionModel, |
| 531 |
siteRateModel, |
| 532 |
branchRateModel, |
| 533 |
freqModel, |
| 534 |
2, |
| 535 |
sequenceLength - 1, |
| 536 |
3 |
| 537 |
); |
| 538 |
|
| 539 |
partitionsList.add(partition1); |
| 540 |
partitionsList.add(Partition); |
| 541 |
partitionsList.add(partition3); |
| 542 |
|
| 543 |
|
| 544 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 545 |
partitionsList); |
| 546 |
|
| 547 |
if (i == (N - 1)) { |
| 548 |
System.out |
| 549 |
.println(simulator.simulate(simulateInPar, false).toString()); |
| 550 |
} else { |
| 551 |
simulator.simulate(simulateInPar, false); |
| 552 |
} |
| 553 |
|
| 554 |
} catch (Exception e) { |
| 555 |
e.printStackTrace(); |
| 556 |
System.exit(-1); |
| 557 |
} |
| 558 |
|
| 559 |
} |
| 560 |
|
| 561 |
static void simulateAminoAcid() { |
| 562 |
|
| 563 |
try { |
| 564 |
|
| 565 |
System.out.println("Test case 4: simulateAminoAcid"); |
| 566 |
|
| 567 |
MathUtils.setSeed(666); |
| 568 |
|
| 569 |
int sequenceLength = 10; |
| 570 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 571 |
|
| 572 |
|
| 573 |
NewickImporter importer = new NewickImporter( |
| 574 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 575 |
Tree tree = importer.importTree(null); |
| 576 |
TreeModel treeModel = new TreeModel(tree); |
| 577 |
|
| 578 |
|
| 579 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 580 |
"siteModel"); |
| 581 |
|
| 582 |
|
| 583 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 584 |
|
| 585 |
|
| 586 |
Parameter freqs = new Parameter.Default(new double[] { 0.05, 0.05, |
| 587 |
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, |
| 588 |
0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 }); |
| 589 |
FrequencyModel freqModel = new FrequencyModel(AminoAcids.INSTANCE, |
| 590 |
freqs); |
| 591 |
|
| 592 |
|
| 593 |
EmpiricalRateMatrix rateMatrix = Blosum62.INSTANCE; |
| 594 |
|
| 595 |
EmpiricalAminoAcidModel empiricalAminoAcidModel = new EmpiricalAminoAcidModel( |
| 596 |
rateMatrix, freqModel); |
| 597 |
|
| 598 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 599 |
empiricalAminoAcidModel); |
| 600 |
|
| 601 |
|
| 602 |
Partition partition1 = new Partition(treeModel, |
| 603 |
substitutionModel, |
| 604 |
siteRateModel, |
| 605 |
branchRateModel, |
| 606 |
freqModel, |
| 607 |
0, |
| 608 |
sequenceLength - 1, |
| 609 |
1 |
| 610 |
); |
| 611 |
|
| 612 |
partitionsList.add(partition1); |
| 613 |
|
| 614 |
|
| 615 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 616 |
partitionsList); |
| 617 |
|
| 618 |
System.out.println(simulator.simulate(simulateInPar, false).toString()); |
| 619 |
|
| 620 |
} catch (Exception e) { |
| 621 |
|
| 622 |
e.printStackTrace(); |
| 623 |
System.exit(-1); |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
} |
| 628 |
|
| 629 |
static void simulateCodon() { |
| 630 |
|
| 631 |
try { |
| 632 |
|
| 633 |
boolean calculateLikelihood = true; |
| 634 |
|
| 635 |
System.out.println("Test case 6: simulate codons"); |
| 636 |
|
| 637 |
MathUtils.setSeed(666); |
| 638 |
|
| 639 |
int sequenceLength = 10; |
| 640 |
ArrayList<Partition> partitionsList = new ArrayList<Partition>(); |
| 641 |
|
| 642 |
|
| 643 |
NewickImporter importer = new NewickImporter( |
| 644 |
"(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);"); |
| 645 |
Tree tree = importer.importTree(null); |
| 646 |
TreeModel treeModel = new TreeModel(tree); |
| 647 |
|
| 648 |
|
| 649 |
GammaSiteRateModel siteRateModel = new GammaSiteRateModel( |
| 650 |
"siteModel"); |
| 651 |
|
| 652 |
|
| 653 |
BranchRateModel branchRateModel = new DefaultBranchRateModel(); |
| 654 |
|
| 655 |
|
| 656 |
Parameter freqs = new Parameter.Default(Utils.UNIFORM_CODON_FREQUENCIES); |
| 657 |
FrequencyModel freqModel = new FrequencyModel(Codons.UNIVERSAL, |
| 658 |
freqs); |
| 659 |
|
| 660 |
|
| 661 |
Parameter alpha = new Parameter.Default(1, 10); |
| 662 |
Parameter beta = new Parameter.Default(1, 5); |
| 663 |
|
| 664 |
MG94CodonModel mg94 = new MG94CodonModel(Codons.UNIVERSAL, alpha, |
| 665 |
beta, freqModel); |
| 666 |
|
| 667 |
HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel( |
| 668 |
mg94); |
| 669 |
|
| 670 |
|
| 671 |
Partition partition1 = new Partition(treeModel, |
| 672 |
substitutionModel, |
| 673 |
siteRateModel, |
| 674 |
branchRateModel, |
| 675 |
freqModel, |
| 676 |
0, |
| 677 |
sequenceLength - 1, |
| 678 |
1 |
| 679 |
); |
| 680 |
|
| 681 |
partitionsList.add(partition1); |
| 682 |
|
| 683 |
|
| 684 |
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator( |
| 685 |
partitionsList); |
| 686 |
|
| 687 |
Alignment alignment = simulator.simulate(simulateInPar, false); |
| 688 |
|
| 689 |
System.out.println(alignment.toString()); |
| 690 |
|
| 691 |
if (calculateLikelihood) { |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
ConvertAlignment convert = new ConvertAlignment( |
| 700 |
Nucleotides.INSTANCE, GeneticCode.UNIVERSAL, alignment); |
| 701 |
|
| 702 |
BeagleTreeLikelihood nbtl = new BeagleTreeLikelihood(convert, |
| 703 |
treeModel, |
| 704 |
substitutionModel, |
| 705 |
siteRateModel, |
| 706 |
branchRateModel, |
| 707 |
null, |
| 708 |
false, |
| 709 |
PartialsRescalingScheme.DEFAULT, true); |
| 710 |
|
| 711 |
System.out.println("likelihood = " + nbtl.getLogLikelihood()); |
| 712 |
|
| 713 |
} |
| 714 |
|
| 715 |
} catch (Exception e) { |
| 716 |
|
| 717 |
e.printStackTrace(); |
| 718 |
System.exit(-1); |
| 719 |
|
| 720 |
} |
| 721 |
|
| 722 |
} |
| 723 |
|
| 724 |
} |