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


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/index.Rmd) and HTML (docs/index.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
Rmd 95ddcaf LucianoRogerio 2022-05-05 Imputation of DArT Genotypic data
html 95ddcaf LucianoRogerio 2022-05-05 Imputation of DArT Genotypic data
Rmd 8204f0e LucianoRogerio 2022-03-03 Start workflowr project.

New Imputation for EMBRAPA with DArT Marker only and DArT plus GBS Markers

Diversity Array Technology LTDA joint all the genotyping data from the four Genotyping Orders that EMBRAPA requested during these six or seven years in one huge file.

So let’s check what we got at the DArT report for EMBRAPA DArT genotyping of 2022

library(genomicMateSelectR)
dir("data/DArT2022")
nskipvcf <- 2
nskipcounts <- 2
VCF2022 <- read.table(here::here("data", "DArT2022", "Report_6902_VCF_Ref_Version6.txt"),
                      sep = "\t", header = T, skip = nskipvcf, comment.char = "",
                      check.names = F)
Counts2022 <- read.table(here::here("data", "DArT2022",
                                    "SEQ_SNPs_counts_0_Target_extend_Ref.csv"),
                         sep = ",", header = T, skip = nskipcounts, check.names = F)
Counts2022[1:10,1:50]
VCF2022[1:10,1:30]
genomicMateSelectR::convertDart2vcf(dartvcfInput = here::here("data", "DArT2022", "Report_6902_VCF_Ref_Version6.txt"),
                                    dartcountsInput = here::here("data", "DArT2022", "SEQ_SNPs_counts_0_Target_extend_Ref.csv"),
                                    nskipvcf = 2, nskipcounts = 2,
                                    outName = "output/DCas22_6902", ncores = 1)

Add the VCF header to the DArT VCF file

system(paste0("bgzip -d -@ 7 output/DArT2022/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf.gz > ",
              "output/DArT2022/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf"))

DArTVCFFileSel <- read.table(file = here::here("output", "DArT2022",
                                               "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf"),
                             sep = "\t", header = T, comment.char = "", check.names = F)

header <- c("##fileformat=VCFv4.0",
            "##FORMAT=<ID=GT,Number=1,Type=String,Description=\"Genotype\">",
            "##FORMAT=<ID=AD,Number=.,Type=Integer,Description=\"Allelic depths for the reference and alternate alleles in the order listed\">",
            "##FORMAT=<ID=DP,Number=1,Type=Integer,Description=\"Read Depth (only filtered reads used for calling)\">",
            "##FORMAT=<ID=PL,Number=3,Type=Float,Description=\"Normalized, Phred-scaled likelihoods for AA,AB,BB genotypes where A=ref and B=alt; not applicable if site is not biallelic\">")

write_lines(header, file = here::here("output", "DCas22_6902",
                                      "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf"),
            append = F)
write.table(x = DArTVCFFileSel, file = here::here("output", "DCas22_6902",
                                                  "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf"),
            quote = F, row.names = F, append = T, col.names = T, sep = "\t")

system(paste0("bgzip -c -@ 7 output/DCas22_6902/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf > ",
              "output/DCas22_6902/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.vcf.gz"))

Filtering the DArT markers previously the Beagle imputation

library(here); library(tidyverse)
library(magrittr); library(dplyr)

## Parameters for the Filter function
inPath <- "output/"
inName <- "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw"
outPath <- "output/"
outName <- "DCas22_6902_DArTseqLD_AllSites_AllChrom_rawFiltered"

FilterLuc <- function(inPath = NULL, inName, outPath = NULL, outName, CRthresh = 0.6){
    system(paste0("vcftools --gzvcf ", inPath, inName, ".vcf.gz --freq2 --out ", 
        outPath, inName))
    system(paste0("vcftools --gzvcf ", inPath, inName, ".vcf.gz --missing-site --out ", 
        outPath, inName))
    
    INFO <- read.table(paste0(outPath, inName, ".frq"), stringsAsFactors = F, 
        header = F, skip = 1) %>%
      rename(CHROM = V1, POS = V2, N_ALLELES = V3,
             N_CHR = V4, FREQ1 = V5, FREQ2 = V6)
    callrate <- read.table(paste0(outPath, inName, ".lmiss"), stringsAsFactors = F, 
        header = T) %>% dplyr::select(CHR, POS, N_DATA, F_MISS) %>%
      mutate(CHROM = CHR,
             CR = 1 - F_MISS,
             .keep = "unused")
    
    stats2filterOn <- left_join(INFO, callrate)
    stats2filterOn %<>% dplyr::mutate(FREQ2 = as.numeric(FREQ2)) %>% 
        dplyr::mutate(MAF = ifelse(FREQ2 > 0.5,
                                   yes = 1 - FREQ2, no = FREQ2)) %>% 
      dplyr::select(-FREQ1, -FREQ2)
    
    MAFthresh <- (1/max(stats2filterOn$N_DATA, na.rm = T))**2
    
    sitesPassingFilters <- stats2filterOn %>%
      dplyr::filter(MAF >= MAFthresh, CR >= CRthresh) %>%
      dplyr::select(CHROM, POS)
    print(paste0(nrow(sitesPassingFilters), " sites passing filter"))
    write.table(sitesPassingFilters, file = paste0(outPath, inName, 
        ".sitesPassing"), row.names = F, col.names = F, quote = F)
    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))
}

FilterLuc(inPath=inPath, inName=inName,
          outPath=outPath, outName=outName,
          CRthresh = 0.6)
Download of the Raw Filtered VCF
cd output/DArT2022

scp lbraatz@cbsulm35.biohpc.cornell.edu:/workdir/lbraatz/DCas22_6902/output/DCas22_6902_DArTseqLD_AllSites_AllChrom_rawFiltered.vcf.gz .

scp lbraatz@cbsulm35.biohpc.cornell.edu:/workdir/lbraatz/DCas22_6902/output/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.lmiss .

scp lbraatz@cbsulm35.biohpc.cornell.edu:/workdir/lbraatz/DCas22_6902/output/DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.frq .

cd ../..
MAF and Call Rate of the Raw data
library(tidyverse); library(here)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.7     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
here() starts at /Users/lbd54/Documents/GitHub/EMBRAPAImputation2022
library(reactable)
INFO <- read.table(here::here("output", "DArT2022", "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.frq"),
                   stringsAsFactors = F, 
                   header = F, skip = 1) %>%
  rename(CHROM = V1, POS = V2, N_ALLELES = V3,
         N_CHR = V4, FREQ1 = V5, FREQ2 = V6)
callrate <- read.table(here::here("output", "DArT2022", "DCas22_6902_DArTseqLD_AllSites_AllChrom_raw.lmiss"),
                       stringsAsFactors = F, 
                       header = T) %>% dplyr::select(CHR, POS, N_DATA, F_MISS) %>%
  mutate(CHROM = CHR,
         CR = 1 - F_MISS,
         .keep = "unused")

stats2filterOn <- left_join(INFO, callrate)
Joining, by = c("CHROM", "POS")
stats2filterOn %<>% dplyr::mutate(FREQ2 = as.numeric(FREQ2)) %>% 
  dplyr::mutate(MAF = ifelse(FREQ2 > 0.5,
                             yes = 1 - FREQ2, no = FREQ2)) %>% 
  dplyr::select(-FREQ1, -FREQ2)
MAFthresh <- (1/max(stats2filterOn$N_DATA, na.rm = T))**2

stats2filterOn %<>% filter(!is.na(CHROM), CR >= 0.6, MAF >= MAFthresh) %>% 
  select(CR, MAF) %>% rename(CallRate = CR) %>% reshape2::melt(.)
No id variables; using all as measure variables
stats2filterOn %>% ggplot(aes(x= value)) + 
  geom_density() + facet_grid(~variable, scales = "free_x") + theme_minimal()

Version Author Date
95ddcaf LucianoRogerio 2022-05-05

Split the VCF per chromosome

require(furrr); plan(multisession, workers = 18)
options(future.globals.maxSize=+Inf); options(future.rng.onMisuse="ignore")
  
vcfIn<-here::here("output/","DCas22_6902_DArTseqLD_AllSites_AllChrom_rawFiltered.vcf.gz")
filters<-"--minDP 4 --maxDP 50" # because using GT not PL for impute (Beagle5)
outPath<-here::here("output/")
outSuffix<-"DCas22_6902_DArTseqLD_AllSites_AllChrom_rawFiltered"

future_map(1:18,
           ~genomicMateSelectR::splitVCFbyChr(Chr=.,
                                              vcfIn=vcfIn,filters=filters,
                                              outPath=outPath,
                                              outSuffix=outSuffix))
plan(sequential)

Genomic Prediction Analysis for Yield traits