Last updated: 2022-06-02
Checks: 6 1
Knit directory: EMBRAPAImputation2022/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has staged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish
to commit the R Markdown file and build the HTML.
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(20220303)
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 95ddcaf. 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: .Rhistory
Ignored: .Rproj.user/
Ignored: data/DArT2018/
Ignored: data/DArT2020/
Ignored: data/DArT2022/
Ignored: data/GBS/
Ignored: output/DArT2022/
Untracked files:
Untracked: DArTCommonMkrs.log
Untracked: MkrsRefandStudyPop.txt
Untracked: analysis/CheckImp.Rmd
Untracked: analysis/Duplicates.Rmd
Untracked: analysis/ImputationEMBRAPA_DCas22_6902.Rmd
Untracked: analysis/PrepareGenData.Rmd
Untracked: code/.DS_Store
Untracked: code/plink/
Untracked: data/AllDArTDuplicates.txt
Untracked: data/CommonMkrsGBSDArT
Untracked: data/CommonMkrsGBSDArT.txt
Untracked: data/CommonMkrsGBSDArTIssues
Untracked: data/DArTClones.csv
Untracked: data/DArTDupDiscordanceIndex.csv
Untracked: data/DArTDuplicates1.txt
Untracked: data/DArTDuplicates2.txt
Untracked: data/DArTDuplicates3.txt
Untracked: data/DArTDuplicates4.txt
Untracked: data/DArTGPInfo.csv
Untracked: data/DArTGPInfo.xlsx
Untracked: data/DArTGPInfo2.csv
Untracked: data/DArTGPInfo2.xlsx
Untracked: data/DArTGenotypingPlates/
Untracked: out.log
Untracked: output/AllChrDCas22_6902_StudyPopimputed.vcf.gz
Untracked: output/AllChrDCas22_6902_StudyPopimputed.vcf.gz.tbi
Untracked: output/AllChrGBSandDArTsitesCommonClones_RefPopImputed.vcf.gz
Untracked: output/AllChrGBSandDArTsitesCommonClones_RefPopImputed.vcf.gz.tbi
Untracked: output/BRTP_Phenotyping2022.txt
Untracked: output/DCas22_6902/
Untracked: output/DCas22_6902RefPopImputed.vcf.gz
Untracked: output/Dados GBS Atualizados.RData
Untracked: output/DadosGBSAtualizados.rds
Untracked: output/DadosGBSAtualizadosRenomeados.rds
Untracked: output/Duplicates/
Untracked: output/Figures/
Untracked: output/GBSDArTPCA.rds
Untracked: output/GmatrixDArTGS.rds
Untracked: output/GmatrixGBSandDArTGS.rds
Untracked: output/RefPop/
Untracked: output/StudyPop/
Unstaged changes:
Modified: .DS_Store
Modified: analysis/DArTImp.Rmd
Modified: analysis/GBS_DArTImp.Rmd
Modified: analysis/_site.yml
Modified: analysis/index.Rmd
Modified: data/.DS_Store
Modified: output/.DS_Store
Modified: output/out.log
Staged changes:
Modified: .DS_Store
New: analysis/DArTImp.Rmd
New: analysis/GBS_DArTImp.Rmd
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.
There are no past versions. Publish this analysis with wflow_publish()
to start tracking its development.
Imputation is performed by chromosome
java -Xms2g -Xmx [maxmem] -jar /programs/beagle/beagle.jar gt= [targetVCF] map= [mapFile] out= [outName] nthreads= [nthreads] impute= [impute] ne= [ne]
runBeagle5Luc <- function(targetVCF, mapFile, outName, nthreads, maxmem = "500g",
impute = TRUE, ne = 1e+05, samplesToExclude = NULL){
system(paste0("java -Xms2g -Xmx", maxmem, " -jar /programs/beagle/beagle.jar ",
"gt=", targetVCF, " ", "map=", mapFile, " ",
"out=", outName, " ", "nthreads=", nthreads,
" impute=", impute, " ne=", ne,
ifelse(!is.null(samplesToExclude),
paste0(" excludesamples=", samplesToExclude), "")))}
targetVCFpath<-here::here("output/") # location of the targetVCF
mapPath<-here::here("data", "CassavaGeneticMapV6updated/")
outPath<-here::here("output/")
outSuffix<-"DCas22_6902"
library(tidyverse); library(magrittr);
purrr::map(1:18,
~runBeagle5Luc(targetVCF=paste0(targetVCFpath,"chr",.,
"_DCas22_6902_DArTseqLD_AllSites_AllChrom_rawFiltered.vcf.gz"),
mapFile=paste0(mapPath,"chr",.,
"_cassava_cM_pred.v6_91019.map"),
outName=paste0(outPath,"chr",.,
"_DCas22_6902_DArT_imputed"),
nthreads=110))
Organize the Beagle logs in a directory
cd ~/Desktop/Genotyping/DArT/EMBRAPA/DCas22_6902/output/
mkdir BeagleLogs
cp *_DCas22_6902_DArT_imputed.log BeagleLogs/.
rm *_DCas22_6902_DArT_imputed.log
Standard post-imputation filter: \(CR≥0.6\), \(MAF≥(1/7827)^2\).
Loop to filter all 18 VCF files in parallel
inPath<-here::here("output/")
outPath<-here::here("output/")
require(furrr); plan(multisession, workers = 18)
future_map(1:18,
~FilterLuc(inPath=inPath,
inName=paste0("chr",.,"_DCas22_6902_DArT_imputed"),
outPath=outPath,
outName=paste0("chr",.,"_DCas22_6902_DArT_imputedAndFiltered"),
CRthresh = 0.6))
plan(sequential)
Let’s check what we got
purrr::map(1:18,~system(paste0("zcat ",here::here("output/"),"chr",.,"_DCas22_6902_DArT_imputedAndFiltered.vcf.gz | wc -l")))
Chr 1 - 1064
Chr 2 - 696
Chr 3 - 682
Chr 4 - 682
Chr 5 - 634
Chr 6 - 656
Chr 7 - 428
Chr 8 - 532
Chr 9 - 520
Chr 10 - 664
Chr 11 - 591
Chr 12 - 468
Chr 13 - 508
Chr 14 - 707
Chr 15 - 516
Chr 16 - 437
Chr 17 - 543
Chr 18 - 480
library(tidyverse); library(magrittr)
### Joint all the 18 Chromosome VCF to one unique file
inPath <- here::here("output/")
future_map(1:18,~system(paste0("tabix -f -p vcf ",inPath,
"chr",.,"_DCas22_6902_DArT_imputedAndFiltered.vcf.gz")))
system(paste0("bcftools concat ",
"--output ",
"AllChrom_DArT_ReadyForGP_2022May05.vcf.gz ",
"--output-type z --threads 7 ",
paste0("chr",1:18,
"_DCas22_6902_DArT_imputedAndFiltered.vcf.gz",
collapse = " ")))
### Post Imputation Filter function
postImputeFilterLuc <- function(inPath=NULL,inName,outPath=NULL,outName,HWEthresh=1e-20){
require(magrittr); require(dplyr)
# Extract imputation quality scores (DR2 and AF) from VCF
system(paste0("vcftools --gzvcf ",inPath,inName,".vcf.gz --hardy --out ",outPath,inName))
# Read scores into R
hwe<-read.table(paste0(outPath,inName,".hwe"),
stringsAsFactors = F, header = T)
stats2filterOn<-hwe %>% rename(CHROM=CHR)
# Compute MAF from AF and make sure numeric
# Identify sites passing filter
sitesPassingFilters<-stats2filterOn %>%
dplyr::filter(P_HWE>HWEthresh) %>%
dplyr::select(CHROM,POS)
print(paste0(nrow(sitesPassingFilters)," sites passing filter"))
# Write a list of positions passing filter to disk
write.table(sitesPassingFilters,
file = paste0(outPath,inName,".sitesPassing"),
row.names = F, col.names = F, quote = F)
# Apply filter to vcf file with vcftools
system(paste0("vcftools --gzvcf ",inPath,inName,".vcf.gz"," ",
"--positions ",outPath,inName,".sitesPassing"," ",
"--recode --stdout | bgzip -c -@ 24 > ",
outPath,outName,".vcf.gz"))
print(paste0("Filtering Complete: ",outName))
}
inPath<-here::here("")
outPath<-here::here("")
ncores <- 7
nclones <- 7827
require(furrr); options(mc.cores=ncores); plan(multiprocess)
postImputeFilterLuc(inPath=inPath,
inName=paste0("AllChrom_DArT_ReadyForGP_2022May05"),
outPath=outPath,
outName=paste0("AllChrom_DArT_ReadyForGP_2022May30"))
system(paste0("vcftools --gzvcf output/AllChrom_DArT_ReadyForGP_2022May30.vcf.gz --maf 0.00025",
" --recode --stdout | bgzip -c -@ 7 > output/AllChrom_DArT_ReadyForGPFil_2022May30.vcf.gz"))
dgenomicMateSelectR::convertVCFtoDosage(pathIn = "output/", pathOut = "output/",
vcfName = "AllChrom_DArT_ReadyForGPFil_2022May30")
snps <- read.table(file = here::here("output", "AllChrom_DArT_ReadyForGPFil_2022May30.raw"),
stringsAsFactor=F, header = T) %>%
dplyr::select(-FID,-PAT,-MAT,-SEX,-PHENOTYPE) %>%
column_to_rownames(var = "IID") %>%
as.matrix()
saveRDS(snps,file = here::here("output", "DCas22_DArT_ReadyForGP_Dos.rds"))
library(tidyverse); library(CMplot)
snps <- readRDS(file = here::here("output", "DArT2022", "DCas22_DArt_ReadyForGP_Dos.rds"))
CMsnps <- tibble(SNP = colnames(snps),
chr = substring(SNP,1,3),
pos = substring(SNP,4)) %>%
mutate(chr = gsub(pattern = "_", replacement = "", x = chr) %>%
gsub(pattern = "S", replacement = "") %>% as.integer,
pos = gsub(pattern = "_[A-Z]", replacement = "", x = pos) %>%
gsub(pattern = "_", replacement = "", x = .) %>% as.integer)
CMplot(CMsnps, plot.type = "d", bin.size = 1e6, col = c("darkgreen", "yellow", "red"),
file = "jpg", memo = "DArTDensityMkrs", dpi = 500, file.output = T, verbose = TRUE)
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] magrittr_2.0.3 data.table_1.14.3 forcats_0.5.1 stringr_1.4.0
[5] dplyr_1.0.9 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0
[9] tibble_3.1.7 ggplot2_3.3.6 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 here_1.0.1 lubridate_1.8.0 assertthat_0.2.1
[5] rprojroot_2.0.3 digest_0.6.29 utf8_1.2.2 R6_2.5.1
[9] cellranger_1.1.0 backports_1.4.1 reprex_2.0.1 evaluate_0.15
[13] highr_0.9 httr_1.4.3 pillar_1.7.0 rlang_1.0.2
[17] readxl_1.4.0 rstudioapi_0.13 jquerylib_0.1.4 rmarkdown_2.14
[21] labeling_0.4.2 munsell_0.5.0 broom_0.8.0 compiler_4.1.2
[25] httpuv_1.6.5 modelr_0.1.8 xfun_0.30 pkgconfig_2.0.3
[29] htmltools_0.5.2 tidyselect_1.1.2 workflowr_1.7.0 fansi_1.0.3
[33] crayon_1.5.1 tzdb_0.3.0 dbplyr_2.1.1 withr_2.5.0
[37] later_1.3.0 grid_4.1.2 jsonlite_1.8.0 gtable_0.3.0
[41] lifecycle_1.0.1 DBI_1.1.2 git2r_0.30.1 scales_1.2.0
[45] cli_3.3.0 stringi_1.7.6 farver_2.1.0 fs_1.5.2
[49] promises_1.2.0.1 xml2_1.3.3 bslib_0.3.1 ellipsis_0.3.2
[53] generics_0.1.2 vctrs_0.4.1 tools_4.1.2 glue_1.6.2
[57] hms_1.1.1 fastmap_1.1.0 yaml_2.3.5 colorspace_2.0-3
[61] rvest_1.0.2 knitr_1.38 haven_2.5.0 sass_0.4.1