MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 6.1

Module 6 · Association · step 1 of 8

6.1One variant by hand

Commands tested on Windows

In short

We count cases and controls who carry at least one copy of a chosen DNA letter at one variant. We compare their odds of disease with those of non-carriers; odds are the number of cases divided by the number of controls.

Do this

You should see: A table of carriers and non-carriers in the retained cohort, and a finite odds ratio.

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.

1report <- guided_path(cfg, "6.1", "example")run_plink(cfg, c("--pfile", guided_path(cfg, "5.7"), "--snp", "9:96426973:A:G", "--export", "A", "--out", report))x <- read.table(paste0(report, ".raw"), header = TRUE, check.names = FALSE)2dose <- as.numeric(x[[7]])psam <- guided_table(paste0(guided_path(cfg, "5.7"), ".psam"))case <- psam$Disease[match(x$IID, psam$IID)] == "2"3tab <- table(case = case, carrier = dose > 0)print(tab)carrier_or <- tab["TRUE", "TRUE"] * tab["FALSE", "FALSE"] / (tab["FALSE", "TRUE"] * tab["TRUE", "FALSE"])print(c(counted_allele_column = names(x)[7], carrier_odds_ratio = carrier_or))# Course bookkeeping: records the counts for the next step. Do not change.guided_artifact_checkpoint(cfg, "6.1", paste0(report, ".raw"), parent = "5.7")
  1. Note 1: Export the number of copies of one DNA letter at the chosen variant.
  2. Note 2: Match the exported samples to their case or control status.
  3. Note 3: Count carriers and non-carriers and compare their odds of disease.

You need

The full cohort from 5.7 and the retained variant 9:96426973:A:G.

What we do

Calculate a simple carrier odds ratio for one variant on an autosome (opens in a new tab) (a non-sex chromosome). The variant passed all quality control.

Why

The odds (opens in a new tab) of an outcome are the number of people with the outcome divided by the number without it. An odds ratio (OR) compares the odds in two groups. An OR of 1 means the odds are equal. A carrier has at least one copy of an allele (opens in a new tab) (one version of the variant). We compare carriers of the allele named in the exported column with non-carriers. This is a teaching calculation. It is not the additive, adjusted model that the real genome-wide association study (GWAS) uses. The counted allele matters: if you count the other allele, the contrast changes.

What each option does

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

Reads s5-7_state.pgen, .pvar and .psam, which hold the final study genotypes and sample details.

--snp

Selects only the variant named 9:96426973:A:G.

--export

Uses A format to write a .raw table with the number of copies of the named allele (DNA version) for each sample.

Modifier of --export: A

Writes one row per sample with allele copy counts of 0, 1 or 2, keeping missing values separate.

--out

Starts output file names with s6-1_example, including the s6-1_example.raw table.

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

A table of carriers and non-carriers in the retained cohort, and a finite odds ratio. Read the direction of the odds ratio with the allele in the exported column. This allele is not always the one that raises risk.

The tested PLINK version is defined in config.R and recorded in software_versions.txt. Validation: executable chunks passed on Windows; main test counts and significance match the expected values.

If something goes wrong

If something goes wrong

Stop at the first error. 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 version of the dataset. See troubleshooting (opens in a new tab).

Quick check

An OR of 2 means that the probability of disease doubled. Is this statement generally correct?

Show the answer

No. Odds and probability are different things. An odds ratio is usually not the same as a risk ratio.

Files created

s6-1_example.raw and the log files.