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 45e6b20. 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/predictUntestedCrosses.Rmd
) and HTML (docs/predictUntestedCrosses.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 | be1e9fc | wolfemd | 2021-03-24 | Build site. |
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. |
# devtools::install_github("wolfemd/predCrossVar", ref = 'master', force=T)
rm(list=ls()); gc()
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# BLUPs -----------
<-readRDS(here::here("data","blups_forawcdata.rds")) %>%
blupsselect(Trait,blups) %>%
unnest(blups) %>%
select(Trait,germplasmName,drgBLUP) %>%
spread(Trait,drgBLUP) %>%
select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order
# Pedigree -----------
<-readRDS(here::here("data","ped_awc.rds")) %>%
peddistinct(sireID,damID)
<-union(ped$sireID,ped$damID)
parents
# Selection weights -----------
<-readRDS(file=here::here("data","selection_index_weights_4traits.rds"))
indices
# GEBVs --------------
<-readRDS(here::here("output","gblups_geneticgroups.rds")) %>%
gebvsfilter(Group=="All",Model=="A") %>%
unnest(GBLUPs) %>%
select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART")))
<-gebvs %>%
gebvMatcolumn_to_rownames(var = "germplasmName") %>%
as.matrix## GEBVs on the "standard" selection index
%<>%
gebvs mutate(stdSI=as.numeric(gebvMat%*%indices$stdSI))
saveRDS(gebvs,here::here("output","gebvs_ModelA_GroupAll_stdSI.rds"))
## The top 100 on the index
<-gebvs %>%
top100stdSIarrange(desc(stdSI)) %>%
slice(1:100) %$% germplasmName
saveRDS(top100stdSI,here::here("output","top100stdSI.rds"))
# table(top100stdSI %in% parents) # only 3
# length(grep("TMS13|TMS14|TMS15",top100stdSI, invert = T)) # 2
# length(grep("TMS13",top100stdSI)) # 52
# length(grep("TMS14",top100stdSI)) # 31
# length(grep("TMS15",top100stdSI)) # 15
## Highest BV -------------
# gebvs %>%
# slice_max(order_by = stdSI, n=1) # TMS13F1095P0013
## Lowest BV
# gebvs %>%
# filter(germplasmName %in% union(parents,top100stdSI)) %>%
# slice_min(order_by = stdSI, n=1) # IITA-TMS-IBA011371
# Crosses To Predict -------------
<-crosses2predict(union(parents,top100stdSI)) %>% # makes df of pairwise non-recprical, selfs-included crosses
CrossesToPredictbind_rows(ped %>% # add the crosses already made (for convenience)
distinct(sireID,damID)) %>%
# avoid duplication
distinct # nrow(CrossesToPredict) # [1] 47083
saveRDS(CrossesToPredict,here::here("output","CrossesToPredict_top100stdSI_and_209originalParents.rds"))
# activate multithread OpenBLAS
export OMP_NUM_THREADS=88;
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# Crosses To Predict -------------
<-readRDS(here::here("output","CrossesToPredict_top100stdSI_and_209originalParents.rds"))
CrossesToPredict
# Pedigree -----------
<-readRDS(here::here("data","ped_awc.rds")) %>%
peddistinct(sireID,damID)
<-union(ped$sireID,ped$damID)
parents<-readRDS(here::here("output","top100stdSI.rds"))
top100stdSI
# Recomb frequency matrix ------------
<-readRDS(here::here("data","recombFreqMat_1minus2c_awcmap_May2020.rds"))
recombFreqMat
# Haplotype Matrix ------------
<-readRDS(file=here::here("data","haps_awc.rds"))
haploMat<-sort(c(paste0(union(parents,top100stdSI),"_HapA"),
parenthapspaste0(union(parents,top100stdSI),"_HapB")))
<-haploMat[parenthaps,colnames(recombFreqMat)]; dim(haploMat)
haploMat
# Parallelization specs ---------
require(furrr);
options(future.globals.maxSize=50000*1024^2)
<-10;
ncores
# MCMC params ------
<-30000; burnIn<-5000; thin<-5
nIter
# Path for output ----------
<-"output/crossPredictions"
outpath
# getUntestedMtCrossVarPreds function -------------
## Function to run for each rep-fold-Model (==unique set of marker effects), predict the relevant cross variances.
source(here::here("code","getUntestedMtCrossVarPreds.R"))
# Divide CrossesToPredict into chunks for each server ------------
<-5
nchunks%<>%
CrossesToPredict mutate(Chunk=rep(1:nchunks, each=ceiling(nrow(.)/nchunks), length.out=nrow(.))) %>%
nest(data=c(sireID,damID))
# cbsulm13 - done
<-1;
chunk# cbsulm15 - done
<-2;
chunk# cbsulm20 - done
<-3;
chunk# cbsulm22 - done
<-4;
chunk# cbsulm23 - done
<-5;
chunk
# Start run on each server / chunk: Aug 03 at 6:50AM
getUntestedMtCrossVarPreds(inprefix = "mt_All_AD",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossTGVs_chunk",chunk,"_AD"),
predType="VPM", Model = "AD", nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict$data[[chunk]],
recombFreqMat=recombFreqMat,haploMat=haploMat,ncores=ncores)
# cbsulm13 - aug 4, 10pm - done
<-1;
chunk# cbsulm15 - aug 4, 10pm - done
<-2;
chunk# cbsulm20 - aug 4, 6:55am - done
<-3;
chunk# cbsulm22 - aug 4, 10pm - done
<-4;
chunk# cbsulm23 - aug 4, 6:55am - done
<-5;
chunk
# Start run on each server / chunk:
getUntestedMtCrossVarPreds(inprefix = "mt_All_A",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossBVs_chunk",chunk,"_A"),
predType="VPM", Model = "A", nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict$data[[chunk]],
recombFreqMat=recombFreqMat,haploMat=haploMat,ncores=ncores)
# activate multithread OpenBLAS
export OMP_NUM_THREADS=112;
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# Crosses To Predict -------------
<-readRDS(here::here("output","CrossesToPredict_top100stdSI_and_209originalParents.rds"))
CrossesToPredict
# Pedigree -----------
<-readRDS(here::here("data","ped_awc.rds")) %>%
peddistinct(sireID,damID)
<-union(ped$sireID,ped$damID)
parents<-readRDS(here::here("output","top100stdSI.rds"))
top100stdSI
# Recomb frequency matrix ------------
<-readRDS(here::here("data","recombFreqMat_1minus2c_awcmap_May2020.rds"))
recombFreqMat
# Haplotype Matrix ------------
<-readRDS(file=here::here("data","haps_awc.rds"))
haploMat<-sort(c(paste0(union(parents,top100stdSI),"_HapA"),
parenthapspaste0(union(parents,top100stdSI),"_HapB")))
<-haploMat[parenthaps,colnames(recombFreqMat)]; dim(haploMat)
haploMat
# SNP data ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_invariant(.);
# Parallelization specs ---------
require(furrr);
options(future.globals.maxSize=50000*1024^2)
<-10;
ncores
# MCMC params ------
<-30000; burnIn<-5000; thin<-5
nIter
# Path for output ----------
<-"output/crossPredictions"
outpath
# getUntestedMtCrossVarPreds function -------------
## Function to run for each rep-fold-Model (==unique set of marker effects), predict the relevant cross variances.
source(here::here("code","getUntestedMtCrossVarPreds.R"))
# Divide CrossesToPredict into chunks for each server ------------
<-4
nchunks%<>%
CrossesToPredict mutate(Chunk=rep(1:nchunks, each=ceiling(nrow(.)/nchunks), length.out=nrow(.))) %>%
nest(data=c(sireID,damID))
# cbsulm13 - Done!
<-1;
chunk# cbsulm17 - Done!
<-2;
chunk# cbsulm12 - Done!
<-3;
chunk# cbsulm16 - Done!
<-4;
chunk
# Start run on each server / chunk:
getDirDomUntestedMtCrossVarTGVpreds(inprefix = "mt_All_DirectionalDom",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossTGVs_chunk",chunk,"_DirDom"),
predType="VPM", nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict$data[[chunk]],
recombFreqMat=recombFreqMat,haploMat=haploMat,ncores=ncores)
# cbsulm26 - Done! (~32hrs)
<-1;
chunk# cbsulm15 - Done!
<-2;
chunk# cbsulm26 - Done!
<-3;
chunk# cbsulm17 - Done!
<-4;
chunk
# Start run on each server / chunk:
getDirDomUntestedMtCrossVarBVpreds(inprefix = "mt_All_DirectionalDom",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossBVs_chunk",chunk,"_DirDom"),
predType="VPM", nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict$data[[chunk]],
recombFreqMat=recombFreqMat,haploMat=haploMat,doseMat=snps,ncores=ncores)
Discovered a bug effecting self-crosses. The original version of predCrossVar run (circa July 2020) incorrectly calculated gametic LD matrices with duplicated haplotypes for cases where sireID==damID. Fixed the bug in the package, archived the original version via Git/GitHub. Re-install predCrossVar on server and re-do predictions of selfs.
# activate multithread OpenBLAS
export OMP_NUM_THREADS=88;
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# Crosses To Predict -------------
<-readRDS(here::here("output","CrossesToPredict_top100stdSI_and_209originalParents.rds"))
CrossesToPredict# just the selfs
%<>% filter(sireID==damID)
CrossesToPredict # Pedigree -----------
<-readRDS(here::here("data","ped_awc.rds")) %>%
peddistinct(sireID,damID)
<-union(ped$sireID,ped$damID)
parents<-readRDS(here::here("output","top100stdSI.rds"))
top100stdSI
# Recomb frequency matrix ------------
<-readRDS(here::here("data","recombFreqMat_1minus2c_awcmap_May2020.rds"))
recombFreqMat
# Haplotype Matrix ------------
<-readRDS(file=here::here("data","haps_awc.rds"))
haploMat<-sort(c(paste0(union(parents,top100stdSI),"_HapA"),
parenthapspaste0(union(parents,top100stdSI),"_HapB")))
<-haploMat[parenthaps,colnames(recombFreqMat)]; dim(haploMat)
haploMat
# Parallelization specs ---------
require(furrr);
options(future.globals.maxSize=50000*1024^2)
<-10;
ncores
# MCMC params ------
<-30000; burnIn<-5000; thin<-5
nIter
# Path for output ----------
<-"output/crossPredictions"
outpath
# getUntestedMtCrossVarPreds function -------------
## Function to run for each rep-fold-Model (==unique set of marker effects), predict the relevant cross variances.
source(here::here("code","getUntestedMtCrossVarPreds.R"))
# Start run on each server / chunk:
getUntestedMtCrossVarPreds(inprefix = "mt_All_AD",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossTGVs_ReDoSelfs_AD"),
predType="VPM", Model = "AD",
nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict,
recombFreqMat=recombFreqMat,
haploMat=haploMat,ncores=ncores)
# Start run on each server / chunk:
getUntestedMtCrossVarPreds(inprefix = "mt_All_A",
outpath = "output/crossPredictions",
outprefix = paste0("predUntestedCrossBVs_ReDoSelfs_A"),
predType="VPM", Model = "A",
nIter=30000, burnIn=5000,thin=5,
CrossesToPredict=CrossesToPredict,
recombFreqMat=recombFreqMat,
haploMat=haploMat,ncores=ncores)
# activate multithread OpenBLAS
export OMP_NUM_THREADS=112;
library(tidyverse); library(magrittr); library(predCrossVar); library(BGLR);
# Crosses To Predict -------------
<-readRDS(here::here("output","CrossesToPredict_top100stdSI_and_209originalParents.rds"))
CrossesToPredict
# Pedigree -----------
<-readRDS(here::here("data","ped_awc.rds")) %>%
peddistinct(sireID,damID)
<-union(ped$sireID,ped$damID)
parents<-readRDS(here::here("output","top100stdSI.rds"))
top100stdSI
# SNP data ------------
<-readRDS(here::here("data","dosages_awc.rds")) %>%
snpsremove_invariant(.);
# Parallelization specs ---------
require(furrr);
options(future.globals.maxSize=50000*1024^2)
<-10;
ncores
# MCMC params ------
<-30000; burnIn<-5000; thin<-5
nIter
# Path for output ----------
<-"output/crossPredictions"
outpath
# getMtCrossMeanPreds function -------------
source(here::here("code","getMtCrossMeanPreds.R"))
# getDirectionalDomMtCrossMeanPreds function -------------
source(here::here("code","getDirectionalDomMtCrossMeanPreds.R"))
# sampleIDs -------
<-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) %>%
select(germplasmName,all_of(c("DM","logFYLD","MCMDS","TCHART"))) # precaution to ensure consistent column order
<-blups$germplasmName[blups$germplasmName %in% rownames(snps)]
sampleIDsrm(blups)
# Done Aug 8
<-getMtCrossMeanPreds(outprefix="mt_All_A",
predictedUntestedCrossMeansBVModel="A",
CrossesToPredict=CrossesToPredict,
doseMat=snps,
sampleIDs = sampleIDs)
<-getMtCrossMeanPreds(outprefix="mt_All_AD",
predictedUntestedCrossMeansTGVModel="AD",
CrossesToPredict=CrossesToPredict,
doseMat=snps,
sampleIDs = sampleIDs)
saveRDS(predictedUntestedCrossMeansBV,file=here::here("output/crossPredictions","predictedUntestedCrossMeansBV.rds"))
saveRDS(predictedUntestedCrossMeansTGV,file=here::here("output/crossPredictions","predictedUntestedCrossMeansTGV.rds"))
<-getDirectionalDomMtCrossMeanPreds(outprefix="mt_All_DirectionalDom",
predictedUntestedCrossMeansDirDomCrossesToPredict=CrossesToPredict,
doseMat=snps,
sampleIDs = sampleIDs)
saveRDS(predictedUntestedCrossMeansDirDom,
file=here::here("output/crossPredictions","predictedUntestedCrossMeansDirDom.rds"))
Next step, used a server, unpacking output for 10 varcomps x ~47K crosses.
Keep the dom. variance in the “tidied” output long enough to calculate dom. variance on the sel. indices. This was previously not done.
Calc. VarTGV=VarA + VarD only for the sup. tables (Tables S17 and S18), which are used for plots and summaries in the manuscript.
library(tidyverse); library(magrittr); library(predCrossVar)
# Model A
<-list.files(here::here("output/crossPredictions")) %>%
predUntestedCrossVarBVsgrep("predUntestedCrossBVs",.,value = T) %>%
tibble(File=.) %>%
mutate(Model=ifelse(grepl("_A_",File),"A","DirDomBV"),
crossPredictions=map(File,~readRDS(here::here("output/crossPredictions",.)))) %>%
unnest_wider(crossPredictions) %>%
unnest(varcovars) %>%
select(-totcomputetime) %>%
unnest_wider(varcomps) # 10 variances/covariances x 5 chunks x 1 models = 50 blocks of ~10K crosses chunk per varcomp
require(furrr); options(mc.cores=50); plan(multiprocess)
%<>% # in parallel across the 50 chunks
predUntestedCrossVarBVs mutate(predictedfamvars=future_map(predictedfamvars,~unnest(.,predVars) %>% select(-PMV))) %>%
select(-totcomputetime) %>%
unnest(predictedfamvars) %>%
rename(predVar=VPM) %>%
mutate(predOf="VarBV")
%<>% select(-VarComp,-totcomputetime) predUntestedCrossVarBVs
library(tidyverse); library(magrittr); library(predCrossVar)
# Model AD
<-list.files(here::here("output/crossPredictions")) %>%
predUntestedCrossVarTGVsgrep("predUntestedCrossTGVs",.,value = T) %>%
tibble(File=.) %>%
mutate(Model=ifelse(grepl("_AD_",File),"AD","DirDomAD"),
crossPredictions=map(File,~readRDS(here::here("output/crossPredictions",.)))) %>%
unnest_wider(crossPredictions) %>%
unnest(varcovars) %>%
select(-totcomputetime) %>%
unnest_wider(varcomps) # 10 variances/covariances x 5 chunks x 2 models = 100 blocks of ~10K crosses chunk per varcomp
$predictedfamvars[[1]] %>%
predUntestedCrossVarTGVsmutate(Nsegsnps=map_dbl(predVars,~.$Nsegsnps[1]))
require(furrr); options(mc.cores=50); plan(multiprocess)
%<>% # in parallel across the 100 chunks
predUntestedCrossVarTGVs mutate(predictedfamvars=future_map(predictedfamvars,function(predictedfamvars){
return(predictedfamvars %<>%
# format each families output in serial
mutate(Nsegsnps=map_dbl(predVars,~.$Nsegsnps[1]),
predVars=map(predVars,function(predVars){
return(predVars %>%
select(VarComp,VPM)) })) %>%
unnest(predVars))})) %>%
select(-totcomputetime) %>%
unnest(predictedfamvars) %>%
rename(predVar=VPM) %>%
rename(predOf=VarComp)
Remove the original predictions for selfs and replace with the correct predictions.
# verify nrow before removing "re-do's"
%>% dim() # [1] 947780 9
predUntestedCrossVarBVs # df of re-predicted selfs
## should only be from the ClassicAD model
<-predUntestedCrossVarBVs %>%
redoBVsfilter(grepl("_ReDoSelfs_",File))
dim(redoBVs) # [1] 6120 9
%>% count(Model,predOf)
redoBVs # Model predOf n
# <chr> <chr> <int>
# 1 A VarBV 3060
# df of original predictions (selfs and outcrosses)
# predUntestedCrossVarBVs %>%
# filter(!grepl("_ReDoSelfs_",File)) %>% # dim() # [1] 941660 9 # verify redo's removed
# filter(sireID==damID) %>% # dim() # [1] 6120 9 original self's predictions remain at this point
%<>%
predUntestedCrossVarBVs # remove all selfs from the ClassicAD model
filter(sireID!=damID | (sireID==damID & Model=="DirDomBV")) %>% # dim() # [1] 935540 9
# add back the corrected predictions for selfs
bind_rows(.,redoBVs)
<-predUntestedCrossVarTGVs %>%
redoTGVsfilter(grepl("_ReDoSelfs_",File))
dim(redoTGVs) # [1] 12240 11
%<>%
predUntestedCrossVarTGVs # remove all selfs
filter(sireID!=damID | (sireID==damID & Model=="DirDomAD")) %>% # dim() # [1] 1871080 11
# add back the corrected predictions for selfs
bind_rows(.,redoTGVs)
# dim(predUntestedCrossVarTGVs) # [1] 1883320 9
<-bind_rows(predUntestedCrossVarBVs,
predUntestedCrossVars
predUntestedCrossVarTGVs)# left_join(predUntestedCrossVarBVs %>%
# rename(predVarBV=predVarA) %>%
# select(-totcomputetime,-File),
# predUntestedCrossVarTGVs %>%
# rename(predVarTGV=predVarTot) %>%
# select(-predVarA,-predVarD,-totcomputetime,-File)) %>%
# pivot_longer(cols=c(predVarBV,predVarTGV),
# names_to = "predOf",values_to = "predVar")
# predUntestedCrossVars<-bind_rows(predUntestedCrossVarBVs,
# predUntestedCrossVarTGVs)
#predUntestedCrossVars %<>% select(Model,Trait1,Trait2,sireID,damID,predOf,predVar,Nsegsnps,totcomputetime)
saveRDS(predUntestedCrossVars,here::here("output/crossPredictions","predictedUntestedCrossVars_tidy_traits.rds"))
library(tidyverse); library(magrittr); library(predCrossVar)
<-readRDS(here::here("output/crossPredictions","predictedUntestedCrossMeansBV.rds")) %>%
predictedUntestedCrossMeansBVpluck("predictedCrossMeans")
<-readRDS(here::here("output/crossPredictions","predictedUntestedCrossMeansTGV.rds")) %>%
predictedUntestedCrossMeansTGVpluck("predictedCrossMeans")
<-readRDS(here::here("output/crossPredictions","predictedUntestedCrossMeansDirDom.rds")) %>%
predictedUntestedCrossMeansDirDompluck("predictedCrossMeans")
<-predictedUntestedCrossMeansBV %>%
predictedUntestedCrossMeansleft_join(predictedUntestedCrossMeansTGV) %>%
mutate(Model="ClassicAD") %>%
bind_rows(predictedUntestedCrossMeansDirDom %>%
mutate(Model="DirDom"))
saveRDS(predictedUntestedCrossMeans,here::here("output/crossPredictions","predictedUntestedCrossMeans_tidy_traits.rds"))
Our focus in evaluating predictions of untested crosses will be on predictions on the two SI.
times
for predicted means and variances.
library(tidyverse); library(magrittr);
# Selection weights -----------
<-readRDS(file=here::here("data","selection_index_weights_4traits.rds"))
indices
<-readRDS(here::here("output/crossPredictions","predictedUntestedCrossVars_tidy_traits.rds"))
predictedUntestedCrossVars# select(-predVarD,-totcomputetime)
## Predicted Index Variances
<-predictedUntestedCrossVars %>%
predictedUntestedCrossVars_SI# filter(Model=="A") %>%
# mutate(Model="ClassicAD") %>%
# rename(predVarBV=predVarA) %>%
# select(-predVarTot) %>%
# left_join(predictedUntestedCrossVars %>%
# filter(Model=="ClassicAD") %>%
# rename(predVarTGV=predVarTot) %>%
# select(-predVarA)) %>%
# bind_rows(predictedUntestedCrossVars %>%
# filter(Model=="DirDomAD") %>%
# rename(predVarBV=predVarA,
# predVarTGV=predVarTot)) %>%
# pivot_longer(cols=c(predVarBV,predVarTGV),names_to = "predOf",values_to = "predVar") %>%
nest(varcovars=c(Trait1,Trait2,predVar))
require(furrr); options(mc.cores=50); plan(multiprocess)
%<>%
predictedUntestedCrossVars_SI mutate(varcovars=future_map(varcovars,
function(varcovars){
# pairwise to square symmetric matrix
<-varcovars %>%
gmatspread(Trait2,predVar) %>%
column_to_rownames(var = "Trait1") %>%
%>%
as.matrix $Trait,indices$Trait]
.[indiceslower.tri(gmat)]<-t(gmat)[lower.tri(gmat)]
gmat[return(gmat) }))
%<>%
predictedUntestedCrossVars_SI mutate(stdSI=future_map_dbl(varcovars,~t(indices$stdSI)%*%.%*%indices$stdSI),
biofortSI=future_map_dbl(varcovars,~t(indices$biofortSI)%*%.%*%indices$biofortSI)) %>%
select(-varcovars)
%<>%
predictedUntestedCrossVars_SI pivot_longer(cols = c(stdSI,biofortSI),
names_to = "Trait1",
values_to = "predVar") %>%
mutate(Trait2=Trait1)
# pivot_wider(names_from = "predOf", values_from = "predVar")
# predictedUntestedCrossVars_SI %<>%
# pivot_longer(cols = c(predVarBV,predVarTGV), names_to = "predOf", values_to = "predVar")
%<>%
predictedUntestedCrossVars_SI select(Trait1,Trait2,sireID,damID,Nsegsnps,Model,predOf,predVar)
saveRDS(predictedUntestedCrossVars_SI,here::here("output/crossPredictions","predictedUntestedCrossVars_SelIndices.rds"))
# Selection weights -----------
<-readRDS(file=here::here("data","selection_index_weights_4traits.rds"))
indices<-readRDS(here::here("output/crossPredictions","predictedUntestedCrossMeans_tidy_traits.rds"))
predictedUntestedCrossMeans%<>%
predictedUntestedCrossMeans pivot_longer(cols = c(sireGEBV,damGEBV,predMeanBV,predMeanGV), names_to = "predOf", values_to = "predMean")
## Predicted Index Means
%<>%
predictedUntestedCrossMeans spread(Trait,predMean) %>%
nest(predMeans=all_of(indices$Trait)) %>%
mutate(stdSI=map_dbl(predMeans,~as.matrix(.)%*%indices$stdSI),
biofortSI=map_dbl(predMeans,~as.matrix(.)%*%indices$biofortSI)) %>%
select(-predMeans) %>%
pivot_longer(cols = c(stdSI,biofortSI), names_to = "Trait", values_to = "predMean")
%<>%
predictedUntestedCrossMeans pivot_wider(names_from = "predOf", values_from = "predMean") %>%
select(sireID,damID,Model,Trait,sireGEBV,damGEBV,predMeanBV,predMeanGV)
saveRDS(predictedUntestedCrossMeans,here::here("output/crossPredictions","predictedUntestedCrossMeans_SelIndices.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