MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 2.5

Module 2 · Files and formats · step 5 of 8

2.5Alleles and strand

Commands tested on Windows

In short

We compare the DNA letters at each site with the supplied reference table. We correct 400 sites read from the opposite DNA strand and remove 3,013 sites whose letters cannot establish a clear match.

Do this

You should see: 400 sites are flipped and 3,013 sites are excluded. 2,016 samples and 296,510 variants remain.

Command

Module setup, needed before this step

R: module setup

source("R/guided.R")cfg <- guided_init()

Blue: PLINK option · Orange: value you can change · Green: file name

R command

Type or paste into the RStudio console.

1bim <- read_ws(paste0(cfg$input, ".bim"), header = FALSE)ann <- guided_table(file.path(cfg$data_dir, "array", "sim2026_array_annotation.tsv"))2k <- match(bim[[2]], ann$Name)stopifnot(!anyNA(k))3pair <- function(a, b) ifelse(a < b, paste0(a, b), paste0(b, a))observed <- pair(bim[[5]], bim[[6]])reference <- pair(ann$Ref_Plus[k], ann$Alt_Plus[k])4complement <- chartr("ACGT", "TGCA", reference)complement <- pair(substr(complement, 1, 1), substr(complement, 2, 2))5palindromic <- reference %in% c("AT", "CG")flip <- !palindromic & observed != reference & observed == complementexclude <- palindromic | (observed != reference & observed != complement)6flip_file <- guided_list(bim[[2]][flip], guided_path(cfg, "2.5", "flip.txt"))exclude_file <- guided_list(bim[[2]][exclude], guided_path(cfg, "2.5", "exclude.txt"))stopifnot(sum(flip) == 400L, sum(exclude) == 3013L)7run_plink(cfg, c("--pfile", guided_path(cfg, "2.2"), "--flip", flip_file, "--exclude", exclude_file,  "--make-pgen", "--out", guided_path(cfg, "2.5")))8stopifnot(all(guided_counts(guided_path(cfg, "2.5")) == c(2016, 296510)))# Course bookkeeping: records the counts for the next step. Do not change.ops <- data.frame(option = c("--flip", "--exclude"), value = c(flip_file, exclude_file))guided_register(cfg, "2.5", "2.2", 2016, 296510, operations = ops)
  1. Note 1: Read the laboratory variant table and the reference DNA letters.
  2. Note 2: Match every laboratory site to the reference table by its identifier.
  3. Note 3: Put each pair of DNA letters in a consistent order for comparison.
  4. Note 4: Find the reference letter pairs as they would appear on the opposite strand.
  5. Note 5: Identify sites to correct and sites with ambiguous or incompatible letters.
  6. Note 6: Save both lists and check their expected sizes.
  7. Note 7: Correct the listed sites and remove the excluded sites in a new copy.
  8. Note 8: Check that 2,016 samples and 296,510 variants remain.

You need

You need the BIM file from 2.1, the annotation from 1.1 and the PGEN files from 2.2.

What we do

We compare the allele pairs from the laboratory with the supplied plus-strand annotation. We flip the pairs that are complementary. We remove the sites that are ambiguous or incompatible.

Why

An allele (opens in a new tab) is one of the versions of a variant, written as a base: A, C, G or T. DNA has two strands, and the bases pair up in a fixed way: A with T, and C with G. An A/C site on one strand reads T/G on the other strand.

Some sites are palindromic (opens in a new tab): A/T and C/G. After a strand flip, they show the same pair as before. So the pair alone cannot tell us the orientation. This course removes these sites instead of guessing from allele frequency.

Allele order is not strand. A/G and G/A contain the same pair.

What each option does

Each option, with the modifiers under the option they belong to.
Option or modifierWhat it does
--pfile

Reads the PGEN, PVAR and PSAM files named results/guided/s2-2_state.

--flip

Uses s2-5_flip.txt to replace each DNA letter by its partner on the opposite strand at 400 sites: A pairs with T, and C with G.

--exclude

Removes the 3,013 sites listed in s2-5_exclude.txt because their DNA letter pairs are ambiguous or incompatible with the reference table.

--make-pgen

Saves the corrected data as PGEN, PVAR and PSAM files.

--out

Starts the corrected file names with results/guided/s2-5_state.

Every command also uses --threads 2 (PLINK runs at most two tasks at the same time) and --memory 2048 (PLINK uses at most about 2 GB of memory).

PLINK terminal equivalent. Optional: you do not need it for the course.

Blue: PLINK option · Orange: value you can change · Green: file name

Terminal equivalent: plain PLINK 2

Select any option to see what it does. Do not paste terminal commands into the R console.

Command

bin/plink2

No option selected. Each underlined part of the command is an option you can open.

Use bin\plink2.exe on Windows.

Expected result

Show the expected result

400 sites are flipped and 3,013 sites are excluded. 2,016 samples and 296,510 variants remain. The planted problem categories overlap, so do not simply add their nominal counts.

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. Check that the previous step finished. Keep the command and the console output (the text printed in R). Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).

What this check can reveal

It can reveal strand differences, palindromic sites and incompatible alleles. Agreement with this annotation does not prove that the genome reference sequence itself is correct.

Quick check

Can A/T versus T/A tell you whether the strand is correct?

Show the answer

No. The pair is palindromic, so the strand cannot be found from the pair alone.

Files created

The flip and exclusion lists, and s2-5_state.pgen/.pvar/.psam.