Module 5 · Population structure · step 3 of 7
5.3Match build, position and alleles
Commands tested on Windows
In short
We check that each shared site has the same chromosome, DNA position and the two DNA letters that can occur at that site, in both files. This prevents us from comparing different sites that happen to share a name.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: All 48,614 shared IDs agree on chromosome, GRCh38 position and allele pair.
Command
Module setup, needed before this step
R: module setup
source("R/guided.R")cfg <- guided_init()R command
Type or paste into the RStudio console.
1common <- readLines(guided_path(cfg, "5.2", "common.txt"))study <- guided_table(paste0(guided_path(cfg, "4.6"), ".pvar"))reference <- file.path(cfg$data_dir, "pca_reference", "ref1000g_grch38")ref <- guided_table(paste0(reference, ".pvar"))2a <- match(common, study$ID); b <- match(common, ref$ID)pair <- function(a, b) ifelse(a < b, paste0(a, b), paste0(b, a))3stopifnot(all(sub("^chr", "", study$CHROM[a]) == sub("^chr", "", ref$CHROM[b])), all(study$POS[a] == ref$POS[b]), all(pair(study$REF[a], study$ALT[a]) == pair(ref$REF[b], ref$ALT[b])))cat("All", length(common), "shared sites agree on chromosome, position and alleles\n")- Note 1: Read the shared site names and both site tables.
- Note 2: Match site names and compare allele pairs in either order.
- Note 3: Check chromosomes, positions and alleles and print the matched count.
You need
The list of common sites from step 5.2, and the two variant tables (the .pvar files) of the study and the reference.
What we do
Check that the shared variants are really the same variants in both files, before the projection.
Why
Two variants with the same rsID (opens in a new tab) (a public name for a variant) are not always the same variant. For each shared variant, check four things: the genome build, the chromosome, the position and the pair of alleles (opens in a new tab). In step 4.5 the array-style names were replaced by IDs made of position and alleles.
If two files list the same two alleles in a different order, the variant is still compatible. If the allele pair differs, or the DNA strand is not resolved, we cannot accept the match without checking. The projection uses the named allele in each weight. It does not use the order of rows in the two files.
PLINK terminal equivalent. Optional: you do not need it for the course.
Not applicable: this step needs no PLINK command. The R chunk is the complete command.
R reads or calculates the displayed values without changing the genotype files.
Expected result
Show the expected result
All 48,614 shared IDs agree on chromosome, GRCh38 position and allele pair. This checks that the two supplied files are compatible. It is not an independent check against a reference genome sequence file (a FASTA file).
The tested PLINK version is defined in config.R and recorded in
software_versions.txt. Validation: executable chunks and the expected counts passed on Windows.
If something goes wrong
If something goes wrong
Stop at the first error message. Check the input file named in the message and the previous step. Keep the command and the console log. Do not use files from a different dataset version. See troubleshooting (opens in a new tab).
Quick check
Is it safe to match variants only by row position if both .pvar files contain 48,614 rows?
Show the answer
No. Match the variant IDs, and check the position and the alleles.
Files created
None. If a variant does not match, the code stops before the projection.