Converts a VCFArrow object to Treemix format infile
Usage
vcf2treemix(
vcf_arrow,
out_file,
keep_groups = NULL,
gzip = grepl("\\.gz$", out_file)
)Details
This function converts a VCFArrow object to an external Treemix 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 first line holds the group names; each further line one SNP, with the REF and ALT allele counts of each group as "ref,alt", separated by spaces. TreeMix reads gzip-compressed input (treemix -i file.gz): name out_file with the extension .gz to compress it.
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
vcf2treemix(vcf, out_file = tempfile(fileext = ".gz"))
#> ℹ Building Treemix: 9313 variants x 4 pops (0 MiB raw storage)
#> ℹ Writing Treemix file...
#> ✔ Treemix file written to /tmp/Rtmpq4egqB/file1db2319a2494.gz