Last updated: 2021-07-14

Checks: 7 0

Knit directory: implementGMSinCassava/

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(20210504) 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 2953ee6. 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/accuracies.png
    Ignored:    analysis/fig2.png
    Ignored:    analysis/fig3.png
    Ignored:    analysis/fig4.png
    Ignored:    code/.DS_Store
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  accuracies.png
    Untracked:  analysis/docs/
    Untracked:  analysis/speedUpPredCrossVar.Rmd
    Untracked:  code/AlphaAssign-Python/
    Untracked:  code/calcGameticLD.cpp
    Untracked:  code/col_sums.cpp
    Untracked:  code/convertDart2vcf.R
    Untracked:  code/helloworld.cpp
    Untracked:  code/imputationFunctions.R
    Untracked:  code/matmult.cpp
    Untracked:  code/misc.cpp
    Untracked:  code/test.cpp
    Untracked:  data/CassavaGeneticMap/
    Untracked:  data/DatabaseDownload_2021May04/
    Untracked:  data/GBSdataMasterList_31818.csv
    Untracked:  data/IITA_GBStoPhenoMaster_33018.csv
    Untracked:  data/NRCRI_GBStoPhenoMaster_40318.csv
    Untracked:  data/PedigreeGeneticGainCycleTime_aafolabi_01122020.xls
    Untracked:  data/blups_forCrossVal.rds
    Untracked:  data/chr1_RefPanelAndGSprogeny_ReadyForGP_72719.fam
    Untracked:  data/dosages_IITA_filtered_2021May13.rds
    Untracked:  data/genmap_2021May13.rds
    Untracked:  data/haps_IITA_filtered_2021May13.rds
    Untracked:  data/recombFreqMat_1minus2c_2021May13.rds
    Untracked:  fig2.png
    Untracked:  fig3.png
    Untracked:  figure/
    Untracked:  output/IITA_CleanedTrialData_2021May10.rds
    Untracked:  output/IITA_ExptDesignsDetected_2021May10.rds
    Untracked:  output/IITA_blupsForModelTraining_twostage_asreml_2021May10.rds
    Untracked:  output/IITA_trials_NOT_identifiable.csv
    Untracked:  output/crossValPredsA.rds
    Untracked:  output/crossValPredsAD.rds
    Untracked:  output/cvAD_5rep5fold_markerEffects.rds
    Untracked:  output/cvAD_5rep5fold_meanPredAccuracy.rds
    Untracked:  output/cvAD_5rep5fold_parentfolds.rds
    Untracked:  output/cvAD_5rep5fold_predMeans.rds
    Untracked:  output/cvAD_5rep5fold_predVars.rds
    Untracked:  output/cvAD_5rep5fold_varPredAccuracy.rds
    Untracked:  output/cvDirDom_5rep5fold_markerEffects.rds
    Untracked:  output/cvDirDom_5rep5fold_meanPredAccuracy.rds
    Untracked:  output/cvDirDom_5rep5fold_parentfolds.rds
    Untracked:  output/cvDirDom_5rep5fold_predMeans.rds
    Untracked:  output/cvDirDom_5rep5fold_predVars.rds
    Untracked:  output/cvDirDom_5rep5fold_varPredAccuracy.rds
    Untracked:  output/cvMeanPredAccuracyA.rds
    Untracked:  output/cvMeanPredAccuracyAD.rds
    Untracked:  output/cvPredMeansA.rds
    Untracked:  output/cvPredMeansAD.rds
    Untracked:  output/cvVarPredAccuracyA.rds
    Untracked:  output/cvVarPredAccuracyAD.rds
    Untracked:  output/genomicPredictions_ModelAD.rds
    Untracked:  output/genomicPredictions_ModelDirDom.rds
    Untracked:  output/kinship_A_IITA_2021May13.rds
    Untracked:  output/kinship_D_IITA_2021May13.rds
    Untracked:  output/markEffsTest.rds
    Untracked:  output/markerEffects.rds
    Untracked:  output/markerEffectsA.rds
    Untracked:  output/markerEffectsAD.rds
    Untracked:  output/maxNOHAV_byStudy.csv
    Untracked:  output/obsCrossMeansAndVars.rds
    Untracked:  output/parentfolds.rds
    Untracked:  output/ped2check_genome.rds
    Untracked:  output/ped2genos.txt
    Untracked:  output/pednames2keep.txt
    Untracked:  output/pednames_Prune100_25_pt25.log
    Untracked:  output/pednames_Prune100_25_pt25.nosex
    Untracked:  output/pednames_Prune100_25_pt25.prune.in
    Untracked:  output/pednames_Prune100_25_pt25.prune.out
    Untracked:  output/potential_dams.txt
    Untracked:  output/potential_sires.txt
    Untracked:  output/predVarTest.rds
    Untracked:  output/samples2keep_IITA_2021May13.txt
    Untracked:  output/samples2keep_IITA_MAFpt01_prune50_25_pt98.log
    Untracked:  output/samples2keep_IITA_MAFpt01_prune50_25_pt98.nosex
    Untracked:  output/samples2keep_IITA_MAFpt01_prune50_25_pt98.prune.in
    Untracked:  output/samples2keep_IITA_MAFpt01_prune50_25_pt98.prune.out
    Untracked:  output/verified_ped.txt

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/06-GenomicPredictions.Rmd) and HTML (docs/06-GenomicPredictions.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 cc1eb4b wolfemd 2021-07-14 Build site.
Rmd 772750a wolfemd 2021-07-14 DirDom model and selection index calc fully integrated functions.
Rmd b43ee90 wolfemd 2021-07-12 Completed predictCrosses function, which predicts cross usefullness on SELINDs and component traits. Work is shown.
Rmd 0ac841c wolfemd 2021-07-11 Full genomic prediction including (1) genomic prediction of clone GBLUPs and (2) prediction of cross usefulness. (1) is completed. Work shown. (2) is TO DO still.

Previous step

  1. Parent-wise cross-validation: Compute parent-wise cross-validation folds using the validated pedigree. Fit models to get marker effects and make subsequent predictions of cross means and (co)variances.

Current steps

  1. Genomic prediction of clone GEBV/GETGV. Fit GBLUP model, using genotypic add-dom partition. NEW: modelType=“DirDom”, include genome-wide inbreeding effect in GEBV/GETGV predictions after backsolving SNP effects. For all models, extract GBLUPs and backsolve SNP effects for use in cross usefulness predictions (mean+variance predictions). ALSO NEW: selection index predictions.

  2. Genomic prediction of cross \(UC_{parent}\) and \(UC_{variety}\). Rank potential parents on SI. Predict all possible crosses of some portion of best parents.

Genomic prediction of clone GEBV/GETGV

Operate R within a singularity Linux shell within a screen shell.

# 1) start a screen shell 
screen; # or screen -r if re-attaching...
# 2) start the singularity Linux shell inside that
singularity shell /workdir/$USER/rocker.sif; 
# Project directory, so R will use as working dir.
cd /home/mw489/implementGMSinCassava/;
# 3) Start R
R

Load input data

require(tidyverse); require(magrittr); 
# 5 threads per Rsession for matrix math (openblas)
RhpcBLASctl::blas_set_num_threads(5)
# GENOMIC MATE SELECTION FUNCTIONS
source(here::here("code","gmsFunctions.R")) 
source(here::here("code","predCrossVar.R")) 

# GENOMIC RELATIONSHIP MATRICES (GRMS)
grms<-list(A=readRDS(file=here::here("output","kinship_A_IITA_2021May13.rds")),
           D=readRDS(file=here::here("output","kinship_domGenotypic_IITA_2021July5.rds")))

# DOSAGE MATRIX
dosages<-readRDS(file=here::here("data",
                                 "dosages_IITA_filtered_2021May13.rds"))

# BLUPs
blups<-readRDS(file=here::here("data","blups_forCrossVal.rds")) %>% 
  dplyr::select(-varcomp) %>% 
  rename(TrainingData=blups) # for compatibility with downstream functions

# SELECTION INDEX WEIGHTS
## from IYR+IK
## note that not ALL predicted traits are on index
SIwts<-c(logFYLD=20,
         HI=10,
         DM=15,
         MCMDS=-10,
         logRTNO=12,
         logDYLD=20,
         logTOPYLD=15,
         PLTHT=10) 

Run the “AD” and “DirDom” modelTypes built into runGenomicPredictions().

Output contains both GBLUPs for selection of indivuals and SNP effects to use as input for prediction of cross usefulness and subsequent mate selection.

start<-proc.time()[3]
gpreds_ad<-runGenomicPredictions(modelType="AD",selInd=TRUE, SIwts=SIwts,
                                 getMarkEffs=TRUE,
                                 returnPEV=FALSE,
                                 blups=blups,grms=grms,dosages=dosages,
                                 ncores=20,nBLASthreads=5)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(gpreds_ad,file = here::here("output","genomicPredictions_ModelAD.rds"))

gpreds_dirdom<-runGenomicPredictions(modelType="DirDom",selInd=TRUE, SIwts=SIwts,
                                     getMarkEffs=TRUE,
                                     returnPEV=FALSE,
                                     blups=blups,grms=grms,dosages=dosages,
                                     ncores=20,nBLASthreads=5)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(gpreds_dirdom,file = here::here("output","genomicPredictions_ModelDirDom.rds"))

Genomic mate predictions: cross usefulness

  1. Use GBLUPs on SELIND to choose some to fraction of the clones.
  2. For those selected parents, predict the SELIND usefulness for all pairwise matings.
# 1) start a screen shell 
screen; # or screen -r if re-attaching...
# 2) start the singularity Linux shell inside that
singularity shell /workdir/$USER/rocker.sif; 
# Project directory, so R will use as working dir.
cd /home/mw489/implementGMSinCassava/;
# 3) Start R
R

Load input data

require(tidyverse); require(magrittr); 
# 5 threads per Rsession for matrix math (openblas)
#RhpcBLASctl::blas_set_num_threads(5)
# GENOMIC MATE SELECTION FUNCTIONS
source(here::here("code","gmsFunctions.R")) 
source(here::here("code","predCrossVar.R")) 

# DOSAGE MATRIX
dosages<-readRDS(file=here::here("data",
                                 "dosages_IITA_filtered_2021May13.rds"))

# RECOMBINATION FREQUENCY MATRIX
recombFreqMat<-readRDS(file=here::here("data",
                                       "recombFreqMat_1minus2c_2021May13.rds"))
# HAPLOTYPE MATRIX
## keep only haplos for parents-in-the-pedigree
## those which will be used in prediction, saves memory
haploMat<-readRDS(file=here::here("data","haps_IITA_filtered_2021May13.rds"))
parents<-union(ped$sireID,ped$damID) 
parenthaps<-sort(c(paste0(parents,"_HapA"),
                   paste0(parents,"_HapB")))
haploMat<-haploMat[parenthaps,colnames(recombFreqMat)]

# SELECTION INDEX WEIGHTS
## from IYR+IK
## note that not ALL predicted traits are on index
SIwts<-c(logFYLD=20,
         HI=10,
         DM=15,
         MCMDS=-10,
         logRTNO=12,
         logDYLD=20,
         logTOPYLD=15,
         PLTHT=10) 

# SNP EFFECTS - FROM PREVIOUS STEP 
### Two models AD and DirDom
gpreds_ad<-readRDS(file = here::here("output","genomicPredictions_ModelAD.rds"))
gpreds_dirdom<-readRDS(file = here::here("output","genomicPredictions_ModelDirDom.rds"))
### Cor between SELIND GEBV and GETGV between models?
# left_join(gpreds_ad$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELINDad=SELIND),
#           gpreds_dirdom$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELINDdirdom=SELIND)) %>% 
#   group_by(predOf) %>% summarize(SELIND_corModels=cor(SELINDad,SELINDdirdom))
# predOf SELIND_corModels
# GEBV  0.9890091           
# GETGV 0.9373170   

# SELECTION OF CROSSES-TO-BE-PREDICTED
nParentsToSelect<-100
union_bestGEBVandGETGVdirdom<-union(gpreds_dirdom$gblups[[1]] %>% 
                                         filter(predOf=="GEBV") %>% 
                                         arrange(desc(SELIND)) %>% 
                                         slice(1:nParentsToSelect) %$% GID,
                                       gpreds_dirdom$gblups[[1]] %>% 
                                         filter(predOf=="GETGV") %>% 
                                         arrange(desc(SELIND)) %>% 
                                         slice(1:nParentsToSelect) %$% GID)
union_bestGEBVandGETGVad<-union(gpreds_ad$gblups[[1]] %>% 
                                         filter(predOf=="GEBV") %>% 
                                         arrange(desc(SELIND)) %>% 
                                         slice(1:nParentsToSelect) %$% GID,
                                       gpreds_ad$gblups[[1]] %>% 
                                         filter(predOf=="GETGV") %>% 
                                         arrange(desc(SELIND)) %>% 
                                         slice(1:nParentsToSelect) %$% GID)
union_bestGEBVandGETGV<-union(union_bestGEBVandGETGVdirdom,
                              union_bestGEBVandGETGVad)
length(union_bestGEBVandGETGV) 
# [1] 121 parents in top nParentsToSelect on SELIND for GEBV/GETGV - DirDom/AD model.

CrossesToPredict<-crosses2predict(union_bestGEBVandGETGV)
nrow(CrossesToPredict)
# [1] 7381 

Run the “AD” and “DirDom” modelTypes.

cbsulm15 - July 13 - 3:30pm

start<-proc.time()[3]
crossPreds_dirdom<-predictCrosses(modelType="DirDom",stdSelInt = 2.67, 
                                  selInd=TRUE, SIwts=SIwts,
                                  CrossesToPredict=CrossesToPredict,
                                  snpeffs=gpreds_dirdom$genomicPredOut[[1]],
                                  dosages=dosages,
                                  haploMat=haploMat,recombFreqMat=recombFreqMat,
                                  ncores=15,nBLASthreads=5)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(crossPreds_dirdom,file = here::here("output","genomicMatePredictions_top121parents_ModelDirDom.rds"))

# Error: Problem with `mutate()` column `predVars`.
# ℹ `predVars = future_pmap(...)`.
# ✖ Failed to retrieve the value of MultisessionFuture (<none>) from cluster RichSOCKnode #20 (PID 28094 on ‘localhost’). The reason reported was ‘error reading from connection’
# Run `rlang::last_error()` to see where the error occurred.
# In addition: Warning message:
# In list(...) : closing unused connection 3 (localhost)
# > runtime<-proc.time()[3]-start; runtime/60
#  elapsed
# 45.65038

cbsulm15

start<-proc.time()[3]
crossPreds_ad<-predictCrosses(modelType="AD",stdSelInt = 2.67, 
                              selInd=TRUE, SIwts=SIwts,
                              CrossesToPredict=CrossesToPredict,
                              snpeffs=gpreds_ad$genomicPredOut[[1]],
                              dosages=dosages,
                              haploMat=haploMat,recombFreqMat=recombFreqMat,
                              ncores=15,nBLASthreads=5)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(crossPreds_ad,file = here::here("output","genomicMatePredictions_top121parents_ModelAD.rds"))

[TO DO] Write predictions to disk

Add genetic groups and tidy format

# unique_gids<-predModelA %>%
#   dplyr::select(genomicPredOut) %>%
#   unnest(genomicPredOut) %>%
#   select(-varcomps) %>%
#   unnest(gblups) %$%
#   GID %>%
#   unique
# 
# c1a<-unique_gids %>%
#   grep("c1a",.,value = T,ignore.case = T) %>%
#   union(.,unique_gids %>%
#           grep("^F",.,value = T,ignore.case = T) %>%
#           grep("c1b",.,value = T,ignore.case = T,invert = T))
# c1b<-unique_gids%>% grep("c1b",.,value = T,ignore.case = T)
# c2a<-unique_gids %>%
#   grep("C2a",.,value = T,ignore.case = T) %>%
#   grep("NR17",.,value = T,ignore.case = T)
# c2b<-unique_gids %>%
#   grep("C2b",.,value = T,ignore.case = T) %>%
#   .[!. %in% c(c1a,c1b,c2a)]
# c3a<-unique_gids %>%
#   grep("C3a",.,value = T,ignore.case = T) %>%
#   .[!. %in% c(c1a,c1b,c2a,c2b)]
# c3b<-unique_gids %>%
#   grep("NR20C3",.,value = T,ignore.case = T) %>%
#   .[!. %in% c(c1a,c1b,c2a,c2b,c3a)]
# nrTP<-setdiff(unique_gids,unique(c(c1a,c1b,c2a,c2b,c3a,c3b)))

Write CSV’s

# ## Format and write GEBV
# predModelA %>% 
#   select(Trait,genomicPredOut) %>% 
#   unnest(genomicPredOut) %>% 
#   select(-varcomps) %>% 
#   unnest(gblups) %>% 
#   select(-GETGV,-contains("PEV")) %>%
#   spread(Trait,GEBV) %>% 
#   mutate(Group=case_when(GID %in% nrTP ~ "nrTP",
#                          GID %in% c1a ~ "C1a",
#                          GID %in% c1b ~ "C1b",
#                          GID %in% c2a ~ "C2a",
#                          GID %in% c2b ~ "C2b",
#                          GID %in% c3a ~ "C3a",
#                          GID %in% c3b ~ "C3b")) %>% 
#   select(Group,GID,any_of(traits)) %>% 
#   arrange(desc(Group)) %>% 
#   write.csv(., file = here::here("output","GEBV_NRCRI_ModelA_2021May03.csv"), row.names = F)
# 
# ## Format and write GETGV
# predModelADE %>% 
#   select(Trait,genomicPredOut) %>% 
#   unnest(genomicPredOut) %>% 
#   select(-varcomps) %>% 
#   unnest(gblups) %>% 
#   select(GID,Trait,GETGV) %>% 
#   spread(Trait,GETGV) %>% 
#   mutate(Group=case_when(GID %in% nrTP ~ "nrTP",
#                          GID %in% c1a ~ "C1a",
#                          GID %in% c1b ~ "C1b",
#                          GID %in% c2a ~ "C2a",
#                          GID %in% c2b ~ "C2b",
#                          GID %in% c3a ~ "C3a",
#                          GID %in% c3b ~ "C3b")) %>% 
#   select(Group,GID,any_of(traits)) %>% 
#   arrange(desc(Group)) %>% 
#   write.csv(., file = here::here("output","GETGV_NRCRI_ModelADE_2021May03.csv"), row.names = F)
# 
# ### Make a unified "tidy" long-form: 
# predModelA %>% 
#   select(Trait,genomicPredOut) %>% 
#   unnest(genomicPredOut) %>% 
#   select(-varcomps) %>% 
#   unnest(gblups) %>% 
#   select(-GETGV) %>% 
#   full_join(predModelADE %>% 
#               select(Trait,genomicPredOut) %>% 
#               unnest(genomicPredOut) %>% 
#               select(-varcomps) %>% 
#               unnest(gblups) %>% 
#               rename(GEBV_modelADE=GEBV,
#                      PEV_modelADE=PEVa) %>% 
#               select(-genomicPredOut)) %>% 
#   mutate(Group=case_when(GID %in% nrTP ~ "nrTP",
#                          GID %in% c1a ~ "C1a",
#                          GID %in% c1b ~ "C1b",
#                          GID %in% c2a ~ "C2a",
#                          GID %in% c2b ~ "C2b",
#                          GID %in% c3a ~ "C3a",
#                          GID %in% c3b ~ "C3b")) %>% 
#   relocate(Group,.before = GID) %>% 
#   write.csv(., file = here::here("output","genomicPredictions_NRCRI_2021May03.csv"), row.names = F)

Results

See Results: Home for plots and summary tables.


sessionInfo()