Last updated: 2021-03-24

Checks: 7 0

Knit directory: PredictOutbredCrossVar/

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(20191123) 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 f73b05f. 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/
    Ignored:    output/.DS_Store

Untracked files:
    Untracked:  Icon
    Untracked:  PredictOutbredCrossVarMS_ResponseToReviews_R1.gdoc
    Untracked:  figure/
    Untracked:  manuscript/
    Untracked:  output/crossPredictions/
    Untracked:  output/gblups_DirectionalDom_parentwise_crossVal_folds.rds
    Untracked:  output/gblups_geneticgroups.rds
    Untracked:  output/gblups_parentwise_crossVal_folds.rds
    Untracked:  output/mtMarkerEffects/

Unstaged changes:
    Modified:   analysis/NGCleadersCall.Rmd
    Modified:   code/fitDirectionalDomMtBRR.R
    Modified:   code/fitmtBRR.R
    Modified:   code/getDirectionalDomGenomicBLUPs.R
    Modified:   code/getDirectionalDomMtCrossMeanPreds.R
    Modified:   code/getDirectionalDomMtCrossVarBVpreds.R
    Modified:   code/getDirectionalDomMtCrossVarTGVpreds.R
    Modified:   code/getDirectionalDomVarComps.R
    Modified:   code/getGenomicBLUPs.R
    Modified:   code/getMtCrossMeanPreds.R
    Modified:   code/getMtCrossVarPreds.R
    Modified:   code/getUntestedMtCrossVarPreds.R
    Modified:   code/getVarComps.R
    Modified:   data/blups_forawcdata.rds
    Modified:   data/genmap_awc_May2020.rds
    Modified:   data/parentwise_crossVal_folds.rds
    Modified:   data/ped_awc.rds
    Modified:   data/selection_index_weights_4traits.rds
    Modified:   output/CrossesToPredict_top100stdSI_and_209originalParents.rds
    Modified:   output/accuraciesMeans.rds
    Modified:   output/accuraciesUC.rds
    Modified:   output/accuraciesVars.rds
    Modified:   output/crossRealizations/realizedCrossMeans.rds
    Modified:   output/crossRealizations/realizedCrossMeans_BLUPs.rds
    Modified:   output/crossRealizations/realizedCrossMetrics.rds
    Modified:   output/crossRealizations/realizedCrossVars.rds
    Modified:   output/crossRealizations/realizedCrossVars_BLUPs.rds
    Modified:   output/crossRealizations/realized_cross_means_and_covs_traits.rds
    Modified:   output/crossRealizations/realized_cross_means_and_vars_selindices.rds
    Modified:   output/ddEffects.rds
    Modified:   output/gebvs_ModelA_GroupAll_stdSI.rds
    Modified:   output/obsVSpredMeans.rds
    Modified:   output/obsVSpredUC.rds
    Modified:   output/obsVSpredVars.rds
    Modified:   output/pmv_DirectionalDom_varcomps_geneticgroups.rds
    Modified:   output/pmv_varcomps_geneticgroups.rds
    Modified:   output/pmv_varcomps_geneticgroups_tidy_includingSIvars.rds
    Modified:   output/propHomozygous.rds
    Modified:   output/top100stdSI.rds

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/fitMtBRRs.Rmd) and HTML (docs/fitMtBRRs.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 f73b05f wolfemd 2021-03-24 Update to match revised manuscript. Several comparisons moved to Appendix to streamline primary results, figures, etc.
html 4de1330 wolfemd 2021-02-01 Build site.
Rmd 883b1d4 wolfemd 2021-02-01 Update the syntax highlighting and code-block formatting throughout for
Rmd 6a10c30 wolfemd 2021-01-04 Submission and GitHub ready version.
html 6a10c30 wolfemd 2021-01-04 Submission and GitHub ready version.

Parent-wise cross-validation

Define parent-wise cross-validation folds

Goal is to assess the accuracy of predicting untested crosses of outbred parents.

5-folds times 5-replications of parent-wise cross-validation, defined as follows:

  • 209 parents in IITA pedigree
  • Divide set of parents into k-folds
  • For each k
    • Training data: Test parents + all non-test parent descendants.
      • That is, remove all offspring, grandchildren, greatgrandchildren, etc. of test parents
      • Predict each cross test parents were involved in
    • Validation data: The inverse of the training set, including all offspring and descendants of the test parents (but not the test parents themselves or the other training samples).
    • Use genomic-model on validation set to get at observed mean and variance in BV / TGV in families
library(tidyverse); library(magrittr); library(rsample)
ped<-readRDS(here::here("data","ped_awc.rds"))
set.seed(42)
parentfolds<-vfold_cv(tibble(Parents=union(ped$sireID,ped$damID)),v = 5,repeats = 5) %>% 
  dplyr::mutate(folds=map(splits,function(splits){
    #splits<-parentfolds$splits[[1]]
    testparents<-testing(splits)$Parents
    trainparents<-training(splits)$Parents
    offspring<-ped %>% 
      filter(sireID %in% testparents | damID %in% testparents) %$% 
      unique(FullSampleName)
    grandkids<-ped %>% 
      filter(sireID %in% offspring | damID %in% offspring) %$% 
      unique(FullSampleName)
    greatgrandkids<-ped %>% 
      filter(sireID %in% grandkids | damID %in% grandkids) %$% 
      unique(FullSampleName)
    testset<-unique(c(offspring,grandkids,greatgrandkids)) %>% .[!. %in% c(testparents,trainparents)]
    nontestdescendents<-ped %>% 
      filter(!FullSampleName %in% testset) %$% 
      unique(FullSampleName)
    trainset<-union(testparents,trainparents) %>% 
      union(.,nontestdescendents)
    out<-tibble(testparents=list(testparents),
                trainset=list(trainset),
                testset=list(testset))
    return(out) })) %>% 
  unnest(folds)
# table(parentfolds$trainset[[1]] %in% parentfolds$testparents[[1]])
# table(parentfolds$testset[[1]] %in% parentfolds$testparents[[1]])
# table(parentfolds$testset[[1]] %in% parentfolds$trainset[[1]])
saveRDS(parentfolds,file = here::here("data","parentwise_crossVal_folds.rds"))

Fit A and AD models

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);

# BLUPs -----------
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# Training datasets -----------
parentfolds<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>% 
  rename(Repeat=id,Fold=id2) %>% 
  select(Repeat,Fold,trainset,testset) %>% 
  pivot_longer(c(trainset,testset),
               names_to = "Dataset",
               values_to = "sampleIDs") %>% 
  crossing(Model=c("A","AD")) %>% 
  arrange(desc(Dataset),Repeat,Fold) %>% 
  mutate(blups=map(sampleIDs,~filter(blups,germplasmName %in% .)),
         outName=paste0("mt_",Repeat,"_",Fold,"_",Dataset,"_",Model))

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# fitMtBRR function -------------
## Wrapper function for BGLR::Multitrait()
## For a given set of training blups+snps for either model "A" or "AD"
source(here::here("code","fitMtBRR.R"))

# Parallelization specs ---------
require(furrr); options(mc.cores=10); plan(multiprocess)
options(future.globals.maxSize= 10000*1024^2)

Run MtBRRs

# cbsulm19 - Jun 17, 07:09am - 
parentfolds %>% 
  slice(1:10) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm21 - Jun 17, 07:10pm - 
parentfolds %>% 
  slice(11:20) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm22 - Jun 17, 07:10pm - 
parentfolds %>% 
  slice(21:30) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm26 - Jun 17, 07:10pm - 
parentfolds %>% 
  slice(31:40) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm27 - Jun 17, 07:10pm - 
parentfolds %>% 
  slice(41:50) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm19 - Jun 17, 11:51am - 
parentfolds %>% 
  slice(51:60) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm26 - Jun 17, 12:25pm - 
parentfolds %>% 
  slice(61:70) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm21 - Jun 17, 01:04pm - 
parentfolds %>% 
  slice(71:80) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm22 - Jun 17, 01:04pm - 
parentfolds %>% 
  slice(81:90) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

# cbsulm27 - Jun 17, 01:04pm - 
parentfolds %>% 
  slice(91:100) %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

Fit DirDom model

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);

# BLUPs -----------
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# Training datasets -----------
parentfolds<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>% 
  rename(Repeat=id,Fold=id2) %>% 
  select(Repeat,Fold,trainset,testset) %>% 
  pivot_longer(c(trainset,testset),
               names_to = "Dataset",
               values_to = "sampleIDs") %>% 
  mutate(Model="DirectionalDom") %>% 
  arrange(desc(Dataset),Repeat,Fold) %>% 
  mutate(blups=map(sampleIDs,~filter(blups,germplasmName %in% .)),
         outName=paste0("mt_",Repeat,"_",Fold,"_",Dataset,"_",Model))

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# fitDirectionalDomMtBRR function -------------
## Wrapper function for BGLR::Multitrait()
## For a given set of training blups+snps, fit a directional dominance model as in Xiang et al. 2016.
## using "biologically" partitioned additive and dominance effects + a mean effect for overall proportion homozygous (inbreeding).
source(here::here("code","fitDirectionalDomMtBRR.R"))

# Parallelization specs ---------
require(furrr); options(mc.cores=10); plan(multiprocess)
options(future.globals.maxSize= 10000*1024^2)

# Divide parentfolds into chunks for each server ------------
nchunks<-5
parentfolds %<>% 
  mutate(Chunk=rep(1:nchunks, each=ceiling(nrow(.)/nchunks), length.out=nrow(.))) %>% 
  nest(data=c(-Chunk))

Run Mt BRRs

# cbsulm19
chunk<-1;
# cbsulm21
chunk<-2;
# cbsulm22
chunk<-3;
# cbsulm26
chunk<-4;
# cbsulm27
chunk<-5;
# Start run on each server / chunk: Jun 29, 5:20pm
parentfolds$data[[chunk]] %>% 
  future_pmap(.,fitDirectionalDomMtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5)

Genetic groups

  • GG, GG+C1, GG+C1+C2, GG+C1+C2+C3

Fit A and AD models

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# Training datasets -----------
geneticgroups<-blups %>% 
  filter(!grepl("TMS13|TMS14|TMS15",germplasmName)) %>% 
  mutate(Group="GG") %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS13",germplasmName)) %>% 
              mutate(Group="TMS13")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS14",germplasmName)) %>% 
              mutate(Group="TMS14")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS15",germplasmName)) %>% 
              mutate(Group="TMS15")) %>% 
  bind_rows(blups %>% 
              mutate(Group="All")) %>% 
  nest(blups=-Group) %>% 
  crossing(Model=c("A","AD")) %>% 
  mutate(blups=map(blups,~filter(.,germplasmName %in% rownames(snps))),
         outName=paste0("mt_",Group,"_",Model))

# fitMtBRR function -------------
## Wrapper function for BGLR::Multitrait()
## For a given set of training blups+snps for either model "A" or "AD"
source(here::here("code","fitMtBRR.R"))

# Parallelization specs ---------
require(furrr); options(mc.cores=10); plan(multiprocess)
options(future.globals.maxSize= 10000*1024^2)

Run Mt BRRs

geneticgroups %>% 
  mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))

Fit DirDom model

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# Training datasets -----------
geneticgroups<-blups %>% 
  filter(!grepl("TMS13|TMS14|TMS15",germplasmName)) %>% 
  mutate(Group="GG") %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS13",germplasmName)) %>% 
              mutate(Group="TMS13")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS14",germplasmName)) %>% 
              mutate(Group="TMS14")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS15",germplasmName)) %>% 
              mutate(Group="TMS15")) %>% 
  bind_rows(blups %>% 
              mutate(Group="All")) %>% 
  nest(blups=-Group) %>% 
  mutate(Model="DirectionalDom") %>% 
  mutate(blups=map(blups,~filter(.,germplasmName %in% rownames(snps))),
         outName=paste0("mt_",Group,"_",Model))

# fitDirectionalDomMtBRR function -------------
## Wrapper function for BGLR::Multitrait()
## For a given set of training blups+snps, fit a directional dominance model as in Xiang et al. 2016.
## using "biologically" partitioned additive and dominance effects + a mean effect for overall proportion homozygous (inbreeding).
source(here::here("code","fitDirectionalDomMtBRR.R"))

# Parallelization specs ---------
require(furrr); options(mc.cores=5); plan(multiprocess)
options(future.globals.maxSize= 20000*1024^2)

Run Mt BRRs

# Start run on cbsulm15: July 29, 11:15pm - 
geneticgroups %>% 
  future_pmap(.,fitDirectionalDomMtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5)

Get Genomic BLUPs

Fit A and AD models

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# BLUPs -----------
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# Training datasets -----------
## Parent-wise CV folds
parentfolds<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>% 
  rename(Repeat=id,Fold=id2) %>% 
  select(Repeat,Fold,trainset,testset) %>% 
  pivot_longer(c(trainset,testset),
               names_to = "Dataset",
               values_to = "sampleIDs") %>% 
  crossing(Model=c("A","AD")) %>% 
  arrange(desc(Dataset),Repeat,Fold) %>% 
  mutate(blups=map(sampleIDs,~filter(blups,germplasmName %in% .)),
         outName=paste0("mt_",Repeat,"_",Fold,"_",Dataset,"_",Model)) %>% 
  select(Repeat,Fold,Dataset,Model,outName)
## Genetic groups
geneticgroups<-blups %>% 
  filter(!grepl("TMS13|TMS14|TMS15",germplasmName)) %>% 
  mutate(Group="GG") %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS13",germplasmName)) %>% 
              mutate(Group="TMS13")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS14",germplasmName)) %>% 
              mutate(Group="TMS14")) %>% 
  bind_rows(blups %>% 
              filter(grepl("TMS15",germplasmName)) %>% 
              mutate(Group="TMS15")) %>% 
  bind_rows(blups %>% 
              mutate(Group="All")) %>% 
  nest(blups=-Group) %>% 
  crossing(Model=c("A","AD")) %>% 
  mutate(blups=map(blups,~filter(.,germplasmName %in% rownames(snps))),
         outName=paste0("mt_",Group,"_",Model))

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# Parallelization specs ---------
require(furrr); options(future.globals.maxSize=10000*1024^2)
plan(multiprocess); options(mc.cores=25); 

# getGenomicBLUPs function -----------------
## Wrapper function for either Model=="A" or "AD"
## For a given set of multi-trait posterior mean marker effects
## and a given set of SNPs, load the effects and compute GEBV and GETGV
source(here::here("code","getGenomicBLUPs.R"))

Compute GEBV and GETGV

Parent-wise CV folds

parentfolds %<>% 
  mutate(GBLUPs=future_pmap(.,getGenomicBLUPs,snps=snps))
saveRDS(parentfolds,here::here("output","gblups_parentwise_crossVal_folds.rds"))

Genetic groups

geneticgroups %<>% 
 mutate(GBLUPs=future_pmap(.,getGenomicBLUPs,snps=snps))
saveRDS(geneticgroups,here::here("output","gblups_geneticgroups.rds"))

Fit DirDom model

Set-up

# activate multithread OpenBLAS
export OMP_NUM_THREADS=112
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# BLUPs -----------
blups<-readRDS(here::here("data","blups_forawcdata.rds")) %>% 
  select(Trait,blups) %>% # BLUPs long-->wide for multivar analysis
  unnest(blups) %>% 
  select(Trait,germplasmName,drgBLUP) %>% 
  spread(Trait,drgBLUP) %>%  # choosing de-regressed BLUPs as responses despite unweighted analysis
  select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order

# Training datasets -----------
## Parent-wise CV folds
parentfolds<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>% 
  rename(Repeat=id,Fold=id2) %>% 
  select(Repeat,Fold,trainset,testset) %>% 
  pivot_longer(c(trainset,testset),
               names_to = "Dataset",
               values_to = "sampleIDs") %>% 
  mutate(Model="DirectionalDom") %>% 
  arrange(desc(Dataset),Repeat,Fold) %>% 
  mutate(blups=map(sampleIDs,~filter(blups,germplasmName %in% .)),
         outName=paste0("mt_",Repeat,"_",Fold,"_",Dataset,"_",Model))

# SNP data ------------
snps<-readRDS(here::here("data","dosages_awc.rds")) %>% 
  remove_invariant(.); dim(snps) # [1] 5591 38093

# Parallelization specs ---------
require(furrr); options(future.globals.maxSize=10000*1024^2)
plan(multiprocess); options(mc.cores=25); 

# getGenomicBLUPs function -----------------
## Similar to "getGenomicBLUPs.R"
## For a given set of multi-trait posterior mean marker effects
## and a given set of SNPs, load the effects and compute GEBV and GETGV
# 1. inbreeding effect for each trait is extracted from the BGLR output,
### divided by N snps and added to the vector of SNP effects
# 2. Allele substitution effects are computed as a+d(q-p) and used to predict GEBV
# 3. GETGV = sum(X_a*a + X_d*d)
source(here::here("code","getDirectionalDomGenomicBLUPs.R"))

Compute GEBV and GETGV

parentfolds %<>% 
  mutate(GBLUPs=future_pmap(.,getDirectionalDomGenomicBLUPs,snps=snps))
saveRDS(parentfolds,here::here("output","gblups_DirectionalDom_parentwise_crossVal_folds.rds"))

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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6        whisker_0.4       knitr_1.31        magrittr_2.0.1   
 [5] R6_2.5.0          rlang_0.4.10      fansi_0.4.2       stringr_1.4.0    
 [9] tools_4.0.3       xfun_0.22         utf8_1.2.1        git2r_0.28.0     
[13] jquerylib_0.1.3   htmltools_0.5.1.1 ellipsis_0.3.1    rprojroot_2.0.2  
[17] yaml_2.2.1        digest_0.6.27     tibble_3.1.0      lifecycle_1.0.0  
[21] crayon_1.4.1      later_1.1.0.1     sass_0.3.1        vctrs_0.3.6      
[25] promises_1.2.0.1  fs_1.5.0          glue_1.4.2        evaluate_0.14    
[29] rmarkdown_2.7     stringi_1.5.3     bslib_0.2.4       compiler_4.0.3   
[33] pillar_1.5.1      jsonlite_1.7.2    httpuv_1.5.5      pkgconfig_2.0.3