Skip to contents

Converts a VCFArrow object to BayesAss format infile

Usage

vcf2bayesass(vcf_arrow, out_file, keep_groups = NULL)

Arguments

vcf_arrow

-> VCFArrow object

out_file

-> name of file to output, no default (character)

keep_groups

-> groups to retain, default NULL (character)

Value

Invisibly returns the input VCFArrow object; called for its side effect of writing out_file.

Details

This function converts a VCFArrow object to an external BayesAss formatted file. Writing occurs in chunks whose size is determined by the read_vcf() function. Larger chunks result in faster writing speeds. If no groups are defined, the default behavior is to use all groups. Only biallelic SNVs are exported (multiallelic sites and indels are left out), and every sample must be assigned to a group (see set_vcf_groups()), also when keep_groups is NULL. The file is in BA3's native format: one line per individual and locus, 'indivID popID locID allele1 allele2', separated by spaces, with the alleles labeled 1 (REF) and 2 (ALT) and a missing genotype as '0 0'. Sample names, group labels and locus names must not contain spaces. BA3 accepts at most 100,000 loci, 100 populations and 20,000 individuals; a warning is given above these limits.

Author

Tomas Hrbek May 2026

Examples

f <- system.file("extdata", "vaillantii_discosnp_sub.vcf.gz",
                 package = "VCFArrow")
vcf <- read_vcf(f) |> set_vcf_groups(dirname(f))
#> ℹ VCF is being read in chunks of 50000 variants
#> ✔ VCF successfully read into a VCFArrow object
vcf2bayesass(vcf, out_file = tempfile(fileext = ".immanc"))
#> ℹ Accumulating BayesAss: 9313 variants x 18 samples (0 MiB raw storage)
#> ℹ Writing BayesAss file...
#> ✔ BayesAss file written to /tmp/Rtmpq4egqB/file1db2333ebfd3.immanc