#' @title Convert vcfR object to SNAPP format data..
#' @description The function converts vcfR format data to SNAPP nexus format.
#' @param vcf a vcfR object.
#' @param outfile name of output file.
#' @return SNAPP nexus format file.
#'
#' @details
#' This function converts the vcfR object to a SNAPP nexus format file.
#'
#'
#' @export
vcf2SNAPP <- function(vcf, file = "snapp.nex") {
vcf <- extract.indels(vcf)
vcf <- vcf[is.biallelic(vcf),]
gt.filtered <- extract.gt(vcf, element = "GT", as.numeric = T, convertNA = T)
gt.filtered[is.na(gt.filtered)] <- "?"
gt.filtered <- t(gt.filtered)
ape::write.nexus.data(gt.filtered, file)
snapp.file <- scan(file, what = "character", sep = "\n",
quiet = TRUE)
bgn <- grep("BEGIN", snapp.file)
snapp.file[bgn] <- "BEGIN CHARACTERS;"
fmt <- grep("FORMAT", snapp.file)
snapp.file[fmt] <- " FORMAT DATATYPE=INTEGER MISSING=? GAP=- SYMBOLS=\"012\" LABELS=LEFT TRANSPOSE=NO INTERLEAVE=NO;"
#return(snapp.file)
write(snapp.file, file)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.