## METADATA =============================================================== ## Hagen et al. Earth history events shaped the evolution of uneven biodiversity across tropical moist forests. PNAS ## Description: Config creator for gen3sis experiment ## ## R version: 4.0.0 for Windows ## Date: 2020-07-14 16:20:32 ## License: GPL3 ## Author: Oskar Hagen (oskar@hagen.bio) and Alexander Skeels (alexander.skeels@gmail.com) ##=======================================================================## ###### set working directory ###### HOME <- "PATH/TO/HOME" setwd(HOME) ###### libraries and functions ###### library(randtoolbox) linMap <- function(x, from, to) {(x - min(x)) / max(x - min(x)) * (to - from) + from} ###### create Sobol sequences for four parameters ###### n <- 500 # number of simulation params_table <- data.frame(sobol(n, 4, init = T)) # Paramater short hands # TW = Temperature niche width (omega) # Tev = temperature evolution paramater (sigma) # S = genetic divergerence threshold (S) # WeibullShape = shape of the Weibull distribution for the dispersal function (phi) colnames(params_table) <- c("Tev", "TW", "S", "WeibullShape") ###### Rescale parameters between desired range ###### #Tev params_table[,"Tev"] <- round(linMap(params_table[,"Tev"], from=0.001, to=0.02),4) #TW params_table[,"TW"] <- round(linMap(params_table[,"TW"], from=0.04, to=0.1),3) #S params_table[,"S"] <- round(linMap(params_table[,"S"], from=1.5, to=3),3) # # Weibull shape params_table[,"WeibullShape"] <- round(linMap(params_table[,"WeibullShape"], from=2, to=15),3) # Set the fixed parameters #initial abundance params_table$initialAbundance = 1 # grid cell size params_table$grid_cell_distance = 222 #seed params_table$seed = c(1:500) #start time params_table$start = round(110/0.16667) # 660 is 110mya # model name params_table$model <- sapply(seq(1, n, 1), FUN=function(x){paste("2D_FA_", x, sep="_")}) ###### Write parameters table ###### write.csv(params_table, file="Dataset_S4.csv", row.names = F) ###### Generate config files ####### setwd(HOME) for(i in 1:nrow(params_table)){ setwd(HOME) params <- params_table[i,] output_dir <- paste0('output/config_', i) config_i <- readLines('config_template_pantropics_2D_FA.R') config_i <- gsub('*.params\\$initialAbundance', params$initialAbundance, config_i) config_i <- gsub('*.params\\$S', params$S, config_i) config_i <- gsub('*.params\\$Tev', params$Tev, config_i) config_i <- gsub('*.params\\$TW', params$TW, config_i) config_i <- gsub('*.params\\$seed', params$seed, config_i) config_i <- gsub('*.params\\$start', params$start, config_i) config_i <- gsub('*.params\\$grid_cell_distance', params$grid_cell_distance, config_i) config_i <- gsub('*.params\\$WeibullShape', params$WeibullShape, config_i) setwd(# ADD THE LOCATION TO SAVE THE CONFIG FILES ) writeLines(config_i, paste0('pantropical_param_exploration_2D_FA_', i, '.R')) setwd("../") }