Commit 8a1fb271 authored by Jean-Francois Rey's avatar Jean-Francois Rey
Browse files

Check Genes are affected to cultivars, otherwise remove them from simulation...

Check Genes are affected to cultivars, otherwise remove them from simulation (only in LandsepiParams simul call)
parent fb93c7d5
......@@ -559,10 +559,25 @@ runSimul <- function(params, graphic=TRUE, writeTXT=TRUE, videoMP4=FALSE, keepRa
initPath <- getwd()
setwd(params@OutputDir)
## remove genes not used from CultivarsGenes and Genes
drop_genes <- lapply(1:ncol(params@CultivarsGenes), FUN = function(c) {
if(sum(params@CultivarsGenes[,c]) == 0) return(c);
})
drop_genes <- which(!sapply(drop_genes,is.null))
if( !is.null(drop_genes) && length(drop_genes) > 0){
print(paste0("Genes not affected ",params@Genes[drop_genes,1]))
cultivarsGenes_tmp <- params@CultivarsGenes[,-drop_genes]
Genes_tmp <- params@Genes[-drop_genes,]
} else {
cultivarsGenes_tmp <- params@CultivarsGenes
Genes_tmp <- params@Genes
}
cultivars_genes_list <- lapply(1:nrow(params@Cultivars), FUN = function(i) {
return(which(params@CultivarsGenes[i, ] == 1) - 1)
return(which(cultivarsGenes_tmp[i, ] == 1) - 1)
})
cdf <- as.data.frame(params@Landscape)
ncol <- length(grep("^year_", colnames(cdf)) %in% colnames(cdf))
## TODO: use value of Nyears in previous line?
......@@ -576,7 +591,7 @@ runSimul <- function(params, graphic=TRUE, writeTXT=TRUE, videoMP4=FALSE, keepRa
croptype_names = params@Croptypes$croptypeName,
cultivars = params@Cultivars,
cultivars_genes_list = cultivars_genes_list,
genes = params@Genes,
genes = Genes_tmp,
landscape = as_Spatial(st_geometry(params@Landscape)),
area = as.vector(params@Landscape$area[, 1]),
rotation = rotation,
......
......@@ -257,7 +257,7 @@ simul_landsepi <- function(seed = 12345, time_param = list(Nyears = 20, nTSpY =
sigmoid_plateau_host = 1,
cultivars_genes_list = cultivars_genes_list
)
# Evolution parameters
genes_param <- list(
name = as.character(genes$geneName),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment