Merge variant info from two sources with allele-flip-aware matching
Source:R/sumstatsQc.R
mergeVariantInfo.RdMerges variant metadata (chromosome, position, ref, alt) from two sources, detecting and correcting allele flips (where alt/ref are swapped). Creates a canonical key from sorted alleles to match across datasets.
Arguments
- variants1
A data.frame with columns
chrom,pos,alt,ref, or aGRangeswith corresponding metadata columns.- variants2
A data.frame or
GRangeswith the same columns.- all
Logical. If TRUE (default), returns the union of both sets. If FALSE, returns only variants from
variants2(flipped to matchvariants1's allele orientation).
Examples
v1 <- data.frame(chrom = "1", pos = 1:3, alt = "A", ref = "G")
v2 <- data.frame(chrom = "1", pos = 2:4, alt = "A", ref = "G")
mergeVariantInfo(v1, v2, all = TRUE)
#> # A tibble: 4 × 4
#> chrom pos alt ref
#> <chr> <int> <chr> <chr>
#> 1 1 1 A G
#> 2 1 2 A G
#> 3 1 3 A G
#> 4 1 4 A G