/
04-GetGBLUPs.Rmd
166 lines (143 loc) · 5.23 KB
/
04-GetGBLUPs.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
---
title: "Genomic predictions"
author: "Marnin Wolfe"
date: "2020-December-21"
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,
tidy='styler', tidy.opts=list(strict=FALSE,width.cutoff=100), highlight=TRUE)
```
# Previous step
3. [Check prediction accuracy](03-CrossValidation.html): Evaluate prediction accuracy with cross-validation.
# Objective
**Current Step**
4. [Genomic prediction](09-GetGBLUPs.html): Predict _genomic_ BLUPs (GEBV and GETGV) for all selection candidates using all available data.
# Set-up
```{bash, eval=F}
cd /home/jj332_cas/marnin/TARI_2020GS/;
export OMP_NUM_THREADS=56 # activate multithread OpenBLAS
```
```{r, eval=F}
library(tidyverse); library(magrittr);
source(here::here("code","gsFunctions.R"))
A<-readRDS(file=here::here("output","Kinship_A_TARI_2021Jan21.rds"))
# BLUPs from the 2 stage procedure
# (stage 1 of 2)
blups<-readRDS(file=here::here("output","tari_blupsForModelTraining_twostage_asreml_2021Jan21.rds")) %>%
select(Trait,blups) %>%
unnest(blups) %>%
select(-`std error`) %>%
filter(GID %in% rownames(A)) %>%
nest(TrainingData=-Trait)
```
# Prediction
`runGenomicPredictions()`
cbsurobbins (112 cores; 512GB)
Model A
```{r, eval=F}
options(future.globals.maxSize= 1500*1024^2)
predModelA<-runGenomicPredictions(blups,modelType="A",grms=list(A=A),gid="GID",ncores=14)
saveRDS(predModelA,file = here::here("output","genomicPredictions_ModelA_twostage_TARI_2021Jan21.rds"))
```
Model ADE
```{r, eval=F}
D<-readRDS(file=here::here("output","Kinship_D_TARI_2021Jan21.rds"))
AD<-readRDS(file=here::here("output","Kinship_AD_TARI_2021Jan21.rds"))
options(future.globals.maxSize= 3000*1024^2)
predModelADE<-runGenomicPredictions(blups,modelType="ADE",grms=list(A=A,D=D,AD=AD),gid="GID",ncores=14)
saveRDS(predModelADE,file = here::here("output","genomicPredictions_ModelADE_twostage_TARI_2021Jan21.rds"))
```
# Write GEBV/GETV to disk
```{r}
rm(list=ls()); gc()
library(tidyverse); library(magrittr);
predModelA<-readRDS(file = here::here("output","genomicPredictions_ModelA_twostage_TARI_2021Jan21.rds"))
predModelADE<-readRDS(file = here::here("output","genomicPredictions_ModelADE_twostage_TARI_2021Jan21.rds"))
traits<-c("MCMDS","MCBSDS","CBSDRS","CGMS1","CGMS2","DM","PLTHT","HI",
"logDYLD", "logFYLD","logTOPYLD","logRTNO")
```
```{r}
# 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)]
# nrTP<-setdiff(unique_gids,unique(c(c1a,c1b,c2a,c2b,c3a)))
```
```{r}
## Format and write GEBV
predModelA %>%
select(Trait,genomicPredOut) %>%
unnest(genomicPredOut) %>%
select(-varcomps) %>%
unnest(gblups) %>%
select(-GETGV,-contains("PEV")) %>%
spread(Trait,GEBV) %>%
mutate(Group=ifelse(grepl("[...]",GID),"DCas20_5629","TARI_TP")) %>%
select(Group,GID,any_of(traits)) %>%
arrange(desc(Group)) %>%
write.csv(., file = here::here("output","GEBV_TARI_ModelA_2021Jan21.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=ifelse(grepl("[...]",GID),"DCas20_5629","TARI_TP")) %>%
select(Group,GID,any_of(traits)) %>%
arrange(desc(Group)) %>%
write.csv(., file = here::here("output","GETGV_TARI_ModelADE_2021Jan21.csv"), row.names = F)
```
```{r}
#
# ### Make a unified "tidy" long-form:
# predModelA %>%
# select(Trait,Dataset,genomicPredOut) %>%
# unnest(genomicPredOut) %>%
# select(-varcomps) %>%
# unnest(gblups) %>%
# select(-GETGV) %>%
# full_join(predModelADE %>%
# select(Trait,Dataset,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")) %>%
# relocate(Group,.before = GID) %>%
# write.csv(., file = here::here("output","genomicPredictions_TARI_2020Oct15.csv"), row.names = F)
```
# Results
See [Results](05-Results.html): Home for plots and summary tables.