/
ImputeDCas21_6038.Rmd
192 lines (156 loc) · 7.41 KB
/
ImputeDCas21_6038.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
---
title: "Impute IITA DCas21-6038"
site: workflowr::wflow_site
date: "2021-Aug-08"
output: workflowr::wflow_html
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = FALSE)
```
# Previous
1. [Convert DCas21-6038 report to VCF for imputation](convertDCas21_6038_ToVCF.html):
# Copy data
Copy the imputation reference panel from 2019 to the `data/` folder.
```{bash,eval = FALSE}
mkdir /workdir/mw489/;
cp -r ~/IITA_2021GS /workdir/mw489/;
cp -r /home/jj332_cas/CassavaGenotypeData/CassavaGeneticMap /workdir/mw489/IITA_2021GS/data/;
cp /home/jj332_cas/CassavaGenotypeData/nextgenImputation2019/ImputationStageIII_72619/chr*_RefPanelAndGSprogeny_ReadyForGP_72719.vcf.gz /workdir/mw489/IITA_2021GS/data/;
```
# Impute with West Africa RefPanel
Impute with [Beagle V5.0](https://faculty.washington.edu/browning/beagle/b5_0.html).
Use the "imputation reference panel" dataset from 2019 merged with the imputed GS progeny TMS13-14-15 + TMS18, e.g. `chr1_RefPanelAndGSprogeny_ReadyForGP_72719.vcf.gz` as reference for the current imputation.
Used 1 large memory Cornell CBSU machine (e.g. [cbsulm17; 112 cores, 512 GB RAM](https://biohpc.cornell.edu/lab/hardware.aspx)), running 1 chromosome at a time.
```{bash set-up R environment, eval=F}
# 1) start a screen shell
screen; # or screen -r if re-attaching...
# Project directory, so R will use as working dir.
cd /workdir/mw489/IITA_2021GS/
# 3) Start R
R
```
```{r,eval = FALSE}
targetVCFpath<-here::here("data/Report-DCas21-6038/") # location of the targetVCF
refVCFpath<-here::here("data/")
mapPath<-here::here("data/CassavaGeneticMap/")
outPath<-here::here("output/")
outSuffix<-"DCas21_6038"
```
```{r,eval = FALSE}
library(tidyverse); library(magrittr);
library(genomicMateSelectR)
purrr::map(1:18,
~genomicMateSelectR::runBeagle5(targetVCF=paste0(targetVCFpath,"chr",.,
"_DCas21_6038.vcf.gz"),
refVCF=paste0(refVCFpath,"chr",.,
"_RefPanelAndGSprogeny_ReadyForGP_72719.vcf.gz"),
mapFile=paste0(mapPath,"chr",.,
"_cassava_cM_pred.v6_91019.map"),
outName=paste0(outPath,"chr",.,
"_DCas21_6038_WA_REFimputed"),
nthreads=112))
```
Clean up Beagle log files after run. Move to sub-directory `output/BeagleLogs/`.
```{bash,eval = FALSE}
cd /workdir/mw489/IITA_2021GS/output/;
mkdir BeagleLogs;
cp *_DCas21_6038_WA_REFimputed.log BeagleLogs/
cp -r BeagleLogs ~/IITA_2021GS/output/
cp *_DCas21_6038_WA_REFimputed* ~/IITA_2021GS/output/
cp *_DCas21_6038_WA_REFimputed.vcf.gz ~/IITA_2021GS/output/
```
# Post-impute filter
Standard post-imputation filter: AR2>0.75 (DR2>0.75 as of Beagle5.0), P_HWE>1e-20, MAF>0.005 [0.5%].
Loop to filter all 18 VCF files in parallel
```{r,eval = FALSE}
inPath<-here::here("output/")
outPath<-here::here("output/")
require(furrr); plan(multisession, workers = 18)
future_map(1:18,
~genomicMateSelectR::postImputeFilter(inPath=inPath,
inName=paste0("chr",.,"_DCas21_6038_WA_REFimputed"),
outPath=outPath,
outName=paste0("chr",.,"_DCas21_6038_WA_REFimputedAndFiltered")))
plan(sequential)
```
Check what's left
```{r,eval = FALSE}
purrr::map(1:18,~system(paste0("zcat ",here::here("output/"),"chr",.,"_DCas21_6038_WA_REFimputedAndFiltered.vcf.gz | wc -l")))
# 7580
# 3604
# 3685
# 3411
# 3721
# 3349
# 1716
# 3151
# 3286
# 2635
# 2897
# 2745
# 2625
# 5219
# 3519
# 2751
# 2612
# 2913
```
```{bash, eval=F}
cd /workdir/mw489/IITA_2021GS/output/;
cp -r *_DCas21_6038_WA_REFimputed* ~/IITA_2021GS/output/
```
# Formats for downstream analysis
Need to create a genome-wide VCF with the RefPanel + DCas21_6038 VCFs merged.
The downstream [preprocessing steps](04-PreprocessDataFiles.html) in the pipeline will take that as input to create haplotype and dosage matrices, etc.
```{bash, eval=F}
cd /workdir/mw489/IITA_2021GS/
R;
```
```{r, eval=F}
require(furrr); plan(multisession, workers = 18)
# 1. Subset RefPanel to sites remaining after post-impute filter of DCas21_6038
future_map(1:18,~system(paste0("vcftools --gzvcf ","/workdir/mw489/IITA_2021GS/data/chr",
.,"_RefPanelAndGSprogeny_ReadyForGP_72719.vcf.gz"," ",
"--positions ","/workdir/mw489/IITA_2021GS/data/chr",.,
"_DCas21_6038_WA_REFimputed.sitesPassing"," ",
"--recode --stdout | bgzip -c -@ 24 > ",
"/workdir/mw489/IITA_2021GS/output/chr",.,
"_RefPanelAndGSprogeny72719_SubsetAndReadyToMerge.vcf.gz")))
plan(sequential)
# 2. Merge RefPanel and DCas21_6038
library(tidyverse); library(magrittr); library(genomicMateSelectR)
inPath<-here::here("output/")
outPath<-here::here("output/")
future_map(1:18,~mergeVCFs(inPath=inPath,
inVCF1=paste0("chr",.,"_RefPanelAndGSprogeny72719_SubsetAndReadyToMerge"),
inVCF2=paste0("chr",.,"_DCas21_6038_WA_REFimputedAndFiltered"),
outPath=outPath,
outName=paste0("chr",.,"_RefPanelAndGSprogeny_ReadyForGP_2021Aug08")))
# 3. Concatenate chromosomes
## Index with tabix first
future_map(1:18,~system(paste0("tabix -f -p vcf ",inPath,
"chr",.,"_RefPanelAndGSprogeny_ReadyForGP_2021Aug08.vcf.gz")))
plan(sequential)
## bcftools concat
system(paste0("bcftools concat ",
"--output ",outPath,
"AllChrom_RefPanelAndGSprogeny_ReadyForGP_2021Aug08.vcf.gz ",
"--output-type z --threads 18 ",
paste0(inPath,"chr",1:18,
"_RefPanelAndGSprogeny_ReadyForGP_2021Aug08.vcf.gz",
collapse = " ")))
```
```{bash, eval=F}
cd /workdir/mw489/IITA_2021GS/output/
cp *_RefPanelAndGSprogeny_ReadyForGP_2021Aug08* ~/IITA_2021GS/output/
# vcftools --gzvcf AllChrom_RefPanelAndGSprogeny_ReadyForGP_2021Aug08.vcf.gz
# After filtering, kept 23332 out of 23332 Individuals
# After filtering, kept 61239 out of a possible 61239 Sites
```
# Next
1. [Prepare training dataset](01-cleanTPdata.html): Download data from DB, "Clean" and format DB data.
2. [Get BLUPs combining all trial data](02-GetBLUPs.html): Combine data from all trait-trials to get BLUPs for downstream genomic prediction. Fit mixed-model to multi-trial dataset and extract BLUPs, de-regressed BLUPs and weights. Include two rounds of outlier removal.
3. **[uses imputed data as input]** [Validate the pedigree obtained from cassavabase](03-validatePedigree.html): Before setting up a cross-validation scheme for predictions that depend on a correct pedigree, add a basic verification step to the pipeline. Not trying to fill unknown relationships or otherwise correct the pedigree. Assess evidence that relationship is correct, remove if incorrect.
4. **[uses imputed data as input]** [Preprocess data files](04-PreprocessDataFiles.html): Prepare haplotype and dosage matrices, GRMs, pedigree and BLUPs, genetic map *and* recombination frequency matrix, for use in predictions.