gaynorr / AlphaSimR

R package for breeding program simulations
https://gaynorr.github.io/AlphaSimR/
Other
43 stars 18 forks source link

Bug: reduceGenome() does not work in combination with SP$setTrackRec() #37

Closed gregorgorjanc closed 2 years ago

gregorgorjanc commented 2 years ago

I think I discovered a bug related to reduceGenome() and SP$setTrackRec(). Below I show that reduceGenome() works fine on its own, but when combined with SP$setTrackRec() I reproducibly get the same error:

# Fresh session where reduceGenome() works
> library(AlphaSimR)
Loading required package: R6
> founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
> SP <- SimParam$new(founderGenomes)
> basePop <- newPop(founderGenomes)
> reduceGenome(basePop[1], nProgeny = 10)
An object of class "Pop" 
Ploidy: 1 
Individuals: 10 
Chromosomes: 1 
Loci: 100 
Traits: 0 
# Fresh session where reduceGenome() DOES not work in combination with `SP$setTrackRec()`
> library(AlphaSimR)
Loading required package: R6
> founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
> SP <- SimParam$new(founderGenomes)
> SP$setTrackRec(isTrackRec = TRUE)
> basePop <- newPop(founderGenomes)

> reduceGenome(basePop[1], nProgeny = 10)
Error in lastId - private$.lastId : 
  non-numeric argument to binary operator

> traceback()
2: simParam$addToRec(tmp$recHist)
1: reduceGenome(basePop[1], nProgeny = 10)

> packageDescription("AlphaSimR")
Package: AlphaSimR
Type: Package
Title: Breeding Program Simulations
Version: 1.0.4
Date: 2021-09-08
...
Date/Publication: 2021-09-08 15:50:02 UTC
Built: R 4.1.0; x86_64-apple-darwin17.0; 2021-09-09 12:06:31 UTC; unix
gaynorr commented 2 years ago

This should now with version 1.1.2

gregorgorjanc commented 2 years ago

@gaynorr I am still experiencing issues - below is our SIMplyBee code that breaks when I turn on tracking of recombinations - will try to assemble reproducible AlphaSimR code

> founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
> SP <- SimParam$new(founderGenomes)
> SP$setTrackRec(isTrackRec = TRUE)
> basePop <- newPop(founderGenomes)
> drones <- createFounderDrones(pop = basePop[1], nDronesPerQueen = 10)
> colony1 <- createColony(queen = basePop[2], fathers = drones[1:5])
> colony2 <- createColony(queen = basePop[3], fathers = drones[6:10])
> colony1 <- addWorkers(colony1, nInd = 10)
 Error in lastId - private$.lastId : 
  non-numeric argument to binary operator 
> traceback()
5: simParam$addToRec(newHist)
4: mergeGenome(females = gametesFromTheQueen, males = drones, crossPlan = pairs, 
       simParam = simParamBee) at Functions_L1_Pop.R#474
3: beeCross(queen = getQueen(x), drones = getFathers(x), nProgeny = nInd, 
       simParamBee = simParamBee) at Functions_L1_Pop.R#389
2: createWorkers(x, nInd, exact = exact, simParamBee = simParamBee) at Functions_L2_Colony.R#311
1: addWorkers(colony1, nInd = 10)
gregorgorjanc commented 2 years ago

@gaynorr I can confirm that the reduceGenome() works in 1.1.2! But mergeGenome() does not :(

> library(AlphaSimR)
> founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
> SP <- SimParam$new(founderGenomes)
> basePop <- newPop(founderGenomes)
> x = reduceGenome(basePop[1], nProgeny = 10)
> mergeGenome(x, x, crossPlan = cbind(x@id, x@id))
An object of class "Pop" 
Ploidy: 2 
Individuals: 10 
Chromosomes: 1 
Loci: 100 
Traits: 0 
> library(AlphaSimR)
> founderGenomes <- quickHaplo(nInd = 3, nChr = 1, segSites = 100)
> SP <- SimParam$new(founderGenomes)
> SP$setTrackRec(isTrackRec = TRUE)
> basePop <- newPop(founderGenomes)
> x = reduceGenome(basePop[1], nProgeny = 10)
> mergeGenome(x, x, crossPlan = cbind(x@id, x@id))
Error in lastId - private$.lastId : 
  non-numeric argument to binary operator
gregorgorjanc commented 2 years ago

I think that this pull requests solves this issue https://github.com/gaynorr/AlphaSimR/pull/47