Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ exportClasses(TraitADG)
exportClasses(TraitAE)
exportClasses(TraitAEG)
exportClasses(TraitAG)
exportMethods(makeCross)
exportMethods(makeCross2)
exportMethods(makeDH)
exportMethods(randCross)
exportMethods(randCross2)
exportMethods(selectCross)
exportMethods(self)
exportMethods(setPheno)
import(Rcpp)
importFrom(R6,R6Class)
importFrom(Rdpack,reprompt)
Expand Down
209 changes: 190 additions & 19 deletions R/crossing.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,29 @@
#' pop2 = makeCross(pop, crossPlan, simParam=SP)
#'
#' @export
makeCross = function(pop,crossPlan,nProgeny=1,
simParam=NULL,nThreads=NULL){
setGeneric(
"makeCross",
function(pop, crossPlan, nProgeny=1, simParam=NULL, nThreads=NULL){
standardGeneric("makeCross")
}
)

#' @describeIn makeCross Method for \code{\link{Pop-class}}
#' @export
setMethod(
"makeCross",
signature(pop = "Pop"),
function(pop, crossPlan, nProgeny=1, simParam=NULL, nThreads=NULL){
.makeCross_internal(
pop=pop, crossPlan=crossPlan, nProgeny=nProgeny, simParam=simParam,
nThreads=nThreads)
}
)

# Internal implementation shared by makeCross methods
#' @keywords internal
.makeCross_internal = function(pop,crossPlan,nProgeny=1,
simParam=NULL,nThreads=NULL){
if(is.null(simParam)){
simParam = get("SP",envir=.GlobalEnv)
}
Expand All @@ -42,7 +63,7 @@ makeCross = function(pop,crossPlan,nProgeny=1,
nThreads = as.integer(nThreads)
}
if(pop@ploidy%%2L != 0L){
stop("You can not cross indiviuals with odd ploidy levels")
stop("You can not cross individuals with odd ploidy levels")
}
if(is.character(crossPlan)){ #Match by ID
crossPlan = cbind(match(crossPlan[,1],pop@id),
Expand Down Expand Up @@ -102,7 +123,7 @@ makeCross = function(pop,crossPlan,nProgeny=1,
#'
#' @description
#' A wrapper for \code{\link{makeCross}} that randomly
#' selects parental combinations for all possible combinantions.
#' selects parental combinations for all possible combinations.
#'
#' @param pop an object of \code{\link{Pop-class}}
#' @param nCrosses total number of crosses to make
Expand Down Expand Up @@ -132,7 +153,33 @@ makeCross = function(pop,crossPlan,nProgeny=1,
#' pop2 = randCross(pop, 10, simParam=SP)
#'
#' @export
randCross = function(pop,nCrosses,nProgeny=1,
setGeneric(
"randCross",
function(
pop, nCrosses, nProgeny=1, balance=TRUE, parents=NULL, ignoreSexes=FALSE,
simParam=NULL, nThreads=NULL){
standardGeneric("randCross")
}
)

#' @describeIn randCross Method for \code{\link{Pop-class}}
#' @export
setMethod(
"randCross",
signature(pop = "Pop"),
function(
pop, nCrosses, nProgeny=1, balance=TRUE, parents=NULL, ignoreSexes=FALSE,
simParam=NULL, nThreads=NULL){
.randCross_internal(
pop=pop, nCrosses=nCrosses, nProgeny=nProgeny, balance=balance,
parents=parents, ignoreSexes=ignoreSexes, simParam=simParam,
nThreads=nThreads)
}
)

# Internal implementation shared by randCross methods
#' @keywords internal
.randCross_internal = function(pop,nCrosses,nProgeny=1,
balance=TRUE,parents=NULL,
ignoreSexes=FALSE,
simParam=NULL,nThreads=NULL){
Expand Down Expand Up @@ -250,7 +297,34 @@ randCross = function(pop,nCrosses,nProgeny=1,
#' pop2 = selectCross(pop, nInd=4, nCrosses=8, simParam=SP)
#'
#' @export
selectCross = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses,
setGeneric(
"selectCross",
function(
pop, nInd=NULL, nFemale=NULL, nMale=NULL, nCrosses, nProgeny=1, trait=1,
use="pheno", selectTop=TRUE, simParam=NULL, nThreads=NULL, ..., balance=TRUE){
standardGeneric("selectCross")
}
)


#' @describeIn selectCross Method for \code{\link{Pop-class}}
#' @export
setMethod(
"selectCross",
signature(pop = "Pop"),
function(
pop, nInd=NULL, nFemale=NULL, nMale=NULL, nCrosses, nProgeny=1, trait=1,
use="pheno", selectTop=T, simParam=NULL, nThreads=NULL, ..., balance=TRUE){
.selectCross_internal(
pop=pop, nInd=nInd, nFemale=nFemale, nMale=nMale, nCrosses=nCrosses,
nProgeny=nProgeny, trait=trait, use=use, selectTop=selectTop,
simParam=simParam, nThreads=nThreads, ..., balance=balance)
}
)

# Internal implementation shared by selectCross methods
#' @keywords internal
.selectCross_internal = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses,
nProgeny=1,trait=1,use="pheno",selectTop=TRUE,
simParam=NULL,nThreads=NULL,...,balance=TRUE){
if(is.null(simParam)){
Expand Down Expand Up @@ -324,7 +398,28 @@ selectCross = function(pop,nInd=NULL,nFemale=NULL,nMale=NULL,nCrosses,
#' pop2 = makeCross2(pop, pop, crossPlan, simParam=SP)
#'
#' @export
makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL,
setGeneric(
"makeCross2",
function(females,males,crossPlan,nProgeny=1,simParam=NULL, nThreads=NULL){
standardGeneric("makeCross2")
}
)

#' @describeIn makeCross2 Method for \code{\link{Pop-class}}
#' @export
setMethod(
"makeCross2",
signature(females = "Pop", males = "Pop"),
function(females,males,crossPlan,nProgeny=1,simParam=NULL, nThreads=NULL){
.makeCross2_internal(
females=females, males=males, crossPlan=crossPlan, nProgeny=nProgeny,
simParam=simParam, nThreads=nThreads)
}
)

# Internal implementation shared by makeCross2 methods
#' @keywords internal
.makeCross2_internal = function(females,males,crossPlan,nProgeny=1,simParam=NULL,
nThreads=NULL){
if(is.null(simParam)){
simParam = get("SP",envir=.GlobalEnv)
Expand All @@ -336,7 +431,7 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL,
}
if((females@ploidy%%2L != 0L) |
(males@ploidy%%2L != 0L)){
stop("You can not cross indiviuals with odd ploidy levels")
stop("You can not cross individuals with odd ploidy levels")
}
if(is.character(crossPlan)){ #Match by ID
crossPlan = cbind(match(crossPlan[,1],females@id),
Expand Down Expand Up @@ -397,7 +492,7 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL,
#'
#' @description
#' A wrapper for \code{\link{makeCross2}} that randomly
#' selects parental combinations for all possible combinantions between
#' selects parental combinations for all possible combinations between
#' two populations.
#'
#' @param females an object of \code{\link{Pop-class}} for female parents.
Expand Down Expand Up @@ -432,10 +527,37 @@ makeCross2 = function(females,males,crossPlan,nProgeny=1,simParam=NULL,
#' pop2 = randCross2(pop, pop, 10, simParam=SP)
#'
#' @export
randCross2 = function(females,males,nCrosses,nProgeny=1,
balance=TRUE,femaleParents=NULL,
maleParents=NULL,ignoreSexes=FALSE,
simParam=NULL,nThreads=NULL){
setGeneric(
"randCross2",
function(
females, males, nCrosses, nProgeny=1, balance=TRUE, femaleParents=NULL,
maleParents=NULL, ignoreSexes=FALSE, simParam=NULL, nThreads=NULL){
standardGeneric("randCross2")
}
)

#' @describeIn randCross2 Method for \code{\link{Pop-class}}
#' @export
setMethod(
"randCross2",
signature(females = "Pop", males = "Pop"),
function(
females, males, nCrosses, nProgeny=1, balance=TRUE, femaleParents=NULL,
maleParents=NULL, ignoreSexes=FALSE, simParam=NULL, nThreads=NULL){
.randCross2_internal(
females = females, males = males, nCrosses = nCrosses,
nProgeny = nProgeny, balance = balance, femaleParents = femaleParents,
maleParents = maleParents, ignoreSexes = ignoreSexes,
simParam = simParam, nThreads = nThreads)
}
)

# Internal implementation shared by randCross2 methods
#' @keywords internal
.randCross2_internal = function(
females, males, nCrosses, nProgeny=1, balance=TRUE, femaleParents=NULL,
maleParents=NULL, ignoreSexes=FALSE, simParam=NULL, nThreads=NULL){

if(is.null(simParam)){
simParam = get("SP",envir=.GlobalEnv)
}
Expand Down Expand Up @@ -528,8 +650,34 @@ randCross2 = function(females,males,nCrosses,nProgeny=1,
#' pop2 = self(pop, simParam=SP)
#'
#' @export
self = function(pop,nProgeny=1,parents=NULL,keepParents=TRUE,
simParam=NULL,nThreads=NULL){
setGeneric(
"self",
function(
pop, nProgeny=1, parents=NULL, keepParents=TRUE, simParam=NULL,
nThreads=NULL){
standardGeneric("self")
}
)

#' @describeIn self Method for \code{\link{Pop-class}}
#' @export
setMethod(
"self",
signature(pop = "Pop"),
function(
pop, nProgeny=1, parents=NULL, keepParents=TRUE, simParam=NULL,
nThreads=NULL){
.self_internal(
pop=pop, nProgeny=nProgeny, parents=parents, keepParents=keepParents,
simParam=simParam, nThreads = nThreads
)
}
)

# Internal implementation shared by self methods
#' @keywords internal
.self_internal = function(
pop,nProgeny=1,parents=NULL,keepParents=TRUE,simParam=NULL,nThreads=NULL){
if(is.null(simParam)){
simParam = get("SP",envir=.GlobalEnv)
}
Expand Down Expand Up @@ -639,8 +787,31 @@ self = function(pop,nProgeny=1,parents=NULL,keepParents=TRUE,
#' pop2 = makeDH(pop, simParam=SP)
#'
#' @export
makeDH = function(pop,nDH=1,useFemale=TRUE,keepParents=TRUE,
simParam=NULL,nThreads=NULL){
setGeneric(
"makeDH",
function(
pop,nDH=1,useFemale=TRUE,keepParents=TRUE,simParam=NULL,nThreads=NULL){
standardGeneric("makeDH")
}
)

#' @describeIn makeDH Method for \code{\link{Pop-class}}
#' @export
setMethod(
"makeDH",
signature(pop = "Pop"),
function(
pop,nDH=1,useFemale=TRUE,keepParents=TRUE,simParam=NULL,nThreads=NULL){
.makeDH_internal(
pop=pop, nDH=nDH, useFemale=useFemale, keepParents=keepParents,
simParam=simParam, nThreads=nThreads)
}
)

# Internal implementation shared by .makeDH_internal methods
#' @keywords internal
.makeDH_internal = function(
pop,nDH=1,useFemale=TRUE,keepParents=TRUE,simParam=NULL,nThreads=NULL){
if(is.null(simParam)){
simParam = get("SP",envir=.GlobalEnv)
}
Expand Down Expand Up @@ -756,7 +927,7 @@ sortPed = function(id, mother, father, maxCycle=100){
}
}
if(any(unsorted)){
stop("Failed to sort pedigree, may contain loops or require a higher maxGen")
stop("Failed to sort pedigree, may contain loops or require a higher maxCycle")
}
return(output)
}
Expand All @@ -769,7 +940,7 @@ sortPed = function(id, mother, father, maxCycle=100){
#'
#' @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
#' in the pedigree. The values of these IDs are separate 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
Expand Down
Loading