Skip to content

Commit

Permalink
Merge pull request #93 from gaynorr/devel
Browse files Browse the repository at this point in the history
Version 1.3.2
  • Loading branch information
gaynorr authored Nov 2, 2022
2 parents 18c7574 + ecfbc87 commit c44c860
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ vignettes/*.pdf
Notes.txt
.Rproj.user/
docs
.DS_Store
4 changes: 2 additions & 2 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.3.1
Date: 2022-8-25
Version: 1.3.2
Date: 2022-11-2
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
16 changes: 12 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# AlphaSimR 1.3.2

*fixed column name bug with multiple traits in `setEBV`

*fixed CTD caused by `runMacs` when too many segSites are requested

*fixed missing names in GV when using `resetPop`

*fixed bug in `importTrait`

*`popVar` now deals with matrices having 1 row

# AlphaSimR 1.3.1

*updated link to Gaynor, 2017
Expand Down Expand Up @@ -49,10 +61,6 @@
*added `pullMarkerGeno` and `pullMarkerHaplo` to make it easier to extract genotypes and haplotypes of specific loci without defining a trait or SNP chip

*`reduceGenome`, `mergeGenome` and `doubleGenome` should really now work with pedigree and recombination tracking

## Known issues

*`pedigreeCross` fails without an appropriate warning for some incomplete pedigrees

# AlphaSimR 1.1.2

Expand Down
11 changes: 11 additions & 0 deletions R/Class-Pop.R
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ 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,
ncol=simParam$nTraits)
Expand All @@ -756,6 +761,8 @@ resetPop = function(pop,simParam=NULL){
pop@gv = matrix(NA_real_,nrow=pop@nInd,
ncol=simParam$nTraits)
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)
Expand All @@ -765,6 +772,10 @@ resetPop = function(pop,simParam=NULL){
}
}
}

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

return(pop)
}

Expand Down
2 changes: 1 addition & 1 deletion R/Class-SimParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ SimParam = R6Class(
useDom = TRUE
domEff = as.matrix(domEff)
stopifnot(nrow(addEff)==nrow(domEff),
ncol(addEff)==nrow(domEff))
ncol(addEff)==ncol(domEff))
}

# Prepare the intercept
Expand Down
3 changes: 3 additions & 0 deletions R/GS.R
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ setEBV = function(pop, solution, value="gv", targetPop=NULL,
nrow=pop@nInd,
ncol=nTraits)

# Placeholder names
colnames(ebv) = as.character(1:nTraits)

value = tolower(value)

if(value=="gv"){
Expand Down
12 changes: 12 additions & 0 deletions R/founderPop.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,34 @@ runMacs = function(nInd,nChr=1, segSites=NULL, inbred=FALSE, species="GENERIC",
}
command = paste0(popSize," ",speciesParams,splitI," ",speciesHist,splitJ," -s ")
}

if(!is.null(manualGenLen)){
genLen = manualGenLen
}

if(length(genLen)==1){
genLen = rep(genLen, nChr)
}

# Run MaCS
macsOut = MaCS(command, segSites, inbred, ploidy,
nThreads, seed)
dim(macsOut$geno) = NULL # Account for matrix bug in RcppArmadillo

# Check if desired number of loci were obtained
nLoci = sapply(macsOut$genMap,length)
isLimited = segSites>0
if(any(nLoci[isLimited] != segSites[isLimited])){
stop("MaCS did not return enough segSites, use segSites=NULL to return all sites generated by MaCS")
}

genMap = vector("list",nChr)
for(i in 1:nChr){
genMap[[i]] = genLen[i]*c(macsOut$genMap[[i]]-macsOut$genMap[[i]][1])
names(genMap[[i]]) = paste(i,1:length(genMap[[i]]),sep="_")
}
names(genMap) = as.character(1:nChr)

output = new("MapPop",
nInd=nInd,
nChr=nChr,
Expand Down
6 changes: 6 additions & 0 deletions R/misc.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Converts a matrix to integer type
# Intended for genotype matrices of raw type
convToImat = function(X){
return(matrix(as.integer(X), nrow=nrow(X) ,ncol=ncol(X)))
}

#' @rdname isFemale
#' @title Test if individuals of a population are female or male
#'
Expand Down
4 changes: 0 additions & 4 deletions R/pullGeno.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
convToImat = function(X){
return(matrix(as.integer(X), nrow=nrow(X) ,ncol=ncol(X)))
}

selectLoci = function(chr, inLociPerChr, inLociLoc){
if(is.null(chr)){
return(list(lociPerChr=inLociPerChr,
Expand Down
6 changes: 5 additions & 1 deletion src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ unsigned char toByte(std::bitset<8> bits){
//' @export
// [[Rcpp::export]]
arma::mat popVar(const arma::mat& X) {
return arma::cov(X,1);
if(X.n_rows==1){
return(arma::mat(X.n_cols,X.n_cols,arma::fill::zeros));
}else{
return arma::cov(X,1);
}
}

// Merges geno objects, i.e. fields containing cubes of unsigned char
Expand Down
7 changes: 2 additions & 5 deletions src/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ Rcpp::List MaCS(Rcpp::String args, arma::uvec maxSites, bool inbred,
//Check input
string t = args;
if (t == "") {
Rcpp::stop("error");
Rcpp::stop("error passing argument string");
}

// Output objects
Expand All @@ -715,9 +715,6 @@ Rcpp::List MaCS(Rcpp::String args, arma::uvec maxSites, bool inbred,
// Run MaCS and check for valid output
vector<AlphaSimRReturn> macsOutput;
macsOutput = runFromAlphaSimR(args+seed(chr));
if(macsOutput.empty()){
Rcpp::stop("Macs has failed to run.");
}

arma::uword nSites, nBins, nHap, nInd;
nSites = macsOutput.size();
Expand All @@ -730,7 +727,7 @@ Rcpp::List MaCS(Rcpp::String args, arma::uvec maxSites, bool inbred,
arma::uvec selSites;
if(maxSites(chr)>0){
if(nSites<maxSites(chr)){
Rcpp::stop("Not enough segregating sites generated");
maxSites(chr) = nSites;
}
selSites = sampleInt(maxSites(chr),nSites);
nSites = maxSites(chr);
Expand Down

0 comments on commit c44c860

Please sign in to comment.