R/vcf2plink.R

Defines functions vcf2plink

#' @export
vcf2plink <- function(vcf, out, mode = 1L) {
  
  if(missing(out)) out <- rm.extension(vcf)
  
  # Checking if required programs are installed on system path
  program_on_path("plink")
  
  # Checking mode
  if(!mode %in% 1:2)
    stop("mode must be 1 (for binary files ─ .bed/.bim/.fam) or 2 (for human-readable files ─ .ped/.map).")
  
  # Conversion from VCF to Plink format
  if(mode == 1L) {
    # Conversion from VCF to Plink binary format
    plink(`--vcf` = vcf, "--make-bed", `--out` = out)
  } else {
    # Conversion from VCF to Plink human-readable format
    plink(`--vcf` = vcf, "--recode", `--out` = out)
  }  
  
}
cmcouto-silva/gt documentation built on June 6, 2021, 7:14 p.m.