Last updated: 2021-04-22

Checks: 7 0

Knit directory: BreedingSchemeOptGroup/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210422) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 9df9d9b. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  data/BaselineControlFile.txt
    Untracked:  data/BaselinePopulationFile.txt
    Untracked:  data/inst/

Unstaged changes:
    Modified:   README.md

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/example-simulation-reducing-error-with-new-tools.Rmd) and HTML (docs/example-simulation-reducing-error-with-new-tools.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 9df9d9b wolfemd 2021-04-22 Publish the initial files for the Breeding Scheme Optimization Group project

Previously

AlphaSimHlpR first steps: Installation and quickly running the AlphaSimHlpR tutorial example.

Simulation with a burn-in period

Generate a baseline population. As this is an example, I won’t use empirical inputs. Ignore costs for now.

  • Initialized with the provided “small” example control files. Made some minor manual changes, which I will print below.
  • See the files BaselineControlFile.txt and BaselinePopulationFile.txt in this repository.

I want to set-up “burn-in” generations of phenotypic selection. See if I can work that in AlphaSimHlpR.

SPOILER ALERT: Not quite working yet. More work needed.

The first step is to read in the control files defining the baseline breeding program and other breeding scheme parameters in a list bsp.

The tutorial example repeatedly runs the runBreedingScheme() function, which in turn depends on specified functions: initializeFunc=initFuncADChk, productPipeline=prodPipeFncChk, populationImprovement=popImprov1Cyc.

selCritPipeAdv and selCritPopImprov are set to selCritIID.

Now, to continue, we can’t use the runBreedingScheme() function because it will re-run the initializeFunc() and subsequently runMacs2(), which overwrites our founder haplotypes.

Make my own function: runBreedingScheme_wBurnIn().

Specify number of burn-in and post-burn in cycles.

Also let’s uses two separate bsp objects, one for before, another for after. Use with caution.

rm(list=ls()); gc()
          used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
Ncells  713178 38.1    1331791 71.2         NA  1331791 71.2
Vcells 1324981 10.2    8388608 64.0      65536  1981424 15.2
library(tidyverse); library(magrittr); 
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.3     ✓ purrr   0.3.4
✓ tibble  3.1.1     ✓ dplyr   1.0.5
✓ tidyr   1.1.3     ✓ stringr 1.4.0
✓ readr   1.4.0     ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()

Attaching package: 'magrittr'
The following object is masked from 'package:purrr':

    set_names
The following object is masked from 'package:tidyr':

    extract
suppressMessages(library(AlphaSimHlpR))
Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
Warning: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'.
bsp <- specifyPopulation(ctrlFileName="data/BaselinePopulationFile.txt")
bsp <- specifyPipeline(bsp, ctrlFileName="data/BaselineControlFile.txt")
runBreedingScheme_wBurnIn <- function(replication=NULL, 
                                      nBurnInCycles=10,nPostBurnInCycles=10,
                                      bspBurnIn,bspPostBurnIn,
                                      initializeFunc, 
                                      productPipeline, 
                                      populationImprovement){
  
  cat("******", replication, "\n")
  
  # This initiates the founding population 
  initList <- initializeFunc(bspBurnIn)
  SP <- initList$SP
  bspBurnIn <- initList$bsp
  records <- initList$records
  
  # Burn-in cycles
  for (cycle in 1:nBurnInCycles){
    cat(cycle, " ")
    records <- productPipeline(records, bspBurnIn, SP)
    records <- populationImprovement(records, bspBurnIn, SP)
  }
  # records <- AlphaSimHlpR:::lastCycStgOut(records, bspPostBurnIn, SP)

  cat("\n")
  cat("Burn-in Cycles")
  cat("\n")
  # Post burn-in cycles
  
  for (cycle in (nBurnInCycles+1):(nBurnInCycles+nPostBurnInCycles)){
    cat(cycle, " ")
    records <- productPipeline(records, bspPostBurnIn, SP)
    records <- populationImprovement(records, bspPostBurnIn, SP)
  }
  cat("\n")
  # Finalize the stageOutputs
  records <- AlphaSimHlpR:::lastCycStgOut(records, bspPostBurnIn, SP)
  
  return(list(records=records,
              bspBurnIn=bspBurnIn,
              bspPostBurnIn=bspPostBurnIn,
              SP=SP))
}

For burn-in, using phenotypic selection, so the bsp already created.

For post burn-in, change selCritPopImprov to selCritGRM, but ignore selCritPipeAdv for now.

bspBurnIn<-bsp
bspPostBurnIn<-bspBurnIn
bspPostBurnIn[["selCritPopImprov"]] <- selCritGRM

test_sim<-runBreedingScheme_wBurnIn(replication = 1, 
                                    nBurnInCycles=2,nPostBurnInCycles=2,
                                    bspBurnIn=bspBurnIn,
                                    bspPostBurnIn=bspPostBurnIn,
                                    initializeFunc=initializeScheme, 
                                    productPipeline=productPipeline, 
                                    populationImprovement=popImprov1Cyc)

Unfortunately, haven’t gotten this to work yet. It seems likely more tweaking to the package is necessary.

I traced the problem at least as far as the populationImprovement() function in the post-burn-in phase and the makeGRM().

Simulation - no burn-in

Set-up an experiment. No burn-in simulations.

# rm(list=ls()); gc()
# library(tidyverse); library(magrittr); 
# suppressMessages(library(AlphaSimHlpR))
# bsp <- specifyPopulation(ctrlFileName="BaselinePopulationFile.txt")
# bsp <- specifyPipeline(bsp, ctrlFileName="BaselineControlFile.txt")
# test<-runBreedingScheme(replication = 1, nCycles = 5, # just 5 for now 
#                         initializeFunc=initializeScheme, 
#                         productPipeline=prodPipeFncChk, 
#                         populationImprovement=popImprov1Cyc, bsp)
# 
# test_burnin$records$stageOutputs %>% ggplot(.,aes(x=year,y=genValMean, color=stage)) + geom_line()
# test_burnin$records

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] AlphaSimHlpR_0.2.0 MCMCpack_1.5-0     coda_0.19-4        optiSel_2.0.5     
 [5] sommer_4.1.3       crayon_1.4.1       lattice_0.20-41    MASS_7.3-53.1     
 [9] lme4_1.1-26        Matrix_1.3-2       plotrix_3.8-1      AlphaSimR_0.13.0  
[13] R6_2.5.0           magrittr_2.0.1     forcats_0.5.1      stringr_1.4.0     
[17] dplyr_1.0.5        purrr_0.3.4        readr_1.4.0        tidyr_1.1.3       
[21] tibble_3.1.1       ggplot2_3.3.3      tidyverse_1.3.1    workflowr_1.6.2   

loaded via a namespace (and not attached):
  [1] minqa_1.2.4             colorspace_2.0-0        ellipsis_0.3.1         
  [4] rprojroot_2.0.2         fs_1.5.0                rstudioapi_0.13        
  [7] MatrixModels_0.5-0      fansi_0.4.2             lubridate_1.7.10       
 [10] xml2_1.3.2              codetools_0.2-18        splines_4.0.3          
 [13] doParallel_1.0.16       pedigree_1.4            cachem_1.0.4           
 [16] knitr_1.32              shapes_1.2.6            optiSolve_0.1.2        
 [19] jsonlite_1.7.2          kinship2_1.8.5          nloptr_1.2.2.2         
 [22] mcmc_0.9-7              broom_0.7.6             dbplyr_2.1.1           
 [25] shiny_1.6.0             compiler_4.0.3          httr_1.4.2             
 [28] backports_1.2.1         assertthat_0.2.1        fastmap_1.1.0          
 [31] cli_2.4.0               later_1.1.0.1           quantreg_5.85          
 [34] htmltools_0.5.1.1       tools_4.0.3             gtable_0.3.0           
 [37] glue_1.4.2              reshape2_1.4.4          Rcpp_1.0.6             
 [40] cellranger_1.1.0        jquerylib_0.1.3         pkgdown_1.6.1          
 [43] vctrs_0.3.7             nlme_3.1-152            conquer_1.0.2          
 [46] iterators_1.0.13        crosstalk_1.1.1         xfun_0.22              
 [49] rvest_1.0.0             mime_0.10               miniUI_0.1.1.1         
 [52] lifecycle_1.0.0         ECOSolveR_0.5.4         statmod_1.4.35         
 [55] nadiv_2.17.1            scales_1.1.1            hms_1.0.0              
 [58] promises_1.2.0.1        SparseM_1.81            yaml_2.2.1             
 [61] HaploSim_1.8.4          memoise_2.0.0           sass_0.3.1             
 [64] stringi_1.5.3           foreach_1.5.1           boot_1.3-27            
 [67] manipulateWidget_0.10.1 matrixStats_0.58.0      rlang_0.4.10           
 [70] pkgconfig_2.0.3         rgl_0.106.6             evaluate_0.14          
 [73] htmlwidgets_1.5.3       tidyselect_1.1.0        plyr_1.8.6             
 [76] generics_0.1.0          DBI_1.1.1               pillar_1.6.0           
 [79] haven_2.4.0             whisker_0.4             withr_2.4.2            
 [82] abind_1.4-5             scatterplot3d_0.3-41    cccp_0.2-7             
 [85] pspline_1.0-18          modelr_0.1.8            utf8_1.2.1             
 [88] alabama_2015.3-1        rmarkdown_2.7           grid_4.0.3             
 [91] readxl_1.3.1            minpack.lm_1.2-1        data.table_1.14.0      
 [94] git2r_0.28.0            reprex_2.0.0            digest_0.6.27          
 [97] webshot_0.5.2           xtable_1.8-4            httpuv_1.5.5           
[100] numDeriv_2016.8-1.1     munsell_0.5.0           bslib_0.2.4            
[103] magic_1.5-9             quadprog_1.5-8