/
06-GenomicPredictions.Rmd
728 lines (593 loc) · 29.8 KB
/
06-GenomicPredictions.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
---
title: "Genomic predictions"
author: "Marnin Wolfe"
date: "2021-July-08"
output:
workflowr::wflow_html:
toc: true
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = F,
eval = FALSE, # <- NOTE THAT EVAL SET TO FALSE!
tidy='styler', tidy.opts=list(strict=FALSE,width.cutoff=100), highlight=TRUE)
```
# Previous step
5. [Parent-wise cross-validation](05-CrossValidation.html): 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
```{bash Renv, eval=F}
# 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
```{r inputs for GP}
# 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).
```{r GP analysis chunks}
# 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"
```
```{r run GP for each snpset}
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.
```{bash Renv for crossPreds, eval=F}
# 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
```
```{r crossPred input}
# 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"))
```
```{r cor of GBLUPs among snpsets, eval=F}
# 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.
```{r select best parents for crossPreds, eval=F}
# 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.
```{r crossPred analysis chunks, eval=F}
# 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
```
```{r run crossPreds for each snpset, eval=F}
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")))
```
## Predict crosses for clones in Ubiaja
September 10th, 2021: received from I. Kayondo a list of plots in Ubiaja available for crosses (`data/Mate_selection_parental.pool.xlsx`). Match these lines to genomic data and (if not already done) predict matings!
First thing, match the germplasm in the list provided to genotype data...
```{r, eval=F}
library(genomicMateSelectR)
library(tidyverse); library(magrittr)
dbdata<-readRDS(here::here("output","IITA_ExptDesignsDetected_2021Aug08.rds"))
dosages<-readRDS(file=here::here("data","dosages_IITA_2021Aug09.rds"))
parent_candidates<-readxl::read_xlsx(here::here("data","Mate_selection_parental.pool.xlsx")) %>%
distinct(accession_name) %>%
rename(germplasmName=accession_name) %>%
left_join(dbdata %>%
distinct(germplasmName,GID,FullSampleName))
```
1354 unique germplasm to select among. Some genotyped multiple times, so 1576 geno matches.
```{r, eval=F}
parent_candidates %>%
filter(is.na(GID)) %>%
distinct(germplasmName) %>%
write.table(.,file=here::here("output","parent_candidates_NOGENOS.txt"),col.names = F, row.names = F, quote = F)
parent_candidates %>%
filter(!FullSampleName %in% rownames(dosages),
!is.na(FullSampleName)) %>%
distinct(germplasmName) %>%
write.table(.,file=here::here("output","parent_candidates_PEDIGREEREJECT.txt"),col.names = F, row.names = F, quote = F)
parent_candidates %<>%
filter(FullSampleName %in% rownames(dosages)) %>%
distinct(germplasmName,FullSampleName) %>%
group_by(germplasmName) %>%
slice(1)
parent_candidates %>%
write.table(.,file=here::here("output","parent_candidates_TOPREDICT.txt"),col.names = F, row.names = F, quote = F)
CrossesToPredict<-genomicMateSelectR::crosses2predict(parents)
# nrow(CrossesToPredict)
# [1] 258840 possible crosses of 719 parents
saveRDS(CrossesToPredict,
file = here::here("output",
"CrossesToPredict_2021Sep13.rds"))
```
13 lines don't seem to have matches in SNP data.
552 lines DO have SNP data, but seem to have been excluded from my analyses at the [pedigree-validation step here](03-validatePedigree.html) because they had neither BLUPs (useful training data) nor could their pedigree be validated.
That might not be what you want, since as long as the genomic data matches the clone in the field, even without a verified pedigree it could be a useful parent for crossing. Also, my pedigree verification could have false rejections. So care should be taken. Two lists of clones for you: `output/parent_candidates_NOGENOS.txt`, `output/parent_candidates_PEDIGREEREJECT.txt`.
719 germplasmName have genotype data matches and verified pedigrees. Some have more than one DNA sample, so I will choose one for each.
Because there are PLENTY of candidate parents, I suggest to proceed for now, but some action or decision should be made about the 552 germplasm not-yet-considered.
File with the list I suggeset to work from: `ouptput/parent_candidates_TOPREDICT.txt`.
You can match the predictions I make with your field plots based on match the "germplasmName" column in this file with the "accession_name" column in the `Mate_selection_parental.pool.xlsx` file you shared with me.
Regarding the number of crosses I can predict:
It took 21 hrs on a single 112 core server to predict 20100 crosses (pairwise for 200 parents).
For pairwise crosses among 719 in-field parents, 258840 crosses-to-predict. 271 hrs or 11 days.
I could secure at least 3 servers and do it in about 3-5 actual days.
Or I could take the top 500 parents (125250 crosses) or 400 parents (80200 crosses) and cut it down to as little as 2 days.
Delivery end of week vs mid-week?
```{bash, eval=F}
# 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
```
```{r, eval=F}
# 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 FOR CROSS PREDICTIONS
parents<-read.table(here::here("output","parent_candidates_TOPREDICT.txt"), header = F, stringsAsFactors = F)$V2
# SUBSET HAPS
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)
# CROSSES TO PREDICT
CrossesToPredict<-readRDS(here::here("output",
"CrossesToPredict_2021Sep13.rds"))
```
```{r full_set predMeans, eval=F}
# cbsulm26 - 88 cores, 512 GB RAM - 2021 Sep 13
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()
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=17,nBLASthreads=5,
predTheMeans = predTheMeans,
predTheVars = predTheVars)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(crossPreds,file = here::here("output",
paste0("genomicMatePredictions_",
snpSet,"_2021Sep13.rds")))
# elapsed
# 14.7936 minutes
```
```{r medium_set predVars in 3 chunks, eval=F}
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()
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
# DIVIDE CROSSES-TO-PREDICT INTO 3 CHUNKS
CrossesToPredict %<>%
mutate(Chunk=rep_along(along = CrossesToPredict$sireID, 1:3) %>% sort(.)) %>%
nest(Crosses=c(sireID,damID))
# cbsulm26 - 88 cores, 512 GB RAM - 2021 Sep 13, 10:20am
CrossesToPredict<-CrossesToPredict$Crosses[[1]]
chunk<-1
# [1] "Done predicting fam vars. Took 3867.09 mins for 86280 crosses" = 64.45 hrs = 2.68 days
# [1] "Done predicting fam vars. Took 1658.5 mins for 86280 crosses"
# 5548.574
## two runs of predCrossVars() function internally
## to predictCrosses() for the DirDom model
## 3867.09/86280 = 0.045 min per cross
## (3867.09*2)/86280 = 0.089 total mins per cross (for DirDom model)
# cbsulm18 - 88 cores, 512 GB RAM - 2021 Sep 13, 9:30am
CrossesToPredict<-CrossesToPredict$Crosses[[2]]
chunk<-2
# [1] "Done predicting fam vars. Took 3700.52 mins for 86280 crosses" = 61.67 hrs = 2.57 days
# [1] "Done predicting fam vars. Took 1600.63 mins for 86280 crosses"
# 5323.687 mins elapsed total
# cbsulm19 - 88 cores, 512 GB RAM - 2021 Sep 13, 9:30am
CrossesToPredict<-CrossesToPredict$Crosses[[3]]
chunk<-3
# [1] "Done predicting fam vars. Took 3659.66 mins for 86280 crosses"
# [1] "Done predicting fam vars. Took 1609.88 mins for 86280 crosses"
# 5292.067 = 88.2 hrs = 3.67 days
CrossesToPredict %>% head
## 128.9 hrs = 5.37 days expected for 3 servers (each 88 core, 512 GB RAM)
## to deliver ~260K cross predictions for an directional dominance model with
## an 8 trait SI and 13K SNPs
```
```{r, eval=F}
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=17,nBLASthreads=5,
predTheMeans = predTheMeans,
predTheVars = predTheVars)
runtime<-proc.time()[3]-start; runtime/60
saveRDS(crossPreds,file = here::here("output",
paste0("genomicMatePredictions_",
snpSet,"_chunk",chunk,"_2021Sep13.rds")))
```
# Write tidy breeder-friendly predictions to disk
## August 2021
Add genetic groups and cohort identifiers and tidy format
```{r output tidy csv of gebv/getgv, eval=F}
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.
```{r load usefulness predictions, eval=F}
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_medium$rawPreds[[1]]
```
```{r corPredMeans full-medium, eval=F}
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.
```{r plot predMeans full vs medium, eval=F}
# 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.
```{r output tidy UC predictions, eval=F}
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)
```
## September 2021
**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.
```{r, eval=F}
library(tidyverse); library(magrittr)
crossPreds_full<-readRDS(file = here::here("output","genomicMatePredictions_full_set_2021Sep13.rds"))
crossPreds_medium<-readRDS(file = here::here("output","genomicMatePredictions_medium_set_chunk1_2021Sep13.rds")) %>%
bind_rows(readRDS(file = here::here("output","genomicMatePredictions_medium_set_chunk2_2021Sep13.rds"))) %>%
bind_rows(readRDS(file = here::here("output","genomicMatePredictions_medium_set_chunk3_2021Sep13.rds"))) %>%
select(tidyPreds) %>%
unnest(tidyPreds)
```
```{r, eval=F}
crossPreds_full$tidyPreds[[1]] %>%
rename(predMean_full=predMean) %>%
left_join(crossPreds_medium %>%
rename(predMean_medium=predMean)) %>%
group_by(predOf,Trait) %>%
summarize(corPredMeans=cor(predMean_full,predMean_medium),.groups = 'drop') %>%
arrange(desc(corPredMeans)) %$% summary(corPredMeans)
# Joining, by = c("sireID", "damID", "predOf", "Trait")
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 0.9585 0.9732 0.9863 0.9818 0.9889 0.9964
```
The lowest corPredMeans was 0.95 for the SELIND, perhaps unsurprisingly.
Mean corPredMeans=0.98. 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.
Recompute **predUsefulness** using **predMean_full** before saving to disk.
```{r, eval=F}
crossPreds_full$tidyPreds[[1]] %>%
left_join(crossPreds_medium %>%
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_2021Sep18.csv"),
row.names = F)
```
# Results
See [Results](07-Results.html): Home for plots and summary tables.