MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 3.7

Module 3 · Sample quality control · step 7 of 8

3.7Batch effects

Commands tested on Windows

In short

We compare the fraction of successful genotype calls across laboratory plates. We remove the faulty plate in these simulated data because samples processed together can share technical problems.

Do this

You should see: Plate P14 has a median call rate of approximately 98.56%.

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, "3.7", "missing")2run_plink(cfg, c("--pfile", guided_path(cfg, "3.6"), "--missing", "sample-only", "--out", report))3missing <- guided_table(paste0(report, ".smiss"))metadata <- guided_metadata(cfg)plate <- metadata$Plate[match(missing$IID, metadata$IID)]4median_missing <- tapply(as.numeric(missing$F_MISS), plate, median)print(sort(1 - median_missing))5worst <- names(which.max(median_missing))stopifnot(worst == "P14")6remove_file <- guided_list(missing$IID[plate == worst], guided_path(cfg, "3.7", "remove.txt"), TRUE)7run_plink(cfg, c("--pfile", guided_path(cfg, "3.6"), "--remove", remove_file, "--make-pgen", "--out", guided_path(cfg, "3.7")))# Course bookkeeping: records the counts for the next step. Do not change.ops <- guided_replay_lists(cfg, "3.7", "3.6")guided_register(cfg, "3.7", "3.6", 1844, 296360, operations = ops)
  1. Note 1: Choose the name for the missing-call report.
  2. Note 2: Count missing calls for each sample.
  3. Note 3: Read the report and match each sample to its laboratory plate.
  4. Note 4: Calculate and print the middle call rate for each plate.
  5. Note 5: Find the plate with the most missing calls and check its name.
  6. Note 6: Write the list of samples from the faulty plate.
  7. Note 7: Save the dataset without samples from that plate.

You need

State 3.6 and the sample sheet from step 1.4. You also need the heterozygosity report from step 3.5.

What we do

We compare the call rate of each plate. A plate is a tray of 96 wells. We remove the plate that is clearly faulty in the simulated data.

Why

Samples that are processed together can share the same technical faults (artefacts). We call this a batch effect. We compare the laboratory groups with the call rate and with the heterozygosity.

A plate with many cases must not be removed only because it has many cases. Here we remove a plate because its technical measurements are poor.

After you remove any batch, check again how cases and controls are spread across the data.

What each option does

Command 1: measure missing calls by sample

Command 1: measure missing calls by sample. Each option, with the modifiers under the option they belong to.
Option or modifierWhat it does
--pfile

Reads the PGEN, PVAR and PSAM input files that share the given name prefix.

--missing

Writes a report of missing genotype calls.

Modifier of --missing: sample-only

Writes one row per sample and skips the report for variants.

--out

Sets the shared beginning of the output file names.

Command 2: remove samples from the faulty plate

Command 2: remove samples from the faulty plate. Each option, with the modifiers under the option they belong to.
Option or modifierWhat it does
--pfile

Reads the PGEN, PVAR and PSAM input files that share the given name prefix.

--remove

Removes the samples named in the supplied sample list.

--make-pgen

Saves a new dataset as PGEN, PVAR and PSAM files.

--out

Sets the shared beginning of the output file names.

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 1 of 2

bin/plink2

Command 2 of 2

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

Plate P14 has a median call rate of approximately 98.56%. The other plates have 99.84%. The 76 remaining wells of plate P14 are removed. 1,844 samples and 296,360 variants remain.

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. Your numbers should be the same.

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 messages. Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).

What this check can reveal

A laboratory effect that a group of samples shares. The same pattern can confound an association (mix up the effect of the group with the effect of the disease) if the processing groups and the phenotype groups overlap.

Quick check

Why are 76 wells removed from a plate that originally had 96?

Show the answer

Earlier QC steps had already removed some wells of that plate.

Files created

The report of missingness for each sample, the plate-based removal list and s3-7_state.*.