/examples/example_V2.2.R

http://github.com/sbotond/phylosim · R · 39 lines · 14 code · 11 blank · 14 comment · 0 complexity · f949c1707f0bb5306b655c726d326cba MD5 · raw file

  1. #!/usr/bin/env Rscript
  2. ##
  3. ## Example V2.1.1: Simulating substitutions under the HKY model
  4. ## See also the package vignette (vignette("PhyloSim",package="phylosim")).
  5. ##
  6. # load PhyloSim
  7. library("phylosim")
  8. # Construct an HKY substitution process object:
  9. p<-HKY(rate.params=list( "Alpha"=10,"Beta"=2),
  10. base.freqs=c(4,3,2,1)/10
  11. )
  12. # Get a plot of the instantaneous substitution matrix and equilibrium distribution of the p process (bubble plot):
  13. plot(p,scale=0.5)
  14. # Construct the root sequence, attach the substitution
  15. # process to root sequence via the constructor and sample states:
  16. root.len50.seq<-NucleotideSequence(length=50,processes=list(list(p)))
  17. sampleStates(root.len50.seq)
  18. # Print out root sequence:
  19. print(root.len50.seq)
  20. # Construct a PhyloSim object, set the phylo object and the root sequence:
  21. sim<-PhyloSim(
  22. root.seq=root.len50.seq,
  23. phylo=read.tree("data/3taxa.nwk")
  24. );
  25. # Run simulation:
  26. Simulate(sim)
  27. # Save the resulting alignment (fasta format):
  28. saveAlignment(sim,file="HKY_sim.fas")