Skip to content

Instantly share code, notes, and snippets.

@rdinnager
Created July 22, 2014 04:16
Show Gist options
  • Save rdinnager/8a2a374386a6286f7416 to your computer and use it in GitHub Desktop.
Save rdinnager/8a2a374386a6286f7416 to your computer and use it in GitHub Desktop.
Code to run simple ALF simulation from R
## Generate ALF simulations
library(whisker)
ALF_template <- function() {
" webRequest := false;
uuid := '4e4937bd-70e5-4caf-8521-f4340a4b7e09';
# name of simulation - you may want to change this
mname := {{{simname}}};
# directories for file storage - you may want to change these
wdir := '{{{dir}}}';
dbdir := 'DB/';
dbAncdir := 'DBancestral/';
# time scale for simulation (PAM is default)
unitIsPam := true:
# parameters concerning the root genome
realseed := false;
protStart := {{ngenes}};
minGeneLength := {{mingenelen}};
gammaLengthDist := [2.4019, 133.8063];
blocksize := 3:
# parameters concerning the species tree
treeType := 'BDTree';
birthRate := {{brate}};
deathRate := {{drate}};
NSpecies := {{nspec}};
ultrametric := true;
mutRate := {{PAMunits}};
scaleTree := false;
# parameters concerning the substitution models
substModels := [SubstitutionModel('CPAM')];
indelModels := [IndelModel({{indelrate}}, ZIPF, [1.821], 50)];
rateVarModels := [RateVarModel(Gamma, 5, 0.01, 1)];
modelAssignments := [1]:
modelSwitchS := [[1]]:
modelSwitchD := [[1]]:
# parameters concerning gene duplication
geneDuplRate := 0;
numberDupl := 0;
transDupl := 0;
fissionDupl := 0;
fusionDupl := 0;
P_pseudogene := 0;
P_neofunc := 0;
P_subfunc := 0;
# parameters concerning gene loss
geneLossRate := 0;
# parameters concerning LGT
lgtRate := 0;
lgtGRate := 0;
lgtGSize := 0;
# parameters concerning rate heterogeneity among genes
amongGeneDistr := 'Gamma';
aGAlpha := 1;"
}
gen_ALF_drw <- function(simname, nspec, ngenes, mingenelen, PAMunits, brate, drate, indelrate, dir) {
parms <- list(simname = simname, nspec = nspec, ngenes = ngenes, mingenelen = mingenelen,
PAMunits = PAMunits, brate = brate, drate = drate, indelrate = indelrate,
dir = dir)
whisker.render(ALF_template(), parms)
}
run_ALF <- function(simname, nspec, ngenes, mingenelen, PAMunits, brate, drate, indelrate, dir, ALF_dir) {
filename <- paste0(dir, "/", simname, ".drw")
cat(gen_ALF_drw(simname, nspec, ngenes, mingenelen, PAMunits, brate, drate, indelrate, dir), file = filename)
system(paste0(ALF_dir, "/alfsim ", filename))
return(paste0(dir, "/", simname))
}
## example
dir <- "/home/din02g/Testing"
run_ALF("test", 15, 20, 400, 100, 0.04, 0.025, 0.0001, dir, "/home/din02g/ALF_standalone/bin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment