From 9b4e7fbe9b78c360b350f40e49f72ca18f9079d9 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 29 Mar 2023 10:44:04 -0500 Subject: [PATCH 01/20] fixed `writePlink` bug --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/writePlink.R | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5c042e8c..f704b331 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations -Version: 1.4.3 +Version: 1.4.3.9990 Date: 2023-3-27 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), diff --git a/NEWS.md b/NEWS.md index bc05c17f..d3b8ea9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# AlphaSimR 1.4.3.9990 + +* fixed bug in `writePlink` to correctly export map positions in cM + # AlphaSimR 1.4.3 * another citation fix diff --git a/R/writePlink.R b/R/writePlink.R index 6898c027..085c79ac 100644 --- a/R/writePlink.R +++ b/R/writePlink.R @@ -126,7 +126,7 @@ writePlink = function(pop, baseName, traits=1, use="pheno", ## Make .map file map = rbind(map$chr, # Chromosome map$id, # Variant id - as.character(map$pos*10), # Genetic map position (cM) + as.character(map$pos*100), # Genetic map position (cM) as.character(map$site) # Physical map position ) From 47099e141f368452538d599f543b7044893256c2 Mon Sep 17 00:00:00 2001 From: philipbg <58154543+philipbg@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:18:00 +0100 Subject: [PATCH 02/20] Update misc.R Test --- R/misc.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/misc.R b/R/misc.R index cdfe6a23..b06ab14e 100644 --- a/R/misc.R +++ b/R/misc.R @@ -29,6 +29,8 @@ isFemale <- function(x) { return(ret) } +##Test + #' @describeIn isFemale Test if individuals of a population are female or male #' @export isMale <- function(x) { From b2a78426e3d2683b03fa91b8010ed28a313e8b48 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Thu, 29 Jun 2023 17:17:06 -0500 Subject: [PATCH 03/20] fixed ped as vector bug in `importInbredGeno` and `importHaplo` --- DESCRIPTION | 4 ++-- R/importData.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 91820644..b43e70ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations Version: 1.4.2.9990 -Date: 2023-3-27 +Date: 2023-6-29 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), person("Gregor", "Gorjanc", role = "ctb", @@ -12,7 +12,7 @@ Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", person("Daniel", "Money", role = "ctb", comment = c(ORCID = "0000-0001-5151-3648")), person("David", "Wilson", role = "ctb"), - person("Thiago","Oliveira", role = "ctb", + person("Thiago", "Oliveira", role = "ctb", comment = c(ORCID = "0000-0002-4555-2584")), person("Audrey", "Martin", role = "ctb", comment = c(ORCID = "0000-0003-2235-0098"))) diff --git a/R/importData.R b/R/importData.R index 2920529f..34056927 100644 --- a/R/importData.R +++ b/R/importData.R @@ -106,7 +106,7 @@ importInbredGeno = function(geno, genMap, ped=NULL){ # Extract pedigree, if supplied if(!is.null(ped)){ if(is.vector(ped)){ - id = as.character(ped[,1]) + id = as.character(ped) stopifnot(length(id)==nrow(geno), !any(duplicated(id))) mother = father = rep("0", length(id)) @@ -238,7 +238,7 @@ importHaplo = function(haplo, genMap, ploidy=2L, ped=NULL){ # Extract pedigree, if supplied if(!is.null(ped)){ if(is.vector(ped)){ - id = as.character(ped[,1]) + id = as.character(ped) stopifnot(length(id)==(nrow(haplo)/ploidy), !any(duplicated(id))) mother = father = rep("0", length(id)) From c62d3bed9756e2017e8f8f7f9874bd330769365c Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Thu, 29 Jun 2023 17:17:06 -0500 Subject: [PATCH 04/20] fixed ped as vector bug in `importInbredGeno` and `importHaplo` #141 --- DESCRIPTION | 4 ++-- R/importData.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 91820644..b43e70ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations Version: 1.4.2.9990 -Date: 2023-3-27 +Date: 2023-6-29 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), person("Gregor", "Gorjanc", role = "ctb", @@ -12,7 +12,7 @@ Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", person("Daniel", "Money", role = "ctb", comment = c(ORCID = "0000-0001-5151-3648")), person("David", "Wilson", role = "ctb"), - person("Thiago","Oliveira", role = "ctb", + person("Thiago", "Oliveira", role = "ctb", comment = c(ORCID = "0000-0002-4555-2584")), person("Audrey", "Martin", role = "ctb", comment = c(ORCID = "0000-0003-2235-0098"))) diff --git a/R/importData.R b/R/importData.R index 2920529f..34056927 100644 --- a/R/importData.R +++ b/R/importData.R @@ -106,7 +106,7 @@ importInbredGeno = function(geno, genMap, ped=NULL){ # Extract pedigree, if supplied if(!is.null(ped)){ if(is.vector(ped)){ - id = as.character(ped[,1]) + id = as.character(ped) stopifnot(length(id)==nrow(geno), !any(duplicated(id))) mother = father = rep("0", length(id)) @@ -238,7 +238,7 @@ importHaplo = function(haplo, genMap, ploidy=2L, ped=NULL){ # Extract pedigree, if supplied if(!is.null(ped)){ if(is.vector(ped)){ - id = as.character(ped[,1]) + id = as.character(ped) stopifnot(length(id)==(nrow(haplo)/ploidy), !any(duplicated(id))) mother = father = rep("0", length(id)) From 7dd1aa2f054b2ab86277aeaafa4515801455da55 Mon Sep 17 00:00:00 2001 From: philipbg <58154543+philipbg@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:08:08 +0100 Subject: [PATCH 05/20] Changed MegaPop to MultiPop --- R/Class-Pop.R | 72 +++++------ R/crossing.R | 320 ++++++++++++++++++++++++------------------------- R/hybrids.R | 186 ++++++++++++++-------------- R/mergePops.R | 30 ++--- R/phenotypes.R | 146 +++++++++++----------- R/popSummary.R | 296 ++++++++++++++++++++++----------------------- R/selection.R | 214 ++++++++++++++++----------------- 7 files changed, 632 insertions(+), 632 deletions(-) diff --git a/R/Class-Pop.R b/R/Class-Pop.R index 1c91cf54..4d01974a 100644 --- a/R/Class-Pop.R +++ b/R/Class-Pop.R @@ -797,8 +797,8 @@ isPop = function(x) { #' @title Creates an empty population #' #' @description -#' Creates an empty \code{\link{Pop-class}} object with user -#' defined ploidy and other parameters taken from simParam. +#' Creates an empty \code{\link{Pop-class}} object with user +#' defined ploidy and other parameters taken from simParam. #' #' @param ploidy the ploidy of the population #' @param simParam an object of \code{\link{SimParam}} @@ -823,24 +823,24 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP", envir=.GlobalEnv) } - + # Create 0 x nTrait matrix with trait names # For pheno and gv slots traitMat = matrix(NA_real_, nrow = 0L, ncol = simParam$nTraits) - + traitNames = character(simParam$nTraits) - + if(simParam$nTraits > 0L){ # Get trait names for(i in 1:simParam$nTraits){ traitNames[i] = simParam$traits[[i]]@name } } - + colnames(traitMat) = traitNames - + # Create empty geno list nLoci = unname(sapply(simParam$genMap, length)) geno = vector("list", simParam$nChr) @@ -848,7 +848,7 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){ DIM1 = nLoci[i]%/%8L + (nLoci[i]%%8L > 0L) geno[[i]] = array(as.raw(0), dim=c(DIM1, ploidy, 0)) } - + output = new("Pop", nInd = 0L, nChr = simParam$nChr, @@ -872,33 +872,33 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){ return(output) } -# MegaPop ------------------------------------------------------------------ +# MultiPop ------------------------------------------------------------------ -#' @title Mega-Population +#' @title Multi-Population #' #' @description #' The mega-population represents a population of populations. #' It is designed to behave like a list of populations. #' -#' @param x a 'MegaPop' object +#' @param x a 'MultiPop' object #' @param i index of populations or mega-populations -#' @param ... additional 'MegaPop' or 'Pop' objects +#' @param ... additional 'MultiPop' or 'Pop' objects #' #' @slot pops list of \code{\link{Pop-class}} and/or -#' \code{MegaPop-class} +#' \code{MultiPop-class} #' #' #' @export -setClass("MegaPop", +setClass("MultiPop", slots=c(pops="list")) -setValidity("MegaPop",function(object){ +setValidity("MultiPop",function(object){ errors = character() # Check that all populations are valid for(i in 1:length(object@pops)){ if(!validObject(object@pops[[i]]) & (is(object@pops[[i]], "Pop") | - is(object@pops[[i]],"MegaPop"))){ + is(object@pops[[i]],"MultiPop"))){ errors = c(errors,paste("object",i,"is not a valid pop")) } } @@ -909,26 +909,26 @@ setValidity("MegaPop",function(object){ } }) -#' @describeIn MegaPop Extract MegaPop by index +#' @describeIn MultiPop Extract MultiPop by index setMethod("[", - signature(x = "MegaPop"), + signature(x = "MultiPop"), function(x, i){ x@pops = x@pops[i] return(x) } ) -#' @describeIn MegaPop Extract Pop by index +#' @describeIn MultiPop Extract Pop by index setMethod("[[", - signature(x = "MegaPop"), + signature(x = "MultiPop"), function (x, i){ return(x@pops[[i]]) } ) -#' @describeIn MegaPop Combine multiple MegaPops +#' @describeIn MultiPop Combine multiple MultiPops setMethod("c", - signature(x = "MegaPop"), + signature(x = "MultiPop"), function (x, ...){ for(y in list(...)){ if(is(y,"NULL")){ @@ -937,7 +937,7 @@ setMethod("c", if(is(y,"Pop")){ x@pops = c(x@pops, y) }else{ - stopifnot(is(y,"MegaPop")) + stopifnot(is(y,"MultiPop")) x@pops = c(x@pops, y@pops) } } @@ -946,17 +946,17 @@ setMethod("c", } ) -#' @title Create new Mega Population +#' @title Create new Multi Population #' #' @description -#' Creates a new \code{\link{MegaPop-class}} from one or more -#' \code{\link{Pop-class}} and/or \code{\link{MegaPop-class}} +#' Creates a new \code{\link{MultiPop-class}} from one or more +#' \code{\link{Pop-class}} and/or \code{\link{MultiPop-class}} #' objects. #' #' @param ... one or more \code{\link{Pop-class}} and/or -#' \code{\link{MegaPop-class}} objects. +#' \code{\link{MultiPop-class}} objects. #' -#' @return Returns an object of \code{\link{MegaPop-class}} +#' @return Returns an object of \code{\link{MultiPop-class}} #' #' @examples #' #Create founder haplotypes @@ -968,21 +968,21 @@ setMethod("c", #' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' megaPop = newMegaPop(pop=pop) -#' isMegaPop(megaPop) +#' megaPop = newMultiPop(pop=pop) +#' isMultiPop(megaPop) #' #' @export -newMegaPop = function(...){ +newMultiPop = function(...){ input = list(...) class = sapply(input, "class") - stopifnot(all(class=="Pop" | class=="MegaPop")) - output = new("MegaPop", pops=input) + stopifnot(all(class=="Pop" | class=="MultiPop")) + output = new("MultiPop", pops=input) return(output) } -#' @describeIn MegaPop Test if object is of a MegaPop class +#' @describeIn MultiPop Test if object is of a MultiPop class #' @export -isMegaPop = function(x) { - ret = is(x, class2 = "MegaPop") +isMultiPop = function(x) { + ret = is(x, class2 = "MultiPop") return(ret) } diff --git a/R/crossing.R b/R/crossing.R index dbbcb5a3..e0fa994b 100644 --- a/R/crossing.R +++ b/R/crossing.R @@ -1,28 +1,28 @@ #' @title Make designed crosses -#' +#' #' @description -#' Makes crosses within a population using a user supplied +#' Makes crosses within a population using a user supplied #' crossing plan. #' #' @param pop an object of \code{\link{Pop-class}} -#' @param crossPlan a matrix with two column representing -#' female and male parents. Either integers for the position in +#' @param crossPlan a matrix with two column representing +#' female and male parents. Either integers for the position in #' population or character strings for the IDs. #' @param nProgeny number of progeny per cross #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Cross individual 1 with individual 10 #' crossPlan = matrix(c(1,10), nrow=1, ncol=2) #' pop2 = makeCross(pop, crossPlan, simParam=SP) @@ -90,35 +90,35 @@ makeCross = function(pop,crossPlan,nProgeny=1, } #' @title Make random crosses -#' -#' @description -#' A wrapper for \code{\link{makeCross}} that randomly -#' selects parental combinations for all possible combinantions. -#' +#' +#' @description +#' A wrapper for \code{\link{makeCross}} that randomly +#' selects parental combinations for all possible combinantions. +#' #' @param pop an object of \code{\link{Pop-class}} #' @param nCrosses total number of crosses to make #' @param nProgeny number of progeny per cross -#' @param balance if using sexes, this option will balance the number +#' @param balance if using sexes, this option will balance the number #' of progeny per parent #' @param parents an optional vector of indices for allowable parents #' @param ignoreSexes should sexes be ignored #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Make 10 crosses #' pop2 = randCross(pop, 10, simParam=SP) -#' +#' #' @export randCross = function(pop,nCrosses,nProgeny=1, balance=TRUE,parents=NULL, @@ -175,59 +175,59 @@ randCross = function(pop,nCrosses,nProgeny=1, } #' @title Select and randomly cross -#' -#' @description -#' This is a wrapper that combines the functionalities of -#' \code{\link{randCross}} and \code{\link{selectInd}}. The -#' purpose of this wrapper is to combine both selection and -#' crossing in one function call that minimized the amount -#' of intermediate populations created. This reduces RAM usage -#' and simplifies code writing. Note that this wrapper does not -#' provide the full functionality of either function. -#' +#' +#' @description +#' This is a wrapper that combines the functionalities of +#' \code{\link{randCross}} and \code{\link{selectInd}}. The +#' purpose of this wrapper is to combine both selection and +#' crossing in one function call that minimized the amount +#' of intermediate populations created. This reduces RAM usage +#' and simplifies code writing. Note that this wrapper does not +#' provide the full functionality of either function. +#' #' @param pop an object of \code{\link{Pop-class}} -#' @param nInd the number of individuals to select. These individuals -#' are selected without regards to sex and it supercedes values -#' for nFemale and nMale. Thus if the simulation uses sexes, it is -#' likely better to leave this value as NULL and use nFemale and nMale +#' @param nInd the number of individuals to select. These individuals +#' are selected without regards to sex and it supercedes values +#' for nFemale and nMale. Thus if the simulation uses sexes, it is +#' likely better to leave this value as NULL and use nFemale and nMale #' instead. -#' @param nFemale the number of females to select. This value is ignored +#' @param nFemale the number of females to select. This value is ignored #' if nInd is set. -#' @param nMale the number of males to select. This value is ignored +#' @param nMale the number of males to select. This value is ignored #' if nInd is set. #' @param nCrosses total number of crosses to make #' @param nProgeny number of progeny per cross -#' @param trait the trait for selection. Either a number indicating +#' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. #' @param use select on genetic values "gv", estimated -#' breeding values "ebv", breeding values "bv", phenotypes "pheno", +#' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" -#' @param selectTop selects highest values if true. +#' @param selectTop selects highest values if true. #' Selects lowest values if false. #' @param simParam an object of \code{\link{SimParam}} -#' @param ... additional arguments if using a function for +#' @param ... additional arguments if using a function for #' trait -#' @param balance if using sexes, this option will balance the number -#' of progeny per parent. This argument occurs after ..., so the argument +#' @param balance if using sexes, this option will balance the number +#' of progeny per parent. This argument occurs after ..., so the argument #' name must be matched exactly. -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Select 4 individuals and make 8 crosses #' pop2 = selectCross(pop, nInd=4, nCrosses=8, simParam=SP) -#' +#' #' @export selectCross = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses, nProgeny=1,trait=1,use="pheno",selectTop=TRUE, @@ -254,48 +254,48 @@ selectCross = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses, returnPop=FALSE,simParam=simParam,...) parents = c(females,males) } - + return(randCross(pop=pop,nCrosses=nCrosses,nProgeny=nProgeny, balance=balance,parents=parents, ignoreSexes=FALSE,simParam=simParam)) } #' @title Make designed crosses -#' +#' #' @description -#' Makes crosses between two populations using a user supplied +#' Makes crosses between two populations using a user supplied #' crossing plan. #' #' @param females an object of \code{\link{Pop-class}} for female parents. #' @param males an object of \code{\link{Pop-class}} for male parents. -#' @param crossPlan a matrix with two column representing -#' female and male parents. Either integers for the position in +#' @param crossPlan a matrix with two column representing +#' female and male parents. Either integers for the position in #' population or character strings for the IDs. #' @param nProgeny number of progeny per cross #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return Returns an object of \code{\link{Pop-class}} #' -#' @examples +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Cross individual 1 with individual 10 #' crossPlan = matrix(c(1,10), nrow=1, ncol=2) #' pop2 = makeCross2(pop, pop, crossPlan, simParam=SP) -#' +#' #' @export makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if((females@ploidy%%2L != 0L) | + if((females@ploidy%%2L != 0L) | (males@ploidy%%2L != 0L)){ stop("You can not cross indiviuals with odd ploidy levels") } @@ -306,7 +306,7 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL){ stop("Failed to match supplied IDs") } } - if((max(crossPlan[,1])>nInd(females)) | + if((max(crossPlan[,1])>nInd(females)) | (max(crossPlan[,2])>nInd(males)) | (min(crossPlan)<1L)){ stop("Invalid crossPlan") @@ -354,40 +354,40 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL){ } #' @title Make random crosses -#' -#' @description -#' A wrapper for \code{\link{makeCross2}} that randomly -#' selects parental combinations for all possible combinantions between +#' +#' @description +#' A wrapper for \code{\link{makeCross2}} that randomly +#' selects parental combinations for all possible combinantions between #' two populations. -#' +#' #' @param females an object of \code{\link{Pop-class}} for female parents. #' @param males an object of \code{\link{Pop-class}} for male parents. #' @param nCrosses total number of crosses to make #' @param nProgeny number of progeny per cross -#' @param balance this option will balance the number +#' @param balance this option will balance the number #' of progeny per parent -#' @param femaleParents an optional vector of indices for allowable +#' @param femaleParents an optional vector of indices for allowable #' female parents -#' @param maleParents an optional vector of indices for allowable +#' @param maleParents an optional vector of indices for allowable #' male parents #' @param ignoreSexes should sex be ignored #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Make 10 crosses #' pop2 = randCross2(pop, pop, 10, simParam=SP) -#' +#' #' @export randCross2 = function(females,males,nCrosses,nProgeny=1, balance=TRUE,femaleParents=NULL, @@ -411,12 +411,12 @@ randCross2 = function(females,males,nCrosses,nProgeny=1, female = femaleParents male = maleParents }else{ - female = which(females@sex=="F" & + female = which(females@sex=="F" & (1:females@nInd)%in%femaleParents) if(length(female)==0){ stop("population doesn't contain any females") } - male = which(males@sex=="M" & + male = which(males@sex=="M" & (1:males@nInd)%in%maleParents) if(length(male)==0){ stop("population doesn't contain any males") @@ -449,43 +449,43 @@ randCross2 = function(females,males,nCrosses,nProgeny=1, } #' @title Self individuals -#' -#' @description -#' Creates selfed progeny from each individual in a +#' +#' @description +#' Creates selfed progeny from each individual in a #' population. Only works when sexes is "no". -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param nProgeny total number of selfed progeny per individual #' @param parents an optional vector of indices for allowable parents -#' @param keepParents should previous parents be used for mother and -#' father. +#' @param keepParents should previous parents be used for mother and +#' father. #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Self pollinate each individual #' pop2 = self(pop, simParam=SP) -#' +#' #' @export self = function(pop,nProgeny=1,parents=NULL,keepParents=TRUE, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(is.null(parents)) - pop@pops = lapply(pop@pops, self, nProgeny=nProgeny, - parents=NULL, keepParents=keepParents, + pop@pops = lapply(pop@pops, self, nProgeny=nProgeny, + parents=NULL, keepParents=keepParents, simParam=simParam) return(pop) } @@ -550,40 +550,40 @@ self = function(pop,nProgeny=1,parents=NULL,keepParents=TRUE, } #' @title Generates DH lines -#' -#' @description Creates DH lines from each individual in a population. -#' Only works with diploid individuals. For polyploids, use +#' +#' @description Creates DH lines from each individual in a population. +#' Only works with diploid individuals. For polyploids, use #' \code{\link{reduceGenome}} and \code{\link{doubleGenome}}. -#' +#' #' @param pop an object of 'Pop' superclass #' @param nDH total number of DH lines per individual -#' @param useFemale should female recombination rates be used. -#' @param keepParents should previous parents be used for mother and -#' father. +#' @param useFemale should female recombination rates be used. +#' @param keepParents should previous parents be used for mother and +#' father. #' @param simParam an object of 'SimParam' class -#' +#' #' @return Returns an object of \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Create 1 DH for each individual #' pop2 = makeDH(pop, simParam=SP) -#' +#' #' @export makeDH = function(pop,nDH=1,useFemale=TRUE,keepParents=TRUE, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ pop@pops = lapply(pop@pops, makeDH, nDH=nDH, useFemale=useFemale, keepParents=keepParents, simParam=simParam) return(pop) @@ -693,69 +693,69 @@ sortPed = function(id, mother, father, maxCycle=100){ } #' @title Pedigree cross -#' +#' #' @description -#' Creates a \code{\link{Pop-class}} from a generic -#' pedigree and a set of founder individuals. +#' Creates a \code{\link{Pop-class}} from a generic +#' pedigree and a set of founder individuals. #' #' @param founderPop a \code{\link{Pop-class}} -#' @param id a vector of unique identifiers for individuals -#' in the pedigree. The values of these IDs are seperate from +#' @param id a vector of unique identifiers for individuals +#' in the pedigree. The values of these IDs are seperate from #' the IDs in the founderPop if matchID=FALSE. -#' @param mother a vector of identifiers for the mothers -#' of individuals in the pedigree. Must match one of the +#' @param mother a vector of identifiers for the mothers +#' of individuals in the pedigree. Must match one of the #' elements in the id vector or they will be treated as unknown. -#' @param father a vector of identifiers for the fathers -#' of individuals in the pedigree. Must match one of the +#' @param father a vector of identifiers for the fathers +#' of individuals in the pedigree. Must match one of the #' elements in the id vector or they will be treated as unknown. -#' @param matchID indicates if the IDs in founderPop should be +#' @param matchID indicates if the IDs in founderPop should be #' matched to the id argument. See details. -#' @param maxCycle the maximum number of loops to make over the pedigree +#' @param maxCycle the maximum number of loops to make over the pedigree #' to sort it. -#' @param DH an optional vector indicating if an individual +#' @param DH an optional vector indicating if an individual #' should be made a doubled haploid. -#' @param nSelf an optional vector indicating how many generations an +#' @param nSelf an optional vector indicating how many generations an #' individual should be selfed. -#' @param useFemale If creating DH lines, should female recombination +#' @param useFemale If creating DH lines, should female recombination #' rates be used. This parameter has no effect if, recombRatio=1. #' @param simParam an object of 'SimParam' class -#' -#' @description -#' The way in which the user supplied pedigree is used depends on -#' the value of matchID. If matchID is TRUE, the IDs in the user -#' supplied pedigree are matched against founderNames. If matchID -#' is FALSE, founder individuals in the user supplied pedigree are +#' +#' @description +#' The way in which the user supplied pedigree is used depends on +#' the value of matchID. If matchID is TRUE, the IDs in the user +#' supplied pedigree are matched against founderNames. If matchID +#' is FALSE, founder individuals in the user supplied pedigree are #' randomly sampled from founderPop. -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Pedigree for a biparental cross with 7 generations of selfing #' id = 1:10 #' mother = c(0,0,1,3:9) #' father = c(0,0,2,3:9) #' pop2 = pedigreeCross(pop, id, mother, father, simParam=SP) -#' -#' +#' +#' #' @export -pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, - maxCycle=100, DH=NULL, nSelf=NULL, useFemale=TRUE, +pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, + maxCycle=100, DH=NULL, nSelf=NULL, useFemale=TRUE, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - + if(simParam$sexes!="no"){ stop("pedigreeCross currently only works with sex='no'") } - + # Coerce input data id = as.character(id) mother = as.character(mother) @@ -768,22 +768,22 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, if(is.null(nSelf)){ nSelf = rep(0, length(id)) } - + # Check input data stopifnot(!any(duplicated(id)), length(id)==length(mother), length(id)==length(father), length(id)==length(DH), length(id)==length(nSelf)) - + # Sort pedigree (identifies potential problems) - ped = sortPed(id=id, mother=mother, father=father, + ped = sortPed(id=id, mother=mother, father=father, maxCycle=maxCycle) - + # Create list for new population output = vector("list", length=length(id)) - - # Order and assign founders + + # Order and assign founders isFounder = is.na(ped$father) & is.na(ped$mother) motherIsFounder = is.na(ped$mother) & !is.na(ped$father) fatherIsFounder = is.na(ped$father) & !is.na(ped$mother) @@ -802,17 +802,17 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, if(nFounder>founderPop@nInd){ stop(paste("Pedigree requires",nFounder,"founders, but only",founderPop@nInd,"were supplied")) } - + # Randomly assign individuals as founders founderPop = founderPop[sample.int(founderPop@nInd,nFounder)] - + # isFounder n1 = 1 n2 = sum(isFounder) founderPop@id[n1:n2] = id[isFounder] founderPop@mother[n1:n2] = mother[isFounder] founderPop@father[n1:n2] = father[isFounder] - + # motherIsFounder n = sum(motherIsFounder) if(n>=1){ @@ -822,7 +822,7 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, founderPop@mother[n1:n2] = rep("0", n2-n1+1) founderPop@father[n1:n2] = rep("0", n2-n1+1) } - + # fatherIsFounder n = sum(fatherIsFounder) if(n>=1){ @@ -833,7 +833,7 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, founderPop@father[n1:n2] = rep("0", n2-n1+1) } } - + # Create individuals crossPlan = matrix(c(1,1),ncol=2) for(gen in 1:max(ped$gen)){ @@ -862,7 +862,7 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, simParam=simParam) } } - + # Self? if(nSelf[i]>0){ for(j in 1:nSelf[i]){ @@ -870,7 +870,7 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, simParam=simParam) } } - + # Make the individual a DH? if(DH[i]){ output[[i]] = makeDH(output[[i]], @@ -879,15 +879,15 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, } } } - + # Collapse list to a population output = mergePops(output) - + # Copy over names output@id = id output@mother = mother output@father = father - + return(output) } diff --git a/R/hybrids.R b/R/hybrids.R index b60fa856..0005941b 100644 --- a/R/hybrids.R +++ b/R/hybrids.R @@ -1,35 +1,35 @@ #' @title Hybrid crossing -#' -#' @description -#' A convience function for hybrid plant breeding simulations. Allows for -#' easy specification of a test cross scheme and/or creation of an object -#' of \code{\link{HybridPop-class}}. Note that the \code{\link{HybridPop-class}} -#' should only be used if the parents were created using the \code{\link{makeDH}} -#' function or \code{\link{newPop}} using inbred founders. The id for +#' +#' @description +#' A convience function for hybrid plant breeding simulations. Allows for +#' easy specification of a test cross scheme and/or creation of an object +#' of \code{\link{HybridPop-class}}. Note that the \code{\link{HybridPop-class}} +#' should only be used if the parents were created using the \code{\link{makeDH}} +#' function or \code{\link{newPop}} using inbred founders. The id for #' new individuals is [mother_id]_[father_id] -#' +#' #' @param females female population, an object of \code{\link{Pop-class}} #' @param males male population, an object of \code{\link{Pop-class}} -#' @param crossPlan either "testcross" for all possible combinantions +#' @param crossPlan either "testcross" for all possible combinantions #' or a matrix with two columns for designed crosses -#' @param returnHybridPop should results be returned as -#' \code{\link{HybridPop-class}}. If false returns results as +#' @param returnHybridPop should results be returned as +#' \code{\link{HybridPop-class}}. If false returns results as #' \code{\link{Pop-class}}. Population must be fully inbred if TRUE. #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Make crosses for full diallele #' pop2 = hybridCross(pop, pop, simParam=SP) -#' +#' #' @export hybridCross = function(females, males, crossPlan="testcross", @@ -38,7 +38,7 @@ hybridCross = function(females, males, if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if((females@ploidy%%2L != 0L) | + if((females@ploidy%%2L != 0L) | (males@ploidy%%2L != 0L)){ stop("You can not cross indiviuals with odd ploidy levels") } @@ -51,12 +51,12 @@ hybridCross = function(females, males, stop(paste0("crossPlan=",crossPlan," is not a valid option")) } } - + #Set id femaleParents = females@id[crossPlan[,1]] maleParents = males@id[crossPlan[,2]] id = paste(femaleParents, maleParents, sep="_") - + #Return Pop-class if(!returnHybridPop){ return(makeCross2(females=females, @@ -64,7 +64,7 @@ hybridCross = function(females, males, crossPlan=crossPlan, simParam=simParam)) } - + #Return HybridPop-class gv = matrix(NA_real_, nrow=length(id), @@ -85,7 +85,7 @@ hybridCross = function(females, males, } } if(simParam$nTraits>0){ - pheno = addError(gv, simParam$varE, + pheno = addError(gv, simParam$varE, reps=rep(1, simParam$nTraits)) }else{ pheno = gv @@ -103,32 +103,32 @@ hybridCross = function(females, males, } #' @title Calculate GCA -#' -#' @description -#' Calculate general combining ability of test crosses. Intended for -#' output from hybridCross using the "testcross" option, but will work +#' +#' @description +#' Calculate general combining ability of test crosses. Intended for +#' output from hybridCross using the "testcross" option, but will work #' for any population. -#' -#' @param pop an object of \code{\link{Pop-class}} or +#' +#' @param pop an object of \code{\link{Pop-class}} or #' \code{\link{HybridPop-class}} #' @param use tabulate either genetic values "gv", estimated #' breeding values "ebv", or phenotypes "pheno" -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Make crosses for full diallele #' pop2 = hybridCross(pop, pop, simParam=SP) #' GCA = calcGCA(pop2, use="gv") -#' +#' #' @export calcGCA = function(pop,use="pheno"){ if(use=="pheno"){ @@ -219,11 +219,11 @@ calcGCA = function(pop,use="pheno"){ } #' @title Set GCA as phenotype -#' -#' @description -#' Calculates general combining ability from a set of testers and +#' +#' @description +#' Calculates general combining ability from a set of testers and #' returns these values as phenotypes for a population. -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param testers an object of \code{\link{Pop-class}} #' @param use true genetic value (\code{gv}) or phenotypes (\code{pheno}, default) @@ -231,53 +231,53 @@ calcGCA = function(pop,use="pheno"){ #' each trait. See details in \code{\link{setPheno}}. #' @param H2 a vector of desired broad-sense heritabilities for #' each trait. See details in \code{\link{setPheno}}. -#' @param varE error (co)variances for traits. +#' @param varE error (co)variances for traits. #' See details in \code{\link{setPheno}}. -#' @param corE an optional matrix for correlations between errors. +#' @param corE an optional matrix for correlations between errors. #' See details in \code{\link{setPheno}}. -#' @param reps number of replications for phenotype. +#' @param reps number of replications for phenotype. #' See details in \code{\link{setPheno}}. -#' @param fixEff fixed effect to assign to the population. Used +#' @param fixEff fixed effect to assign to the population. Used #' by genomic selection models only. -#' @param p the p-value for the environmental covariate +#' @param p the p-value for the environmental covariate #' used by GxE traits. If NULL, a value is #' sampled at random. -#' @param inbred are both pop and testers fully inbred. They are only -#' fully inbred if created by \code{\link{newPop}} using inbred founders +#' @param inbred are both pop and testers fully inbred. They are only +#' fully inbred if created by \code{\link{newPop}} using inbred founders #' or by the \code{\link{makeDH}} function #' @param onlyPheno should only the phenotype be returned, see return #' @param simParam an object of \code{\link{SimParam}} -#' -#' -#' @return Returns an object of \code{\link{Pop-class}} or +#' +#' +#' @return Returns an object of \code{\link{Pop-class}} or #' a matrix if onlyPheno=TRUE -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Set phenotype to average per #' pop2 = setPhenoGCA(pop, pop, use="gv", inbred=TRUE, simParam=SP) -#' +#' #' @export setPhenoGCA = function(pop, testers, use="pheno", h2=NULL, H2=NULL, - varE=NULL, corE=NULL, reps=1, fixEff=1L, p=NULL, + varE=NULL, corE=NULL, reps=1, fixEff=1L, p=NULL, inbred=FALSE, onlyPheno=FALSE, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(class(testers)=="Pop", !onlyPheno) - pop@pops = lapply(pop@pops, setPhenoGCA, testers=testers, - use=use, h2=h2, H2=H2, varE=varE, corE=corE, - reps=reps, fixEff=fixEff, p=p, inbred=inbred, + pop@pops = lapply(pop@pops, setPhenoGCA, testers=testers, + use=use, h2=h2, H2=H2, varE=varE, corE=corE, + reps=reps, fixEff=fixEff, p=p, inbred=inbred, onlyPheno=FALSE, simParam=simParam) return(pop) } @@ -291,7 +291,7 @@ setPhenoGCA = function(pop, testers, use="pheno", h2=NULL, H2=NULL, returnHybridPop=inbred, simParam=simParam) #Get response if(use=="pheno"){ - y = setPheno(tmp, h2=h2, H2=H2, varE=varE, corE=corE, + y = setPheno(tmp, h2=h2, H2=H2, varE=varE, corE=corE, p=p, reps=reps, onlyPheno=TRUE, simParam=simParam) }else if(use=="gv"){ y = tmp@gv @@ -322,74 +322,74 @@ setPhenoGCA = function(pop, testers, use="pheno", h2=NULL, H2=NULL, } #' @title Set progeny test as phenotype -#' -#' @description -#' Models a progeny test of individuals in 'pop'. Returns 'pop' with a phenotype +#' +#' @description +#' Models a progeny test of individuals in 'pop'. Returns 'pop' with a phenotype #' representing the average performance of their progeny. The phenotype is generated -#' by mating individuals in 'pop' to randomly chosen individuals in testPop a +#' by mating individuals in 'pop' to randomly chosen individuals in testPop a #' number of times equal to 'nMatePerInd'. -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param testPop an object of \code{\link{Pop-class}} -#' @param nMatePerInd number of times an individual in 'pop' is mated to an +#' @param nMatePerInd number of times an individual in 'pop' is mated to an #' individual in testPop #' @param use true genetic value (\code{gv}) or phenotypes (\code{pheno}, default) #' @param h2 a vector of desired narrow-sense heritabilities for #' each trait. See details in \code{\link{setPheno}}. #' @param H2 a vector of desired broad-sense heritabilities for #' each trait. See details in \code{\link{setPheno}}. -#' @param varE error (co)variances for traits. +#' @param varE error (co)variances for traits. #' See details in \code{\link{setPheno}}. -#' @param corE an optional matrix for correlations between errors. +#' @param corE an optional matrix for correlations between errors. #' See details in \code{\link{setPheno}}. -#' @param reps number of replications for phenotype. +#' @param reps number of replications for phenotype. #' See details in \code{\link{setPheno}}. -#' @param fixEff fixed effect to assign to the population. Used +#' @param fixEff fixed effect to assign to the population. Used #' by genomic selection models only. -#' @param p the p-value for the environmental covariate +#' @param p the p-value for the environmental covariate #' used by GxE traits. If NULL, a value is #' sampled at random. #' @param onlyPheno should only the phenotype be returned, see return #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @details -#' The reps parameter is for convenient representation of replicated data. -#' It was intended for representation of replicated yield trials in plant -#' breeding programs. In this case, varE is set to the plot error and -#' reps is set to the number plots per entry. The resulting phenotype +#' The reps parameter is for convenient representation of replicated data. +#' It was intended for representation of replicated yield trials in plant +#' breeding programs. In this case, varE is set to the plot error and +#' reps is set to the number plots per entry. The resulting phenotype #' would reflect the mean of all replications. -#' -#' @return Returns an object of \code{\link{Pop-class}} or +#' +#' @return Returns an object of \code{\link{Pop-class}} or #' a matrix if onlyPheno=TRUE -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) -#' +#' #' #Create two populations of 5 individuals #' pop1 = newPop(founderPop[1:5], simParam=SP) #' pop2 = newPop(founderPop[6:10], simParam=SP) -#' +#' #' #Set phenotype according to a progeny test #' pop3 = setPhenoProgTest(pop1, pop2, use="gv", simParam=SP) -#' +#' #' @export -setPhenoProgTest = function(pop, testPop, nMatePerInd=1L, use="pheno", - h2=NULL, H2=NULL, varE=NULL, corE=NULL, - reps=1, fixEff=1L, p=NULL, onlyPheno=FALSE, +setPhenoProgTest = function(pop, testPop, nMatePerInd=1L, use="pheno", + h2=NULL, H2=NULL, varE=NULL, corE=NULL, + reps=1, fixEff=1L, p=NULL, onlyPheno=FALSE, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(class(testPop)=="Pop", !onlyPheno) - pop@pops = lapply(pop@pops, setPhenoProgTest, testPop=testPop, - nMatePerInd=nMatePerInd, use=use, h2=h2, H2=H2, - varE=varE, corE=corE, reps=reps, fixEff=fixEff, + pop@pops = lapply(pop@pops, setPhenoProgTest, testPop=testPop, + nMatePerInd=nMatePerInd, use=use, h2=h2, H2=H2, + varE=varE, corE=corE, reps=reps, fixEff=fixEff, p=p, onlyPheno=FALSE, simParam=simParam) return(pop) } @@ -403,7 +403,7 @@ setPhenoProgTest = function(pop, testPop, nMatePerInd=1L, use="pheno", balance=TRUE, simParam=simParam) #Get response if(use=="pheno"){ - y = setPheno(tmp, h2=h2, H2=H2, varE=varE, corE=corE, + y = setPheno(tmp, h2=h2, H2=H2, varE=varE, corE=corE, reps=reps, p=p, onlyPheno=TRUE, simParam=simParam) }else if(use=="gv"){ y = tmp@gv @@ -417,7 +417,7 @@ setPhenoProgTest = function(pop, testPop, nMatePerInd=1L, use="pheno", #Calculate simple means tmp = aggregate(y~female, FUN=mean) GCAf = unname(as.matrix(tmp[,-1,drop=F])) - + if(onlyPheno){ return(GCAf) } diff --git a/R/mergePops.R b/R/mergePops.R index 8a924bb5..21aa8991 100644 --- a/R/mergePops.R +++ b/R/mergePops.R @@ -1,36 +1,36 @@ #' @title Merge list of populations -#' +#' #' @description Rapidly merges a list of populations into a #' single population -#' -#' @param popList a list containing \code{\link{Pop-class}} elements -#' or a \code{\link{MegaPop-class}} -#' +#' +#' @param popList a list containing \code{\link{Pop-class}} elements +#' or a \code{\link{MultiPop-class}} +#' #' @return Returns a \code{\link{Pop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) -#' +#' #' #Create a list of populations and merge list #' pop = newPop(founderPop, simParam=SP) #' popList = list(pop, pop) #' pop2 = mergePops(popList) -#' +#' #' @export mergePops = function(popList){ - if(is(popList,"MegaPop")){ + if(is(popList,"MultiPop")){ for(i in 1:length(popList@pops)){ - if(is(popList@pops[i],"MegaPop")){ + if(is(popList@pops[i],"MultiPop")){ popList@pops[i] = mergePops(popList@pops[i]) } } popList = popList@pops } - + classes = do.call("c",lapply(popList, function(x) class(x))) if(any(classes=="NULL")){ @@ -76,12 +76,12 @@ mergePops = function(popList){ fixEff= do.call("c", lapply(popList, function(x) x@fixEff)) - + #misc misc = do.call("c", lapply(popList, function(x) x@misc)) - + #sex sex = do.call("c", lapply(popList, diff --git a/R/phenotypes.R b/R/phenotypes.R index e2ba96b7..3def62fc 100644 --- a/R/phenotypes.R +++ b/R/phenotypes.R @@ -27,118 +27,118 @@ addError = function(gv, varE, reps){ #See setPheno documentation calcPheno = function(pop, varE, reps, p, traits, simParam){ nTraits = length(traits) - + if(nTraits==0L){ return(pop@pheno) } - + gv = pop@gv for(i in 1:nTraits){ if(.hasSlot(simParam$traits[[traits[i]]], "envVar")){ stdDev = sqrt(simParam$traits[[traits[i]]]@envVar) - gv[,traits[i]] = gv[,traits[i]] + + gv[,traits[i]] = gv[,traits[i]] + pop@gxe[[traits[i]]]*qnorm(p[i], sd=stdDev) } } gv = gv[,traits,drop=FALSE] - + # Calculate new phenotypes newPheno = addError(gv=gv, varE=varE, reps=reps) - + # Add to old phenotype pheno = pop@pheno pheno[,traits] = newPheno - + return(pheno) } #' @title Set phenotypes -#' -#' @description -#' Sets phenotypes for all traits by adding random error +#' +#' @description +#' Sets phenotypes for all traits by adding random error #' from a multivariate normal distribution. -#' -#' @param pop an object of \code{\link{Pop-class}} or +#' +#' @param pop an object of \code{\link{Pop-class}} or #' \code{\link{HybridPop-class}} #' @param h2 a vector of desired narrow-sense heritabilities for #' each trait. See details. #' @param H2 a vector of desired broad-sense heritabilities for #' each trait. See details. #' @param varE error (co)variances for traits. See details. -#' @param corE an optional matrix for correlations between errors. +#' @param corE an optional matrix for correlations between errors. #' See details. #' @param reps number of replications for phenotype. See details. -#' @param fixEff fixed effect to assign to the population. Used +#' @param fixEff fixed effect to assign to the population. Used #' by genomic selection models only. -#' @param p the p-value for the environmental covariate +#' @param p the p-value for the environmental covariate #' used by GxE traits. If NULL, a value is #' sampled at random. #' @param onlyPheno should only the phenotype be returned, see return #' @param traits an integer vector indicate which traits to set. If NULL, #' all traits will be set. #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @details -#' There are three arguments for setting the error variance of a -#' phenotype: h2, H2, and varE. The user should only use one of these -#' arguments. If the user supplies values for more than one, only one +#' There are three arguments for setting the error variance of a +#' phenotype: h2, H2, and varE. The user should only use one of these +#' arguments. If the user supplies values for more than one, only one #' will be used according to order in which they are listed above. -#' -#' The h2 argument allows the user to specify the error variance +#' +#' The h2 argument allows the user to specify the error variance #' according to narrow-sense heritability. This calculation uses the -#' additive genetic variance and total genetic variance in the founder -#' population. Thus, the heritability relates to the founder population +#' additive genetic variance and total genetic variance in the founder +#' population. Thus, the heritability relates to the founder population #' and not the current population. -#' -#' The H2 argument allows the user to specify the error variance +#' +#' The H2 argument allows the user to specify the error variance #' according to broad-sense heritability. This calculation uses the -#' total genetic variance in the founder population. Thus, the heritability +#' total genetic variance in the founder population. Thus, the heritability #' relates to the founder population and not the current population. -#' +#' #' The varE argument allows the user to specify the error variance -#' directly. The user may supply a vector describing the error variance -#' for each trait or supply a matrix that specify the covariance of +#' directly. The user may supply a vector describing the error variance +#' for each trait or supply a matrix that specify the covariance of #' the errors. -#' -#' The corE argument allows the user to specify correlations for the -#' error covariance matrix. These correlations are be supplied in addition -#' to the h2, H2, or varE arguments. These correlations will be used to -#' construct a covariance matrix from a vector of variances. If the user -#' supplied a covariance matrix to varE, these correlations will supercede +#' +#' The corE argument allows the user to specify correlations for the +#' error covariance matrix. These correlations are be supplied in addition +#' to the h2, H2, or varE arguments. These correlations will be used to +#' construct a covariance matrix from a vector of variances. If the user +#' supplied a covariance matrix to varE, these correlations will supercede #' values provided in that matrix. -#' -#' The reps parameter is for convenient representation of replicated data. -#' It is intended to represent replicated yield trials in plant -#' breeding programs. In this case, varE is set to the plot error and -#' reps is set to the number of plots per entry. The resulting phenotype +#' +#' The reps parameter is for convenient representation of replicated data. +#' It is intended to represent replicated yield trials in plant +#' breeding programs. In this case, varE is set to the plot error and +#' reps is set to the number of plots per entry. The resulting phenotype #' represents the entry-means. -#' -#' @return Returns an object of \code{\link{Pop-class}} or -#' \code{\link{HybridPop-class}} if onlyPheno=FALSE, if +#' +#' @return Returns an object of \code{\link{Pop-class}} or +#' \code{\link{HybridPop-class}} if onlyPheno=FALSE, if #' onlyPheno=TRUE a matrix is returned -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Add phenotype with error variance of 1 #' pop = setPheno(pop, varE=1) -#' +#' #' @export -setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, +setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, reps=1, fixEff=1L, p=NULL, onlyPheno=FALSE, traits=NULL, simParam=NULL){ if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - + # Determine which traits are selected if(is.null(traits)){ if(simParam$nTraits>0L){ @@ -148,19 +148,19 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, } }else{ traits = as.integer(traits) - stopifnot(all(traits>0L), - all(!duplicated(traits)), - max(traits)<=simParam$nTraits) + stopifnot(all(traits>0L), + all(!duplicated(traits)), + max(traits)<=simParam$nTraits) } nTraits = length(traits) - + # Check for valid length of reps vector if(length(reps)==1){ reps = rep(reps, nTraits) }else{ stopifnot(length(reps)==nTraits) } - + # Set p-value for GxE traits if(is.null(p)){ p = rep(runif(1), nTraits) @@ -169,7 +169,7 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, }else{ stopifnot(length(p)==nTraits) } - + # Calculate varE if using h2 or H2 if(!is.null(h2)){ if(length(h2)==1){ @@ -177,9 +177,9 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, } varA = simParam$varA[traits] varG = simParam$varG[traits] - + stopifnot(length(h2)==nTraits, - all(varA>0), + all(varA>0), all(varG>0)) varE = numeric(nTraits) for(i in 1:nTraits){ @@ -194,7 +194,7 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, H2 = rep(H2, nTraits) } varG = simParam$varG[traits] - + stopifnot(length(H2)==nTraits) varE = numeric(nTraits) for(i in 1:nTraits){ @@ -211,7 +211,7 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, }else{ varE = simParam$varE[traits] } - + # Set error correlations if(!is.null(corE)){ if(is.matrix(varE)){ @@ -219,40 +219,40 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, } stopifnot(length(varE)==nrow(corE), isSymmetric(corE)) - + varE = diag(sqrt(varE), nrow=nTraits, ncol=nTraits) varE = varE%*%corE%*%varE } - - - # Use lapply if object is a MegaPop + + + # Use lapply if object is a MultiPop # Only passing varE after previous processing - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(!onlyPheno) pop@pops = lapply(pop@pops, setPheno, h2=NULL, H2=NULL, - varE=varE, corE=NULL, reps=reps, fixEff=fixEff, + varE=varE, corE=NULL, reps=reps, fixEff=fixEff, p=p, traits=traits, simParam=simParam) return(pop) } - + # Create phenotypes - pheno = calcPheno(pop=pop, varE=varE, reps=reps, p=p, + pheno = calcPheno(pop=pop, varE=varE, reps=reps, p=p, traits=traits, simParam=simParam) - + colnames(pheno) = colnames(pop@gv) - + if(onlyPheno){ return(pheno) } - + pop@pheno = pheno - + if(is(pop,"Pop")){ pop@fixEff = rep(as.integer(fixEff), pop@nInd) } - + return(pop) } diff --git a/R/popSummary.R b/R/popSummary.R index eb7d5584..19d1d5ad 100644 --- a/R/popSummary.R +++ b/R/popSummary.R @@ -1,76 +1,76 @@ # Internal function for calculating mean EBV of populations -# Used selectPop MegaPop-class +# Used selectPop MultiPop-class meanEBV = function(pop){ colMeans(pop@ebv) } #' @title Mean genetic values -#' +#' #' @description Returns the mean genetic values for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' meanG(pop) -#' +#' #' @export meanG = function(pop){ colMeans(pop@gv) } #' @title Mean phenotypic values -#' +#' #' @description Returns the mean phenotypic values for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' meanP(pop) -#' +#' #' @export meanP = function(pop){ colMeans(pop@pheno) } #' @title Total genetic variance -#' +#' #' @description Returns total genetic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varG(pop) -#' +#' #' @export varG = function(pop){ G = popVar(pop@gv) @@ -79,24 +79,24 @@ varG = function(pop){ } #' @title Phenotypic variance -#' +#' #' @description Returns phenotypic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varP(pop) -#' +#' #' @export varP = function(pop){ P = popVar(pop@pheno) @@ -105,14 +105,14 @@ varP = function(pop){ } #' @title Sumarize genetic parameters -#' -#' @description -#' Calculates genetic and genic additive and dominance variances +#' +#' @description +#' Calculates genetic and genic additive and dominance variances #' for an object of \code{\link{Pop-class}} -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' +#' #' @return #' \describe{ #' \item{varA}{an nTrait by nTrait matrix of additive genetic variances} @@ -145,20 +145,20 @@ varP = function(pop){ #' \item{gv_d}{a matrix of dominance genetic values with dimensions nInd by nTraits} #' \item{gv_aa}{a matrix of additive-by-additive genetic values with dimensions nInd by nTraits} #' } -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' ans = genParam(pop, simParam=SP) -#' +#' #' @export genParam = function(pop,simParam=NULL){ if(is.null(simParam)){ @@ -168,17 +168,17 @@ genParam = function(pop,simParam=NULL){ nInd = nInd(pop) nTraits = simParam$nTraits traitNames = simParam$traitNames - + # Blank nInd x nTrait matrices gv = matrix(NA_real_, nrow=nInd, ncol=nTraits) colnames(gv) = traitNames bv = dd = aa = gv_a = gv_d = gv_aa = gv - + # Blank nTrait vectors genicVarA = rep(NA_real_, nTraits) names(genicVarA) = traitNames genicVarD = genicVarAA = covA_HW = covD_HW = covAA_HW = - covG_HW = mu = mu_HW = gv_mu = covAAA_L = covDAA_L = + covG_HW = mu = mu_HW = gv_mu = covAAA_L = covDAA_L = covAD_L = genicVarA #Loop through trait calculations @@ -225,22 +225,22 @@ genParam = function(pop,simParam=NULL){ covDAA_L[i] = popVar(cbind(dd[,i],aa[,i]))[1,2] } } - + varA = popVar(bv) rownames(varA) = colnames(varA) = traitNames - + varD = popVar(dd) rownames(varD) = colnames(varD) = traitNames - + varAA = popVar(aa) rownames(varAA) = colnames(varAA) = traitNames - + varG = popVar(gv) rownames(varG) = colnames(varG) = traitNames - + genicVarG = genicVarA + genicVarD + genicVarAA covG_HW = covA_HW + covD_HW + covAA_HW - + output = list(varA=varA, varD=varD, varAA=varAA, @@ -274,249 +274,249 @@ genParam = function(pop,simParam=NULL){ } #' @title Additive variance -#' +#' #' @description Returns additive variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varA(pop, simParam=SP) -#' +#' #' @export varA = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$varA } #' @title Dominance variance -#' +#' #' @description Returns dominance variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varD(pop, simParam=SP) -#' +#' #' @export varD = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$varD } #' @title Additive-by-additive epistatic variance -#' -#' @description Returns additive-by-additive epistatic +#' +#' @description Returns additive-by-additive epistatic #' variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varAA(pop, simParam=SP) -#' +#' #' @export varAA = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$varAA } #' @title Breeding value -#' +#' #' @description Returns breeding values for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' bv(pop, simParam=SP) -#' +#' #' @export bv = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$bv } #' @title Dominance deviations -#' +#' #' @description Returns dominance deviations for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' dd(pop, simParam=SP) -#' +#' #' @export dd = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$dd } #' @title Additive-by-additive epistatic deviations -#' -#' @description Returns additive-by-additive epistatic +#' +#' @description Returns additive-by-additive epistatic #' deviations for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' aa(pop, simParam=SP) -#' +#' #' @export aa = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$aa } #' @title Additive genic variance -#' +#' #' @description Returns additive genic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' genicVarA(pop, simParam=SP) -#' +#' #' @export genicVarA = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$genicVarA } #' @title Dominance genic variance -#' +#' #' @description Returns dominance genic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' genicVarD(pop, simParam=SP) -#' +#' #' @export genicVarD = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$genicVarD } #' @title Additive-by-additive genic variance -#' -#' @description Returns additive-by-additive epistatic +#' +#' @description Returns additive-by-additive epistatic #' genic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' genicVarAA(pop, simParam=SP) -#' +#' #' @export genicVarAA = function(pop,simParam=NULL){ genParam(pop,simParam=simParam)$genicVarAA } #' @title Total genic variance -#' +#' #' @description Returns total genic variance for all traits -#' +#' #' @param pop an object of \code{\link{Pop-class}} #' @param simParam an object of \code{\link{SimParam}} -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' genicVarG(pop, simParam=SP) @@ -527,97 +527,97 @@ genicVarG = function(pop,simParam=NULL){ } #' @title Genetic value -#' +#' #' @description A wrapper for accessing the gv slot -#' +#' #' @param pop a \code{\link{Pop-class}} or similar object -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' gv(pop) -#' +#' #' @export gv = function(pop){ pop@gv } #' @title Phenotype -#' +#' #' @description A wrapper for accessing the pheno slot -#' +#' #' @param pop a \code{\link{Pop-class}} or similar object -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' pheno(pop) -#' +#' #' @export pheno = function(pop){ pop@pheno } #' @title Estimated breeding value -#' +#' #' @description A wrapper for accessing the ebv slot -#' +#' #' @param pop a \code{\link{Pop-class}} or similar object -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' pop@ebv = matrix(rnorm(pop@nInd), nrow=pop@nInd, ncol=1) #' ebv(pop) -#' +#' #' @export ebv = function(pop){ pop@ebv } #' @title Number of individuals -#' +#' #' @description A wrapper for accessing the nInd slot -#' +#' #' @param pop a \code{\link{Pop-class}} or similar object -#' -#' @examples +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' nInd(pop) -#' +#' #' @export nInd = function(pop){ pop@nInd diff --git a/R/selection.R b/R/selection.R index cff76412..dcd130b7 100644 --- a/R/selection.R +++ b/R/selection.R @@ -91,49 +91,49 @@ getFam = function(pop,famType){ } #' @title Select individuals -#' -#' @description Selects a subset of nInd individuals from a +#' +#' @description Selects a subset of nInd individuals from a #' population. -#' -#' @param pop and object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +#' +#' @param pop and object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} #' @param nInd the number of individuals to select -#' @param trait the trait for selection. Either a number indicating +#' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. #' @param use select on genetic values "gv", estimated -#' breeding values "ebv", breeding values "bv", phenotypes "pheno", +#' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" -#' @param sex which sex to select. Use "B" for both, "F" for -#' females and "M" for males. If the simulation is not using sexes, +#' @param sex which sex to select. Use "B" for both, "F" for +#' females and "M" for males. If the simulation is not using sexes, #' the argument is ignored. -#' @param selectTop selects highest values if true. +#' @param selectTop selects highest values if true. #' Selects lowest values if false. -#' @param returnPop should results be returned as a -#' \code{\link{Pop-class}}. If FALSE, only the index of selected +#' @param returnPop should results be returned as a +#' \code{\link{Pop-class}}. If FALSE, only the index of selected #' individuals is returned. -#' @param candidates an optional vector of eligible selection candidates. +#' @param candidates an optional vector of eligible selection candidates. #' @param simParam an object of \code{\link{SimParam}} -#' @param ... additional arguments if using a function for +#' @param ... additional arguments if using a function for #' trait -#' -#' @return Returns an object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} -#' -#' @examples +#' +#' @return Returns an object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Select best 5 #' pop2 = selectInd(pop, 5, simParam=SP) -#' +#' #' @export selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", selectTop=TRUE,returnPop=TRUE, @@ -142,11 +142,11 @@ selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(returnPop, is.null(candidates)) pop@pops = lapply(pop@pops, selectInd, nInd=nInd, trait=trait, - use=use, sex=sex, selectTop=selectTop, - returnPop=TRUE, candidates=NULL, + use=use, sex=sex, selectTop=selectTop, + returnPop=TRUE, candidates=NULL, simParam=simParam, ...) return(pop) } @@ -173,55 +173,55 @@ selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", } #' @title Select families -#' -#' @description Selects a subset of full-sib families from a +#' +#' @description Selects a subset of full-sib families from a #' population. -#' -#' @param pop and object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +#' +#' @param pop and object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} #' @param nFam the number of families to select -#' @param trait the trait for selection. Either a number indicating +#' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. #' @param use select on genetic values "gv", estimated -#' breeding values "ebv", breeding values "bv", phenotypes "pheno", +#' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" -#' @param sex which sex to select. Use "B" for both, "F" for -#' females and "M" for males. If the simulation is not using sexes, +#' @param sex which sex to select. Use "B" for both, "F" for +#' females and "M" for males. If the simulation is not using sexes, #' the argument is ignored. -#' @param famType which type of family to select. Use "B" for -#' full-sib families, "F" for half-sib families on female side and "M" +#' @param famType which type of family to select. Use "B" for +#' full-sib families, "F" for half-sib families on female side and "M" #' for half-sib families on the male side. -#' @param selectTop selects highest values if true. +#' @param selectTop selects highest values if true. #' Selects lowest values if false. -#' @param returnPop should results be returned as a -#' \code{\link{Pop-class}}. If FALSE, only the index of selected +#' @param returnPop should results be returned as a +#' \code{\link{Pop-class}}. If FALSE, only the index of selected #' individuals is returned. #' @param candidates an optional vector of eligible selection candidates. #' @param simParam an object of \code{\link{SimParam}} -#' @param ... additional arguments if using a function for +#' @param ... additional arguments if using a function for #' trait -#' -#' @return Returns an object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} -#' -#' @examples +#' +#' @return Returns an object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Create 3 biparental families with 10 progeny #' pop2 = randCross(pop, nCrosses=3, nProgeny=10, simParam=SP) -#' +#' #' #Select best 2 families #' pop3 = selectFam(pop2, 2, simParam=SP) -#' +#' #' @export selectFam = function(pop,nFam,trait=1,use="pheno",sex="B", famType="B",selectTop=TRUE,returnPop=TRUE, @@ -230,11 +230,11 @@ selectFam = function(pop,nFam,trait=1,use="pheno",sex="B", if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(returnPop, is.null(candidates)) pop@pops = lapply(pop@pops, selectFam, nFam=nFam, trait=trait, - use=use, sex=sex, famType=famType, - selectTop=selectTop, returnPop=TRUE, + use=use, sex=sex, famType=famType, + selectTop=selectTop, returnPop=TRUE, candidates=NULL, simParam=simParam, ...) return(pop) } @@ -270,56 +270,56 @@ selectFam = function(pop,nFam,trait=1,use="pheno",sex="B", } #' @title Select individuals within families -#' -#' @description Selects a subset of nInd individuals from each -#' full-sib family within a population. Will return all individuals +#' +#' @description Selects a subset of nInd individuals from each +#' full-sib family within a population. Will return all individuals #' from a full-sib family if it has less than or equal to nInd individuals. -#' -#' @param pop and object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +#' +#' @param pop and object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} #' @param nInd the number of individuals to select within a family -#' @param trait the trait for selection. Either a number indicating +#' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. #' @param use select on genetic values "gv", estimated -#' breeding values "ebv", breeding values "bv", phenotypes "pheno", +#' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" -#' @param sex which sex to select. Use "B" for both, "F" for -#' females and "M" for males. If the simulation is not using sexes, +#' @param sex which sex to select. Use "B" for both, "F" for +#' females and "M" for males. If the simulation is not using sexes, #' the argument is ignored. -#' @param famType which type of family to select. Use "B" for -#' full-sib families, "F" for half-sib families on female side and "M" +#' @param famType which type of family to select. Use "B" for +#' full-sib families, "F" for half-sib families on female side and "M" #' for half-sib families on the male side. -#' @param selectTop selects highest values if true. +#' @param selectTop selects highest values if true. #' Selects lowest values if false. -#' @param returnPop should results be returned as a -#' \code{\link{Pop-class}}. If FALSE, only the index of selected +#' @param returnPop should results be returned as a +#' \code{\link{Pop-class}}. If FALSE, only the index of selected #' individuals is returned. #' @param candidates an optional vector of eligible selection candidates. #' @param simParam an object of \code{\link{SimParam}} -#' @param ... additional arguments if using a function for +#' @param ... additional arguments if using a function for #' trait -#' -#' @return Returns an object of \code{\link{Pop-class}}, -#' \code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} -#' -#' @examples +#' +#' @return Returns an object of \code{\link{Pop-class}}, +#' \code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Create 3 biparental families with 10 progeny #' pop2 = randCross(pop, nCrosses=3, nProgeny=10, simParam=SP) -#' +#' #' #Select best individual per family #' pop3 = selectWithinFam(pop2, 1, simParam=SP) -#' +#' #' @export selectWithinFam = function(pop,nInd,trait=1,use="pheno",sex="B", famType="B",selectTop=TRUE,returnPop=TRUE, @@ -328,11 +328,11 @@ selectWithinFam = function(pop,nInd,trait=1,use="pheno",sex="B", if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(returnPop, is.null(candidates)) pop@pops = lapply(pop@pops, selectWithinFam, nInd=nInd, trait=trait, - use=use, sex=sex, selectTop=selectTop, - returnPop=TRUE, candidates=NULL, + use=use, sex=sex, selectTop=selectTop, + returnPop=TRUE, candidates=NULL, simParam=simParam, ...) return(pop) } @@ -371,51 +371,51 @@ selectWithinFam = function(pop,nInd,trait=1,use="pheno",sex="B", } #' @title Select open pollinating plants -#' -#' @description -#' This function models selection in an open pollinating -#' plant population. It allows for varying the percentage of -#' selfing. The function also provides an option for modeling +#' +#' @description +#' This function models selection in an open pollinating +#' plant population. It allows for varying the percentage of +#' selfing. The function also provides an option for modeling #' selection as occuring before or after pollination. -#' -#' @param pop and object of \code{\link{Pop-class}} -#' or \code{\link{MegaPop-class}} +#' +#' @param pop and object of \code{\link{Pop-class}} +#' or \code{\link{MultiPop-class}} #' @param nInd the number of plants to select #' @param nSeeds number of seeds per plant -#' @param probSelf percentage of seeds expected from selfing. +#' @param probSelf percentage of seeds expected from selfing. #' Value ranges from 0 to 1. #' @param pollenControl are plants selected before pollination -#' @param trait the trait for selection. Either a number indicating +#' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. #' @param use select on genetic values "gv", estimated -#' breeding values "ebv", breeding values "bv", phenotypes "pheno", +#' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" -#' @param selectTop selects highest values if true. +#' @param selectTop selects highest values if true. #' Selects lowest values if false. #' @param candidates an optional vector of eligible selection candidates. #' @param simParam an object of \code{\link{SimParam}} -#' @param ... additional arguments if using a function for +#' @param ... additional arguments if using a function for #' trait -#' -#' @return Returns an object of \code{\link{Pop-class}} -#' or \code{\link{MegaPop-class}} -#' -#' @examples +#' +#' @return Returns an object of \code{\link{Pop-class}} +#' or \code{\link{MultiPop-class}} +#' +#' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) -#' +#' #' #Set simulation parameters #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) -#' +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) -#' +#' #' #Create new population by selecting the best 3 plant #' #Assuming 50% selfing in plants and 10 seeds per plant #' pop2 = selectOP(pop, nInd=3, nSeeds=10, probSelf=0.5, simParam=SP) -#' +#' #' @export selectOP = function(pop,nInd,nSeeds,probSelf=0, pollenControl=FALSE,trait=1, @@ -425,11 +425,11 @@ selectOP = function(pop,nInd,nSeeds,probSelf=0, if(is.null(simParam)){ simParam = get("SP",envir=.GlobalEnv) } - if(is(pop,"MegaPop")){ + if(is(pop,"MultiPop")){ stopifnot(is.null(candidates)) pop@pops = lapply(pop@pops, selectOP, nInd=nInd, nSeeds=nSeeds, pollenControl=pollenControl, trait=trait, use=use, - selectTop=selectTop, candidates=NULL, + selectTop=selectTop, candidates=NULL, simParam=simParam, ...) return(pop) } From cb6e1c1c893c59c080ce65691e5a7e25ef88a655 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 12 Jul 2023 07:08:04 -0500 Subject: [PATCH 06/20] Resolving Namespace error --- DESCRIPTION | 2 +- NAMESPACE | 6 ++-- NEWS.md | 2 ++ man/MegaPop-class.Rd | 51 -------------------------- man/MultiPop-class.Rd | 51 ++++++++++++++++++++++++++ man/aa.Rd | 2 +- man/calcGCA.Rd | 6 ++-- man/genParam.Rd | 2 +- man/genicVarAA.Rd | 2 +- man/hybridCross.Rd | 16 ++++----- man/makeCross.Rd | 6 ++-- man/makeCross2.Rd | 6 ++-- man/makeDH.Rd | 6 ++-- man/mergePops.Rd | 4 +-- man/newEmptyPop.Rd | 2 +- man/{newMegaPop.Rd => newMultiPop.Rd} | 20 +++++------ man/pedigreeCross.Rd | 32 ++++++++--------- man/randCross.Rd | 4 +-- man/randCross2.Rd | 10 +++--- man/selectCross.Rd | 36 +++++++++---------- man/selectFam.Rd | 30 ++++++++-------- man/selectInd.Rd | 26 +++++++------- man/selectOP.Rd | 24 ++++++------- man/selectWithinFam.Rd | 32 ++++++++--------- man/self.Rd | 4 +-- man/setPheno.Rd | 52 +++++++++++++-------------- man/setPhenoGCA.Rd | 18 +++++----- man/setPhenoProgTest.Rd | 26 +++++++------- man/varAA.Rd | 2 +- 29 files changed, 241 insertions(+), 239 deletions(-) delete mode 100644 man/MegaPop-class.Rd create mode 100644 man/MultiPop-class.Rd rename man/{newMegaPop.Rd => newMultiPop.Rd} (54%) diff --git a/DESCRIPTION b/DESCRIPTION index a8256fdc..7a5c8ccb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,7 @@ Depends: R (>= 4.0.0), methods, R6 Imports: Rcpp (>= 0.12.7), Rdpack RdMacros: Rdpack LinkingTo: Rcpp, RcppArmadillo (>= 0.7.500.0.0), BH -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Suggests: knitr, rmarkdown, testthat VignetteBuilder: knitr NeedsCompilation: true diff --git a/NAMESPACE b/NAMESPACE index 167fb905..6c76c2dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -42,7 +42,7 @@ export(isFemale) export(isHybridPop) export(isMale) export(isMapPop) -export(isMegaPop) +export(isMultiPop) export(isNamedMapPop) export(isPop) export(isRawPop) @@ -57,7 +57,7 @@ export(mutate) export(nInd) export(newEmptyPop) export(newMapPop) -export(newMegaPop) +export(newMultiPop) export(newPop) export(pedigreeCross) export(pheno) @@ -115,7 +115,7 @@ export(writeRecords) exportClasses(HybridPop) exportClasses(LociMap) exportClasses(MapPop) -exportClasses(MegaPop) +exportClasses(MultiPop) exportClasses(NamedMapPop) exportClasses(Pop) exportClasses(RRsol) diff --git a/NEWS.md b/NEWS.md index 81308b0f..ec789bb5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # AlphaSimR 1.3.1.9990 +*changed name of `MegaPop` to `MultiPop` + *fixed column name bug with multiple traits in `setEBV` # AlphaSimR 1.3.1 diff --git a/man/MegaPop-class.Rd b/man/MegaPop-class.Rd deleted file mode 100644 index 0f06b03d..00000000 --- a/man/MegaPop-class.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/Class-Pop.R -\docType{class} -\name{MegaPop-class} -\alias{MegaPop-class} -\alias{[,MegaPop-method} -\alias{[[,MegaPop-method} -\alias{c,MegaPop-method} -\alias{isMegaPop} -\title{Mega-Population} -\usage{ -\S4method{[}{MegaPop}(x, i) - -\S4method{[[}{MegaPop}(x, i) - -\S4method{c}{MegaPop}(x, ...) - -isMegaPop(x) -} -\arguments{ -\item{x}{a 'MegaPop' object} - -\item{i}{index of populations or mega-populations} - -\item{...}{additional 'MegaPop' or 'Pop' objects} -} -\description{ -The mega-population represents a population of populations. -It is designed to behave like a list of populations. -} -\section{Methods (by generic)}{ -\itemize{ -\item \code{[}: Extract MegaPop by index - -\item \code{[[}: Extract Pop by index - -\item \code{c(MegaPop)}: Combine multiple MegaPops - -}} -\section{Functions}{ -\itemize{ -\item \code{isMegaPop()}: Test if object is of a MegaPop class - -}} -\section{Slots}{ - -\describe{ -\item{\code{pops}}{list of \code{\link{Pop-class}} and/or -\code{MegaPop-class}} -}} - diff --git a/man/MultiPop-class.Rd b/man/MultiPop-class.Rd new file mode 100644 index 00000000..a9f29013 --- /dev/null +++ b/man/MultiPop-class.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Class-Pop.R +\docType{class} +\name{MultiPop-class} +\alias{MultiPop-class} +\alias{[,MultiPop-method} +\alias{[[,MultiPop-method} +\alias{c,MultiPop-method} +\alias{isMultiPop} +\title{Multi-Population} +\usage{ +\S4method{[}{MultiPop}(x, i) + +\S4method{[[}{MultiPop}(x, i) + +\S4method{c}{MultiPop}(x, ...) + +isMultiPop(x) +} +\arguments{ +\item{x}{a 'MultiPop' object} + +\item{i}{index of populations or mega-populations} + +\item{...}{additional 'MultiPop' or 'Pop' objects} +} +\description{ +The mega-population represents a population of populations. +It is designed to behave like a list of populations. +} +\section{Methods (by generic)}{ +\itemize{ +\item \code{[}: Extract MultiPop by index + +\item \code{[[}: Extract Pop by index + +\item \code{c(MultiPop)}: Combine multiple MultiPops + +}} +\section{Functions}{ +\itemize{ +\item \code{isMultiPop()}: Test if object is of a MultiPop class + +}} +\section{Slots}{ + +\describe{ +\item{\code{pops}}{list of \code{\link{Pop-class}} and/or +\code{MultiPop-class}} +}} + diff --git a/man/aa.Rd b/man/aa.Rd index a45ef038..4bd25b32 100644 --- a/man/aa.Rd +++ b/man/aa.Rd @@ -12,7 +12,7 @@ aa(pop, simParam = NULL) \item{simParam}{an object of \code{\link{SimParam}}} } \description{ -Returns additive-by-additive epistatic +Returns additive-by-additive epistatic deviations for all traits } \examples{ diff --git a/man/calcGCA.Rd b/man/calcGCA.Rd index c71e52fb..8075bdf8 100644 --- a/man/calcGCA.Rd +++ b/man/calcGCA.Rd @@ -7,15 +7,15 @@ calcGCA(pop, use = "pheno") } \arguments{ -\item{pop}{an object of \code{\link{Pop-class}} or +\item{pop}{an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}}} \item{use}{tabulate either genetic values "gv", estimated breeding values "ebv", or phenotypes "pheno"} } \description{ -Calculate general combining ability of test crosses. Intended for -output from hybridCross using the "testcross" option, but will work +Calculate general combining ability of test crosses. Intended for +output from hybridCross using the "testcross" option, but will work for any population. } \examples{ diff --git a/man/genParam.Rd b/man/genParam.Rd index d9104a21..c7496918 100644 --- a/man/genParam.Rd +++ b/man/genParam.Rd @@ -45,7 +45,7 @@ genParam(pop, simParam = NULL) } } \description{ -Calculates genetic and genic additive and dominance variances +Calculates genetic and genic additive and dominance variances for an object of \code{\link{Pop-class}} } \examples{ diff --git a/man/genicVarAA.Rd b/man/genicVarAA.Rd index ffbb29b7..a6c3919b 100644 --- a/man/genicVarAA.Rd +++ b/man/genicVarAA.Rd @@ -12,7 +12,7 @@ genicVarAA(pop, simParam = NULL) \item{simParam}{an object of \code{\link{SimParam}}} } \description{ -Returns additive-by-additive epistatic +Returns additive-by-additive epistatic genic variance for all traits } \examples{ diff --git a/man/hybridCross.Rd b/man/hybridCross.Rd index ced4bd36..ddc22717 100644 --- a/man/hybridCross.Rd +++ b/man/hybridCross.Rd @@ -17,21 +17,21 @@ hybridCross( \item{males}{male population, an object of \code{\link{Pop-class}}} -\item{crossPlan}{either "testcross" for all possible combinantions +\item{crossPlan}{either "testcross" for all possible combinantions or a matrix with two columns for designed crosses} -\item{returnHybridPop}{should results be returned as -\code{\link{HybridPop-class}}. If false returns results as +\item{returnHybridPop}{should results be returned as +\code{\link{HybridPop-class}}. If false returns results as \code{\link{Pop-class}}. Population must be fully inbred if TRUE.} \item{simParam}{an object of \code{\link{SimParam}}} } \description{ -A convience function for hybrid plant breeding simulations. Allows for -easy specification of a test cross scheme and/or creation of an object -of \code{\link{HybridPop-class}}. Note that the \code{\link{HybridPop-class}} -should only be used if the parents were created using the \code{\link{makeDH}} -function or \code{\link{newPop}} using inbred founders. The id for +A convience function for hybrid plant breeding simulations. Allows for +easy specification of a test cross scheme and/or creation of an object +of \code{\link{HybridPop-class}}. Note that the \code{\link{HybridPop-class}} +should only be used if the parents were created using the \code{\link{makeDH}} +function or \code{\link{newPop}} using inbred founders. The id for new individuals is [mother_id]_[father_id] } \examples{ diff --git a/man/makeCross.Rd b/man/makeCross.Rd index 87d5c33b..7434fbb6 100644 --- a/man/makeCross.Rd +++ b/man/makeCross.Rd @@ -9,8 +9,8 @@ makeCross(pop, crossPlan, nProgeny = 1, simParam = NULL) \arguments{ \item{pop}{an object of \code{\link{Pop-class}}} -\item{crossPlan}{a matrix with two column representing -female and male parents. Either integers for the position in +\item{crossPlan}{a matrix with two column representing +female and male parents. Either integers for the position in population or character strings for the IDs.} \item{nProgeny}{number of progeny per cross} @@ -21,7 +21,7 @@ population or character strings for the IDs.} Returns an object of \code{\link{Pop-class}} } \description{ -Makes crosses within a population using a user supplied +Makes crosses within a population using a user supplied crossing plan. } \examples{ diff --git a/man/makeCross2.Rd b/man/makeCross2.Rd index 966318c1..f256e955 100644 --- a/man/makeCross2.Rd +++ b/man/makeCross2.Rd @@ -11,8 +11,8 @@ makeCross2(females, males, crossPlan, nProgeny = 1, simParam = NULL) \item{males}{an object of \code{\link{Pop-class}} for male parents.} -\item{crossPlan}{a matrix with two column representing -female and male parents. Either integers for the position in +\item{crossPlan}{a matrix with two column representing +female and male parents. Either integers for the position in population or character strings for the IDs.} \item{nProgeny}{number of progeny per cross} @@ -23,7 +23,7 @@ population or character strings for the IDs.} Returns an object of \code{\link{Pop-class}} } \description{ -Makes crosses between two populations using a user supplied +Makes crosses between two populations using a user supplied crossing plan. } \examples{ diff --git a/man/makeDH.Rd b/man/makeDH.Rd index 76dccf97..5c6740fb 100644 --- a/man/makeDH.Rd +++ b/man/makeDH.Rd @@ -13,7 +13,7 @@ makeDH(pop, nDH = 1, useFemale = TRUE, keepParents = TRUE, simParam = NULL) \item{useFemale}{should female recombination rates be used.} -\item{keepParents}{should previous parents be used for mother and +\item{keepParents}{should previous parents be used for mother and father.} \item{simParam}{an object of 'SimParam' class} @@ -22,8 +22,8 @@ father.} Returns an object of \code{\link{Pop-class}} } \description{ -Creates DH lines from each individual in a population. -Only works with diploid individuals. For polyploids, use +Creates DH lines from each individual in a population. +Only works with diploid individuals. For polyploids, use \code{\link{reduceGenome}} and \code{\link{doubleGenome}}. } \examples{ diff --git a/man/mergePops.Rd b/man/mergePops.Rd index b3996587..bafdffc3 100644 --- a/man/mergePops.Rd +++ b/man/mergePops.Rd @@ -7,8 +7,8 @@ mergePops(popList) } \arguments{ -\item{popList}{a list containing \code{\link{Pop-class}} elements -or a \code{\link{MegaPop-class}}} +\item{popList}{a list containing \code{\link{Pop-class}} elements +or a \code{\link{MultiPop-class}}} } \value{ Returns a \code{\link{Pop-class}} diff --git a/man/newEmptyPop.Rd b/man/newEmptyPop.Rd index 62cd62c5..6ba7e09a 100644 --- a/man/newEmptyPop.Rd +++ b/man/newEmptyPop.Rd @@ -16,7 +16,7 @@ Returns an object of \code{\link{Pop-class}} with zero individuals } \description{ -Creates an empty \code{\link{Pop-class}} object with user +Creates an empty \code{\link{Pop-class}} object with user defined ploidy and other parameters taken from simParam. } \examples{ diff --git a/man/newMegaPop.Rd b/man/newMultiPop.Rd similarity index 54% rename from man/newMegaPop.Rd rename to man/newMultiPop.Rd index b6569aea..798b1eaa 100644 --- a/man/newMegaPop.Rd +++ b/man/newMultiPop.Rd @@ -1,21 +1,21 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/Class-Pop.R -\name{newMegaPop} -\alias{newMegaPop} -\title{Create new Mega Population} +\name{newMultiPop} +\alias{newMultiPop} +\title{Create new Multi Population} \usage{ -newMegaPop(...) +newMultiPop(...) } \arguments{ \item{...}{one or more \code{\link{Pop-class}} and/or -\code{\link{MegaPop-class}} objects.} +\code{\link{MultiPop-class}} objects.} } \value{ -Returns an object of \code{\link{MegaPop-class}} +Returns an object of \code{\link{MultiPop-class}} } \description{ -Creates a new \code{\link{MegaPop-class}} from one or more -\code{\link{Pop-class}} and/or \code{\link{MegaPop-class}} +Creates a new \code{\link{MultiPop-class}} from one or more +\code{\link{Pop-class}} and/or \code{\link{MultiPop-class}} objects. } \examples{ @@ -28,7 +28,7 @@ SP$addTraitA(10) #Create population pop = newPop(founderPop, simParam=SP) -megaPop = newMegaPop(pop=pop) -isMegaPop(megaPop) +megaPop = newMultiPop(pop=pop) +isMultiPop(megaPop) } diff --git a/man/pedigreeCross.Rd b/man/pedigreeCross.Rd index dc8914d4..59142374 100644 --- a/man/pedigreeCross.Rd +++ b/man/pedigreeCross.Rd @@ -20,43 +20,43 @@ pedigreeCross( \arguments{ \item{founderPop}{a \code{\link{Pop-class}}} -\item{id}{a vector of unique identifiers for individuals -in the pedigree. The values of these IDs are seperate from +\item{id}{a vector of unique identifiers for individuals +in the pedigree. The values of these IDs are seperate from the IDs in the founderPop if matchID=FALSE.} -\item{mother}{a vector of identifiers for the mothers -of individuals in the pedigree. Must match one of the +\item{mother}{a vector of identifiers for the mothers +of individuals in the pedigree. Must match one of the elements in the id vector or they will be treated as unknown.} -\item{father}{a vector of identifiers for the fathers -of individuals in the pedigree. Must match one of the +\item{father}{a vector of identifiers for the fathers +of individuals in the pedigree. Must match one of the elements in the id vector or they will be treated as unknown.} -\item{matchID}{indicates if the IDs in founderPop should be +\item{matchID}{indicates if the IDs in founderPop should be matched to the id argument. See details.} -\item{maxCycle}{the maximum number of loops to make over the pedigree +\item{maxCycle}{the maximum number of loops to make over the pedigree to sort it.} -\item{DH}{an optional vector indicating if an individual +\item{DH}{an optional vector indicating if an individual should be made a doubled haploid.} -\item{nSelf}{an optional vector indicating how many generations an +\item{nSelf}{an optional vector indicating how many generations an individual should be selfed.} -\item{useFemale}{If creating DH lines, should female recombination +\item{useFemale}{If creating DH lines, should female recombination rates be used. This parameter has no effect if, recombRatio=1.} \item{simParam}{an object of 'SimParam' class} } \description{ -Creates a \code{\link{Pop-class}} from a generic +Creates a \code{\link{Pop-class}} from a generic pedigree and a set of founder individuals. -The way in which the user supplied pedigree is used depends on -the value of matchID. If matchID is TRUE, the IDs in the user -supplied pedigree are matched against founderNames. If matchID -is FALSE, founder individuals in the user supplied pedigree are +The way in which the user supplied pedigree is used depends on +the value of matchID. If matchID is TRUE, the IDs in the user +supplied pedigree are matched against founderNames. If matchID +is FALSE, founder individuals in the user supplied pedigree are randomly sampled from founderPop. } \examples{ diff --git a/man/randCross.Rd b/man/randCross.Rd index d3416a02..e09a2bd3 100644 --- a/man/randCross.Rd +++ b/man/randCross.Rd @@ -21,7 +21,7 @@ randCross( \item{nProgeny}{number of progeny per cross} -\item{balance}{if using sexes, this option will balance the number +\item{balance}{if using sexes, this option will balance the number of progeny per parent} \item{parents}{an optional vector of indices for allowable parents} @@ -34,7 +34,7 @@ of progeny per parent} Returns an object of \code{\link{Pop-class}} } \description{ -A wrapper for \code{\link{makeCross}} that randomly +A wrapper for \code{\link{makeCross}} that randomly selects parental combinations for all possible combinantions. } \examples{ diff --git a/man/randCross2.Rd b/man/randCross2.Rd index 60e50aef..10da5942 100644 --- a/man/randCross2.Rd +++ b/man/randCross2.Rd @@ -25,13 +25,13 @@ randCross2( \item{nProgeny}{number of progeny per cross} -\item{balance}{this option will balance the number +\item{balance}{this option will balance the number of progeny per parent} -\item{femaleParents}{an optional vector of indices for allowable +\item{femaleParents}{an optional vector of indices for allowable female parents} -\item{maleParents}{an optional vector of indices for allowable +\item{maleParents}{an optional vector of indices for allowable male parents} \item{ignoreSexes}{should sex be ignored} @@ -42,8 +42,8 @@ male parents} Returns an object of \code{\link{Pop-class}} } \description{ -A wrapper for \code{\link{makeCross2}} that randomly -selects parental combinations for all possible combinantions between +A wrapper for \code{\link{makeCross2}} that randomly +selects parental combinations for all possible combinantions between two populations. } \examples{ diff --git a/man/selectCross.Rd b/man/selectCross.Rd index 73da4894..c16dba89 100644 --- a/man/selectCross.Rd +++ b/man/selectCross.Rd @@ -22,51 +22,51 @@ selectCross( \arguments{ \item{pop}{an object of \code{\link{Pop-class}}} -\item{nInd}{the number of individuals to select. These individuals -are selected without regards to sex and it supercedes values -for nFemale and nMale. Thus if the simulation uses sexes, it is -likely better to leave this value as NULL and use nFemale and nMale +\item{nInd}{the number of individuals to select. These individuals +are selected without regards to sex and it supercedes values +for nFemale and nMale. Thus if the simulation uses sexes, it is +likely better to leave this value as NULL and use nFemale and nMale instead.} -\item{nFemale}{the number of females to select. This value is ignored +\item{nFemale}{the number of females to select. This value is ignored if nInd is set.} -\item{nMale}{the number of males to select. This value is ignored +\item{nMale}{the number of males to select. This value is ignored if nInd is set.} \item{nCrosses}{total number of crosses to make} \item{nProgeny}{number of progeny per cross} -\item{trait}{the trait for selection. Either a number indicating +\item{trait}{the trait for selection. Either a number indicating a single trait or a function returning a vector of length nInd.} \item{use}{select on genetic values "gv", estimated -breeding values "ebv", breeding values "bv", phenotypes "pheno", +breeding values "ebv", breeding values "bv", phenotypes "pheno", or randomly "rand"} -\item{selectTop}{selects highest values if true. +\item{selectTop}{selects highest values if true. Selects lowest values if false.} \item{simParam}{an object of \code{\link{SimParam}}} -\item{...}{additional arguments if using a function for +\item{...}{additional arguments if using a function for trait} -\item{balance}{if using sexes, this option will balance the number -of progeny per parent. This argument occurs after ..., so the argument +\item{balance}{if using sexes, this option will balance the number +of progeny per parent. This argument occurs after ..., so the argument name must be matched exactly.} } \value{ Returns an object of \code{\link{Pop-class}} } \description{ -This is a wrapper that combines the functionalities of -\code{\link{randCross}} and \code{\link{selectInd}}. The -purpose of this wrapper is to combine both selection and -crossing in one function call that minimized the amount -of intermediate populations created. This reduces RAM usage -and simplifies code writing. Note that this wrapper does not +This is a wrapper that combines the functionalities of +\code{\link{randCross}} and \code{\link{selectInd}}. The +purpose of this wrapper is to combine both selection and +crossing in one function call that minimized the amount +of intermediate populations created. This reduces RAM usage +and simplifies code writing. Note that this wrapper does not provide the full functionality of either function. } \examples{ diff --git a/man/selectFam.Rd b/man/selectFam.Rd index b42b9373..b597caf9 100644 --- a/man/selectFam.Rd +++ b/man/selectFam.Rd @@ -19,46 +19,46 @@ selectFam( ) } \arguments{ -\item{pop}{and object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}}} +\item{pop}{and object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}}} \item{nFam}{the number of families to select} -\item{trait}{the trait for selection. Either a number indicating +\item{trait}{the trait for selection. Either a number indicating a single trait or a function returning a vector of length nInd.} \item{use}{select on genetic values "gv", estimated -breeding values "ebv", breeding values "bv", phenotypes "pheno", +breeding values "ebv", breeding values "bv", phenotypes "pheno", or randomly "rand"} -\item{sex}{which sex to select. Use "B" for both, "F" for -females and "M" for males. If the simulation is not using sexes, +\item{sex}{which sex to select. Use "B" for both, "F" for +females and "M" for males. If the simulation is not using sexes, the argument is ignored.} -\item{famType}{which type of family to select. Use "B" for -full-sib families, "F" for half-sib families on female side and "M" +\item{famType}{which type of family to select. Use "B" for +full-sib families, "F" for half-sib families on female side and "M" for half-sib families on the male side.} -\item{selectTop}{selects highest values if true. +\item{selectTop}{selects highest values if true. Selects lowest values if false.} -\item{returnPop}{should results be returned as a -\code{\link{Pop-class}}. If FALSE, only the index of selected +\item{returnPop}{should results be returned as a +\code{\link{Pop-class}}. If FALSE, only the index of selected individuals is returned.} \item{candidates}{an optional vector of eligible selection candidates.} \item{simParam}{an object of \code{\link{SimParam}}} -\item{...}{additional arguments if using a function for +\item{...}{additional arguments if using a function for trait} } \value{ -Returns an object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +Returns an object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} } \description{ -Selects a subset of full-sib families from a +Selects a subset of full-sib families from a population. } \examples{ diff --git a/man/selectInd.Rd b/man/selectInd.Rd index 4cd91af9..828e2d26 100644 --- a/man/selectInd.Rd +++ b/man/selectInd.Rd @@ -18,42 +18,42 @@ selectInd( ) } \arguments{ -\item{pop}{and object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}}} +\item{pop}{and object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}}} \item{nInd}{the number of individuals to select} -\item{trait}{the trait for selection. Either a number indicating +\item{trait}{the trait for selection. Either a number indicating a single trait or a function returning a vector of length nInd.} \item{use}{select on genetic values "gv", estimated -breeding values "ebv", breeding values "bv", phenotypes "pheno", +breeding values "ebv", breeding values "bv", phenotypes "pheno", or randomly "rand"} -\item{sex}{which sex to select. Use "B" for both, "F" for -females and "M" for males. If the simulation is not using sexes, +\item{sex}{which sex to select. Use "B" for both, "F" for +females and "M" for males. If the simulation is not using sexes, the argument is ignored.} -\item{selectTop}{selects highest values if true. +\item{selectTop}{selects highest values if true. Selects lowest values if false.} -\item{returnPop}{should results be returned as a -\code{\link{Pop-class}}. If FALSE, only the index of selected +\item{returnPop}{should results be returned as a +\code{\link{Pop-class}}. If FALSE, only the index of selected individuals is returned.} \item{candidates}{an optional vector of eligible selection candidates.} \item{simParam}{an object of \code{\link{SimParam}}} -\item{...}{additional arguments if using a function for +\item{...}{additional arguments if using a function for trait} } \value{ -Returns an object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +Returns an object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} } \description{ -Selects a subset of nInd individuals from a +Selects a subset of nInd individuals from a population. } \examples{ diff --git a/man/selectOP.Rd b/man/selectOP.Rd index fb78f776..c7b685b7 100644 --- a/man/selectOP.Rd +++ b/man/selectOP.Rd @@ -19,43 +19,43 @@ selectOP( ) } \arguments{ -\item{pop}{and object of \code{\link{Pop-class}} -or \code{\link{MegaPop-class}}} +\item{pop}{and object of \code{\link{Pop-class}} +or \code{\link{MultiPop-class}}} \item{nInd}{the number of plants to select} \item{nSeeds}{number of seeds per plant} -\item{probSelf}{percentage of seeds expected from selfing. +\item{probSelf}{percentage of seeds expected from selfing. Value ranges from 0 to 1.} \item{pollenControl}{are plants selected before pollination} -\item{trait}{the trait for selection. Either a number indicating +\item{trait}{the trait for selection. Either a number indicating a single trait or a function returning a vector of length nInd.} \item{use}{select on genetic values "gv", estimated -breeding values "ebv", breeding values "bv", phenotypes "pheno", +breeding values "ebv", breeding values "bv", phenotypes "pheno", or randomly "rand"} -\item{selectTop}{selects highest values if true. +\item{selectTop}{selects highest values if true. Selects lowest values if false.} \item{candidates}{an optional vector of eligible selection candidates.} \item{simParam}{an object of \code{\link{SimParam}}} -\item{...}{additional arguments if using a function for +\item{...}{additional arguments if using a function for trait} } \value{ -Returns an object of \code{\link{Pop-class}} -or \code{\link{MegaPop-class}} +Returns an object of \code{\link{Pop-class}} +or \code{\link{MultiPop-class}} } \description{ -This function models selection in an open pollinating -plant population. It allows for varying the percentage of -selfing. The function also provides an option for modeling +This function models selection in an open pollinating +plant population. It allows for varying the percentage of +selfing. The function also provides an option for modeling selection as occuring before or after pollination. } \examples{ diff --git a/man/selectWithinFam.Rd b/man/selectWithinFam.Rd index 2c9903ff..bd58257d 100644 --- a/man/selectWithinFam.Rd +++ b/man/selectWithinFam.Rd @@ -19,47 +19,47 @@ selectWithinFam( ) } \arguments{ -\item{pop}{and object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}}} +\item{pop}{and object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}}} \item{nInd}{the number of individuals to select within a family} -\item{trait}{the trait for selection. Either a number indicating +\item{trait}{the trait for selection. Either a number indicating a single trait or a function returning a vector of length nInd.} \item{use}{select on genetic values "gv", estimated -breeding values "ebv", breeding values "bv", phenotypes "pheno", +breeding values "ebv", breeding values "bv", phenotypes "pheno", or randomly "rand"} -\item{sex}{which sex to select. Use "B" for both, "F" for -females and "M" for males. If the simulation is not using sexes, +\item{sex}{which sex to select. Use "B" for both, "F" for +females and "M" for males. If the simulation is not using sexes, the argument is ignored.} -\item{famType}{which type of family to select. Use "B" for -full-sib families, "F" for half-sib families on female side and "M" +\item{famType}{which type of family to select. Use "B" for +full-sib families, "F" for half-sib families on female side and "M" for half-sib families on the male side.} -\item{selectTop}{selects highest values if true. +\item{selectTop}{selects highest values if true. Selects lowest values if false.} -\item{returnPop}{should results be returned as a -\code{\link{Pop-class}}. If FALSE, only the index of selected +\item{returnPop}{should results be returned as a +\code{\link{Pop-class}}. If FALSE, only the index of selected individuals is returned.} \item{candidates}{an optional vector of eligible selection candidates.} \item{simParam}{an object of \code{\link{SimParam}}} -\item{...}{additional arguments if using a function for +\item{...}{additional arguments if using a function for trait} } \value{ -Returns an object of \code{\link{Pop-class}}, -\code{\link{HybridPop-class}} or \code{\link{MegaPop-class}} +Returns an object of \code{\link{Pop-class}}, +\code{\link{HybridPop-class}} or \code{\link{MultiPop-class}} } \description{ -Selects a subset of nInd individuals from each -full-sib family within a population. Will return all individuals +Selects a subset of nInd individuals from each +full-sib family within a population. Will return all individuals from a full-sib family if it has less than or equal to nInd individuals. } \examples{ diff --git a/man/self.Rd b/man/self.Rd index 301dd1df..5970b90d 100644 --- a/man/self.Rd +++ b/man/self.Rd @@ -13,7 +13,7 @@ self(pop, nProgeny = 1, parents = NULL, keepParents = TRUE, simParam = NULL) \item{parents}{an optional vector of indices for allowable parents} -\item{keepParents}{should previous parents be used for mother and +\item{keepParents}{should previous parents be used for mother and father.} \item{simParam}{an object of \code{\link{SimParam}}} @@ -22,7 +22,7 @@ father.} Returns an object of \code{\link{Pop-class}} } \description{ -Creates selfed progeny from each individual in a +Creates selfed progeny from each individual in a population. Only works when sexes is "no". } \examples{ diff --git a/man/setPheno.Rd b/man/setPheno.Rd index 1548757d..bdbfe238 100644 --- a/man/setPheno.Rd +++ b/man/setPheno.Rd @@ -19,7 +19,7 @@ setPheno( ) } \arguments{ -\item{pop}{an object of \code{\link{Pop-class}} or +\item{pop}{an object of \code{\link{Pop-class}} or \code{\link{HybridPop-class}}} \item{h2}{a vector of desired narrow-sense heritabilities for @@ -30,15 +30,15 @@ each trait. See details.} \item{varE}{error (co)variances for traits. See details.} -\item{corE}{an optional matrix for correlations between errors. +\item{corE}{an optional matrix for correlations between errors. See details.} \item{reps}{number of replications for phenotype. See details.} -\item{fixEff}{fixed effect to assign to the population. Used +\item{fixEff}{fixed effect to assign to the population. Used by genomic selection models only.} -\item{p}{the p-value for the environmental covariate +\item{p}{the p-value for the environmental covariate used by GxE traits. If NULL, a value is sampled at random.} @@ -50,47 +50,47 @@ all traits will be set.} \item{simParam}{an object of \code{\link{SimParam}}} } \value{ -Returns an object of \code{\link{Pop-class}} or -\code{\link{HybridPop-class}} if onlyPheno=FALSE, if +Returns an object of \code{\link{Pop-class}} or +\code{\link{HybridPop-class}} if onlyPheno=FALSE, if onlyPheno=TRUE a matrix is returned } \description{ -Sets phenotypes for all traits by adding random error +Sets phenotypes for all traits by adding random error from a multivariate normal distribution. } \details{ -There are three arguments for setting the error variance of a -phenotype: h2, H2, and varE. The user should only use one of these -arguments. If the user supplies values for more than one, only one +There are three arguments for setting the error variance of a +phenotype: h2, H2, and varE. The user should only use one of these +arguments. If the user supplies values for more than one, only one will be used according to order in which they are listed above. -The h2 argument allows the user to specify the error variance +The h2 argument allows the user to specify the error variance according to narrow-sense heritability. This calculation uses the -additive genetic variance and total genetic variance in the founder -population. Thus, the heritability relates to the founder population +additive genetic variance and total genetic variance in the founder +population. Thus, the heritability relates to the founder population and not the current population. -The H2 argument allows the user to specify the error variance +The H2 argument allows the user to specify the error variance according to broad-sense heritability. This calculation uses the -total genetic variance in the founder population. Thus, the heritability +total genetic variance in the founder population. Thus, the heritability relates to the founder population and not the current population. The varE argument allows the user to specify the error variance -directly. The user may supply a vector describing the error variance -for each trait or supply a matrix that specify the covariance of +directly. The user may supply a vector describing the error variance +for each trait or supply a matrix that specify the covariance of the errors. -The corE argument allows the user to specify correlations for the -error covariance matrix. These correlations are be supplied in addition -to the h2, H2, or varE arguments. These correlations will be used to -construct a covariance matrix from a vector of variances. If the user -supplied a covariance matrix to varE, these correlations will supercede +The corE argument allows the user to specify correlations for the +error covariance matrix. These correlations are be supplied in addition +to the h2, H2, or varE arguments. These correlations will be used to +construct a covariance matrix from a vector of variances. If the user +supplied a covariance matrix to varE, these correlations will supercede values provided in that matrix. -The reps parameter is for convenient representation of replicated data. -It is intended to represent replicated yield trials in plant -breeding programs. In this case, varE is set to the plot error and -reps is set to the number of plots per entry. The resulting phenotype +The reps parameter is for convenient representation of replicated data. +It is intended to represent replicated yield trials in plant +breeding programs. In this case, varE is set to the plot error and +reps is set to the number of plots per entry. The resulting phenotype represents the entry-means. } \examples{ diff --git a/man/setPhenoGCA.Rd b/man/setPhenoGCA.Rd index f767a2c6..837c572a 100644 --- a/man/setPhenoGCA.Rd +++ b/man/setPhenoGCA.Rd @@ -33,24 +33,24 @@ each trait. See details in \code{\link{setPheno}}.} \item{H2}{a vector of desired broad-sense heritabilities for each trait. See details in \code{\link{setPheno}}.} -\item{varE}{error (co)variances for traits. +\item{varE}{error (co)variances for traits. See details in \code{\link{setPheno}}.} -\item{corE}{an optional matrix for correlations between errors. +\item{corE}{an optional matrix for correlations between errors. See details in \code{\link{setPheno}}.} -\item{reps}{number of replications for phenotype. +\item{reps}{number of replications for phenotype. See details in \code{\link{setPheno}}.} -\item{fixEff}{fixed effect to assign to the population. Used +\item{fixEff}{fixed effect to assign to the population. Used by genomic selection models only.} -\item{p}{the p-value for the environmental covariate +\item{p}{the p-value for the environmental covariate used by GxE traits. If NULL, a value is sampled at random.} -\item{inbred}{are both pop and testers fully inbred. They are only -fully inbred if created by \code{\link{newPop}} using inbred founders +\item{inbred}{are both pop and testers fully inbred. They are only +fully inbred if created by \code{\link{newPop}} using inbred founders or by the \code{\link{makeDH}} function} \item{onlyPheno}{should only the phenotype be returned, see return} @@ -58,11 +58,11 @@ or by the \code{\link{makeDH}} function} \item{simParam}{an object of \code{\link{SimParam}}} } \value{ -Returns an object of \code{\link{Pop-class}} or +Returns an object of \code{\link{Pop-class}} or a matrix if onlyPheno=TRUE } \description{ -Calculates general combining ability from a set of testers and +Calculates general combining ability from a set of testers and returns these values as phenotypes for a population. } \examples{ diff --git a/man/setPhenoProgTest.Rd b/man/setPhenoProgTest.Rd index 4206eb7d..4c2930a2 100644 --- a/man/setPhenoProgTest.Rd +++ b/man/setPhenoProgTest.Rd @@ -25,7 +25,7 @@ setPhenoProgTest( \item{testPop}{an object of \code{\link{Pop-class}}} -\item{nMatePerInd}{number of times an individual in 'pop' is mated to an +\item{nMatePerInd}{number of times an individual in 'pop' is mated to an individual in testPop} \item{use}{true genetic value (\code{gv}) or phenotypes (\code{pheno}, default)} @@ -36,19 +36,19 @@ each trait. See details in \code{\link{setPheno}}.} \item{H2}{a vector of desired broad-sense heritabilities for each trait. See details in \code{\link{setPheno}}.} -\item{varE}{error (co)variances for traits. +\item{varE}{error (co)variances for traits. See details in \code{\link{setPheno}}.} -\item{corE}{an optional matrix for correlations between errors. +\item{corE}{an optional matrix for correlations between errors. See details in \code{\link{setPheno}}.} -\item{reps}{number of replications for phenotype. +\item{reps}{number of replications for phenotype. See details in \code{\link{setPheno}}.} -\item{fixEff}{fixed effect to assign to the population. Used +\item{fixEff}{fixed effect to assign to the population. Used by genomic selection models only.} -\item{p}{the p-value for the environmental covariate +\item{p}{the p-value for the environmental covariate used by GxE traits. If NULL, a value is sampled at random.} @@ -57,20 +57,20 @@ sampled at random.} \item{simParam}{an object of \code{\link{SimParam}}} } \value{ -Returns an object of \code{\link{Pop-class}} or +Returns an object of \code{\link{Pop-class}} or a matrix if onlyPheno=TRUE } \description{ -Models a progeny test of individuals in 'pop'. Returns 'pop' with a phenotype +Models a progeny test of individuals in 'pop'. Returns 'pop' with a phenotype representing the average performance of their progeny. The phenotype is generated -by mating individuals in 'pop' to randomly chosen individuals in testPop a +by mating individuals in 'pop' to randomly chosen individuals in testPop a number of times equal to 'nMatePerInd'. } \details{ -The reps parameter is for convenient representation of replicated data. -It was intended for representation of replicated yield trials in plant -breeding programs. In this case, varE is set to the plot error and -reps is set to the number plots per entry. The resulting phenotype +The reps parameter is for convenient representation of replicated data. +It was intended for representation of replicated yield trials in plant +breeding programs. In this case, varE is set to the plot error and +reps is set to the number plots per entry. The resulting phenotype would reflect the mean of all replications. } \examples{ diff --git a/man/varAA.Rd b/man/varAA.Rd index 4bc7bbd2..eacdc7e4 100644 --- a/man/varAA.Rd +++ b/man/varAA.Rd @@ -12,7 +12,7 @@ varAA(pop, simParam = NULL) \item{simParam}{an object of \code{\link{SimParam}}} } \description{ -Returns additive-by-additive epistatic +Returns additive-by-additive epistatic variance for all traits } \examples{ From 503ea55d33e97b4eef5571a79b3363b1edb44dec Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 12 Jul 2023 07:41:21 -0500 Subject: [PATCH 07/20] Adding Philip as a contributor --- DESCRIPTION | 4 +++- NEWS.md | 8 +++++--- man/AlphaSimR-package.Rd | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b43e70ca..e27cfeb2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,9 @@ Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", person("Thiago", "Oliveira", role = "ctb", comment = c(ORCID = "0000-0002-4555-2584")), person("Audrey", "Martin", role = "ctb", - comment = c(ORCID = "0000-0003-2235-0098"))) + comment = c(ORCID = "0000-0003-2235-0098")), + person("Philip", "Greenspoon", role = "ctb", + comment = c(ORCID = "0000-0001-6284-7248"))) Description: The successor to the 'AlphaSim' software for breeding program simulation [Faux et al. (2016) ]. Used for stochastic simulations of breeding programs to the level of DNA diff --git a/NEWS.md b/NEWS.md index 75a8fa33..8f8cc457 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,14 +1,16 @@ # AlphaSimR 1.4.2.9990 -* fixed bug in `writePlink` to correctly export map positions in cM +*renamed `MegaPop` to `MultiPop` + +*fixed bug in `writePlink` to correctly export map positions in cM # AlphaSimR 1.4.2 -* updated MaCS citation to https site +*updated MaCS citation to https site # AlphaSimR 1.4.1 -* Changed citation to use `bibentry` instead of `citEntry` +*Changed citation to use `bibentry` instead of `citEntry` # AlphaSimR 1.4.0 diff --git a/man/AlphaSimR-package.Rd b/man/AlphaSimR-package.Rd index 2e6afff2..d4f8e0bd 100644 --- a/man/AlphaSimR-package.Rd +++ b/man/AlphaSimR-package.Rd @@ -43,6 +43,7 @@ Other contributors: \item David Wilson [contributor] \item Thiago Oliveira (\href{https://orcid.org/0000-0002-4555-2584}{ORCID}) [contributor] \item Audrey Martin (\href{https://orcid.org/0000-0003-2235-0098}{ORCID}) [contributor] + \item Philip Greenspoon (\href{https://orcid.org/0000-0001-6284-7248}{ORCID}) [contributor] } } From 8978be46bba2a5dc199efc6f2f5fbbeccbe28c92 Mon Sep 17 00:00:00 2001 From: gregorgorjanc Date: Tue, 25 Jul 2023 22:23:41 +0100 Subject: [PATCH 08/20] AlphaSimR.Rproj for git inRStudio & defaults The defaults can be changed --- .gitignore | 1 - AlphaSimR.Rproj | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 AlphaSimR.Rproj diff --git a/.gitignore b/.gitignore index 3415e434..12829180 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.Rproj .Rhistory .Rapp.history .RData diff --git a/AlphaSimR.Rproj b/AlphaSimR.Rproj new file mode 100644 index 00000000..49f2092f --- /dev/null +++ b/AlphaSimR.Rproj @@ -0,0 +1,19 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source From a20201b8e5a96929c87c671aca5b3ddfe7cfc0b5 Mon Sep 17 00:00:00 2001 From: gregorgorjanc Date: Tue, 25 Jul 2023 22:57:09 +0100 Subject: [PATCH 09/20] Documenting user defined functions in selectInd() #146 --- R/selection.R | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/R/selection.R b/R/selection.R index dcd130b7..81add9c3 100644 --- a/R/selection.R +++ b/R/selection.R @@ -100,6 +100,8 @@ getFam = function(pop,famType){ #' @param nInd the number of individuals to select #' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. +#' The function must work on a vector or matrix of \code{use} values. +#' See the examples and \code{\link{selIndex}}. #' @param use select on genetic values "gv", estimated #' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" @@ -131,8 +133,21 @@ getFam = function(pop,famType){ #' #Create population #' pop = newPop(founderPop, simParam=SP) #' -#' #Select best 5 +#' #Select top 5 (directional selection) #' pop2 = selectInd(pop, 5, simParam=SP) +#' hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +#' abline(v = pop2@pheno, col = "red", lwd = 2) +#' +#' #Select 5 most deviating from an optima (disruptive selection) +#' squaredDeviation = function(x, optima = 0) (x - optima)^2 +#' pop3 = selectInd(pop, 5, simParam=SP, trait = squaredDeviation, selectTop = TRUE) +#' hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +#' abline(v = pop3@pheno, col = "red", lwd = 2) +#' +#' #Select 5 least deviating from an optima (stabilising selection) +#' pop4 = selectInd(pop, 5, simParam=SP, trait = squaredDeviation, selectTop = FALSE) +#' hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +#' abline(v = pop4@pheno, col = "red", lwd = 2) #' #' @export selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", @@ -182,6 +197,8 @@ selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", #' @param nFam the number of families to select #' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. +#' The function must work on a vector or matrix of \code{use} values. +#' See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}. #' @param use select on genetic values "gv", estimated #' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" @@ -280,6 +297,8 @@ selectFam = function(pop,nFam,trait=1,use="pheno",sex="B", #' @param nInd the number of individuals to select within a family #' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. +#' The function must work on a vector or matrix of \code{use} values. +#' See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}. #' @param use select on genetic values "gv", estimated #' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" @@ -387,6 +406,8 @@ selectWithinFam = function(pop,nInd,trait=1,use="pheno",sex="B", #' @param pollenControl are plants selected before pollination #' @param trait the trait for selection. Either a number indicating #' a single trait or a function returning a vector of length nInd. +#' The function must work on a vector or matrix of \code{use} values. +#' See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}. #' @param use select on genetic values "gv", estimated #' breeding values "ebv", breeding values "bv", phenotypes "pheno", #' or randomly "rand" From 2c35df76b77429bcb3c00bd846d3138e1d988145 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 26 Jul 2023 07:23:06 -0500 Subject: [PATCH 10/20] Delete AlphaSimR.Rproj --- AlphaSimR.Rproj | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 AlphaSimR.Rproj diff --git a/AlphaSimR.Rproj b/AlphaSimR.Rproj deleted file mode 100644 index 49f2092f..00000000 --- a/AlphaSimR.Rproj +++ /dev/null @@ -1,19 +0,0 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -StripTrailingWhitespace: Yes - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source From 7fee3a969c674ace115a1e43f55e0355623800bd Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 26 Jul 2023 07:30:27 -0500 Subject: [PATCH 11/20] Revert "AlphaSimR.Rproj for git inRStudio & defaults" This reverts commit 8978be46bba2a5dc199efc6f2f5fbbeccbe28c92. --- .gitignore | 1 + AlphaSimR.Rproj | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 AlphaSimR.Rproj diff --git a/.gitignore b/.gitignore index 12829180..3415e434 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.Rproj .Rhistory .Rapp.history .RData diff --git a/AlphaSimR.Rproj b/AlphaSimR.Rproj deleted file mode 100644 index 49f2092f..00000000 --- a/AlphaSimR.Rproj +++ /dev/null @@ -1,19 +0,0 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -StripTrailingWhitespace: Yes - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source From 827431614667f6373527180ec4a34c0b88873c28 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Wed, 26 Jul 2023 07:42:21 -0500 Subject: [PATCH 12/20] Updating documentation --- man/selectFam.Rd | 4 +++- man/selectInd.Rd | 19 +++++++++++++++++-- man/selectOP.Rd | 4 +++- man/selectWithinFam.Rd | 4 +++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/man/selectFam.Rd b/man/selectFam.Rd index b597caf9..ab08abd6 100644 --- a/man/selectFam.Rd +++ b/man/selectFam.Rd @@ -25,7 +25,9 @@ selectFam( \item{nFam}{the number of families to select} \item{trait}{the trait for selection. Either a number indicating -a single trait or a function returning a vector of length nInd.} +a single trait or a function returning a vector of length nInd. +The function must work on a vector or matrix of \code{use} values. +See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}.} \item{use}{select on genetic values "gv", estimated breeding values "ebv", breeding values "bv", phenotypes "pheno", diff --git a/man/selectInd.Rd b/man/selectInd.Rd index 828e2d26..38936e4f 100644 --- a/man/selectInd.Rd +++ b/man/selectInd.Rd @@ -24,7 +24,9 @@ selectInd( \item{nInd}{the number of individuals to select} \item{trait}{the trait for selection. Either a number indicating -a single trait or a function returning a vector of length nInd.} +a single trait or a function returning a vector of length nInd. +The function must work on a vector or matrix of \code{use} values. +See the examples and \code{\link{selIndex}}.} \item{use}{select on genetic values "gv", estimated breeding values "ebv", breeding values "bv", phenotypes "pheno", @@ -68,7 +70,20 @@ SP$setVarE(h2=0.5) #Create population pop = newPop(founderPop, simParam=SP) -#Select best 5 +#Select top 5 (directional selection) pop2 = selectInd(pop, 5, simParam=SP) +hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +abline(v = pop2@pheno, col = "red", lwd = 2) + +#Select 5 most deviating from an optima (disruptive selection) +squaredDeviation = function(x, optima = 0) (x - optima)^2 +pop3 = selectInd(pop, 5, simParam=SP, trait = squaredDeviation, selectTop = TRUE) +hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +abline(v = pop3@pheno, col = "red", lwd = 2) + +#Select 5 least deviating from an optima (stabilising selection) +pop4 = selectInd(pop, 5, simParam=SP, trait = squaredDeviation, selectTop = FALSE) +hist(pop@pheno); abline(v = pop@pheno, lwd = 2) +abline(v = pop4@pheno, col = "red", lwd = 2) } diff --git a/man/selectOP.Rd b/man/selectOP.Rd index c7b685b7..25fbd22f 100644 --- a/man/selectOP.Rd +++ b/man/selectOP.Rd @@ -32,7 +32,9 @@ Value ranges from 0 to 1.} \item{pollenControl}{are plants selected before pollination} \item{trait}{the trait for selection. Either a number indicating -a single trait or a function returning a vector of length nInd.} +a single trait or a function returning a vector of length nInd. +The function must work on a vector or matrix of \code{use} values. +See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}.} \item{use}{select on genetic values "gv", estimated breeding values "ebv", breeding values "bv", phenotypes "pheno", diff --git a/man/selectWithinFam.Rd b/man/selectWithinFam.Rd index bd58257d..fe3d2a2c 100644 --- a/man/selectWithinFam.Rd +++ b/man/selectWithinFam.Rd @@ -25,7 +25,9 @@ selectWithinFam( \item{nInd}{the number of individuals to select within a family} \item{trait}{the trait for selection. Either a number indicating -a single trait or a function returning a vector of length nInd.} +a single trait or a function returning a vector of length nInd. +The function must work on a vector or matrix of \code{use} values. +See the examples in \code{\link{selectInd}} and \code{\link{selIndex}}.} \item{use}{select on genetic values "gv", estimated breeding values "ebv", breeding values "bv", phenotypes "pheno", From 2ce9e29813cd385a3c062cab70facadf2cd45a00 Mon Sep 17 00:00:00 2001 From: gregorgorjanc Date: Thu, 24 Aug 2023 20:47:20 +0200 Subject: [PATCH 13/20] More appropriate README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 581f200f..d1858c28 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ [![](http://cranlogs.r-pkg.org/badges/grand-total/AlphaSimR)](https://cran.r-project.org/package=AlphaSimR) [![](http://cranlogs.r-pkg.org/badges/AlphaSimR)](https://cran.r-project.org/package=AlphaSimR) - -The AlphaSimR website is currently under development and has only been made available for testing at this time. This page will change when the website is ready for widespread use. +The successor to the 'AlphaSim' software for breeding program simulation (Faux et al., 2016; https://doi.org/10.3835/plantgenome2016.02.0013). Used for stochastic simulations of breeding programs to the level of DNA sequence for every individual. Contained is a wide range of functions for modeling common tasks in a breeding program, such as selection and crossing. These functions allow for constructing simulations of highly complex plant and animal breeding programs via scripting in the R software environment. Such simulations can be used to evaluate overall breeding program performance and conduct research into breeding program design, such as implementation of genomic selection. Included is the 'Markovian Coalescent Simulator' ('MaCS') for fast simulation of biallelic sequences according to a population demographic history (Chen et al., 2009; https://doi.org/10.1101/gr.083634.108). ## Publication From bda10ca1bb5f6cbc69dc6274431bdaa7d789e278 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Thu, 14 Sep 2023 11:53:51 -0500 Subject: [PATCH 14/20] removed defunct 'reps' from `writeRecords` --- R/writeRecords.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/writeRecords.R b/R/writeRecords.R index ce4d9d72..d4ccc2ff 100644 --- a/R/writeRecords.R +++ b/R/writeRecords.R @@ -61,8 +61,7 @@ writeRecords = function(pop,dir,snpChip=1,useQtl=FALSE, } #Write info.txt info = data.frame(id=pop@id,mother=pop@mother,father=pop@father, - reps=pop@reps,fixEff=pop@fixEff, - stringsAsFactors=FALSE) + fixEff=pop@fixEff,stringsAsFactors=FALSE) filePath = file.path(dir,"info.txt") if(file.exists(filePath)){ write.table(info,filePath,append=TRUE,col.names=FALSE, From 50948f9d066209023a382eb4e0a5d10c94452b49 Mon Sep 17 00:00:00 2001 From: Gregor Gorjanc Date: Fri, 13 Oct 2023 09:28:53 +0100 Subject: [PATCH 15/20] Docs on rate/scale param of the gamma distribution #156 Documenting why we don't provide option to set rate/scale param of the gamma distribution as mentioned in #156 --- R/Class-SimParam.R | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/R/Class-SimParam.R b/R/Class-SimParam.R index e02f3fd5..7fb4269a 100644 --- a/R/Class-SimParam.R +++ b/R/Class-SimParam.R @@ -1,3 +1,4 @@ + #' @title Simulation parameters #' #' @description @@ -465,7 +466,7 @@ SimParam = R6Class( #' @description #' Randomly assigns eligible QTLs for one or more additive traits. - #' If simulating more than one trait, all traits will be pleiotrophic + #' If simulating more than one trait, all traits will be pleiotropic #' with correlated additive effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -474,6 +475,8 @@ SimParam = R6Class( #' @param corA a matrix of correlations between additive effects #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -525,7 +528,7 @@ SimParam = R6Class( #' @description #' Randomly assigns eligible QTLs for one or more traits with dominance. - #' If simulating more than one trait, all traits will be pleiotrophic + #' If simulating more than one trait, all traits will be pleiotropic #' with correlated effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -539,6 +542,8 @@ SimParam = R6Class( #' FALSE, tuning is performed according to total genetic variance. #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -606,8 +611,8 @@ SimParam = R6Class( }, #' @description - #' Randomly assigns eligible QTLs for one ore more additive GxE traits. - #' If simulating more than one trait, all traits will be pleiotrophic + #' Randomly assigns eligible QTLs for one or more additive GxE traits. + #' If simulating more than one trait, all traits will be pleiotropic #' with correlated effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -619,6 +624,8 @@ SimParam = R6Class( #' @param corGxE a matrix of correlations between GxE effects #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -718,6 +725,8 @@ SimParam = R6Class( #' @param useVarA tune according to additive genetic variance if true #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -820,7 +829,7 @@ SimParam = R6Class( #' @description #' Randomly assigns eligible QTLs for one or more additive and epistasis - #' traits. If simulating more than one trait, all traits will be pleiotrophic + #' traits. If simulating more than one trait, all traits will be pleiotropic #' with correlated additive effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -834,6 +843,8 @@ SimParam = R6Class( #' FALSE, tuning is performed according to total genetic variance. #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -902,7 +913,7 @@ SimParam = R6Class( #' @description #' Randomly assigns eligible QTLs for one or more traits with dominance and - #' epistasis. If simulating more than one trait, all traits will be pleiotrophic + #' epistasis. If simulating more than one trait, all traits will be pleiotropic #' with correlated effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -919,6 +930,8 @@ SimParam = R6Class( #' FALSE, tuning is performed according to total genetic variance. #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -1001,7 +1014,7 @@ SimParam = R6Class( #' @description #' Randomly assigns eligible QTLs for one or more additive and epistasis - #' GxE traits. If simulating more than one trait, all traits will be pleiotrophic + #' GxE traits. If simulating more than one trait, all traits will be pleiotropic #' with correlated effects. #' #' @param nQtlPerChr number of QTLs per chromosome. Can be a single value or nChr values. @@ -1018,6 +1031,8 @@ SimParam = R6Class( #' FALSE, tuning is performed according to total genetic variance. #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) @@ -1142,6 +1157,8 @@ SimParam = R6Class( #' @param useVarA tune according to additive genetic variance if true #' @param gamma should a gamma distribution be used instead of normal #' @param shape the shape parameter for the gamma distribution + #' (the rate/scale parameter of the gamma distribution is accounted + #' for via the desired level of genetic variance, the var argument) #' @param force should the check for a running simulation be #' ignored. Only set to TRUE if you know what you are doing. #' @param name optional name for trait(s) From cb1d099c4fe2d9db10bd9b4bb5c1da090738b4ae Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Mon, 30 Oct 2023 08:44:41 -0500 Subject: [PATCH 16/20] -fixed bug in `writeRecords` #154 -added `altAddTraitAD` #140 -add miscPop slot to pop #120 -expanded functionality of candidates in selection #138 --- DESCRIPTION | 4 +- NEWS.md | 8 +- R/Class-Pop.R | 12 +- R/Class-SimParam.R | 118 +++++++++++++++++ R/RcppExports.R | 12 ++ R/mergePops.R | 3 +- R/selection.R | 24 ++++ man/Pop-class.Rd | 3 + man/SimParam.Rd | 158 ++++++++++++++++++++--- src/RcppExports.cpp | 44 +++++++ src/altAddTraitAD.cpp | 291 ++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 654 insertions(+), 23 deletions(-) create mode 100644 src/altAddTraitAD.cpp diff --git a/DESCRIPTION b/DESCRIPTION index e27cfeb2..295b453c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations -Version: 1.4.2.9990 -Date: 2023-6-29 +Version: 1.5.0 +Date: 2023-10-30 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), person("Gregor", "Gorjanc", role = "ctb", diff --git a/NEWS.md b/NEWS.md index 8f8cc457..da7d91a4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,12 @@ *fixed bug in `writePlink` to correctly export map positions in cM +*fixed bug in `writeRecords` due to removed reps slot in pops + +*added `altAddTraitAD` for specifying traits with dominance effects using dominance variance and inbreeding depression + +*add miscPop slot to class `Pop` + # AlphaSimR 1.4.2 *updated MaCS citation to https site @@ -34,8 +40,6 @@ # AlphaSimR 1.3.2 -*changed name of `MegaPop` to `MultiPop` - *fixed column name bug with multiple traits in `setEBV` *fixed CTD caused by `runMacs` when too many segSites are requested diff --git a/R/Class-Pop.R b/R/Class-Pop.R index a6737d49..48e02d64 100644 --- a/R/Class-Pop.R +++ b/R/Class-Pop.R @@ -379,6 +379,8 @@ isNamedMapPop = function(x) { #' population. This list is normally empty and exists solely as an #' open slot available for uses to store extra information about #' individuals. +#' @slot miscPop a list of any length containing optional meta data for the +#' populations. This list is empty unless information is supplied by the user. #' #' @export setClass("Pop", @@ -393,7 +395,8 @@ setClass("Pop", ebv="matrix", gxe="list", fixEff="integer", - misc="list"), + misc="list", + miscPop="list"), contains="RawPop") setValidity("Pop",function(object){ @@ -500,6 +503,7 @@ setMethod("[", for(chr in 1:x@nChr){ x@geno[[chr]] = x@geno[[chr]][,,i,drop=FALSE] } + x@miscPop = list() return(x) } ) @@ -692,7 +696,8 @@ newPop = function(rawPop,simParam=NULL,...){ ebv=matrix(NA_real_, nrow=rawPop@nInd, ncol=0), - misc=vector("list",rawPop@nInd)) + misc=vector("list",rawPop@nInd), + miscPop=list()) if(simParam$nTraits>=1){ output = setPheno(output, varE=NULL, reps=1, fixEff=1L, p=NULL, onlyPheno=FALSE, @@ -879,7 +884,8 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){ ebv = matrix(NA_real_, nrow=0L, ncol=0L), - misc = list()) + misc = list(), + miscPop = list()) return(output) } diff --git a/R/Class-SimParam.R b/R/Class-SimParam.R index 7fb4269a..efe74423 100644 --- a/R/Class-SimParam.R +++ b/R/Class-SimParam.R @@ -609,6 +609,124 @@ SimParam = R6Class( } invisible(self) }, + + #' @description + #' An alternative method for adding a trait with additive and dominance effects + #' to an AlphaSimR simulation. The function attempts to create a trait matching + #' user defined values for number of QTL, inbreeding depression, additive genetic + #' variance and dominance genetic variance. + #' + #' @param nQtlPerChr number of QTLs per chromosome. + #' Can be a single value or nChr values. + #' @param mean desired mean of the trait + #' @param varA desired additive variance + #' @param varD desired dominance variance + #' @param inbrDepr desired inbreeding depression, see details + #' @param limMeanDD limits for meanDD, see details + #' @param limVarDD limits for varDD, see details + #' @param silent should summary details be printed to the console + #' @param force should the check for a running simulation be + #' ignored. Only set to TRUE if you know what you are doing. + #' @param name optional name for trait + #' + #' @details + #' This function will always add a trait to 'SimParam', unless an error occurs + #' with picking QTLs. The resulting trait will always have the desired mean and + #' additive genetic variance. However, it may not have the desired values for + #' inbreeding depression and dominance variance. Thus, it is strongly recommended + #' to check the output printed to the console to determine how close the trait's + #' parameters came to these desired values. + #' + #' The mean and additive genetic variance will always be achieved exactly. The + #' function attempts to achieve the desired dominance variance and inbreeding + #' depression while staying within the user supplied constraints for the + #' acceptable range of dominance degree mean and variance. If the desired values + #' are not being achieved, the acceptable range need to be increased and/or the + #' number of QTL may need to be increased. There are not limits to setting the + #' range for dominance degree mean and variance, but care should be taken to + #' with regards to the biological feasibility of the limits that are supplied. + #' The default limits were somewhat arbitrarily set, so I make not claim to + #' how reasonable these limits are for routine use. + #' + #' Inbreeding depression in this function is defined as the difference in mean + #' genetic value between a population with the same allele frequency as the + #' reference population (population used to initialize SimParam) in + #' Hardy-Weinberg equilibrium compared to a population with the same allele + #' frequency that is fully inbred. This is equivalent to the amount the mean of + #' a population increases when going from an inbreeding coefficient of 1 (fully + #' inbred) to a population with an inbreeding coefficient of 0 (Hardy-Weinberg + #' equilibrium). Note that the sign of the value should (usually) be positive. + #' This corresponds to a detrimental effect of inbreeding when higher values of + #' the trait are considered biologically beneficial. + #' + #' Summary information on this trait is printed to the console when silent=FALSE. + #' The summary information reports the inbreeding depression and dominance + #' variance for the population as well as the dominance degree mean and variance + #' applied to the trait. + #' + #' @examples + #' #Create founder haplotypes + #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) + #' + #' #Set simulation parameters + #' SP = SimParam$new(founderPop) + #' SP$altAddTraitAD(nQtlPerChr=10, mean=0, varA=1, varD=0.05, inbrDepr=0.2) + altAddTraitAD = function(nQtlPerChr,mean=0,varA=1,varD=0,inbrDepr=0, + limMeanDD=c(0,1.5),limVarDD=c(0,0.5), + silent=FALSE,force=FALSE,name=NULL){ + if(!force){ + private$.isRunning() + } + if(length(nQtlPerChr)==1){ + nQtlPerChr = rep(nQtlPerChr,self$nChr) + } + if(is.null(name)){ + name = paste0("Trait",self$nTraits+1) + } + + # Pick QTL + qtlLoci = private$.pickLoci(nQtlPerChr) + + # Create list of arguments for optimization + argsList = argAltAD(LociMap = qtlLoci, + Pop = self$founderPop, + mean = mean, + varA = varA, + varD = varD, + inbrDepr = inbrDepr, + nThreads = self$nThreads) + + # Run optim to optimize meanDD and varDD + optOut = optim(par = c(mean(limMeanDD), mean(sqrt(limVarDD))), + fn = objAltAD, + gr = NULL, + method = "L-BFGS-B", + lower = c(limMeanDD[1], sqrt(limVarDD[1])), + upper = c(limMeanDD[2], sqrt(limVarDD[2])), + args = argsList) + + # Finalize creation of trait + output = finAltAD(input = optOut$par, args = argsList) + trait = new("TraitAD", + qtlLoci, + addEff=c(output$a), + domEff=c(output$d), + intercept=c(output$intercept), + name=name) + private$.addTrait(trait,varA,output$varG) + + # Report trait details + if(!silent){ + cat("A new trait called", name, "was added. \n") + cat(" varD =", output$varD, "\n") + cat(" inbrDepr =", output$inbrDepr, "\n") + cat(" meanDD =", output$meanDD, "\n") + cat(" varDD =", output$varDD, "\n") + } + + invisible(self) + }, + #' @description #' Randomly assigns eligible QTLs for one or more additive GxE traits. diff --git a/R/RcppExports.R b/R/RcppExports.R index edcd5cc3..ca5bf5c7 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -212,6 +212,18 @@ writeASHaplotypes <- function(g, locations, allLocations, snpchips, names, missi invisible(.Call(`_AlphaSimR_writeASHaplotypes`, g, locations, allLocations, snpchips, names, missing, fname)) } +argAltAD <- function(LociMap, Pop, mean, varA, varD, inbrDepr, nThreads) { + .Call(`_AlphaSimR_argAltAD`, LociMap, Pop, mean, varA, varD, inbrDepr, nThreads) +} + +objAltAD <- function(input, args) { + .Call(`_AlphaSimR_objAltAD`, input, args) +} + +finAltAD <- function(input, args) { + .Call(`_AlphaSimR_finAltAD`, input, args) +} + calcGenParam <- function(trait, pop, nThreads) { .Call(`_AlphaSimR_calcGenParam`, trait, pop, nThreads) } diff --git a/R/mergePops.R b/R/mergePops.R index 21aa8991..2b194441 100644 --- a/R/mergePops.R +++ b/R/mergePops.R @@ -144,5 +144,6 @@ mergePops = function(popList){ gxe=gxe, pheno=pheno, ebv=ebv, - misc=misc)) + misc=misc, + miscPop=list())) } diff --git a/R/selection.R b/R/selection.R index 81add9c3..1ef1cd5c 100644 --- a/R/selection.R +++ b/R/selection.R @@ -56,6 +56,27 @@ getResponse = function(pop,trait,use,simParam=NULL,...){ return(response) } +# Converts candidates to a vector of positive numbers +# for the individuals that are candidates. This function +# handle indexing by id and negative value indexing +getCandidates = function(pop, candidates){ + if(is.character(candidates)){ + candidates = match(candidates, pop@id) + if(any(is.na(candidates))){ + stop("Trying to select invalid individuals") + } + if(any(is.null(candidates))){ + stop("Not valid ids") + } + }else{ + if(any(abs(candidates)>pop@nInd)){ + stop("Trying to select invalid individuals") + } + candidates = (1:pop@nInd)[candidates] + } + return(candidates) +} + # Returns a vector of individuals in a population with the required sex checkSexes = function(pop,sex,simParam,...){ sex = toupper(sex) @@ -167,6 +188,7 @@ selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", } eligible = checkSexes(pop=pop,sex=sex,simParam=simParam,...) if(!is.null(candidates)){ + candidates = getCandidates(pop=pop,candidates=candidates) eligible = eligible[eligible%in%candidates] } if(length(eligible)}}\preformatted{SimParam$addTraitA( @@ -784,7 +796,9 @@ with correlated additive effects. \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -812,7 +826,7 @@ SP$addTraitA(10) \if{latex}{\out{\hypertarget{method-SimParam-addTraitAD}{}}} \subsection{Method \code{addTraitAD()}}{ Randomly assigns eligible QTLs for one or more traits with dominance. -If simulating more than one trait, all traits will be pleiotrophic +If simulating more than one trait, all traits will be pleiotropic with correlated effects. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitAD( @@ -853,7 +867,9 @@ FALSE, tuning is performed according to total genetic variance.} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -875,13 +891,113 @@ SP$addTraitAD(10, meanDD=0.5) } +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-SimParam-altAddTraitAD}{}}} +\subsection{Method \code{altAddTraitAD()}}{ +An alternative method for adding a trait with additive and dominance effects +to an AlphaSimR simulation. The function attempts to create a trait matching +user defined values for number of QTL, inbreeding depression, additive genetic +variance and dominance genetic variance. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{SimParam$altAddTraitAD( + nQtlPerChr, + mean = 0, + varA = 1, + varD = 0, + inbrDepr = 0, + limMeanDD = c(0, 1.5), + limVarDD = c(0, 0.5), + silent = FALSE, + force = FALSE, + name = NULL +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{nQtlPerChr}}{number of QTLs per chromosome. +Can be a single value or nChr values.} + +\item{\code{mean}}{desired mean of the trait} + +\item{\code{varA}}{desired additive variance} + +\item{\code{varD}}{desired dominance variance} + +\item{\code{inbrDepr}}{desired inbreeding depression, see details} + +\item{\code{limMeanDD}}{limits for meanDD, see details} + +\item{\code{limVarDD}}{limits for varDD, see details} + +\item{\code{silent}}{should summary details be printed to the console} + +\item{\code{force}}{should the check for a running simulation be +ignored. Only set to TRUE if you know what you are doing.} + +\item{\code{name}}{optional name for trait} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +This function will always add a trait to 'SimParam', unless an error occurs +with picking QTLs. The resulting trait will always have the desired mean and +additive genetic variance. However, it may not have the desired values for +inbreeding depression and dominance variance. Thus, it is strongly recommended +to check the output printed to the console to determine how close the trait's +parameters came to these desired values. + +The mean and additive genetic variance will always be achieved exactly. The +function attempts to achieve the desired dominance variance and inbreeding +depression while staying within the user supplied constraints for the +acceptable range of dominance degree mean and variance. If the desired values +are not being achieved, the acceptable range need to be increased and/or the +number of QTL may need to be increased. There are not limits to setting the +range for dominance degree mean and variance, but care should be taken to +with regards to the biological feasibility of the limits that are supplied. +The default limits were somewhat arbitrarily set, so I make not claim to +how reasonable these limits are for routine use. + +Inbreeding depression in this function is defined as the difference in mean +genetic value between a population with the same allele frequency as the +reference population (population used to initialize SimParam) in +Hardy-Weinberg equilibrium compared to a population with the same allele +frequency that is fully inbred. This is equivalent to the amount the mean of +a population increases when going from an inbreeding coefficient of 1 (fully +inbred) to a population with an inbreeding coefficient of 0 (Hardy-Weinberg +equilibrium). Note that the sign of the value should (usually) be positive. +This corresponds to a detrimental effect of inbreeding when higher values of +the trait are considered biologically beneficial. + +Summary information on this trait is printed to the console when silent=FALSE. +The summary information reports the inbreeding depression and dominance +variance for the population as well as the dominance degree mean and variance +applied to the trait. +} + +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{#Create founder haplotypes +founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) + +#Set simulation parameters +SP = SimParam$new(founderPop) +SP$altAddTraitAD(nQtlPerChr=10, mean=0, varA=1, varD=0.05, inbrDepr=0.2) +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-SimParam-addTraitAG}{}}} \subsection{Method \code{addTraitAG()}}{ -Randomly assigns eligible QTLs for one ore more additive GxE traits. -If simulating more than one trait, all traits will be pleiotrophic +Randomly assigns eligible QTLs for one or more additive GxE traits. +If simulating more than one trait, all traits will be pleiotropic with correlated effects. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitAG( @@ -918,7 +1034,9 @@ with correlated effects. \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -994,7 +1112,9 @@ value or nChr values.} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -1022,7 +1142,7 @@ SP$addTraitADG(10, meanDD=0.5, varGxE=2) \if{latex}{\out{\hypertarget{method-SimParam-addTraitAE}{}}} \subsection{Method \code{addTraitAE()}}{ Randomly assigns eligible QTLs for one or more additive and epistasis -traits. If simulating more than one trait, all traits will be pleiotrophic +traits. If simulating more than one trait, all traits will be pleiotropic with correlated additive effects. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitAE( @@ -1061,7 +1181,9 @@ FALSE, tuning is performed according to total genetic variance.} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -1085,7 +1207,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) \if{latex}{\out{\hypertarget{method-SimParam-addTraitADE}{}}} \subsection{Method \code{addTraitADE()}}{ Randomly assigns eligible QTLs for one or more traits with dominance and -epistasis. If simulating more than one trait, all traits will be pleiotrophic +epistasis. If simulating more than one trait, all traits will be pleiotropic with correlated effects. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitADE( @@ -1133,7 +1255,9 @@ FALSE, tuning is performed according to total genetic variance.} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -1161,7 +1285,7 @@ SP$addTraitADE(10) \if{latex}{\out{\hypertarget{method-SimParam-addTraitAEG}{}}} \subsection{Method \code{addTraitAEG()}}{ Randomly assigns eligible QTLs for one or more additive and epistasis -GxE traits. If simulating more than one trait, all traits will be pleiotrophic +GxE traits. If simulating more than one trait, all traits will be pleiotropic with correlated effects. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitAEG( @@ -1209,7 +1333,9 @@ FALSE, tuning is performed according to total genetic variance.} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} @@ -1293,7 +1419,9 @@ to additive variance in a diploid organism with allele frequency 0.5} \item{\code{gamma}}{should a gamma distribution be used instead of normal} -\item{\code{shape}}{the shape parameter for the gamma distribution} +\item{\code{shape}}{the shape parameter for the gamma distribution +(the rate/scale parameter of the gamma distribution is accounted +for via the desired level of genetic variance, the var argument)} \item{\code{force}}{should the check for a running simulation be ignored. Only set to TRUE if you know what you are doing.} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 572beef4..848613d6 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -381,6 +381,47 @@ BEGIN_RCPP return R_NilValue; END_RCPP } +// argAltAD +Rcpp::List argAltAD(Rcpp::S4 LociMap, Rcpp::S4 Pop, double mean, double varA, double varD, double inbrDepr, int nThreads); +RcppExport SEXP _AlphaSimR_argAltAD(SEXP LociMapSEXP, SEXP PopSEXP, SEXP meanSEXP, SEXP varASEXP, SEXP varDSEXP, SEXP inbrDeprSEXP, SEXP nThreadsSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< Rcpp::S4 >::type LociMap(LociMapSEXP); + Rcpp::traits::input_parameter< Rcpp::S4 >::type Pop(PopSEXP); + Rcpp::traits::input_parameter< double >::type mean(meanSEXP); + Rcpp::traits::input_parameter< double >::type varA(varASEXP); + Rcpp::traits::input_parameter< double >::type varD(varDSEXP); + Rcpp::traits::input_parameter< double >::type inbrDepr(inbrDeprSEXP); + Rcpp::traits::input_parameter< int >::type nThreads(nThreadsSEXP); + rcpp_result_gen = Rcpp::wrap(argAltAD(LociMap, Pop, mean, varA, varD, inbrDepr, nThreads)); + return rcpp_result_gen; +END_RCPP +} +// objAltAD +double objAltAD(arma::vec input, const Rcpp::List& args); +RcppExport SEXP _AlphaSimR_objAltAD(SEXP inputSEXP, SEXP argsSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< arma::vec >::type input(inputSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type args(argsSEXP); + rcpp_result_gen = Rcpp::wrap(objAltAD(input, args)); + return rcpp_result_gen; +END_RCPP +} +// finAltAD +Rcpp::List finAltAD(arma::vec input, const Rcpp::List& args); +RcppExport SEXP _AlphaSimR_finAltAD(SEXP inputSEXP, SEXP argsSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< arma::vec >::type input(inputSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type args(argsSEXP); + rcpp_result_gen = Rcpp::wrap(finAltAD(input, args)); + return rcpp_result_gen; +END_RCPP +} // calcGenParam Rcpp::List calcGenParam(const Rcpp::S4& trait, const Rcpp::S4& pop, int nThreads); RcppExport SEXP _AlphaSimR_calcGenParam(SEXP traitSEXP, SEXP popSEXP, SEXP nThreadsSEXP) { @@ -826,6 +867,9 @@ static const R_CallMethodDef CallEntries[] = { {"_AlphaSimR_solveMKM", (DL_FUNC) &_AlphaSimR_solveMKM, 6}, {"_AlphaSimR_writeASGenotypes", (DL_FUNC) &_AlphaSimR_writeASGenotypes, 7}, {"_AlphaSimR_writeASHaplotypes", (DL_FUNC) &_AlphaSimR_writeASHaplotypes, 7}, + {"_AlphaSimR_argAltAD", (DL_FUNC) &_AlphaSimR_argAltAD, 7}, + {"_AlphaSimR_objAltAD", (DL_FUNC) &_AlphaSimR_objAltAD, 2}, + {"_AlphaSimR_finAltAD", (DL_FUNC) &_AlphaSimR_finAltAD, 2}, {"_AlphaSimR_calcGenParam", (DL_FUNC) &_AlphaSimR_calcGenParam, 3}, {"_AlphaSimR_getGeno", (DL_FUNC) &_AlphaSimR_getGeno, 4}, {"_AlphaSimR_getMaternalGeno", (DL_FUNC) &_AlphaSimR_getMaternalGeno, 4}, diff --git a/src/altAddTraitAD.cpp b/src/altAddTraitAD.cpp new file mode 100644 index 00000000..fb5b2f5b --- /dev/null +++ b/src/altAddTraitAD.cpp @@ -0,0 +1,291 @@ +#include "alphasimr.h" + +// Sets up the list of arguments needed for optimization +// [[Rcpp::export]] +Rcpp::List argAltAD(Rcpp::S4 LociMap, + Rcpp::S4 Pop, + double mean, + double varA, + double varD, + double inbrDepr, + int nThreads){ + + // Create ploidy specific genotype dosage variables + arma::uword ploidy = Pop.slot("ploidy"); + double dP = double(ploidy); + arma::uword nInd = Pop.slot("nInd"); + arma::vec x(ploidy+1); + for(arma::uword i=0; i& lociPerChr = LociMap.slot("lociPerChr"); + arma::uword nLoci = accu(lociPerChr); + arma::uvec lociLoc = LociMap.slot("lociLoc"); + arma::Mat genoMat = getGeno( + Rcpp::as > >(Pop.slot("geno")), + lociPerChr, + lociLoc, + nThreads + ); + + // Calculate genotype frequencies + arma::mat genoFreq(ploidy+1, nLoci, arma::fill::zeros); + arma::vec genoMu(nLoci), hetHWE(nLoci); +#ifdef _OPENMP +#pragma omp parallel for schedule(static) num_threads(nThreads) +#endif + for(arma::uword i=0; i& genoMat = args["genoMat"]; + arma::uword nInd = genoMat.n_rows; + arma::uword nLoci = genoMat.n_cols; + const arma::mat& genoFreq = args["genoFreq"]; + const arma::vec& a = args["a"]; + const arma::vec& domDegDev = args["domDegDev"]; + const arma::vec& x = args["x"]; + const arma::vec& xa = args["xa"]; + const arma::vec& xd = args["xd"]; + const arma::vec& genoMu = args["genoMu"]; + const arma::vec& hetHWE = args["hetHWE"]; + double varA = args["varA"]; + double varD = args["varD"]; + double inbrDepr = args["inbrDepr"]; + int nThreads = args["nThreads"]; + + // Calculate d + arma::vec d = abs(a)%(domDegDev*stdDevDD + meanDD); + + // Allocate matrices for breeding values, dominance deviations, and means + // Number of threads used for efficient parallel computing + arma::mat bvMat(nInd, nThreads, arma::fill::zeros); // Breeding values + arma::mat ddMat(nInd, nThreads, arma::fill::zeros); // Dominance deviations + + // Calculate breeding values and dominance deviations + // Involves regressions for each locus +#ifdef _OPENMP +#pragma omp parallel for schedule(static) num_threads(nThreads) +#endif + for(arma::uword i=0; i& genoMat = args["genoMat"]; + arma::uword nInd = genoMat.n_rows; + arma::uword nLoci = genoMat.n_cols; + const arma::mat& genoFreq = args["genoFreq"]; + arma::vec a = args["a"]; + const arma::vec& domDegDev = args["domDegDev"]; + const arma::vec& x = args["x"]; + const arma::vec& xa = args["xa"]; + const arma::vec& xd = args["xd"]; + const arma::vec& genoMu = args["genoMu"]; + const arma::vec& hetHWE = args["hetHWE"]; + double varA = args["varA"]; + double mean = args["mean"]; + int nThreads = args["nThreads"]; + + // Calculate d + arma::vec d = abs(a)%(domDegDev*stdDevDD + meanDD); + + // Allocate matrices for breeding values, dominance deviations, and means + // Number of threads used for efficient parallel computing + arma::mat bvMat(nInd, nThreads, arma::fill::zeros); // Breeding values + arma::mat ddMat(nInd, nThreads, arma::fill::zeros); // Dominance deviations + + // Calculate breeding values and dominance deviations + // Involves regressions for each locus +#ifdef _OPENMP +#pragma omp parallel for schedule(static) num_threads(nThreads) +#endif + for(arma::uword i=0; i Date: Mon, 30 Oct 2023 10:43:47 -0500 Subject: [PATCH 17/20] Doc update for miscPop --- R/Class-Pop.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/Class-Pop.R b/R/Class-Pop.R index 48e02d64..84ac2105 100644 --- a/R/Class-Pop.R +++ b/R/Class-Pop.R @@ -380,7 +380,8 @@ isNamedMapPop = function(x) { #' open slot available for uses to store extra information about #' individuals. #' @slot miscPop a list of any length containing optional meta data for the -#' populations. This list is empty unless information is supplied by the user. +#' population. This list is empty unless information is supplied by the user. +#' Note that the list is emptied every time the population is subsetted. #' #' @export setClass("Pop", From 28bc0655a7490d1b08ee8e9abc163c0ae5423ebf Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Mon, 30 Oct 2023 14:08:15 -0500 Subject: [PATCH 18/20] fixed CRAN notes --- DESCRIPTION | 5 ++--- R/misc.R | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 295b453c..f192e947 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations -Version: 1.5.0 +Version: 1.5.1 Date: 2023-10-30 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), @@ -32,8 +32,7 @@ Description: The successor to the 'AlphaSim' software for breeding program demographic history [Chen et al. (2009) ]. License: MIT + file LICENSE URL: https://github.com/gaynorr/AlphaSimR, - https://gaynorr.github.io/AlphaSimR/, - https://www.edx.org/course/breeding-programme-modelling-with-alphasimr?utm_source=breeding_alphasimr&utm_medium=partner-marketing&utm_campaign=edinburghx + https://gaynorr.github.io/AlphaSimR/ Encoding: UTF-8 Depends: R (>= 4.0.0), methods, R6 Imports: Rcpp (>= 0.12.7), Rdpack diff --git a/R/misc.R b/R/misc.R index 5553d1cc..50b4b985 100644 --- a/R/misc.R +++ b/R/misc.R @@ -75,9 +75,9 @@ isMale <- function(x) { #' #' n <- nInd(basePop) #' location <- vector(mode = "list", length = n) -#' for (ind in seq_len(n)) { +#' for (ind in seq_len(n)) #' location[[ind]] <- runif(n = 2, min = 0, max = 100) -#' } +#' #' location #' basePop <- setMisc(basePop, node = "location", value = location) #' basePop@misc @@ -85,9 +85,9 @@ isMale <- function(x) { #' #' n <- nInd(basePop) #' location <- vector(mode = "list", length = n) -#' for (ind in c(1, 3)) { +#' for (ind in c(1, 3)) #' location[[ind]] <- runif(n = 2, min = 0, max = 100) -#' } +#' #' location #' basePop <- setMisc(basePop, node = "location", value = location) #' basePop@misc From 7d645043ddf1bff5b8fb4fe92788bebc8474d131 Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Tue, 31 Oct 2023 16:46:30 -0500 Subject: [PATCH 19/20] changing tests to conform to CRANs 2 thread limit with testing --- DESCRIPTION | 5 ++-- NEWS.md | 8 ++++++- R/Class-SimParam.R | 15 ++++++++++++ R/GS.R | 10 ++++++++ R/crossing.R | 8 +++++++ R/founderPop.R | 8 ++++--- R/hybrids.R | 4 ++++ R/mergePops.R | 1 + R/misc.R | 40 +++++++------------------------- R/phenotypes.R | 1 + R/polyploids.R | 3 +++ R/popSummary.R | 19 +++++++++++++++ R/pullGeno.R | 10 ++++++++ R/selection.R | 4 ++++ R/writePlink.R | 1 + man/AlphaSimR-package.Rd | 2 +- man/Pop-class.Rd | 3 ++- man/RRBLUP.Rd | 1 + man/RRBLUP2.Rd | 1 + man/RRBLUP_D.Rd | 1 + man/RRBLUP_D2.Rd | 1 + man/RRBLUP_GCA.Rd | 1 + man/RRBLUP_GCA2.Rd | 1 + man/RRBLUP_SCA.Rd | 1 + man/RRBLUP_SCA2.Rd | 1 + man/SimParam.Rd | 30 ++++++++++++++++++++++++ man/aa.Rd | 1 + man/attrition.Rd | 1 + man/bv.Rd | 1 + man/calcGCA.Rd | 1 + man/dd.Rd | 1 + man/doubleGenome.Rd | 1 + man/ebv.Rd | 1 + man/editGenome.Rd | 1 + man/editGenomeTopQtl.Rd | 1 + man/fastRRBLUP.Rd | 1 + man/genParam.Rd | 1 + man/genicVarA.Rd | 1 + man/genicVarAA.Rd | 1 + man/genicVarD.Rd | 1 + man/genicVarG.Rd | 1 + man/getMisc.Rd | 1 + man/getQtlMap.Rd | 1 + man/getSnpMap.Rd | 1 + man/gv.Rd | 1 + man/hybridCross.Rd | 1 + man/makeCross.Rd | 1 + man/makeCross2.Rd | 1 + man/makeDH.Rd | 1 + man/meanG.Rd | 1 + man/meanP.Rd | 1 + man/mergeGenome.Rd | 1 + man/mergePops.Rd | 1 + man/mutate.Rd | 1 + man/nInd.Rd | 1 + man/pedigreeCross.Rd | 1 + man/pheno.Rd | 1 + man/pullIbdHaplo.Rd | 1 + man/pullMarkerGeno.Rd | 1 + man/pullMarkerHaplo.Rd | 1 + man/pullQtlGeno.Rd | 1 + man/pullQtlHaplo.Rd | 1 + man/pullSegSiteHaplo.Rd | 1 + man/pullSnpGeno.Rd | 1 + man/pullSnpHaplo.Rd | 1 + man/randCross.Rd | 1 + man/randCross2.Rd | 1 + man/reduceGenome.Rd | 1 + man/runMacs.Rd | 3 ++- man/runMacs2.Rd | 3 ++- man/sampleHaplo.Rd | 2 +- man/selIndex.Rd | 1 + man/selectCross.Rd | 1 + man/selectFam.Rd | 1 + man/selectInd.Rd | 1 + man/selectOP.Rd | 1 + man/selectWithinFam.Rd | 1 + man/self.Rd | 1 + man/setEBV.Rd | 1 + man/setMisc.Rd | 33 +------------------------- man/setPheno.Rd | 1 + man/setPhenoGCA.Rd | 1 + man/setPhenoProgTest.Rd | 1 + man/usefulness.Rd | 1 + man/varA.Rd | 1 + man/varAA.Rd | 1 + man/varD.Rd | 1 + man/varG.Rd | 1 + man/varP.Rd | 1 + man/writePlink.Rd | 1 + tests/testthat/test-addTrait.R | 8 +++++++ tests/testthat/test-crossing.R | 8 +++++++ tests/testthat/test-editGenome.R | 1 + tests/testthat/test-hybrids.R | 2 ++ tests/testthat/test-importData.R | 1 + vignettes/intro.Rmd | 5 ++++ 96 files changed, 231 insertions(+), 75 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f192e947..35940494 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations Version: 1.5.1 -Date: 2023-10-30 +Date: 2023-10-31 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), person("Gregor", "Gorjanc", role = "ctb", @@ -32,7 +32,8 @@ Description: The successor to the 'AlphaSim' software for breeding program demographic history [Chen et al. (2009) ]. License: MIT + file LICENSE URL: https://github.com/gaynorr/AlphaSimR, - https://gaynorr.github.io/AlphaSimR/ + https://gaynorr.github.io/AlphaSimR/, + https://www.edx.org/learn/animal-breeding/the-university-of-edinburgh-breeding-programme-modelling-with-alphasimr Encoding: UTF-8 Depends: R (>= 4.0.0), methods, R6 Imports: Rcpp (>= 0.12.7), Rdpack diff --git a/NEWS.md b/NEWS.md index da7d91a4..33a2758d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,10 @@ -# AlphaSimR 1.4.2.9990 +# AlphaSimR 1.5.1 + +*deleted bad example code for `setMisc` + +*changed examples to use a single thread for CRAN testing this change is not shown in the documentation + +# AlphaSimR 1.5.0 *renamed `MegaPop` to `MultiPop` diff --git a/R/Class-SimParam.R b/R/Class-SimParam.R index efe74423..67181291 100644 --- a/R/Class-SimParam.R +++ b/R/Class-SimParam.R @@ -487,6 +487,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) addTraitA = function(nQtlPerChr,mean=0,var=1,corA=NULL, gamma=FALSE,shape=1,force=FALSE,name=NULL){ @@ -554,6 +555,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitAD(10, meanDD=0.5) addTraitAD = function(nQtlPerChr,mean=0,var=1,meanDD=0, varDD=0,corA=NULL,corDD=NULL,useVarA=TRUE, @@ -670,6 +672,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$altAddTraitAD(nQtlPerChr=10, mean=0, varA=1, varD=0.05, inbrDepr=0.2) altAddTraitAD = function(nQtlPerChr,mean=0,varA=1,varD=0,inbrDepr=0, limMeanDD=c(0,1.5),limVarDD=c(0,0.5), @@ -754,6 +757,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitAG(10, varGxE=2) addTraitAG = function(nQtlPerChr,mean=0,var=1,varGxE=1e-6,varEnv=0, corA=NULL,corGxE=NULL,gamma=FALSE,shape=1, @@ -855,6 +859,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitADG(10, meanDD=0.5, varGxE=2) addTraitADG = function(nQtlPerChr,mean=0,var=1,varEnv=0, varGxE=1e-6,meanDD=0,varDD=0,corA=NULL, @@ -970,6 +975,11 @@ SimParam = R6Class( #' @examples #' #Create founder haplotypes #' founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) + #' + #' #Set simulation parameters + #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} + #' SP$addTraitAE(10, relAA=0.1) addTraitAE = function(nQtlPerChr,mean=0,var=1,relAA=0,corA=NULL, corAA=NULL,useVarA=TRUE,gamma=FALSE,shape=1,force=FALSE, name=NULL){ @@ -1060,6 +1070,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitADE(10) addTraitADE = function(nQtlPerChr,mean=0,var=1,meanDD=0, varDD=0,relAA=0,corA=NULL,corDD=NULL,corAA=NULL, @@ -1161,6 +1172,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitAEG(10, varGxE=2) addTraitAEG = function(nQtlPerChr,mean=0,var=1,relAA=0,varGxE=1e-6,varEnv=0, corA=NULL,corAA=NULL,corGxE=NULL,useVarA=TRUE,gamma=FALSE, @@ -1627,6 +1639,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) setVarE = function(h2=NULL, H2=NULL, varE=NULL, corE=NULL){ @@ -1699,6 +1712,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10, mean=c(0,0), var=c(1,1), corA=diag(2)) #' SP$setVarE(varE=c(1,1)) #' E = 0.5*diag(2)+0.5 #Positively correlated error @@ -1752,6 +1766,7 @@ SimParam = R6Class( #' #' #Change mean to 1 #' SP$rescaleTraits(mean=1) + #' \dontshow{SP$nThreads = 1L} #' #Run resetPop for change to take effect #' pop = resetPop(pop, simParam=SP) #' meanG(pop) diff --git a/R/GS.R b/R/GS.R index cc1a13b1..6ace27fb 100644 --- a/R/GS.R +++ b/R/GS.R @@ -49,6 +49,7 @@ convertTraitsToNames = function(traits, simParam){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -173,6 +174,7 @@ fastRRBLUP = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -320,6 +322,7 @@ RRBLUP = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -444,6 +447,7 @@ RRBLUP2 = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -557,6 +561,7 @@ RRBLUP_D = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -693,6 +698,7 @@ RRBLUP_D2 = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -813,6 +819,7 @@ RRBLUP_GCA = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -958,6 +965,7 @@ RRBLUP_GCA2 = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -1081,6 +1089,7 @@ RRBLUP_SCA = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) @@ -1239,6 +1248,7 @@ RRBLUP_SCA2 = function(pop, traits=1, use="pheno", snpChip=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' SP$addSnpChip(10) diff --git a/R/crossing.R b/R/crossing.R index eea11244..81e2ad9e 100644 --- a/R/crossing.R +++ b/R/crossing.R @@ -19,6 +19,7 @@ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -112,6 +113,7 @@ makeCross = function(pop,crossPlan,nProgeny=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -219,6 +221,7 @@ randCross = function(pop,nCrosses,nProgeny=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' @@ -282,6 +285,7 @@ selectCross = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -381,6 +385,7 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -469,6 +474,7 @@ randCross2 = function(females,males,nCrosses,nProgeny=1, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -570,6 +576,7 @@ self = function(pop,nProgeny=1,parents=NULL,keepParents=TRUE, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -733,6 +740,7 @@ sortPed = function(id, mother, father, maxCycle=100){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) diff --git a/R/founderPop.R b/R/founderPop.R index 72fcee27..ca887676 100644 --- a/R/founderPop.R +++ b/R/founderPop.R @@ -138,8 +138,9 @@ newMapPop = function(genMap, haplotypes, inbred=FALSE, #' @examples #' # Creates a populations of 10 outbred individuals #' # Their genome consists of 1 chromosome and 100 segregating sites +#' \dontrun{ #' founderPop = runMacs(nInd=10,nChr=1,segSites=100) -#' +#' } #' @export runMacs = function(nInd,nChr=1, segSites=NULL, inbred=FALSE, species="GENERIC", split=NULL, ploidy=2L, manualCommand=NULL, manualGenLen=NULL, @@ -300,8 +301,9 @@ runMacs = function(nInd,nChr=1, segSites=NULL, inbred=FALSE, species="GENERIC", #' # Creates a populations of 10 outbred individuals #' # Their genome consists of 1 chromosome and 100 segregating sites #' # The command is equivalent to using species="GENERIC" in runMacs +#' \dontrun{ #' founderPop = runMacs2(nInd=10,nChr=1,segSites=100) -#' +#' } #' @export runMacs2 = function(nInd,nChr=1,segSites=NULL,Ne=100, bp=1e8,genLen=1,mutRate=2.5e-8, @@ -361,7 +363,7 @@ runMacs2 = function(nInd,nChr=1,segSites=NULL,Ne=100, #' @return an object of \code{\link{MapPop-class}} #' #' @examples -#' founderPop = quickHaplo(nInd=2,nChr=2,segSites=11,inbred=TRUE) +#' founderPop = quickHaplo(nInd=2,nChr=1,segSites=11,inbred=TRUE) #' founderPop = sampleHaplo(mapPop=founderPop,nInd=20) #' #' @export diff --git a/R/hybrids.R b/R/hybrids.R index 0005941b..239e0264 100644 --- a/R/hybrids.R +++ b/R/hybrids.R @@ -23,6 +23,7 @@ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -120,6 +121,7 @@ hybridCross = function(females, males, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -258,6 +260,7 @@ calcGCA = function(pop,use="pheno"){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -368,6 +371,7 @@ setPhenoGCA = function(pop, testers, use="pheno", h2=NULL, H2=NULL, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create two populations of 5 individuals diff --git a/R/mergePops.R b/R/mergePops.R index 2b194441..6ba27777 100644 --- a/R/mergePops.R +++ b/R/mergePops.R @@ -14,6 +14,7 @@ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create a list of populations and merge list #' pop = newPop(founderPop, simParam=SP) diff --git a/R/misc.R b/R/misc.R index 50b4b985..01960c55 100644 --- a/R/misc.R +++ b/R/misc.R @@ -62,38 +62,7 @@ isMale <- function(x) { #' #' @details A \code{NULL} in \code{value} is ignored #' -#' @return \code{\link{Pop-class}} with \code{x@misc[[*]][[node]]} set -#' basePop <- newPop(founderGenomes) -#' -#' basePop <- setMisc(basePop, node = "info", value = 1) -#' basePop@misc -#' getMisc(x = basePop, node = "info") -#' -#' basePop <- setMisc(basePop, node = "info2", value = c("A", "B", "C")) -#' basePop@misc -#' getMisc(x = basePop, node = "info2") -#' -#' n <- nInd(basePop) -#' location <- vector(mode = "list", length = n) -#' for (ind in seq_len(n)) -#' location[[ind]] <- runif(n = 2, min = 0, max = 100) -#' -#' location -#' basePop <- setMisc(basePop, node = "location", value = location) -#' basePop@misc -#' getMisc(x = basePop, node = "location") -#' -#' n <- nInd(basePop) -#' location <- vector(mode = "list", length = n) -#' for (ind in c(1, 3)) -#' location[[ind]] <- runif(n = 2, min = 0, max = 100) -#' -#' location -#' basePop <- setMisc(basePop, node = "location", value = location) -#' basePop@misc -#' getMisc(x = basePop, node = "location") -#' -#' getMisc(x = basePop) +#' @return \code{\link{Pop-class}} #' #' @export setMisc <- function(x, node = NULL, value = NULL) { @@ -136,6 +105,7 @@ setMisc <- function(x, node = NULL, value = NULL) { #' @examples #' founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100) #' SP <- SimParam$new(founderGenomes) +#' \dontshow{SP$nThreads = 1L} #' basePop <- newPop(founderGenomes) #' #' basePop <- setMisc(basePop, node = "info", value = 1) @@ -285,6 +255,7 @@ smithHazel = function(econWt,varG,varP){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #Model two genetically correlated traits #' G = 1.5*diag(2)-0.5 #Genetic correlation matrix #' SP$addTraitA(10, mean=c(0,0), var=c(1,1), corA=G) @@ -334,6 +305,7 @@ selIndex = function(Y,b,scale=FALSE){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -407,6 +379,7 @@ editGenome = function (pop, ind, chr, segSites, allele, simParam = NULL) { #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -530,6 +503,7 @@ editGenomeTopQtl = function(pop, ind, nQtl, trait = 1, increase = TRUE, simParam #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -653,6 +627,7 @@ transMat = function(R){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -758,6 +733,7 @@ mutate = function(pop, mutRate=2.5e-8, returnPos=FALSE, simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) diff --git a/R/phenotypes.R b/R/phenotypes.R index 35433766..197e1873 100644 --- a/R/phenotypes.R +++ b/R/phenotypes.R @@ -123,6 +123,7 @@ calcPheno = function(pop, varE, reps, p, traits, simParam){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population diff --git a/R/polyploids.R b/R/polyploids.R index 0356d44c..e60b7142 100644 --- a/R/polyploids.R +++ b/R/polyploids.R @@ -23,6 +23,7 @@ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -125,6 +126,7 @@ reduceGenome = function(pop,nProgeny=1,useFemale=TRUE,keepParents=TRUE, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -215,6 +217,7 @@ doubleGenome = function(pop, keepParents=TRUE, #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) diff --git a/R/popSummary.R b/R/popSummary.R index 19d1d5ad..e2b75033 100644 --- a/R/popSummary.R +++ b/R/popSummary.R @@ -18,6 +18,7 @@ meanEBV = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -42,6 +43,7 @@ meanG = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -66,6 +68,7 @@ meanP = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -92,6 +95,7 @@ varG = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -154,6 +158,7 @@ varP = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -288,6 +293,7 @@ genParam = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -313,6 +319,7 @@ varA = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -339,6 +346,7 @@ varD = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -364,6 +372,7 @@ varAA = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -389,6 +398,7 @@ bv = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -415,6 +425,7 @@ dd = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -440,6 +451,7 @@ aa = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -465,6 +477,7 @@ genicVarA = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -491,6 +504,7 @@ genicVarD = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -516,6 +530,7 @@ genicVarAA = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -540,6 +555,7 @@ genicVarG = function(pop,simParam=NULL){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -564,6 +580,7 @@ gv = function(pop){ #' SP = SimParam$new(founderPop) #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) +#' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -586,6 +603,7 @@ pheno = function(pop){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) #' @@ -611,6 +629,7 @@ ebv = function(pop){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitAD(10, meanDD=0.5) #' SP$setVarE(h2=0.5) #' diff --git a/R/pullGeno.R b/R/pullGeno.R index d6f84276..fafbf8b1 100644 --- a/R/pullGeno.R +++ b/R/pullGeno.R @@ -169,6 +169,7 @@ getGenMap = function(object=NULL, sex="A"){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addSnpChip(5) #' #' #Pull SNP map @@ -256,6 +257,7 @@ getSnpMap = function(snpChip=1, sex="A", simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(5) #' #' #Pull SNP map @@ -336,6 +338,7 @@ getQtlMap = function(trait=1, sex="A", simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -400,6 +403,7 @@ pullSnpGeno = function(pop, snpChip=1, chr=NULL, asRaw=FALSE, simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -532,6 +536,7 @@ pullSegSiteGeno = function(pop, chr=NULL, asRaw=FALSE, simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -620,6 +625,7 @@ pullSnpHaplo = function(pop, snpChip=1, haplo="all", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -710,6 +716,7 @@ pullQtlHaplo = function(pop, trait=1, haplo="all", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -801,6 +808,7 @@ pullSegSiteHaplo = function(pop, haplo="all", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' SP$setTrackRec(TRUE) @@ -887,6 +895,7 @@ pullIbdHaplo = function(pop, chr=NULL, snpChip=NULL, simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' @@ -961,6 +970,7 @@ pullMarkerGeno = function(pop, markers, asRaw=FALSE, simParam=NULL){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$addSnpChip(5) #' SP$setTrackRec(TRUE) diff --git a/R/selection.R b/R/selection.R index 1ef1cd5c..2f2133f6 100644 --- a/R/selection.R +++ b/R/selection.R @@ -148,6 +148,7 @@ getFam = function(pop,famType){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' @@ -249,6 +250,7 @@ selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' @@ -350,6 +352,7 @@ selectFam = function(pop,nFam,trait=1,use="pheno",sex="B", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' @@ -451,6 +454,7 @@ selectWithinFam = function(pop,nInd,trait=1,use="pheno",sex="B", #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' SP$setVarE(h2=0.5) #' diff --git a/R/writePlink.R b/R/writePlink.R index 085c79ac..15446896 100644 --- a/R/writePlink.R +++ b/R/writePlink.R @@ -32,6 +32,7 @@ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$setSexes(sex="yes_rand") #' SP$addTraitA(nQtlPerChr=10) #' SP$addSnpChip(nSnpPerChr=5) diff --git a/man/AlphaSimR-package.Rd b/man/AlphaSimR-package.Rd index d4f8e0bd..58e7cbee 100644 --- a/man/AlphaSimR-package.Rd +++ b/man/AlphaSimR-package.Rd @@ -28,7 +28,7 @@ Useful links: \itemize{ \item \url{https://github.com/gaynorr/AlphaSimR} \item \url{https://gaynorr.github.io/AlphaSimR/} - \item \url{https://www.edx.org/course/breeding-programme-modelling-with-alphasimr?utm_source=breeding_alphasimr&utm_medium=partner-marketing&utm_campaign=edinburghx} + \item \url{https://www.edx.org/learn/animal-breeding/the-university-of-edinburgh-breeding-programme-modelling-with-alphasimr} } } diff --git a/man/Pop-class.Rd b/man/Pop-class.Rd index 431b65af..d2dd0004 100644 --- a/man/Pop-class.Rd +++ b/man/Pop-class.Rd @@ -72,6 +72,7 @@ open slot available for uses to store extra information about individuals.} \item{\code{miscPop}}{a list of any length containing optional meta data for the -populations. This list is empty unless information is supplied by the user.} +population. This list is empty unless information is supplied by the user. +Note that the list is emptied every time the population is subsetted.} }} diff --git a/man/RRBLUP.Rd b/man/RRBLUP.Rd index 128b7968..17cff96a 100644 --- a/man/RRBLUP.Rd +++ b/man/RRBLUP.Rd @@ -48,6 +48,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP2.Rd b/man/RRBLUP2.Rd index b2a3ac98..12b548ce 100644 --- a/man/RRBLUP2.Rd +++ b/man/RRBLUP2.Rd @@ -94,6 +94,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_D.Rd b/man/RRBLUP_D.Rd index 926efb9e..0c8e7be1 100644 --- a/man/RRBLUP_D.Rd +++ b/man/RRBLUP_D.Rd @@ -49,6 +49,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_D2.Rd b/man/RRBLUP_D2.Rd index 677183c2..15428e1c 100644 --- a/man/RRBLUP_D2.Rd +++ b/man/RRBLUP_D2.Rd @@ -71,6 +71,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_GCA.Rd b/man/RRBLUP_GCA.Rd index 74a7aaa4..bf7b2e53 100644 --- a/man/RRBLUP_GCA.Rd +++ b/man/RRBLUP_GCA.Rd @@ -50,6 +50,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_GCA2.Rd b/man/RRBLUP_GCA2.Rd index 01c1fb5d..d25928c7 100644 --- a/man/RRBLUP_GCA2.Rd +++ b/man/RRBLUP_GCA2.Rd @@ -70,6 +70,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_SCA.Rd b/man/RRBLUP_SCA.Rd index b61b1aa2..12201d48 100644 --- a/man/RRBLUP_SCA.Rd +++ b/man/RRBLUP_SCA.Rd @@ -49,6 +49,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/RRBLUP_SCA2.Rd b/man/RRBLUP_SCA2.Rd index 94216e8a..e4985642 100644 --- a/man/RRBLUP_SCA2.Rd +++ b/man/RRBLUP_SCA2.Rd @@ -74,6 +74,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/SimParam.Rd b/man/SimParam.Rd index 15ed4a87..733ecc5d 100644 --- a/man/SimParam.Rd +++ b/man/SimParam.Rd @@ -120,6 +120,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) ## ------------------------------------------------ @@ -131,6 +132,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) ## ------------------------------------------------ @@ -142,6 +144,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$altAddTraitAD(nQtlPerChr=10, mean=0, varA=1, varD=0.05, inbrDepr=0.2) ## ------------------------------------------------ @@ -153,6 +156,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAG(10, varGxE=2) ## ------------------------------------------------ @@ -164,6 +168,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADG(10, meanDD=0.5, varGxE=2) ## ------------------------------------------------ @@ -173,6 +178,11 @@ SP$addTraitADG(10, meanDD=0.5, varGxE=2) #Create founder haplotypes founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) +#Set simulation parameters +SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} +SP$addTraitAE(10, relAA=0.1) + ## ------------------------------------------------ ## Method `SimParam$addTraitADE` ## ------------------------------------------------ @@ -182,6 +192,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADE(10) ## ------------------------------------------------ @@ -193,6 +204,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAEG(10, varGxE=2) ## ------------------------------------------------ @@ -215,6 +227,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) @@ -227,6 +240,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10, mean=c(0,0), var=c(1,1), corA=diag(2)) SP$setVarE(varE=c(1,1)) E = 0.5*diag(2)+0.5 #Positively correlated error @@ -249,6 +263,7 @@ meanG(pop) #Change mean to 1 SP$rescaleTraits(mean=1) +\dontshow{SP$nThreads = 1L} #Run resetPop for change to take effect pop = resetPop(pop, simParam=SP) meanG(pop) @@ -814,6 +829,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) } \if{html}{\out{
}} @@ -885,6 +901,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) } \if{html}{\out{
}} @@ -985,6 +1002,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$altAddTraitAD(nQtlPerChr=10, mean=0, varA=1, varD=0.05, inbrDepr=0.2) } \if{html}{\out{
}} @@ -1052,6 +1070,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAG(10, varGxE=2) } \if{html}{\out{
}} @@ -1130,6 +1149,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADG(10, meanDD=0.5, varGxE=2) } \if{html}{\out{
}} @@ -1196,6 +1216,11 @@ ignored. Only set to TRUE if you know what you are doing.} \if{html}{\out{
}} \preformatted{#Create founder haplotypes founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) + +#Set simulation parameters +SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} +SP$addTraitAE(10, relAA=0.1) } \if{html}{\out{
}} @@ -1273,6 +1298,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADE(10) } \if{html}{\out{}} @@ -1351,6 +1377,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAEG(10, varGxE=2) } \if{html}{\out{}} @@ -1593,6 +1620,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) } @@ -1626,6 +1654,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10, mean=c(0,0), var=c(1,1), corA=diag(2)) SP$setVarE(varE=c(1,1)) E = 0.5*diag(2)+0.5 #Positively correlated error @@ -1682,6 +1711,7 @@ meanG(pop) #Change mean to 1 SP$rescaleTraits(mean=1) +\dontshow{SP$nThreads = 1L} #Run resetPop for change to take effect pop = resetPop(pop, simParam=SP) meanG(pop) diff --git a/man/aa.Rd b/man/aa.Rd index 4bd25b32..d4740a46 100644 --- a/man/aa.Rd +++ b/man/aa.Rd @@ -23,6 +23,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/attrition.Rd b/man/attrition.Rd index cbf322a7..fdda086d 100644 --- a/man/attrition.Rd +++ b/man/attrition.Rd @@ -26,6 +26,7 @@ founderPop = quickHaplo(nInd=100, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/bv.Rd b/man/bv.Rd index 48552f8a..9fe2e01c 100644 --- a/man/bv.Rd +++ b/man/bv.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/calcGCA.Rd b/man/calcGCA.Rd index 8075bdf8..617eadd3 100644 --- a/man/calcGCA.Rd +++ b/man/calcGCA.Rd @@ -24,6 +24,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/dd.Rd b/man/dd.Rd index 15e35bc6..6a3dd0c4 100644 --- a/man/dd.Rd +++ b/man/dd.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/doubleGenome.Rd b/man/doubleGenome.Rd index 528d7da4..e77c8c1a 100644 --- a/man/doubleGenome.Rd +++ b/man/doubleGenome.Rd @@ -29,6 +29,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/ebv.Rd b/man/ebv.Rd index dfe32748..60c20ca4 100644 --- a/man/ebv.Rd +++ b/man/ebv.Rd @@ -18,6 +18,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) diff --git a/man/editGenome.Rd b/man/editGenome.Rd index b4fd7aeb..cb26bc90 100644 --- a/man/editGenome.Rd +++ b/man/editGenome.Rd @@ -35,6 +35,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/editGenomeTopQtl.Rd b/man/editGenomeTopQtl.Rd index 2c0e1165..8a2d8b35 100644 --- a/man/editGenomeTopQtl.Rd +++ b/man/editGenomeTopQtl.Rd @@ -33,6 +33,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/fastRRBLUP.Rd b/man/fastRRBLUP.Rd index eef13c80..6bf7483b 100644 --- a/man/fastRRBLUP.Rd +++ b/man/fastRRBLUP.Rd @@ -60,6 +60,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/genParam.Rd b/man/genParam.Rd index c7496918..8ad6ba82 100644 --- a/man/genParam.Rd +++ b/man/genParam.Rd @@ -56,6 +56,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/genicVarA.Rd b/man/genicVarA.Rd index 68d26ce5..14ff85b0 100644 --- a/man/genicVarA.Rd +++ b/man/genicVarA.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/genicVarAA.Rd b/man/genicVarAA.Rd index a6c3919b..73fb4bb2 100644 --- a/man/genicVarAA.Rd +++ b/man/genicVarAA.Rd @@ -23,6 +23,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/genicVarD.Rd b/man/genicVarD.Rd index 3b54e719..4af42efa 100644 --- a/man/genicVarD.Rd +++ b/man/genicVarD.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/genicVarG.Rd b/man/genicVarG.Rd index c56c6135..714cf3b2 100644 --- a/man/genicVarG.Rd +++ b/man/genicVarG.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/getMisc.Rd b/man/getMisc.Rd index 5b430b92..6c2babcb 100644 --- a/man/getMisc.Rd +++ b/man/getMisc.Rd @@ -21,6 +21,7 @@ Get miscelaneous information in a population \examples{ founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100) SP <- SimParam$new(founderGenomes) +\dontshow{SP$nThreads = 1L} basePop <- newPop(founderGenomes) basePop <- setMisc(basePop, node = "info", value = 1) diff --git a/man/getQtlMap.Rd b/man/getQtlMap.Rd index f2ce87ce..76ada42e 100644 --- a/man/getQtlMap.Rd +++ b/man/getQtlMap.Rd @@ -35,6 +35,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(5) #Pull SNP map diff --git a/man/getSnpMap.Rd b/man/getSnpMap.Rd index 06723030..dd0965d2 100644 --- a/man/getSnpMap.Rd +++ b/man/getSnpMap.Rd @@ -36,6 +36,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addSnpChip(5) #Pull SNP map diff --git a/man/gv.Rd b/man/gv.Rd index 73c15148..95aa2222 100644 --- a/man/gv.Rd +++ b/man/gv.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/hybridCross.Rd b/man/hybridCross.Rd index ddc22717..66c594a2 100644 --- a/man/hybridCross.Rd +++ b/man/hybridCross.Rd @@ -40,6 +40,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/makeCross.Rd b/man/makeCross.Rd index 7434fbb6..f844d3ff 100644 --- a/man/makeCross.Rd +++ b/man/makeCross.Rd @@ -30,6 +30,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/makeCross2.Rd b/man/makeCross2.Rd index f256e955..9cfbf4f2 100644 --- a/man/makeCross2.Rd +++ b/man/makeCross2.Rd @@ -32,6 +32,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/makeDH.Rd b/man/makeDH.Rd index 5c6740fb..d704d8de 100644 --- a/man/makeDH.Rd +++ b/man/makeDH.Rd @@ -32,6 +32,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/meanG.Rd b/man/meanG.Rd index a672f6c1..77fc9e36 100644 --- a/man/meanG.Rd +++ b/man/meanG.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitA(10) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/meanP.Rd b/man/meanP.Rd index 22c94275..f9ff6c92 100644 --- a/man/meanP.Rd +++ b/man/meanP.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitA(10) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/mergeGenome.Rd b/man/mergeGenome.Rd index 722267b9..658f65e4 100644 --- a/man/mergeGenome.Rd +++ b/man/mergeGenome.Rd @@ -31,6 +31,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/mergePops.Rd b/man/mergePops.Rd index bafdffc3..e77eb8ec 100644 --- a/man/mergePops.Rd +++ b/man/mergePops.Rd @@ -23,6 +23,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create a list of populations and merge list pop = newPop(founderPop, simParam=SP) diff --git a/man/mutate.Rd b/man/mutate.Rd index 527dd307..5545dd32 100644 --- a/man/mutate.Rd +++ b/man/mutate.Rd @@ -35,6 +35,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/nInd.Rd b/man/nInd.Rd index 03117e0e..afcdaeb0 100644 --- a/man/nInd.Rd +++ b/man/nInd.Rd @@ -18,6 +18,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) diff --git a/man/pedigreeCross.Rd b/man/pedigreeCross.Rd index 59142374..9eb3d5d2 100644 --- a/man/pedigreeCross.Rd +++ b/man/pedigreeCross.Rd @@ -65,6 +65,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/pheno.Rd b/man/pheno.Rd index 8bf05a2e..868d23b2 100644 --- a/man/pheno.Rd +++ b/man/pheno.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/pullIbdHaplo.Rd b/man/pullIbdHaplo.Rd index dded2e8f..9cc3d4d3 100644 --- a/man/pullIbdHaplo.Rd +++ b/man/pullIbdHaplo.Rd @@ -29,6 +29,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) SP$setTrackRec(TRUE) diff --git a/man/pullMarkerGeno.Rd b/man/pullMarkerGeno.Rd index b320803f..a5c04b61 100644 --- a/man/pullMarkerGeno.Rd +++ b/man/pullMarkerGeno.Rd @@ -31,6 +31,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/pullMarkerHaplo.Rd b/man/pullMarkerHaplo.Rd index 5450411f..f6afba09 100644 --- a/man/pullMarkerHaplo.Rd +++ b/man/pullMarkerHaplo.Rd @@ -35,6 +35,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) SP$setTrackRec(TRUE) diff --git a/man/pullQtlGeno.Rd b/man/pullQtlGeno.Rd index 9b682627..a54b2cac 100644 --- a/man/pullQtlGeno.Rd +++ b/man/pullQtlGeno.Rd @@ -31,6 +31,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/pullQtlHaplo.Rd b/man/pullQtlHaplo.Rd index 22ac5467..9f5910a5 100644 --- a/man/pullQtlHaplo.Rd +++ b/man/pullQtlHaplo.Rd @@ -42,6 +42,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/pullSegSiteHaplo.Rd b/man/pullSegSiteHaplo.Rd index 74a43c88..81b60cb4 100644 --- a/man/pullSegSiteHaplo.Rd +++ b/man/pullSegSiteHaplo.Rd @@ -40,6 +40,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/pullSnpGeno.Rd b/man/pullSnpGeno.Rd index 1cc6f5d3..a523a054 100644 --- a/man/pullSnpGeno.Rd +++ b/man/pullSnpGeno.Rd @@ -31,6 +31,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/pullSnpHaplo.Rd b/man/pullSnpHaplo.Rd index 396d6b2a..53ac486a 100644 --- a/man/pullSnpHaplo.Rd +++ b/man/pullSnpHaplo.Rd @@ -42,6 +42,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$addSnpChip(5) diff --git a/man/randCross.Rd b/man/randCross.Rd index e09a2bd3..5935c74e 100644 --- a/man/randCross.Rd +++ b/man/randCross.Rd @@ -43,6 +43,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/randCross2.Rd b/man/randCross2.Rd index 10da5942..53adcede 100644 --- a/man/randCross2.Rd +++ b/man/randCross2.Rd @@ -52,6 +52,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/reduceGenome.Rd b/man/reduceGenome.Rd index 548cb0a0..8e5dcf93 100644 --- a/man/reduceGenome.Rd +++ b/man/reduceGenome.Rd @@ -44,6 +44,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/runMacs.Rd b/man/runMacs.Rd index 710a3592..4cc54bff 100644 --- a/man/runMacs.Rd +++ b/man/runMacs.Rd @@ -71,8 +71,9 @@ in a drastic increase to runtime. \examples{ # Creates a populations of 10 outbred individuals # Their genome consists of 1 chromosome and 100 segregating sites +\dontrun{ founderPop = runMacs(nInd=10,nChr=1,segSites=100) - +} } \references{ \insertAllCited{} diff --git a/man/runMacs2.Rd b/man/runMacs2.Rd index 29c61a93..cb0007f0 100644 --- a/man/runMacs2.Rd +++ b/man/runMacs2.Rd @@ -73,8 +73,9 @@ species="GENERIC" in \code{\link{runMacs}}. # Creates a populations of 10 outbred individuals # Their genome consists of 1 chromosome and 100 segregating sites # The command is equivalent to using species="GENERIC" in runMacs +\dontrun{ founderPop = runMacs2(nInd=10,nChr=1,segSites=100) - +} } \references{ \insertAllCited{} diff --git a/man/sampleHaplo.Rd b/man/sampleHaplo.Rd index aa1b3c4b..89b8eafe 100644 --- a/man/sampleHaplo.Rd +++ b/man/sampleHaplo.Rd @@ -27,7 +27,7 @@ Creates a new \code{\link{MapPop-class}} from an existing \code{\link{MapPop-class}} by randomly sampling haplotypes. } \examples{ -founderPop = quickHaplo(nInd=2,nChr=2,segSites=11,inbred=TRUE) +founderPop = quickHaplo(nInd=2,nChr=1,segSites=11,inbred=TRUE) founderPop = sampleHaplo(mapPop=founderPop,nInd=20) } diff --git a/man/selIndex.Rd b/man/selIndex.Rd index 4dcb507b..801f506b 100644 --- a/man/selIndex.Rd +++ b/man/selIndex.Rd @@ -25,6 +25,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Model two genetically correlated traits G = 1.5*diag(2)-0.5 #Genetic correlation matrix SP$addTraitA(10, mean=c(0,0), var=c(1,1), corA=G) diff --git a/man/selectCross.Rd b/man/selectCross.Rd index c16dba89..f9195da5 100644 --- a/man/selectCross.Rd +++ b/man/selectCross.Rd @@ -75,6 +75,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) diff --git a/man/selectFam.Rd b/man/selectFam.Rd index ab08abd6..e4e47f76 100644 --- a/man/selectFam.Rd +++ b/man/selectFam.Rd @@ -69,6 +69,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) diff --git a/man/selectInd.Rd b/man/selectInd.Rd index 38936e4f..45ccb354 100644 --- a/man/selectInd.Rd +++ b/man/selectInd.Rd @@ -64,6 +64,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) diff --git a/man/selectOP.Rd b/man/selectOP.Rd index 25fbd22f..c9aeda93 100644 --- a/man/selectOP.Rd +++ b/man/selectOP.Rd @@ -66,6 +66,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) diff --git a/man/selectWithinFam.Rd b/man/selectWithinFam.Rd index fe3d2a2c..3c21ee09 100644 --- a/man/selectWithinFam.Rd +++ b/man/selectWithinFam.Rd @@ -70,6 +70,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) diff --git a/man/self.Rd b/man/self.Rd index 5970b90d..c7b060c6 100644 --- a/man/self.Rd +++ b/man/self.Rd @@ -31,6 +31,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/setEBV.Rd b/man/setEBV.Rd index 61eccb60..c2afd081 100644 --- a/man/setEBV.Rd +++ b/man/setEBV.Rd @@ -49,6 +49,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=20) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) SP$setVarE(h2=0.5) SP$addSnpChip(10) diff --git a/man/setMisc.Rd b/man/setMisc.Rd index b76292ca..32801ec8 100644 --- a/man/setMisc.Rd +++ b/man/setMisc.Rd @@ -16,38 +16,7 @@ setMisc(x, node = NULL, value = NULL) it is repeated using \code{rep} (see examples)} } \value{ -\code{\link{Pop-class}} with \code{x@misc[[*]][[node]]} set -basePop <- newPop(founderGenomes) - -basePop <- setMisc(basePop, node = "info", value = 1) -basePop@misc -getMisc(x = basePop, node = "info") - -basePop <- setMisc(basePop, node = "info2", value = c("A", "B", "C")) -basePop@misc -getMisc(x = basePop, node = "info2") - -n <- nInd(basePop) -location <- vector(mode = "list", length = n) -for (ind in seq_len(n)) { - location[[ind]] <- runif(n = 2, min = 0, max = 100) -} -location -basePop <- setMisc(basePop, node = "location", value = location) -basePop@misc -getMisc(x = basePop, node = "location") - -n <- nInd(basePop) -location <- vector(mode = "list", length = n) -for (ind in c(1, 3)) { - location[[ind]] <- runif(n = 2, min = 0, max = 100) -} -location -basePop <- setMisc(basePop, node = "location", value = location) -basePop@misc -getMisc(x = basePop, node = "location") - -getMisc(x = basePop) +\code{\link{Pop-class}} } \description{ Set miscelaneous information in a population diff --git a/man/setPheno.Rd b/man/setPheno.Rd index bdbfe238..aa3866e0 100644 --- a/man/setPheno.Rd +++ b/man/setPheno.Rd @@ -99,6 +99,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/setPhenoGCA.Rd b/man/setPhenoGCA.Rd index 837c572a..ef004a4d 100644 --- a/man/setPhenoGCA.Rd +++ b/man/setPhenoGCA.Rd @@ -71,6 +71,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/setPhenoProgTest.Rd b/man/setPhenoProgTest.Rd index 4c2930a2..82756b63 100644 --- a/man/setPhenoProgTest.Rd +++ b/man/setPhenoProgTest.Rd @@ -79,6 +79,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10, inbred=TRUE) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create two populations of 5 individuals diff --git a/man/usefulness.Rd b/man/usefulness.Rd index 93ca5114..0c7d178c 100644 --- a/man/usefulness.Rd +++ b/man/usefulness.Rd @@ -47,6 +47,7 @@ founderPop = quickHaplo(nInd=2, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitA(10) #Create population diff --git a/man/varA.Rd b/man/varA.Rd index 8ee652c8..184103c9 100644 --- a/man/varA.Rd +++ b/man/varA.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/varAA.Rd b/man/varAA.Rd index eacdc7e4..592b99fc 100644 --- a/man/varAA.Rd +++ b/man/varAA.Rd @@ -23,6 +23,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/varD.Rd b/man/varD.Rd index 514c8bf2..3bef0413 100644 --- a/man/varD.Rd +++ b/man/varD.Rd @@ -22,6 +22,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitAD(10, meanDD=0.5) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/varG.Rd b/man/varG.Rd index 6ffe1f2f..accf077f 100644 --- a/man/varG.Rd +++ b/man/varG.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitA(10) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/varP.Rd b/man/varP.Rd index 3d68cc57..41e35d5a 100644 --- a/man/varP.Rd +++ b/man/varP.Rd @@ -20,6 +20,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) SP = SimParam$new(founderPop) SP$addTraitA(10) SP$setVarE(h2=0.5) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) diff --git a/man/writePlink.Rd b/man/writePlink.Rd index 9e1efeb7..595bd5cf 100644 --- a/man/writePlink.Rd +++ b/man/writePlink.Rd @@ -55,6 +55,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=15) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setSexes(sex="yes_rand") SP$addTraitA(nQtlPerChr=10) SP$addSnpChip(nSnpPerChr=5) diff --git a/tests/testthat/test-addTrait.R b/tests/testthat/test-addTrait.R index f9461c39..9e6b1296 100644 --- a/tests/testthat/test-addTrait.R +++ b/tests/testthat/test-addTrait.R @@ -8,6 +8,7 @@ founderPop = newMapPop(list(c(0)), test_that("addTraitA",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) pop = newPop(founderPop,simParam=SP) expect_equal(abs(SP$traits[[1]]@addEff),1,tolerance=1e-6) @@ -25,6 +26,7 @@ test_that("addTraitA",{ test_that("addTraitAD",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitAD(nQtlPerChr=1,mean=0,var=1,meanDD=1) pop = newPop(founderPop,simParam=SP) expect_equal(abs(SP$traits[[1]]@addEff),1,tolerance=1e-6) @@ -43,6 +45,7 @@ test_that("addTraitAD",{ test_that("addTraitAG",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitAG(nQtlPerChr=1,mean=0,var=1,varEnv=1,varGxE=1) pop = newPop(founderPop,simParam=SP) expect_equal(abs(SP$traits[[1]]@addEff),1,tolerance=1e-6) @@ -54,6 +57,7 @@ test_that("addTraitAG",{ test_that("addTraitADG",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitADG(nQtlPerChr=1,mean=0,var=1,meanDD=1,varEnv=1,varGxE=1) pop = newPop(founderPop,simParam=SP) expect_equal(abs(SP$traits[[1]]@addEff),1,tolerance=1e-6) @@ -71,6 +75,7 @@ founderPop = newMapPop(list(c(0,0)), test_that("addTraitAE",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitAE(nQtlPerChr=2,mean=0,var=1,relAA=1) pop = newPop(founderPop,simParam=SP) expect_equal(SP$varA,1,tolerance=1e-6) @@ -80,6 +85,7 @@ test_that("addTraitAE",{ test_that("addTraitADE",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitADE(nQtlPerChr=2,mean=0,var=1,meanDD=1,relAA=1) pop = newPop(founderPop,simParam=SP) expect_equal(SP$varA,1,tolerance=1e-6) @@ -89,6 +95,7 @@ test_that("addTraitADE",{ test_that("addTraitAEG",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitAEG(nQtlPerChr=2,mean=0,var=1,varEnv=1,varGxE=1,relAA=1) pop = newPop(founderPop,simParam=SP) expect_equal(SP$varA,1,tolerance=1e-6) @@ -98,6 +105,7 @@ test_that("addTraitAEG",{ test_that("addTraitADEG",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitADEG(nQtlPerChr=2,mean=0,var=1,meanDD=1,varEnv=1,varGxE=1,relAA=1) pop = newPop(founderPop,simParam=SP) expect_equal(SP$varA,1,tolerance=1e-6) diff --git a/tests/testthat/test-crossing.R b/tests/testthat/test-crossing.R index 7a8b3288..290cf220 100644 --- a/tests/testthat/test-crossing.R +++ b/tests/testthat/test-crossing.R @@ -6,6 +6,7 @@ founderPop = newMapPop(list(c(0)), test_that("makeCross",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) pop = newPop(founderPop,simParam=SP) @@ -27,6 +28,7 @@ test_that("makeCross",{ test_that("makeCross2",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) pop = newPop(founderPop,simParam=SP) @@ -48,6 +50,7 @@ test_that("makeCross2",{ test_that("randCross",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) SP$setSexes("yes_sys") @@ -62,6 +65,7 @@ test_that("randCross",{ test_that("randCross2",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) SP$setSexes("yes_sys") @@ -76,6 +80,7 @@ test_that("randCross2",{ test_that("self",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) pop = newPop(founderPop,simParam=SP) @@ -90,6 +95,7 @@ test_that("self",{ test_that("makeDH",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) pop = newPop(founderPop,simParam=SP) @@ -104,6 +110,7 @@ test_that("makeDH",{ test_that("selectCross",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) SP$setSexes("yes_sys") @@ -117,6 +124,7 @@ test_that("selectCross",{ test_that("selectOP",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) SP$setTrackPed(TRUE) pop = newPop(founderPop,simParam=SP) diff --git a/tests/testthat/test-editGenome.R b/tests/testthat/test-editGenome.R index 69e0e0a8..e279eb5e 100644 --- a/tests/testthat/test-editGenome.R +++ b/tests/testthat/test-editGenome.R @@ -5,6 +5,7 @@ test_that("editGenome",{ list(matrix(c(0,0,1,1), nrow=4,ncol=1))) SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) pop = newPop(founderPop,simParam=SP) pop = editGenome(pop=pop,ind=1,chr=1,segSites=1,allele=1, diff --git a/tests/testthat/test-hybrids.R b/tests/testthat/test-hybrids.R index 0d851d4b..74b7ca55 100644 --- a/tests/testthat/test-hybrids.R +++ b/tests/testthat/test-hybrids.R @@ -6,6 +6,7 @@ founderPop = newMapPop(list(c(0)), test_that("hybridCross",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=0,var=1) pop = newPop(founderPop,simParam=SP) #2x2 @@ -30,6 +31,7 @@ test_that("hybridCross",{ test_that("calcGCA",{ SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L SP$addTraitA(nQtlPerChr=1,mean=c(0,0),var=c(1,1)) SP$setVarE(varE=c(1,1)) pop = newPop(founderPop,simParam=SP) diff --git a/tests/testthat/test-importData.R b/tests/testthat/test-importData.R index 49a9ed39..9089b788 100644 --- a/tests/testthat/test-importData.R +++ b/tests/testthat/test-importData.R @@ -28,6 +28,7 @@ test_that("importTrait",{ ped = ped) SP = SimParam$new(founderPop=founderPop) + SP$nThreads = 1L # Import trait SP$importTrait(markerNames = myTrait$marker, diff --git a/vignettes/intro.Rmd b/vignettes/intro.Rmd index 8354f242..6f43fcdc 100644 --- a/vignettes/intro.Rmd +++ b/vignettes/intro.Rmd @@ -114,6 +114,11 @@ founderPop = quickHaplo(nInd=1000, nChr=10, segSites=1000) # Setting Simulation Parameters SP = SimParam$new(founderPop) +``` +```{r include=FALSE} +SP$nThreads = 1L +``` +```{r} SP$addTraitA(nQtlPerChr=1000) SP$setSexes("yes_sys") From 3ada1fbfbf724e918c1b3001928733a97ad7347f Mon Sep 17 00:00:00 2001 From: Chris Gaynor Date: Tue, 31 Oct 2023 18:38:36 -0500 Subject: [PATCH 20/20] second round of example fixes for SimParam --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/Class-SimParam.R | 8 ++++++++ man/SimParam.Rd | 16 ++++++++++++++++ vignettes/intro.R | 5 +++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 35940494..0119de9c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations -Version: 1.5.1 +Version: 1.5.2 Date: 2023-10-31 Authors@R: c(person("Chris", "Gaynor", email = "gaynor.robert@hotmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")), diff --git a/NEWS.md b/NEWS.md index 33a2758d..0ee54e3a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# AlphaSimR 1.5.2 + +*fix SimParam examples for CRAN + # AlphaSimR 1.5.1 *deleted bad example code for `setMisc` diff --git a/R/Class-SimParam.R b/R/Class-SimParam.R index 67181291..e808cbd7 100644 --- a/R/Class-SimParam.R +++ b/R/Class-SimParam.R @@ -110,6 +110,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$setTrackPed(TRUE) setTrackPed = function(isTrackPed, force=FALSE){ stopifnot(is.logical(isTrackPed)) @@ -140,6 +141,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$setTrackRec(TRUE) setTrackRec = function(isTrackRec, force=FALSE){ stopifnot(is.logical(isTrackRec)) @@ -167,6 +169,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -206,6 +209,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$restrSegSites(minQtlPerChr=5, minSnpPerChr=5) restrSegSites = function(minQtlPerChr=NULL, minSnpPerChr=NULL, excludeQtl=NULL, excludeSnp=NULL, overlap=FALSE, minSnpFreq=NULL){ @@ -299,6 +303,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$setSexes("yes_sys") setSexes = function(sexes, force=FALSE){ if(!force){ @@ -346,6 +351,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addSnpChip(10) addSnpChip = function(nSnpPerChr, minSnpFreq=NULL, refPop=NULL, name=NULL){ if(length(nSnpPerChr)==1){ @@ -1299,6 +1305,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$addTraitADEG(10, meanDD=0.5, varGxE=2) addTraitADEG = function(nQtlPerChr,mean=0,var=1,varEnv=0, varGxE=1e-6,meanDD=0,varDD=0,relAA=0,corA=NULL, @@ -1857,6 +1864,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' SP$setRecombRatio(2) #Twice as much recombination in females setRecombRatio = function(femaleRatio){ stopifnot(femaleRatio>0) diff --git a/man/SimParam.Rd b/man/SimParam.Rd index 733ecc5d..2205a7ec 100644 --- a/man/SimParam.Rd +++ b/man/SimParam.Rd @@ -35,6 +35,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setTrackPed(TRUE) ## ------------------------------------------------ @@ -46,6 +47,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setTrackRec(TRUE) ## ------------------------------------------------ @@ -57,6 +59,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) @@ -76,6 +79,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$restrSegSites(minQtlPerChr=5, minSnpPerChr=5) ## ------------------------------------------------ @@ -87,6 +91,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setSexes("yes_sys") ## ------------------------------------------------ @@ -98,6 +103,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addSnpChip(10) ## ------------------------------------------------ @@ -216,6 +222,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADEG(10, meanDD=0.5, varGxE=2) ## ------------------------------------------------ @@ -277,6 +284,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setRecombRatio(2) #Twice as much recombination in females } \section{Public fields}{ @@ -479,6 +487,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setTrackPed(TRUE) } \if{html}{\out{}} @@ -517,6 +526,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setTrackRec(TRUE) } \if{html}{\out{}} @@ -551,6 +561,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} #Create population pop = newPop(founderPop, simParam=SP) @@ -612,6 +623,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$restrSegSites(minQtlPerChr=5, minSnpPerChr=5) } \if{html}{\out{}} @@ -653,6 +665,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setSexes("yes_sys") } \if{html}{\out{}} @@ -710,6 +723,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addSnpChip(10) } \if{html}{\out{}} @@ -1464,6 +1478,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$addTraitADEG(10, meanDD=0.5, varGxE=2) } \if{html}{\out{}} @@ -1748,6 +1763,7 @@ founderPop = quickHaplo(nInd=10, nChr=1, segSites=10) #Set simulation parameters SP = SimParam$new(founderPop) +\dontshow{SP$nThreads = 1L} SP$setRecombRatio(2) #Twice as much recombination in females } \if{html}{\out{}} diff --git a/vignettes/intro.R b/vignettes/intro.R index 4c9b901d..8deb9c57 100644 --- a/vignettes/intro.R +++ b/vignettes/intro.R @@ -34,6 +34,11 @@ founderPop = quickHaplo(nInd=1000, nChr=10, segSites=1000) # Setting Simulation Parameters SP = SimParam$new(founderPop) + +## ----include=FALSE------------------------------------------------------------ +SP$nThreads = 1L + +## ----------------------------------------------------------------------------- SP$addTraitA(nQtlPerChr=1000) SP$setSexes("yes_sys")