Last updated: 2021-10-24

Checks: 7 0

Knit directory: BreedingSchemeOpt/

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 e0ca345. 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:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/archive/
    Untracked:  code/runSchemesPostBurnIn_dev.R
    Untracked:  code/scrap.R
    Untracked:  data/baselineScheme.gsheet
    Untracked:  output/Icon
    Untracked:  output/benchmark_sim.rds
    Untracked:  output/benchmark_sims5.rds
    Untracked:  output/burnInSims_bsp1_iita_2021Aug27.rds
    Untracked:  output/burnInSims_bsp2_iita_2021Aug27.rds
    Untracked:  output/burnInSims_bsp3_iita_2021Aug27.rds
    Untracked:  output/burnInSims_iita_2021Aug27.rds
    Untracked:  output/burnIn_test.rds
    Untracked:  output/postBurnInGMS_test_DirDom_UCparent.rds
    Untracked:  output/postBurnInGMS_test_newBSP1.rds
    Untracked:  output/postBurnInGMS_test_newBSP2.rds
    Untracked:  output/postBurnInGMS_test_newBSP3.rds
    Untracked:  output/postBurnInGMS_test_newBSP3_GS.rds
    Untracked:  output/postBurnInGMS_test_newBSP3_PS.rds
    Untracked:  output/postBurnInGS_test.rds
    Untracked:  output/postBurnIn_test.rds
    Untracked:  output/testSims_GMS_DirDom_MeanTGV_2021Sep18.rds
    Untracked:  output/testSims_GMS_DirDom_MeanTGV_50parents_2021Sep18.rds
    Untracked:  output/testSims_GMS_DirDom_UCvariety_2021Sep18.rds
    Untracked:  output/testSims_GMS_ModelA_MeanBV_2021Sep15.rds
    Untracked:  output/testSims_GMS_ModelA_MeanBV_2021Sep18.rds
    Untracked:  output/testSims_GMS_ModelA_UCparent_propSelpt05_2021Sep18.rds
    Untracked:  output/test_burnInSims_2021Sep17.rds
    Untracked:  output/test_burnInSims_GS_2021Sep17.rds
    Untracked:  output/test_burnInSims_GS_noAYT_2021Sep17.rds
    Untracked:  output/test_burnInSims_PS_2021Sep17.rds
    Untracked:  output/test_burnInSims_PS_noAYT_2021Sep17.rds
    Untracked:  output/test_burnIn_sim.rds
    Untracked:  output/test_inputs_for_mmer.Rdata

Unstaged changes:
    Modified:   analysis/AlphaSimHlpR_firstSteps.Rmd
    Modified:   analysis/baselineSim.Rmd
    Modified:   analysis/genomicMateSelSims.Rmd

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
html e0d20bd wolfemd 2021-08-27 Build site.
html 92bd15b wolfemd 2021-04-22 Build site.
html 1d503b6 wolfemd 2021-04-22 Build site.
html fe3048a wolfemd 2021-04-22 Build site.
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  723990 38.7    1356972 72.5         NA  1356972 72.5
Vcells 1341663 10.3    8388608 64.0      65536  2023276 15.5
library(tidyverse); library(magrittr); 
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5     ✓ purrr   0.3.4
✓ tibble  3.1.4     ✓ dplyr   1.0.7
✓ tidyr   1.1.3     ✓ stringr 1.4.0
✓ readr   2.0.1     ✓ 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))
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.1.1 (2021-08-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.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] AlphaSimHlpR_0.2.1 AlphaSimR_1.0.4    R6_2.5.1           magrittr_2.0.1    
 [5] forcats_0.5.1      stringr_1.4.0      dplyr_1.0.7        purrr_0.3.4       
 [9] readr_2.0.1        tidyr_1.1.3        tibble_3.1.4       ggplot2_3.3.5     
[13] tidyverse_1.3.1    workflowr_1.6.2   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       lubridate_1.7.10 assertthat_0.2.1 rprojroot_2.0.2 
 [5] digest_0.6.27    utf8_1.2.2       cellranger_1.1.0 backports_1.2.1 
 [9] reprex_2.0.1     evaluate_0.14    httr_1.4.2       pillar_1.6.2    
[13] rlang_0.4.11     readxl_1.3.1     rstudioapi_0.13  whisker_0.4     
[17] jquerylib_0.1.4  rmarkdown_2.11   munsell_0.5.0    broom_0.7.9     
[21] compiler_4.1.1   httpuv_1.6.3     modelr_0.1.8     xfun_0.26       
[25] pkgconfig_2.0.3  htmltools_0.5.2  tidyselect_1.1.1 fansi_0.5.0     
[29] crayon_1.4.1     tzdb_0.1.2       dbplyr_2.1.1     withr_2.4.2     
[33] later_1.3.0      grid_4.1.1       jsonlite_1.7.2   gtable_0.3.0    
[37] lifecycle_1.0.0  DBI_1.1.1        git2r_0.28.0     scales_1.1.1    
[41] cli_3.0.1        stringi_1.7.4    fs_1.5.0         promises_1.2.0.1
[45] xml2_1.3.2       bslib_0.3.0      ellipsis_0.3.2   generics_0.1.0  
[49] vctrs_0.3.8      tools_4.1.1      glue_1.4.2       hms_1.1.0       
[53] fastmap_1.1.0    yaml_2.2.1       colorspace_2.0-2 rvest_1.0.1     
[57] knitr_1.34       haven_2.4.3      sass_0.4.0