Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.6.0 #195

Merged
merged 31 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
745dabe
blank articles for website
gaynorr Nov 3, 2023
8768c72
Merge branch 'devel' into staging
gaynorr Nov 30, 2023
5b10888
Merge pull request #166 from gaynorr/staging
gaynorr Nov 30, 2023
db59178
Flipping misc orgaisation
gregorgorjanc Dec 22, 2023
193a136
Exploring subsetting and combining with Pop & MultiPop
gregorgorjanc Dec 23, 2023
21bf985
List of pops could work
gregorgorjanc Dec 23, 2023
87dc385
misc slot tests failing at mergePops
gaynorr Dec 23, 2023
c7b66c6
Adding length method for Pop; polish tests for misc
gregorgorjanc Dec 23, 2023
fe6e60e
Changed MultiPop validity function
gaynorr Dec 23, 2023
69c3038
Merge pull request #168 from gregorgorjanc/devel-different_misc_order
gaynorr Dec 23, 2023
4a21ffe
Sorting BibTeX surnames and names to Surname, Name form
gregorgorjanc Jan 9, 2024
0afd950
Sync CATTLE parameters #164
gregorgorjanc Jan 10, 2024
c249a81
Sync CATTLE parameters #164
gregorgorjanc Jan 10, 2024
edf4f80
Merge pull request #172 from gregorgorjanc/fix_164
gaynorr Jan 11, 2024
a578d5b
Enabled passing use as function
gregorgorjanc Jan 19, 2024
67667f7
Merge pull request #174 from gregorgorjanc/feat_173
gaynorr Jan 24, 2024
b62e574
fix for #175
gaynorr Jan 24, 2024
ca2b601
Clarifying that newPop() doesn't recombine founder genomes
gregorgorjanc Jan 28, 2024
4fa286d
Merge pull request #176 from gregorgorjanc/patch-1
gaynorr Jan 28, 2024
a77f3a2
Added check for valid sex in `checkSexes`
gaynorr Mar 14, 2024
304f912
fixed to findQuadrivalentCO to properly account for position of centr…
gaynorr Apr 5, 2024
0a324d6
adding to News
gaynorr Apr 5, 2024
c6e2f2d
fix for #188
gaynorr Apr 19, 2024
d4031b1
extra check for setCorE
gaynorr Apr 19, 2024
c072aed
fix to `mergePops` handling of misc slot
gaynorr Apr 20, 2024
d3ad4ec
exporting alpha and alpha_HW to `genParam`
gaynorr Apr 22, 2024
312b5be
Exported meanEBV() and added varEBV()
gregorgorjanc Jun 30, 2024
b03115d
Merge pull request #189 from gregorgorjanc/devel
gaynorr Jul 1, 2024
37c3a76
tidying code
gaynorr Jul 9, 2024
fd3e86f
tidying code
gaynorr Jul 9, 2024
3f3c57f
1.6.0 release
gaynorr Aug 15, 2024
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
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: AlphaSimR
Type: Package
Title: Breeding Program Simulations
Version: 1.5.3
Date: 2023-11-30
Version: 1.6.0
Date: 2024-08-15
Authors@R: c(person("Chris", "Gaynor", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0558-6656")),
person("Gregor", "Gorjanc", role = "ctb",
Expand Down Expand Up @@ -39,7 +39,7 @@ Depends: R (>= 4.0.0), methods, R6
Imports: Rcpp (>= 0.12.7), Rdpack
RdMacros: Rdpack
LinkingTo: Rcpp, RcppArmadillo (>= 0.7.500.0.0), BH
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Suggests: knitr, rmarkdown, testthat
VignetteBuilder: knitr
NeedsCompilation: true
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export(genicVarAA)
export(genicVarD)
export(genicVarG)
export(getGenMap)
export(getMisc)
export(getNumThreads)
export(getPed)
export(getQtlMap)
Expand All @@ -49,6 +48,7 @@ export(isRawPop)
export(makeCross)
export(makeCross2)
export(makeDH)
export(meanEBV)
export(meanG)
export(meanP)
export(mergeGenome)
Expand Down Expand Up @@ -89,7 +89,6 @@ export(selectWithinFam)
export(self)
export(setEBV)
export(setMarkerHaplo)
export(setMisc)
export(setPheno)
export(setPhenoGCA)
export(setPhenoProgTest)
Expand All @@ -108,6 +107,7 @@ export(usefulness)
export(varA)
export(varAA)
export(varD)
export(varEBV)
export(varG)
export(varP)
export(writePlink)
Expand Down
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# AlphaSimR 1.6.0

*exported `meanEBV` and added `varEBV` to complement `meanP`/`varP` and `meanG`/`varG`

*Changed all parameters of the CATTLE demographic model to exactly match Macleod et al. (2013) - specifically reducing the mutation rate from 2.5e-8 (from human literature) to 1.2e-8 (used in Macleod et al., 2013) and recombination rate from 1e-8 (generic) to 9.26e-9 (used in Macleod et al., 2013). These changes will reduce number of segregating sites to ~240K per chromosome for 100 samples and will run faster.

*changed misc slot in Pop class from a list organised as ind x nodes to to a list organised as nodes x ind (this simplified code and increased speed)

*removed `setMisc` and `getMisc` because the new misc slot structure makes it easy to set and get misc components with base R code

*added `length` method for Pop class that returns number of individuals (like `nInd`)

*added `length` method for MultiPop class that returns number of populations

*fixed bug in quadrivalent pairing resulting in distribution of double reductions not respecting the centromere

# AlphaSimR 1.5.3

*fixed bug in `SimParam$restrSegSites` with excluding sites at end of chromosome
Expand Down
112 changes: 73 additions & 39 deletions R/Class-Pop.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ setValidity("MapPop",function(object){
if(object@nChr!=length(object@genMap)){
errors = c(errors,"nInd!=length(id)")
}
for(i in 1:object@nChr){
for(i in seq_len(object@nChr)){
if(object@nLoci[i]!=length(object@genMap[[i]])){
errors = c(errors,
paste0("nLoci[",i,"]!=length(genMap[[",i,"]]"))
Expand All @@ -168,7 +168,7 @@ setMethod("[",
if(any(abs(i)>x@nInd)){
stop("Trying to select invalid individuals")
}
for(chr in 1:x@nChr){
for(chr in seq_len(x@nChr)){
x@geno[[chr]] = x@geno[[chr]][,,i,drop=FALSE]
}
x@nInd = dim(x@geno[[1]])[3]
Expand Down Expand Up @@ -375,13 +375,19 @@ isNamedMapPop = function(x) {
#' @slot gxe list containing GxE slopes for GxE traits
#' @slot fixEff a fixed effect relating to the phenotype.
#' Used by genomic selection models but otherwise ignored.
#' @slot misc a list whose elements correspond to individuals in the
#' population. This list is normally empty and exists solely as an
#' @slot misc a list whose elements correspond to additional miscellaneous
#' nodes with the items for individuals in the population (see example in
#' \code{\link{newPop}}).
#' 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.
#' @slot miscPop a list of any length containing optional meta data for the
#' population (see example in \code{\link{newPop}}).
#' This list is empty unless information is supplied by the user.
#' Note that the list is emptied every time the population is subsetted or
#' combined because the meta data for old population might not be valid anymore.
#'
#' @seealso \code{\link{newPop}}, \code{\link{newEmptyPop}}, \code{\link{resetPop}}
#'
#' @export
setClass("Pop",
Expand Down Expand Up @@ -456,8 +462,8 @@ setValidity("Pop",function(object){
if(object@nInd!=length(object@fixEff)){
errors = c(errors,"nInd!=length(fixEff)")
}
if(object@nInd!=length(object@misc)){
errors = c(errors,"nInd!=length(misc)")
if(any(object@nInd!=sapply(object@misc, length))){
errors = c(errors,"any(nInd!=sapply(misc, length))")
}
if(length(errors)==0){
return(TRUE)
Expand Down Expand Up @@ -488,7 +494,8 @@ setMethod("[",
x@mother = x@mother[i]
x@father = x@father[i]
x@fixEff = x@fixEff[i]
x@misc = x@misc[i]
x@misc = lapply(x@misc, FUN = function(z) z[i])
x@miscPop = list()
x@gv = x@gv[i,,drop=FALSE]
x@pheno = x@pheno[i,,drop=FALSE]
x@ebv = x@ebv[i,,drop=FALSE]
Expand All @@ -504,7 +511,6 @@ setMethod("[",
for(chr in 1:x@nChr){
x@geno[[chr]] = x@geno[[chr]][,,i,drop=FALSE]
}
x@miscPop = list()
return(x)
}
)
Expand Down Expand Up @@ -534,12 +540,20 @@ setMethod("show",
}
)

#' @describeIn Pop Number of individuals in Pop (the same as nInd())
setMethod("length",
signature(x = "Pop"),
function (x){
return(x@nInd)
}
)

#' @title Create new population
#'
#' @description
#' Creates an initial \code{\link{Pop-class}} from an object of
#' \code{\link{MapPop-class}} or \code{\link{NamedMapPop-class}}.
#' The function is intended for us with output from functions such
#' The function is intended for use with output from functions such
#' as \code{\link{runMacs}}, \code{\link{newMapPop}}, or
#' \code{\link{quickHaplo}}.
#'
Expand All @@ -550,6 +564,14 @@ setMethod("show",
#'
#' @return Returns an object of \code{\link{Pop-class}}
#'
#' @details Note that \code{newPop} takes genomes from the
#' \code{rawPop} and uses them without recombination! Hence, if you
#' call \code{newPop(rawPop = founderGenomes)} twice, you will get
#' two sets of individuals with different id but the same genomes.
#' To get genetically different sets of individuals you can subset the
#' \code{rawPop} input, say first half for one set and the second half
#' for the other set.
#'
#' @examples
#' #Create founder haplotypes
#' founderPop = quickHaplo(nInd=2, nChr=1, segSites=10)
Expand All @@ -562,6 +584,13 @@ setMethod("show",
#' pop = newPop(founderPop, simParam=SP)
#' isPop(pop)
#'
#' #Misc
#' pop@misc$tmp1 = rnorm(n=2)
#' pop@misc$tmp2 = rnorm(n=2)
#'
#' #MiscPop
#' pop@miscPop$tmp1 = sum(pop@misc$tmp1)
#' pop@miscPop$tmp2 = sum(pop@misc$tmp2)
#' @export
newPop = function(rawPop,simParam=NULL,...){
if(is.null(simParam)){
Expand Down Expand Up @@ -602,7 +631,7 @@ newPop = function(rawPop,simParam=NULL,...){
stopifnot(sapply(simParam$genMap,length)==rawPop@nLoci)

lastId = simParam$lastId
iid = (1:rawPop@nInd) + lastId
iid = seq_len(rawPop@nInd) + lastId
lastId = max(iid)

if(is.null(id)){
Expand Down Expand Up @@ -666,7 +695,7 @@ newPop = function(rawPop,simParam=NULL,...){
pheno = gv

if(simParam$nTraits>=1){
for(i in 1:simParam$nTraits){
for(i in seq_len(simParam$nTraits)){
tmp = getGv(simParam$traits[[i]], rawPop, simParam$nThreads)
gv[,i] = tmp[[1]]

Expand All @@ -690,15 +719,15 @@ newPop = function(rawPop,simParam=NULL,...){
mother=mother,
father=father,
fixEff=rep(1L,rawPop@nInd),
misc=list(),
miscPop=list(),
nTraits=simParam$nTraits,
gv=gv,
gxe=gxe,
pheno=pheno,
ebv=matrix(NA_real_,
nrow=rawPop@nInd,
ncol=0),
misc=vector("list",rawPop@nInd),
miscPop=list())
ncol=0))
if(simParam$nTraits>=1){
output = setPheno(output, varE=NULL, reps=1,
fixEff=1L, p=NULL, onlyPheno=FALSE,
Expand Down Expand Up @@ -752,10 +781,10 @@ resetPop = function(pop,simParam=NULL){
simParam = get("SP",envir=.GlobalEnv)
}
pop@nTraits = simParam$nTraits

# Extract names to add back at the end
traitNames = colnames(pop@gv)

# Create empty slots for traits
pop@pheno = matrix(NA_real_,
nrow=pop@nInd,
Expand All @@ -769,19 +798,17 @@ resetPop = function(pop,simParam=NULL){
pop@fixEff = rep(1L,pop@nInd)

# Calculate genetic values
if(simParam$nTraits>=1){
for(i in 1:simParam$nTraits){
tmp = getGv(simParam$traits[[i]],pop,simParam$nThreads)
pop@gv[,i] = tmp[[1]]
if(length(tmp)>1){
pop@gxe[[i]] = tmp[[2]]
}
for(i in seq_len(simParam$nTraits)){
tmp = getGv(simParam$traits[[i]],pop,simParam$nThreads)
pop@gv[,i] = tmp[[1]]
if(length(tmp)>1){
pop@gxe[[i]] = tmp[[2]]
}
}

# Add back trait names
colnames(pop@pheno) = colnames(pop@gv) = traitNames

return(pop)
}

Expand Down Expand Up @@ -848,20 +875,18 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){
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
}

# Get trait names
for(i in seq_len(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)
for(i in 1:simParam$nChr){
for(i in seq_len(simParam$nChr)){
DIM1 = nLoci[i]%/%8L + (nLoci[i]%%8L > 0L)
geno[[i]] = array(as.raw(0), dim=c(DIM1, ploidy, 0))
}
Expand All @@ -878,15 +903,15 @@ newEmptyPop = function(ploidy=2L, simParam=NULL){
mother = character(),
father = character(),
fixEff = integer(),
misc = list(),
miscPop = list(),
nTraits = simParam$nTraits,
gv = traitMat,
gxe = vector("list", simParam$nTraits),
pheno = traitMat,
ebv = matrix(NA_real_,
nrow=0L,
ncol=0L),
misc = list(),
miscPop = list())
ncol=0L))
return(output)
}

Expand All @@ -913,7 +938,7 @@ setClass("MultiPop",
setValidity("MultiPop",function(object){
errors = character()
# Check that all populations are valid
for(i in 1:length(object@pops)){
for(i in seq_len(length(object@pops))){
if(!validObject(object@pops[[i]]) &
(is(object@pops[[i]], "Pop") |
is(object@pops[[i]],"MultiPop"))){
Expand Down Expand Up @@ -964,6 +989,15 @@ setMethod("c",
}
)

#' @describeIn MultiPop Number of pops in MultiPop
setMethod("length",
signature(x = "MultiPop"),
function (x){
n = length(x@pops)
return(n)
}
)

#' @title Create new Multi Population
#'
#' @description
Expand Down
Loading
Loading