# Create founders

cat(" Simulating founder parents \n")

# Generate initial haplotypes
founderPop <- runMacs(nInd     = nFounders, 
                      nChr     = nChr, 
                      segSites = nQtl,
                      inbred   = TRUE, 
                      species  = "WHEAT")
SP = SimParam$new(founderPop)

# Create an input object with FieldSimR for AlphaSim to obtain desired genotype slopes 
input_asr <- multi_asr_input(nenvs  = nEnvTPE, 
                             mean   = MeanG,
                             var    = diag(De), 
                             corA   = Ce, 
                             nterms = k)

# Add additive trait
SP$addTraitA(nQtlPerChr = nQtl,
             mean       = input_asr$mean,
             var        = input_asr$var,
             corA       = input_asr$corA)

# Create founder parents
FoundingParents <- newPop(founderPop)

covs_tpe    <- input_asr$cov.mat              # store covariates for base population


#-------------
rm(founderPop)



# Populate breeding stages with unique genotypes

FoundingF1 <- randCross(FoundingParents, nCrosses)
FoundingDH <- makeDH(FoundingF1, nDH)


