Last updated: 2021-08-26

Checks: 7 0

Knit directory: IITA_2021GS/

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 c2c7dae. 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

Untracked files:
    Untracked:  data/DatabaseDownload_2021Aug08/
    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/Report-DCas21-6038/
    Untracked:  data/blups_forGP.rds
    Untracked:  data/chr1_RefPanelAndGSprogeny_ReadyForGP_72719.fam
    Untracked:  data/dosages_IITA_2021Aug09.rds
    Untracked:  data/haps_IITA_2021Aug09.rds
    Untracked:  data/recombFreqMat_1minus2c_2021Aug02.qs
    Untracked:  output/

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 19c3a38 wolfemd 2021-08-19 Build site.
html e029efc wolfemd 2021-08-12 Build site.
Rmd efebeab wolfemd 2021-08-12 Cross-validation and genomic mate predictions complete. All results updated.
html 1c03315 wolfemd 2021-08-11 Build site.
Rmd e4df79f wolfemd 2021-08-11 Completed IITA_2021GS pipeline including imputation and genomic prediction. Last bit of cross-validation and cross-prediction finishes in 24 hrs.
Rmd 1d017cb wolfemd 2021-07-25 Debugging completed for predictCrosses(). Work shown and tests passed also shown. Full run underway.
html 934141c wolfemd 2021-07-14 Build site.
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

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

Load input data

# NEEDED LIBRARIES
require(tidyverse); require(magrittr); library(qs)
library(genomicMateSelectR)

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

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

# SNP SETS TO ANALYZE
snpsets<-readRDS(file = here::here("data","snpsets.rds"))

# 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 “DirDom” modelTypes built into runGenomicPredictions(). Output will contain both GBLUPs for selection of clones and SNP effects to use as input for prediction of cross usefulness and subsequent mate selection.

Get effects for: full_set (~31K SNPs), medium_set (~13K, LD-pruned) and reduced_set (~9K SNPs, LD-pruned).

# cbsulm30 - 112 cores, 512 GB RAM - 2021 Aug 10 - 8:40am 
snpSet<-"full_set"
grms<-list(A=readRDS(here::here("output","kinship_A_IITA_2021Aug09.rds")), 
           D=readRDS(here::here("output","kinship_Dgeno_IITA_2021Aug09.rds")))
# [1] "Time elapsed: 24.066 mins"

# cbsulm30 - 112 cores, 512 GB RAM - 2021 Aug 10 - 8:40am
snpSet<-"reduced_set"
grms<-list(A=readRDS(here::here("output","kinship_A_ReducedSNPset_IITA_2021Aug09.rds")), 
           D=readRDS(here::here("output","kinship_Dgeno_ReducedSNPset_IITA_2021Aug09.rds")))
# [1] "Time elapsed: 22.431 mins"

# cbsulm20 - 88 cores, 512 GB RAM - 2021 Aug 10 - 2:50pm
snpSet<-"medium_set"
grms<-list(A=readRDS(here::here("output","kinship_A_MediumSNPset_IITA_2021Aug09.rds")), 
           D=readRDS(here::here("output","kinship_Dgeno_MediumSNPset_IITA_2021Aug09.rds")))
# [1] "Time elapsed: 13.299 mins"
snps2keep<-snpsets %>% 
  filter(Set==snpSet) %>% 
  select(snps2keep) %>% 
  unnest(snps2keep)

dosages<-dosages[,snps2keep$FULL_SNP_ID]
rm(snpsets); gc()

starttime<-proc.time()[3]
gpreds<-runGenomicPredictions(modelType="DirDom",selInd=TRUE, SIwts=SIwts,
                              getMarkEffs=TRUE,
                              returnPEV=FALSE,
                              blups=blups,grms=grms,dosages=dosages,
                              ncores=11,nBLASthreads=5)
saveRDS(gpreds,
        file = here::here("output",
                          paste0("genomicPredictions_",snpSet,"_2021Aug09.rds")))
endtime<-proc.time()[3]; print(paste0("Time elapsed: ",
                                      round((endtime-starttime)/60,3)," mins"))

Genomic prediction of cross usefulness

  1. Use GBLUPs on SELIND to choose top fraction of the clones. Cross-reference with ‘accessions_infield’ list.
  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 ~/rocker2.sif; 
# Project directory, so R will use as working dir.
cd /home/mw489/IITA_2021GS/;
# 3) Start R
R
# NEEDED LIBRARIES
require(tidyverse); require(magrittr); library(qs)
library(genomicMateSelectR)

# BLUPs
blups<-readRDS(file=here::here("data","blups_forGP.rds")) %>% 
  dplyr::select(-varcomp)

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

# RECOMBINATION FREQUENCY MATRIX (UNFILTERED)
recombFreqMat<-qread(file=here::here("data",
                                     "recombFreqMat_1minus2c_2021Aug02.qs"))

# HAPLOTYPE MATRIX (UNFILTERED)
## 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_2021Aug09.rds"))
parents<-union(ped$sireID,ped$damID) 
parenthaps<-sort(c(paste0(parents,"_HapA"),
                   paste0(parents,"_HapB")))
haploMat<-haploMat[parenthaps,]

# SNP SETS TO ANALYZE
snpsets<-readRDS(file = here::here("data","snpsets.rds"))

# 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) 

# LIST OF ACCESSIONS LIKELY IN THE FIELD
accessions_infield<-readRDS(here::here("data",
                                       "accessions_possibly_infield_2021Aug10.rds"))
# gpreds_full<-readRDS(file = here::here("output","genomicPredictions_full_set_2021Aug09.rds"))
# gpreds_medium<-readRDS(file = here::here("output","genomicPredictions_medium_set_2021Aug09.rds"))
# gpreds_reduced<-readRDS(file = here::here("output","genomicPredictions_reduced_set_2021Aug09.rds"))
### Quick check that GBLUPs from full and medium_set are strongly correlated
### This will be an additional assurance that similar cross variances
### will be predicted by the reduced SNP model

### Cor between SELIND GEBV and GETGV between full_set and reduced_set of SNPs?
# left_join(gpreds_full$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELIND_full=SELIND),
#           gpreds_reduced$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELIND_reduced=SELIND)) %>%
#   group_by(predOf) %>% 
#   summarize(SELIND_corModels=cor(SELIND_full,SELIND_reduced))
# predOf  SELIND_corModels
# GEBV  0.0363334           
# GETGV 0.7809016   
## TERRIBLE!! :(

### Cor between SELIND GEBV and GETGV between full_set and medium_set of SNPs?
# left_join(gpreds_full$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELIND_full=SELIND),
#           gpreds_medium$gblups[[1]] %>% select(GID,predOf,SELIND) %>% rename(SELIND_medium=SELIND)) %>%
#   group_by(predOf) %>% 
#   summarize(SELIND_corModels=cor(SELIND_full,SELIND_medium))
# predOf  SELIND_corModels
# GEBV  0.9901325           
# GETGV 0.9887326
## EXCELLENT!! :)

Choose the best parents for which to predict crosses. Use the GBLUPs from the full_set of SNPs.

Take the union of the top 300 clones on the SELIND in terms of GEBV and of GETGV. Probably they will be a very similar list.

# SELECT THE BEST PARENTS AS CROSSES-TO-BE-PREDICTED
nParentsToSelect<-300
gpreds_full<-readRDS(file = here::here("output","genomicPredictions_full_set_2021Aug09.rds"))
union_bestGEBVandGETGV<-union(gpreds_full$gblups[[1]] %>% 
                                filter(predOf=="GEBV") %>% 
                                arrange(desc(SELIND)) %>% 
                                slice(1:nParentsToSelect) %$% GID,
                              gpreds_full$gblups[[1]] %>% 
                                filter(predOf=="GETGV") %>% 
                                arrange(desc(SELIND)) %>% 
                                slice(1:nParentsToSelect) %$% GID)
rm(gpreds_full); 
length(union_bestGEBVandGETGV) 
# [1] 365 parents in top nParentsToSelect on SELIND for GEBV/GETGV 

# KEEP ONLY CANDIDATE PARENTS EXPECTED TO BE IN THE FIELD
table(union_bestGEBVandGETGV %in% accessions_infield$FullSampleName)
# FALSE  TRUE 
#   165   200
parentsToPredictCrosses<-union_bestGEBVandGETGV %>% 
  .[. %in% accessions_infield$FullSampleName]
CrossesToPredict<-crosses2predict(parentsToPredictCrosses)
nrow(CrossesToPredict)
# [1] 20100 possible crosses of 200 parents

saveRDS(parentsToPredictCrosses,
        file = here::here("output",
                          "parentsToPredictCrosses_2021Aug10.rds"))
saveRDS(CrossesToPredict,
        file = here::here("output",
                          "CrossesToPredict_2021Aug10.rds"))

Predict all pairwise crosses of those 200 parents.

# cbsulm17 - 112 cores, 512 GB RAM - 2021 Aug 11 - 8:10am
snpSet<-"full_set"
grms<-list(A=readRDS(here::here("output","kinship_A_IITA_2021Aug09.rds")), 
           D=readRDS(here::here("output","kinship_Dgeno_IITA_2021Aug09.rds")))
predTheMeans<-TRUE; predTheVars<-FALSE
gpreds<-readRDS(file = here::here("output","genomicPredictions_full_set_2021Aug09.rds")); gc()
## takes ~2 minutes, predicting means only

# cbsulm17 - 112 cores, 512 GB RAM - 2021 Aug 10 - 8:25am
snpSet<-"medium_set"
grms<-list(A=readRDS(here::here("output","kinship_A_MediumSNPset_IITA_2021Aug09.rds")), 
           D=readRDS(here::here("output","kinship_Dgeno_MediumSNPset_IITA_2021Aug09.rds")))
predTheMeans<-TRUE; predTheVars<-TRUE
gpreds<-readRDS(file = here::here("output","genomicPredictions_medium_set_2021Aug09.rds")); gc()
# 1263.904
snps2keep<-snpsets %>% 
  filter(Set==snpSet) %>% 
  select(snps2keep) %>% 
  unnest(snps2keep)

dosages<-dosages[,snps2keep$FULL_SNP_ID]
haploMat<-haploMat[,snps2keep$FULL_SNP_ID]
recombFreqMat<-recombFreqMat[snps2keep$FULL_SNP_ID,snps2keep$FULL_SNP_ID]
rm(snpsets); gc()
snpSet; dim(dosages); predTheMeans; predTheVars

start<-proc.time()[3]
crossPreds<-predictCrosses(modelType="DirDom",stdSelInt = 2.0627128, 
                           selInd=TRUE, SIwts=SIwts,
                           CrossesToPredict=CrossesToPredict,
                           snpeffs=gpreds$genomicPredOut[[1]],
                           dosages=dosages,
                           haploMat=haploMat,recombFreqMat=recombFreqMat,
                           ncores=20,nBLASthreads=5,
                           predTheMeans = predTheMeans,
                           predTheVars = predTheVars)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(crossPreds,file = here::here("output",
                                     paste0("genomicMatePredictions_",
                                            snpSet,"_2021Aug10.rds")))

Write tidy breeder-friendly predictions to disk

Add genetic groups and cohort identifiers and tidy format

library(tidyverse); library(magrittr)
gpreds<-readRDS(file = here::here("output","genomicPredictions_full_set_2021Aug09.rds")) 
gpreds$gblups[[1]] %>% 
  mutate(GeneticGroup=case_when(grepl("2013_|TMS13",GID)~"C1",
                                grepl("TMS14",GID)~"C2",
                                grepl("TMS15",GID)~"C3",
                                grepl("TMS18",GID)~"C4",
                                grepl("TMS20",GID)~"C5",
                                grepl("TMS16",GID)~"TMS16",
                                grepl("TMS17",GID)~"TMS17",
                                grepl("TMS19",GID)~"TMS19",
                                !grepl("2013_|TMS13|TMS14|TMS15|TMS16|TMS17|TMS18|TMS19|TMS20",GID)~"PreGS"),
         #GeneticGroup=factor(GeneticGroup,levels = c("PreGS","C1","C2","C3","C4","C5","TMS16","TMS17","TMS19")),
         Cohort=case_when(grepl("2013_|TMS13",GID)~"TMS13",
                          grepl("TMS14",GID)~"TMS14",
                          grepl("TMS15",GID)~"TMS15",
                          grepl("TMS16",GID)~"TMS16",
                          grepl("TMS17",GID)~"TMS17",
                          grepl("TMS18",GID)~"TMS18",
                          grepl("TMS19",GID)~"TMS19",
                          grepl("TMS20",GID)~"TMS20",
                          !grepl("2013_|TMS13|TMS14|TMS15|TMS16|TMS17|TMS18|TMS19|TMS20",GID)~"PreGS")) %>% 
  relocate(GeneticGroup,.after = "predOf") %>% 
  relocate(Cohort,.after = "GeneticGroup") %>% 
  arrange(predOf,desc(SELIND)) %>% 
  write.csv(.,file = here::here("output","genomicPredictions_full_set_2021Aug09.csv"),
            row.names = F)

NOTE: For cross predictions, check that the predMean from full and medium set are highly correlated. As long as that is true, combine the predMean from full set with pred var from medium set.

crossPreds_full<-readRDS(file = here::here("output","genomicMatePredictions_full_set_2021Aug10.rds"))
crossPreds_medium<-readRDS(file = here::here("output","genomicMatePredictions_medium_set_2021Aug10.rds"))
crossPreds_full$tidyPreds[[1]] %>% 
  rename(predMean_full=predMean) %>% 
  left_join(crossPreds_medium$tidyPreds[[1]] %>% 
              rename(predMean_medium=predMean)) %>% 
  group_by(predOf,Trait) %>% 
  summarize(corPredMeans=cor(predMean_full,predMean_medium),.groups = 'drop') %>% 
  arrange(desc(corPredMeans)) %$% summary(corPredMeans)
 #   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 # 0.9493  0.9798  0.9928  0.9855  0.9960  0.9981 

The lowest corPredMeans was 0.95 for the SELIND, perhaps unsurprisingly.

Mean corPredMeans=0.9855. I think we are good to go.

Make a plot (below) to examine the scaling of predMean_medium vs. predMean_full to be sure that combining predMean_full with predSD_medium is safe. Seems like it. Everything is on the same scale as expected.

# crossPreds_full$tidyPreds[[1]] %>% 
#   rename(predMean_full=predMean) %>% 
#   left_join(crossPreds_medium$tidyPreds[[1]] %>% 
#               rename(predMean_medium=predMean)) %>% 
#   ggplot(aes(x=predMean_full,y=predMean_medium)) + 
#   geom_point() + 
#   geom_abline(slope=1,color='darkred') +
#   facet_wrap(~Trait, scales='free')

Recompute predUsefulness using predMean_full before saving to disk.

crossPreds_full$tidyPreds[[1]] %>% 
  left_join(crossPreds_medium$tidyPreds[[1]] %>% 
              rename(predMean_medium=predMean)) %>% 
  mutate(predUsefulness=predMean+(2.0627128*predSD),
         sireGroup=case_when(grepl("2013_|TMS13",sireID)~"TMS13",
                                    grepl("TMS14",sireID)~"TMS14",
                                    grepl("TMS15",sireID)~"TMS15",
                                    grepl("TMS16",sireID)~"TMS16",
                                    grepl("TMS17",sireID)~"TMS17",
                                    grepl("TMS18",sireID)~"TMS18",
                                    grepl("TMS19",sireID)~"TMS19",
                                    grepl("TMS20",sireID)~"TMS20",
                                    !grepl("2013_|TMS13|TMS14|TMS15|TMS16|TMS17|TMS18|TMS19|TMS20",sireID)~"PreGS"),
         damGroup=case_when(grepl("2013_|TMS13",damID)~"TMS13",
                                    grepl("TMS14",damID)~"TMS14",
                                    grepl("TMS15",damID)~"TMS15",
                                    grepl("TMS16",damID)~"TMS16",
                                    grepl("TMS17",damID)~"TMS17",
                                    grepl("TMS18",damID)~"TMS18",
                                    grepl("TMS19",damID)~"TMS19",
                                    grepl("TMS20",damID)~"TMS20",
                            !grepl("2013_|TMS13|TMS14|TMS15|TMS16|TMS17|TMS18|TMS19|TMS20",damID)~"PreGS"),
         CrossGroup=paste0(sireGroup,"x",damGroup)) %>%
  relocate(contains("Group"),.before = "Nsegsnps") %>% 
  relocate(predMean,.before = "predMean_medium") %>% 
  arrange(predOf,Trait,desc(predUsefulness)) %>% 
  write.csv(.,file = here::here("output","genomicMatePredictions_2021Aug10.csv"),
            row.names = F)

Results

See Results: Home for plots and summary tables.


sessionInfo()