# Loading Existing Data into a Simulation

#### Jean-Luc Jannink

#### 2018-03-31

#### Load the BreedingSchemeLanguage.

    library(BreedingSchemeLanguage)

#### Avoid writing over a previously existing simulation environment

    if (exists("simEnv")){
      rm(list=names(simEnv), envir=simEnv)
      rm(simEnv)
    }

#### Find the path to the HapMap file in the package

    filePathName <- system.file("extdata", "exampleHapMapFile.hmp", package = "BreedingSchemeLanguage")

- This is what the file looks like

    ## locus alleles chrom pos col5 col6 effectID actionType effects col10 col11 ind1 ind2 ...
    ## locus1 A/G 1 0.77 NA NA NA NA NA NA NA AA AG AA AA AA AA AA GA AA AA AA AG GA AA AA ...
    ## locus2 T/G 1 1.79 NA NA NA NA NA NA NA GG GG GG TG GG TG GG GG GG GT GT GG GT GT GT ...
    ## locus3 G/T 1 1.99 NA NA NA NA NA NA NA TT TT TT TT TT TT TT TT TT TT TT TT TT TT TT ...
    ## locus4 G/T 1 2.29 NA NA NA NA NA NA NA GG GG GG TG TG GG TG TG TG TG TT TT GG TG GT ...
    ## locus5 G/C 1 3.1 NA NA NA NA NA NA NA GG GG GG GG GG GG GG CG GG GG GG GG GG GG GG  ...
    ## locus6 G/C 1 4.29 NA NA NA NA NA NA NA GG GG GG GG GG GG GG CG GG GG GG GG GG GG GG ...
    ## locus7 A/G 1 4.53 NA NA NA NA NA NA NA GA AA AG AA GA GA GG GG AA AG AG AA GA GA GA ...
    ## locus8 C/T 1 5.61 NA NA 17 0 -1.311 NA NA TT TT TT TT CT TT TT TT CT TC TT TT TT TT ...
    ## locus9 T/G 1 5.86 NA NA NA NA NA NA NA TT GT TG TT TT TT GT TT TT GT TT TT GT GT GG ...
    ##  ...

- The first row is a header
- The ninth row (locus8) has specification for a QTL
  - 17 is an unordered effect ID
  - 0 indicates additive gene action
  - -1.311 is the QTL effect

#### Load the historical haplotypes into the simulation environment

    simEnv <- defineSpecies(loadData=NULL, importFounderHap=filePathName, nChr=5, lengthChr=100, nMarkers=300)
    initializePopulation()

- Also create the population of diploid founders

#### Run selection on founders

    phenotype()
    genotype()
    predictValue()
    select(nSelect=50)
    cross(equalContribution=T)

- Since the population was just genotyped, the default is for `predictValue()` to use markers to enable information sharing across observations
- The `equalContribution` parameter in `cross()` ensures that all parents contribute to the same number of progeny

#### Intense selection on genomic predictions

    genotype()
    predictValue()
    select(nSelect=5)
    cross()
    cycleMeans <- plotData()

- The penultimate population was not phenotyped before selection
- The final `cross()` function serves to evaluate the response to genomic selection
- Note that this simulation only allows one replication: there will be variability in response including the possibility of a negative response to genomic selection