diff --git a/DESCRIPTION b/DESCRIPTION index 727ff355..0119de9c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: AlphaSimR Type: Package Title: Breeding Program Simulations -Version: 1.4.2 -Date: 2023-3-27 +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")), person("Gregor", "Gorjanc", role = "ctb", @@ -12,10 +12,12 @@ 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"))) + 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 @@ -31,7 +33,7 @@ Description: The successor to the 'AlphaSim' software for breeding program 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://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/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 ad4f7374..0ee54e3a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,32 @@ +# AlphaSimR 1.5.2 + +*fix SimParam examples for CRAN + +# 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` + +*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 +*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/R/Class-Pop.R b/R/Class-Pop.R index 7b3d9509..84ac2105 100644 --- a/R/Class-Pop.R +++ b/R/Class-Pop.R @@ -379,6 +379,9 @@ 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 +#' 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", @@ -393,7 +396,8 @@ setClass("Pop", ebv="matrix", gxe="list", fixEff="integer", - misc="list"), + misc="list", + miscPop="list"), contains="RawPop") setValidity("Pop",function(object){ @@ -500,6 +504,7 @@ setMethod("[", for(chr in 1:x@nChr){ x@geno[[chr]] = x@geno[[chr]][,,i,drop=FALSE] } + x@miscPop = list() return(x) } ) @@ -692,7 +697,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, @@ -808,8 +814,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}} @@ -834,24 +840,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) @@ -859,7 +865,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, @@ -879,37 +885,38 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){ ebv = matrix(NA_real_, nrow=0L, ncol=0L), - misc = list()) + misc = list(), + miscPop = list()) 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")) } } @@ -920,26 +927,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")){ @@ -948,7 +955,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) } } @@ -957,17 +964,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 @@ -979,21 +986,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/Class-SimParam.R b/R/Class-SimParam.R index e02f3fd5..e808cbd7 100644 --- a/R/Class-SimParam.R +++ b/R/Class-SimParam.R @@ -1,3 +1,4 @@ + #' @title Simulation parameters #' #' @description @@ -109,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)) @@ -139,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)) @@ -166,6 +169,7 @@ SimParam = R6Class( #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) + #' \dontshow{SP$nThreads = 1L} #' #' #Create population #' pop = newPop(founderPop, simParam=SP) @@ -205,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){ @@ -298,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){ @@ -345,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){ @@ -465,7 +472,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 +481,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) @@ -484,6 +493,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){ @@ -525,7 +535,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 +549,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) @@ -549,6 +561,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, @@ -604,10 +617,129 @@ 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) + #' \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), + 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 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 +751,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) @@ -629,6 +763,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, @@ -718,6 +853,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) @@ -728,6 +865,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, @@ -820,7 +958,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 +972,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) @@ -841,6 +981,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){ @@ -902,7 +1047,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 +1064,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) @@ -929,6 +1076,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, @@ -1001,7 +1149,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 +1166,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) @@ -1028,6 +1178,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, @@ -1142,6 +1293,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) @@ -1152,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, @@ -1492,6 +1646,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){ @@ -1564,6 +1719,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 @@ -1617,6 +1773,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) @@ -1707,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/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/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/crossing.R b/R/crossing.R index 2be57efb..81e2ad9e 100644 --- a/R/crossing.R +++ b/R/crossing.R @@ -1,28 +1,29 @@ #' @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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +91,36 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +177,60 @@ 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) +#' \dontshow{SP$nThreads = 1L} #' 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 +257,49 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +310,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 +358,41 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +416,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 +454,44 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +556,41 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +700,70 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +776,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 +810,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 +830,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 +841,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 +870,7 @@ pedigreeCross = function(founderPop, id, mother, father, matchID=FALSE, simParam=simParam) } } - + # Self? if(nSelf[i]>0){ for(j in 1:nSelf[i]){ @@ -870,7 +878,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 +887,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/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 b60fa856..239e0264 100644 --- a/R/hybrids.R +++ b/R/hybrids.R @@ -1,35 +1,36 @@ #' @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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +39,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 +52,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 +65,7 @@ hybridCross = function(females, males, crossPlan=crossPlan, simParam=simParam)) } - + #Return HybridPop-class gv = matrix(NA_real_, nrow=length(id), @@ -85,7 +86,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 +104,33 @@ 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) +#' \dontshow{SP$nThreads = 1L} #' 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 +221,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 +233,54 @@ 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) +#' \dontshow{SP$nThreads = 1L} #' 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 +294,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 +325,75 @@ 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) +#' \dontshow{SP$nThreads = 1L} #' 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 +407,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 +421,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/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)) diff --git a/R/mergePops.R b/R/mergePops.R index 8a924bb5..6ba27777 100644 --- a/R/mergePops.R +++ b/R/mergePops.R @@ -1,36 +1,37 @@ #' @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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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 +77,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, @@ -144,5 +145,6 @@ mergePops = function(popList){ gxe=gxe, pheno=pheno, ebv=ebv, - misc=misc)) + misc=misc, + miscPop=list())) } diff --git a/R/misc.R b/R/misc.R index 0e3ad344..01960c55 100644 --- a/R/misc.R +++ b/R/misc.R @@ -35,6 +35,8 @@ isFemale <- function(x) { return(ret) } +##Test + #' @describeIn isFemale Test if individuals of a population are female or male #' @export isMale <- function(x) { @@ -60,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) { @@ -134,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) @@ -283,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) @@ -332,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 @@ -405,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 @@ -528,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 @@ -651,6 +627,7 @@ transMat = function(R){ #' #' #Set simulation parameters #' SP = SimParam$new(founderPop) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' #' #Create population @@ -756,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 1bd8ddb0..197e1873 100644 --- a/R/phenotypes.R +++ b/R/phenotypes.R @@ -27,118 +27,119 @@ 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) +#' \dontshow{SP$nThreads = 1L} #' 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 +149,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 +170,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 +178,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 +195,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){ @@ -215,7 +216,7 @@ setPheno = function(pop, h2=NULL, H2=NULL, varE=NULL, corE=NULL, varE = simParam$varE[traits] } } - + # Set error correlations if(!is.null(corE)){ if(is.matrix(varE)){ @@ -223,40 +224,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/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 eb7d5584..e2b75033 100644 --- a/R/popSummary.R +++ b/R/popSummary.R @@ -1,76 +1,79 @@ # 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varG(pop) -#' +#' #' @export varG = function(pop){ G = popVar(pop@gv) @@ -79,24 +82,25 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' varP(pop) -#' +#' #' @export varP = function(pop){ P = popVar(pop@pheno) @@ -105,14 +109,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 +149,21 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' ans = genParam(pop, simParam=SP) -#' +#' #' @export genParam = function(pop,simParam=NULL){ if(is.null(simParam)){ @@ -168,17 +173,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 +230,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 +279,259 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #Create population #' pop = newPop(founderPop, simParam=SP) #' genicVarG(pop, simParam=SP) @@ -527,97 +542,101 @@ 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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) -#' +#' \dontshow{SP$nThreads = 1L} +#' #' #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) +#' \dontshow{SP$nThreads = 1L} #' 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) +#' \dontshow{SP$nThreads = 1L} #' 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/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 cff76412..2f2133f6 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) @@ -91,49 +112,65 @@ 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. +#' 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", +#' 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) +#' \dontshow{SP$nThreads = 1L} #' SP$addTraitA(10) #' 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) +#' #' @export selectInd = function(pop,nInd,trait=1,use="pheno",sex="B", selectTop=TRUE,returnPop=TRUE, @@ -142,16 +179,17 @@ 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) } 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)}} @@ -490,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{}} @@ -524,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) @@ -585,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{}} @@ -626,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{}} @@ -683,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{}} @@ -756,7 +797,7 @@ ignored. Only set to TRUE if you know what you are doing.} \if{latex}{\out{\hypertarget{method-SimParam-addTraitA}{}}} \subsection{Method \code{addTraitA()}}{ 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. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{SimParam$addTraitA( @@ -784,7 +825,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.} @@ -800,6 +843,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{
}} @@ -812,7 +856,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 +897,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.} @@ -869,19 +915,121 @@ 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{
}} } +} +\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) +\dontshow{SP$nThreads = 1L} +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 +1066,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.} @@ -934,6 +1084,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{
}} @@ -994,7 +1145,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.} @@ -1010,6 +1163,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{}} @@ -1022,7 +1176,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 +1215,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.} @@ -1074,6 +1230,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{
}} @@ -1085,7 +1246,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 +1294,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.} @@ -1149,6 +1312,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{
}} @@ -1161,7 +1325,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 +1373,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.} @@ -1225,6 +1391,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{
}} @@ -1293,7 +1460,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.} @@ -1309,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{
}} @@ -1465,6 +1635,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) } @@ -1498,6 +1669,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 @@ -1554,6 +1726,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) @@ -1590,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/man/aa.Rd b/man/aa.Rd index a45ef038..d4740a46 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{ @@ -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 c71e52fb..617eadd3 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{ @@ -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 d9104a21..8ad6ba82 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{ @@ -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 ffbb29b7..73fb4bb2 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{ @@ -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 ced4bd36..66c594a2 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{ @@ -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 87d5c33b..f844d3ff 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{ @@ -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 966318c1..9cfbf4f2 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{ @@ -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 76dccf97..d704d8de 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{ @@ -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 b3996587..e77eb8ec 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}} @@ -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/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..9eb3d5d2 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{ @@ -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 d3416a02..5935c74e 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{ @@ -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 60e50aef..53adcede 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{ @@ -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 73da4894..f9195da5 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{ @@ -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 b42b9373..e4e47f76 100644 --- a/man/selectFam.Rd +++ b/man/selectFam.Rd @@ -19,46 +19,48 @@ 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 -a single trait or a function returning a vector of length nInd.} +\item{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}}.} \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{ @@ -67,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 4cd91af9..45ccb354 100644 --- a/man/selectInd.Rd +++ b/man/selectInd.Rd @@ -18,42 +18,44 @@ 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 -a single trait or a function returning a vector of length nInd.} +\item{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}}.} \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{ @@ -62,13 +64,27 @@ 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) #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 fb78f776..c9aeda93 100644 --- a/man/selectOP.Rd +++ b/man/selectOP.Rd @@ -19,43 +19,45 @@ 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 -a single trait or a function returning a vector of length nInd.} +\item{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}}.} \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{ @@ -64,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 2c9903ff..3c21ee09 100644 --- a/man/selectWithinFam.Rd +++ b/man/selectWithinFam.Rd @@ -19,47 +19,49 @@ 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 -a single trait or a function returning a vector of length nInd.} +\item{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}}.} \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{ @@ -68,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 301dd1df..c7b060c6 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{ @@ -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 1548757d..aa3866e0 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{ @@ -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 f767a2c6..ef004a4d 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{ @@ -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 4206eb7d..82756b63 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{ @@ -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 4bc7bbd2..592b99fc 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{ @@ -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/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