as_vcf()
converts a SNP data.frame generated by make_snp()
to a VCF-like data.frame.
Only the "CHROM", "FORMAT", and "gt" columns are filled.
add_pos_id()
is useful to fill the "POS" and "ID" columns.
it assigns sequential integers to the "POS" column for each "CHROM",
and combines it with "CHROM" to make a unique "ID" values.
write_vcf()
and read_vcf()
are used to write and read VCF files.
If a SNP data.frame is given, it is converted before writing.
Usage
as_vcf(x, phased = TRUE, chrom = NA_character_, pos = NA_integer_)
add_pos_id(x)
write_vcf(x, file)
read_vcf(file)
as_vcf_gt(x, phased = TRUE)
Value
A VCF-like data.frame with "vcf" subclass.
as_vcf_gt()
returns a single-column data.frame with "vcf_gt" subclass.
See also
make_snp()
to generate SNP data.frames.
https://samtools.github.io/hts-specs/ for VCF format specification.
Examples
RNGkind("L'Ecuyer-CMRG")
set.seed(666)
result = tekka("-y20 -l2 --sa 2,2 --sj 2,2")
samples = result$sample_family[[1L]]
ss = c(chr1 = 3, chr2 = 2)
snp = make_snp(samples, ss)
vcf = as_vcf(snp) |> add_pos_id()
vcf
#> # A tibble: 5 × 10
#> CHROM POS ID REF ALT QUAL FILTER INFO FORMAT gt
#> <chr> <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 chr1 1 chr1-1 NA NA NA NA NA GT "0|0\t0|0\t0|0\t0|0\…
#> 2 chr1 2 chr1-2 NA NA NA NA NA GT "0|0\t0|0\t0|0\t0|0\…
#> 3 chr1 3 chr1-3 NA NA NA NA NA GT "0|1\t0|0\t0|0\t0|0\…
#> 4 chr2 1 chr2-1 NA NA NA NA NA GT "0|0\t0|0\t0|0\t0|0\…
#> 5 chr2 2 chr2-2 NA NA NA NA NA GT "0|0\t0|0\t0|0\t0|0\…