Module 4 · Variant quality control · step 1 of 6
4.1Variant call rate
Commands tested on Windows
In short
We remove variants with more than 2% of their results missing. This keeps sites in the DNA with results for at least 98% of the remaining people.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: 801 variants are removed.
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.
1run_plink(cfg, c("--pfile", guided_path(cfg, "3.8"), "--geno", "0.02", "--make-pgen", "--out", guided_path(cfg, "4.1")))# Course bookkeeping: records the counts for the next step. Do not change.ops <- guided_replay_lists(cfg, "4.1", "3.8")guided_register(cfg, "4.1", "3.8", 1844, 295559, operations = ops)- Note 1: Remove variants with more than 2% of their results missing.
You need
The full dataset saved at the end of sample QC. This saved point is called a checkpoint (opens in a new tab). Here it is boundary 3.8, made in step 3.8.
What we do
We remove variants with a call rate below 98%. We do this after sample quality control (opens in a new tab) (QC), which already removed the poor samples in module 3.
Why
A call is the result for one variant in one sample. A failed call is called missing data, or missingness (opens in a new tab). The call rate of a variant is the share of samples where the call worked.
In module 3 we checked each sample. Now we check each variant in the samples that remain. A probe (opens in a new tab) is the small piece of DNA on the chip that measures one variant. A probe can work badly in many wells, even when every sample passes sample QC. A well is one small hole on the plate that holds one sample.
The number of failing variants can be higher than the number of failures planted on purpose. The simulation planted 800 low-call variants. Natural patterns in the genotypes (opens in a new tab) also cause some failures. The earlier removals also change which samples are counted.
What each option does
| Option or modifier | What it does |
|---|---|
| --pfile | Reads the PGEN, PVAR and PSAM files named results/guided/s3-8_state. |
| --geno | Removes variants with more than 2% of their genotype calls missing. |
| --make-pgen | Saves the remaining data as PGEN, PVAR and PSAM files. |
| --out | Starts the output file names with results/guided/s4-1_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.
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
801 variants are removed. This is not exactly the 800 planted low-call variants. 1,844 samples and 295,559 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.
If something goes wrong
If something goes wrong
Stop at the first error. Check the input file named in the error message, and check the previous step. Keep your 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
It can reveal poor probes, problems in the software that assigns genotypes (called cluster calling) and failures that depend on the sample. Look at which samples are affected. Do not assume that every rejected variant has the same cause.
Quick check
Why can a simulation with 800 planted failures give 801 removed variants?
Show the answer
The rule works on the observed data, including other variants. Its result does not have to match the planted list.
Files created
s4-1_state.*, the lists of excluded IDs and the records that let the course repeat this step.
Try other thresholds (optional)
Try other thresholds (optional)
Try it
Call rate of variants: --geno
Each point starts from the same input (1,844 samples, 296,360 variants) and changes one threshold.
--geno 0.02: 801 variants removed (course value).
| Threshold | Removed | Remaining |
|---|---|---|
| 0.01 | 1,053 | 295,307 |
| 0.02(course value) | 801 | 295,559 |
| 0.05 | 561 | 295,799 |
| 0.1 | 0 | 296,360 |
| 0.2 | 0 | 296,360 |
This box is not part of the main path. No later step uses it. It does not change your results.
At this step --geno 0.02 removes variants with more than 2% missing calls in the samples that remain. A strict limit removes more variants, but each variant that stays has more complete data. A generous limit keeps more variants with more missing calls. Missing calls that depend on the disease status can create false associations, which is why a clear limit matters. Each trial starts from the cohort saved at 3.8 and changes the limit only.
# Optional. Each trial starts from the same input and changes one threshold only.
thresholds <- c(0.01, 0.02, 0.05, 0.10, 0.20)
trial <- threshold_counts(cfg, guided_path(cfg, "3.8"), "--geno", thresholds)
trial$course_value <- trial$threshold == 0.02
trial
# Plot the removed variants. The course value is the large diamond.
plot_threshold_trials(trial, "Variants removed")
# Optional: add engine = "ggplot2" to plot_threshold_trials() to draw the plot with ggplot2 (install.packages("ggplot2") once first).
Plain PLINK 2 command for one trial. It writes only small files with the name that you give to --out, never a new dataset:
bin/plink2 --pfile results/guided/s3-8_state --geno 0.05 --make-just-pvar --out results/trials/s4-1_trial --threads 2 --memory 2048
The log file results/trials/s4-1_trial.log states how many variants were removed. To repeat the trial, change the number after --geno and use a new --out name.
The expected result of the trials:
| Threshold | Variants removed | Variants remaining |
|---|---|---|
| 0.01 | 1,053 | 295,307 |
| 0.02 (course value) | 801 | 295,559 |
| 0.05 | 561 | 295,799 |
| 0.1 | 0 | 296,360 |
| 0.2 | 0 | 296,360 |
How to read it. At 0.10 and 0.20 no variant is removed, because step 3.1 already removed the variants above 10% missing. From 0.05 to 0.01 the number of removed variants grows from 561 to 1,053. The course value of 0.02 removes 801.
Expected plot. For --geno, the horizontal axis shows the threshold and the vertical axis shows the number of variants removed. A red diamond marks the course value (0.02), where 801 variants are removed. The line joins the points in the order of the thresholds, so you can see how fast the count changes. The same plot with ggplot2 looks the same and has a light grid.