MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 5.2

Module 5 · Population structure · step 2 of 7

5.2Prepare variants for reference PCA

Commands tested on Windows

In short

We find and save the 48,614 sites present in both the cleaned study and the reference. We need the same sites to compare genetic patterns in the two groups.

Do this

You should see: 48,614 shared sites are kept for the reference PCA and the projection.

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.

1reference <- file.path(cfg$data_dir, "pca_reference", "ref1000g_grch38")study_sites <- guided_table(paste0(guided_path(cfg, "4.6"), ".pvar"))reference_sites <- guided_table(paste0(reference, ".pvar"))2common <- sort(intersect(study_sites$ID, reference_sites$ID))3guided_list(common, guided_path(cfg, "5.2", "common.txt"))stopifnot(length(common) == 48614L)cat(length(common), "shared autosomal sites kept\n")# Course bookkeeping: records the counts for the next step. Do not change.guided_artifact_checkpoint(cfg, "5.2", guided_path(cfg, "5.2", "common.txt"), parent = "4.6")
  1. Note 1: Read the study and reference site tables.
  2. Note 2: Find the site names that occur in both tables.
  3. Note 3: Save the shared site names and check their number.

You need

The saved state from step 4.6, and the reference subset supplied at step 0.5.

What we do

Find the sites that are present in both the reference subset and the cleaned study. Only common sites on the autosomes (opens in a new tab) (chromosomes 1 to 22) are used.

Why

Nearby sites are often inherited together, so they carry the same information. This is called linkage disequilibrium (LD (opens in a new tab)). If PCA uses many such sites, one long correlated stretch can dominate the result. To avoid this, the supplied reference was built with LD pruning (opens in a new tab), which keeps one site from each correlated group. It kept only common autosomal array sites. It used an r^2 (opens in a new tab) limit of 0.15 in windows of 200 kb, and it kept at most 50,000 sites.

We keep only the sites that are in both the reference and the study after quality control (QC). We do not add back sites that failed earlier checks. We will prune the sites again later, after we define the final cohort.

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

48,614 shared sites are kept for the reference PCA and the projection.

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

Should we add back sites that failed variant QC just because they exist in the reference?

Show the answer

No. The comparison with the reference uses only the study sites that passed QC.

Files created

s5-2_common.txt.