HighlanderLab / SIMplyBee

SIMplyBee R package extends AlphaSimR for simulating honeybee populations and breeding programmes
http://www.simplybee.info/
Other
0 stars 5 forks source link

Fix failing cross example #540

Closed gregorgorjanc closed 8 months ago

gregorgorjanc commented 8 months ago
❯ checking examples ... ERROR
  Running examples in ‘SIMplyBee-Ex.R’ failed
  The error most likely occurred in:

  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: createCrossPlan
  > ### Title: Create a plan for crossing virgin queens
  > ### Aliases: createCrossPlan
  > 
  > ### ** Examples
  > 
  > founderGenomes <- quickHaplo(nInd = 1000, nChr = 1, segSites = 100)
  > SP <- SimParamBee$new(founderGenomes)
  > ## Don't show: 
  > SP$nThreads = 1L
  > ## End(Don't show)
  > basePop <- createVirginQueens(founderGenomes)
  > 
  > # Create three virgin MultiColony objects with locations
  > virginColonies1 <- createMultiColony(basePop[1:30])
  > virginColonies1 <- setLocation(virginColonies1,
  +                                location = Map(c, runif(30, 0, 2*pi),
  +                                                  runif(30, 0, 2*pi)))
  > virginColonies2 <- createMultiColony(basePop[31:60])
  > virginColonies2 <- setLocation(virginColonies2,
  +                                location = Map(c, runif(30, 0, 2*pi),
  +                                                  runif(30, 0, 2*pi)))
  > virginColonies3 <- createMultiColony(basePop[61:90])
  > virginColonies3 <- setLocation(virginColonies3,
  +                                location = Map(c, runif(30, 0, 2*pi),
  +                                                  runif(30, 0, 2*pi)))
  > 
  > # Create drone colonies
  > droneColonies <- createMultiColony(basePop[121:200])
  > droneColonies <- setLocation(droneColonies,
  +                              location = Map(c, runif(80, 0, 2*pi),
  +                                                runif(80, 0, 2*pi)))
  > 
  > # Create some drones to mate initial drone colonies with
  > DCA <- createDrones(basePop[201:300], nInd = 20)
  > # Cross initial virgin drone colonies to the DCA with a random cross plan
  > randomCrossPlan <- createCrossPlan(x = droneColonies,
  +                                    drones = DCA,
  +                                    nDrones = nFathersPoisson,
  +                                    spatial = FALSE)
  > droneColonies <- cross(droneColonies,
  +                        drones = DCA,
  +                        nDrones = nFathersPoisson,
  +                        crossPlan = randomCrossPlan)
  > 
  > # Plot the colonies in space
  > virginLocations <- as.data.frame(getLocation(c(virginColonies1, virginColonies2, virginColonies3),
  +                                              collapse= TRUE))
  > virginLocations$Type <- "Virgin"
  > droneLocations <- as.data.frame(getLocation(droneColonies, collapse= TRUE))
  > droneLocations$Type <- "Drone"
  > locations <- rbind(virginLocations, droneLocations)
  > 
  > plot(x = locations$V1, y = locations$V2,
  +      col = c("red", "blue")[as.numeric(as.factor(locations$Type))])
  > 
  > # Cross according to a spatial cross plan according to the colonies' locations
  > crossPlanSpatial <- createCrossPlan(x = virginColonies1,
  +                                    droneColonies = droneColonies,
  +                                    nDrones = nFathersPoisson,
  +                                    spatial = TRUE,
  +                                    radius = 1.5)
  > 
  > # Plot the crossing for the first colony in the crossPlan
  > virginLocations1 <- as.data.frame(getLocation(virginColonies1, collapse= TRUE))
  > virginLocations1$Type <- "Virgin"
  > droneLocations <- as.data.frame(getLocation(droneColonies, collapse= TRUE))
  > droneLocations$Type <- "Drone"
  > locations1 <- rbind(virginLocations1, droneLocations)
  > 
  > # Blue marks the target virgin colony and blue marks the drone colonies in the chosen radius
  > plot(x = locations1$V1, y = locations1$V2, pch = c(1, 2)[as.numeric(as.factor(locations1$Type))],
  +   col = ifelse(rownames(locations1) %in% crossPlanSpatial[[1]],
  +                              "red",
  +                              ifelse(rownames(locations1) == names(crossPlanSpatial)[[1]],
  +                              "blue", "black")))
  > 
  > colonies1 <- cross(x = virginColonies1,
  +                    crossPlan = crossPlanSpatial,
  +                    droneColonies = droneColonies,
  +                    nDrones = nFathersPoisson)
  > nFathers(colonies1)
   1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
  17 20 16 12 13 13 16 15 15 14 18 10 10 15 12 12 16 16 11 12  9 15 17 12 15 13 
  27 28 29 30 
  14 16 14 11 
  > 
  > # Cross according to a cross plan that is created internally within the cross function
  > # The cross plan is created at random, regardless the location of the colonies
  > colonies2 <- cross(x = virginColonies2,
  +                    droneColonies = droneColonies,
  +                    nDrones = nFathersPoisson,
  +                    crossPlan = "create")
  [1] "Cross plan, drone colonies"
  > 
  > # Mate spatially with cross plan created internally by the cross function
  > colonies3 <- cross(x = virginColonies3,
  +                    droneColonies = droneColonies,
  +                    crossPlan = "create",
  +                    checkCross = "warning",
  +                    spatial = TRUE,
  +                    radius = 1)
  There are no potential crosses for some colonies! The cross() will fail
                unless argument checkCross is set to 'warning'.
  Crossing failed!
  Error in reQueen(x, virginQueen) : object 'virginQueen' not found
  Calls: cross -> cross -> reQueen -> isPop -> is
  Execution halted
gregorgorjanc commented 8 months ago

I think @janaobsteter sorted this these days.