Last updated: 2021-02-01
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 883b1d4. 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: analysis/.DS_Store
Ignored: code/.DS_Store
Ignored: data/.DS_Store
Ignored: output/.DS_Store
Ignored: output/crossRealizations/.DS_Store
Untracked files:
Untracked: .gitignore
Untracked: Icon
Untracked: PredictOutbredCrossVar.Rproj
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
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 | 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. |
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:
library(tidyverse); library(magrittr); library(rsample)
<-readRDS(here::here("data","ped_awc.rds"))
pedset.seed(42)
<-vfold_cv(tibble(Parents=union(ped$sireID,ped$damID)),v = 5,repeats = 5) %>%
parentfolds::mutate(folds=map(splits,function(splits){
dplyr#splits<-parentfolds$splits[[1]]
<-testing(splits)$Parents
testparents<-training(splits)$Parents
trainparents<-ped %>%
offspringfilter(sireID %in% testparents | damID %in% testparents) %$%
unique(FullSampleName)
<-ped %>%
grandkidsfilter(sireID %in% offspring | damID %in% offspring) %$%
unique(FullSampleName)
<-ped %>%
greatgrandkidsfilter(sireID %in% grandkids | damID %in% grandkids) %$%
unique(FullSampleName)
<-unique(c(offspring,grandkids,greatgrandkids)) %>% .[!. %in% c(testparents,trainparents)]
testset<-ped %>%
nontestdescendentsfilter(!FullSampleName %in% testset) %$%
unique(FullSampleName)
<-union(testparents,trainparents) %>%
trainsetunion(.,nontestdescendents)
<-tibble(testparents=list(testparents),
outtrainset=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"))
# 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")) %>%
blupsselect(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 -----------
<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>%
parentfoldsrename(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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_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)
# 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))
# 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")) %>%
blupsselect(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 -----------
<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>%
parentfoldsrename(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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_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 ------------
<-5
nchunks%<>%
parentfolds mutate(Chunk=rep(1:nchunks, each=ceiling(nrow(.)/nchunks), length.out=nrow(.))) %>%
nest(data=c(-Chunk))
# cbsulm19
<-1;
chunk# cbsulm21
<-2;
chunk# cbsulm22
<-3;
chunk# cbsulm26
<-4;
chunk# cbsulm27
<-5;
chunk# Start run on each server / chunk: Jun 29, 5:20pm
$data[[chunk]] %>%
parentfoldsfuture_pmap(.,fitDirectionalDomMtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5)
# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
<-readRDS(here::here("data","blups_forawcdata.rds")) %>%
blupsselect(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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_invariant(.); dim(snps) # [1] 5591 38093
# Training datasets -----------
<-blups %>%
geneticgroupsfilter(!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)
%>%
geneticgroups mutate(mtbrrFit=future_pmap(.,fitmtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5))
# activate multithread OpenBLAS
export OMP_NUM_THREADS=88
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
<-readRDS(here::here("data","blups_forawcdata.rds")) %>%
blupsselect(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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_invariant(.); dim(snps) # [1] 5591 38093
# Training datasets -----------
<-blups %>%
geneticgroupsfilter(!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)
# Start run on cbsulm15: July 29, 11:15pm -
%>%
geneticgroups future_pmap(.,fitDirectionalDomMtBRR,snps=snps,outPath="output/mtMarkerEffects", nIter=30000, burnIn=5000,thin=5)
# 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")) %>%
blupsselect(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
<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>%
parentfoldsrename(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
<-blups %>%
geneticgroupsfilter(!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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_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"))
%<>%
parentfolds mutate(GBLUPs=future_pmap(.,getGenomicBLUPs,snps=snps))
saveRDS(parentfolds,here::here("output","gblups_parentwise_crossVal_folds.rds"))
%<>%
geneticgroups mutate(GBLUPs=future_pmap(.,getGenomicBLUPs,snps=snps))
saveRDS(geneticgroups,here::here("output","gblups_geneticgroups.rds"))
# activate multithread OpenBLAS
export OMP_NUM_THREADS=112
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# BLUPs -----------
<-readRDS(here::here("data","blups_forawcdata.rds")) %>%
blupsselect(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
<-readRDS(file = here::here("data","parentwise_crossVal_folds.rds")) %>%
parentfoldsrename(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 ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_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"))
%<>%
parentfolds mutate(GBLUPs=future_pmap(.,getDirectionalDomGenomicBLUPs,snps=snps))
saveRDS(parentfolds,here::here("output","gblups_DirectionalDom_parentwise_crossVal_folds.rds"))
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
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
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 whisker_0.4 knitr_1.31 magrittr_2.0.1
[5] workflowr_1.6.2 R6_2.5.0 rlang_0.4.10 stringr_1.4.0
[9] tools_4.0.2 xfun_0.20 git2r_0.28.0 htmltools_0.5.1.1
[13] ellipsis_0.3.1 yaml_2.2.1 digest_0.6.27 rprojroot_2.0.2
[17] tibble_3.0.6 lifecycle_0.2.0 crayon_1.3.4 later_1.1.0.1
[21] vctrs_0.3.6 fs_1.5.0 promises_1.1.1 glue_1.4.2
[25] evaluate_0.14 rmarkdown_2.6 stringi_1.5.3 compiler_4.0.2
[29] pillar_1.4.7 httpuv_1.5.5 pkgconfig_2.0.3