Level 0 function that creates a plan for crossing virgin queens or virgin colonies by sampling drones or drone producing colonies to mate with a the virgin queens/colonies either at random (spatial = FALSE) or according to the distance between colonies (spatial = TRUE).

createCrossPlan(
  x,
  drones = NULL,
  droneColonies = NULL,
  nDrones = NULL,
  spatial = FALSE,
  radius,
  simParamBee = NULL,
  ...
)

Arguments

x

Pop-class or codeColony-class or MultiColony-class, the object with the virgin queens that need to be crossed. When spatial = TRUE, the argument needs to be a codeColony-class or MultiColony-class with the location set

drones

Pop-class, a population of drones (resembling a drone congregation area) available for mating. When spatial = TRUE, the user can not provide drones, but needs to provide drone producing colonies instead (see argument droneColonies)

droneColonies

MultiColony-class, drone producing colonies available for mating. When spatial = TRUE, the object needs to have the location set

nDrones,

integer or function, number of drones to sample for each crossing. You need to provide this to provide this argument even when sampling drone producing colonies (otherwise, the default value will be used)

spatial

logical, whether the drone producing colonies should be sampled according to their distance from the virgin colony (that is, in a radius)

radius

numeric, the radius from the virgin colony in which to sample mating partners, only needed when spatial = TRUE

simParamBee

SimParamBee, global simulation parameters

...

other arguments for nDrones, when nDrones is a function

Value

named list with names being virgin queens/colonies IDs with each list element holding the IDs of selected drones or drone producing colonies

Examples

founderGenomes <- quickHaplo(nInd = 1000, nChr = 1, segSites = 100)
SP <- SimParamBee$new(founderGenomes)
SP$nThreads = 1L
basePop <- createVirginQueens(founderGenomes)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found

# Create three virgin MultiColony objects with locations
virginColonies1 <- createMultiColony(basePop[1:30])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
virginColonies1 <- setLocation(virginColonies1,
                               location = Map(c, runif(30, 0, 2*pi),
                                                 runif(30, 0, 2*pi)))
#> Error in eval(expr, envir, enclos): object 'virginColonies1' not found
virginColonies2 <- createMultiColony(basePop[31:60])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
virginColonies2 <- setLocation(virginColonies2,
                               location = Map(c, runif(30, 0, 2*pi),
                                                 runif(30, 0, 2*pi)))
#> Error in eval(expr, envir, enclos): object 'virginColonies2' not found
virginColonies3 <- createMultiColony(basePop[61:90])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
virginColonies3 <- setLocation(virginColonies3,
                               location = Map(c, runif(30, 0, 2*pi),
                                                 runif(30, 0, 2*pi)))
#> Error in eval(expr, envir, enclos): object 'virginColonies3' not found

# Create drone colonies
droneColonies <- createMultiColony(basePop[121:200])
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
droneColonies <- setLocation(droneColonies,
                             location = Map(c, runif(80, 0, 2*pi),
                                               runif(80, 0, 2*pi)))
#> Error in eval(expr, envir, enclos): object 'droneColonies' not found

# Create some drones to mate initial drone colonies with
DCA <- createDrones(basePop[201:300], nInd = 20)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
# Cross initial virgin drone colonies to the DCA with a random cross plan
randomCrossPlan <- createCrossPlan(x = droneColonies,
                                   drones = DCA,
                                   nDrones = nFathersPoisson,
                                   spatial = FALSE)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
droneColonies <- cross(droneColonies,
                       drones = DCA,
                       nDrones = nFathersPoisson,
                       crossPlan = randomCrossPlan)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found

# Plot the colonies in space
virginLocations <- as.data.frame(getLocation(c(virginColonies1, virginColonies2, virginColonies3),
                                             collapse= TRUE))
#> Error in eval(expr, envir, enclos): object 'virginColonies1' not found
virginLocations$Type <- "Virgin"
#> Error: object 'virginLocations' not found
droneLocations <- as.data.frame(getLocation(droneColonies, collapse= TRUE))
#> Error in eval(expr, envir, enclos): object 'droneColonies' not found
droneLocations$Type <- "Drone"
#> Error: object 'droneLocations' not found
locations <- rbind(virginLocations, droneLocations)
#> Error in eval(expr, envir, enclos): object 'virginLocations' not found

plot(x = locations$V1, y = locations$V2,
     col = c("red", "blue")[as.numeric(as.factor(locations$Type))])
#> Error in eval(expr, envir, enclos): object 'locations' not found

# 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)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found

# Plot the crossing for the first colony in the crossPlan
virginLocations1 <- as.data.frame(getLocation(virginColonies1, collapse= TRUE))
#> Error in eval(expr, envir, enclos): object 'virginColonies1' not found
virginLocations1$Type <- "Virgin"
#> Error: object 'virginLocations1' not found
droneLocations <- as.data.frame(getLocation(droneColonies, collapse= TRUE))
#> Error in eval(expr, envir, enclos): object 'droneColonies' not found
droneLocations$Type <- "Drone"
#> Error: object 'droneLocations' not found
locations1 <- rbind(virginLocations1, droneLocations)
#> Error in eval(expr, envir, enclos): object 'virginLocations1' not found

# 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")))
#> Error in eval(expr, envir, enclos): object 'locations1' not found

colonies1 <- cross(x = virginColonies1,
                   crossPlan = crossPlanSpatial,
                   droneColonies = droneColonies,
                   nDrones = nFathersPoisson)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found
nFathers(colonies1)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found

# 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")
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found

# 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)
#> Error in get(x = "SP", envir = .GlobalEnv): object 'SP' not found