Module 4 · Variant quality control · step 3 of 6
4.3Allele frequency
Commands tested on Windows
In short
We keep variants whose less common DNA version appears in at least 1% of the chromosome copies. This removes variants with too little information for the main disease analysis.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: 56,420 variants are removed because of their observed frequencies. 239,019 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.
1run_plink(cfg, c("--pfile", guided_path(cfg, "4.2"), "--maf", "0.01", "--make-pgen", "--out", guided_path(cfg, "4.3")))# Course bookkeeping: records the counts for the next step. Do not change.ops <- guided_replay_lists(cfg, "4.3", "4.2")guided_register(cfg, "4.3", "4.2", 1844, 239019, operations = ops)- Note 1: Remove variants whose less common DNA version occurs in fewer than 1% of copies.
You need
The dataset from step 4.2, which we call state 4.2.
What we do
We keep variants with a minor allele frequency of at least 1%. We use this rule for the main array scan.
Why
The minor allele frequency (MAF) is how often the less common allele appears in the samples we analyse. For example, if one allele is found in 3 of 100 copies, the MAF is 3%.
A rare allele gives very few samples in some genotype groups. The ordinary logistic regression (opens in a new tab), the test we use later for association, is then unstable. A 1% filter is a choice made for this course. It does not define what is biologically important.
Frequencies depend on ancestry (opens in a new tab), which is the geographic origin of a person's ancestors. They also depend on how the samples were selected. They depend on how PLINK counts chromosome copies too. For example, men have one X chromosome and women have two.
What each option does
| Option or modifier | What it does |
|---|---|
| --pfile | Reads the PGEN, PVAR and PSAM files named results/guided/s4-2_state. |
| --maf | Removes variants whose less common allele, or DNA version, appears in fewer than 1% of chromosome copies. |
| --make-pgen | Saves the remaining data as PGEN, PVAR and PSAM files. |
| --out | Starts the output file names with results/guided/s4-3_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
56,420 variants are removed because of their observed frequencies. 239,019 variants remain. The simulation did not plant a special list of rare artefacts (errors caused by the technology).
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 finds sparse variants, which carry little information in this sample. It does not tell you whether a rare allele is real. It also does not tell you whether the variant could be analysed in a larger study.
Quick check
Can the minor and major label of an allele change between populations?
Show the answer
Yes. The label describes how common the allele is in the sample. It is not a fixed property of the allele.
Files created
s4-3_state.* and the list of excluded variants that lets the course repeat this step.
Try other thresholds (optional)
Try other thresholds (optional)
Try it
Allele frequency: --maf
Each point starts from the same input (1,844 samples, 295,439 variants) and changes one threshold.
--maf 0.01: 56,420 variants removed (course value).
| Threshold | Removed | Remaining |
|---|---|---|
| 0.001 | 33,951 | 261,488 |
| 0.005 | 47,184 | 248,255 |
| 0.01(course value) | 56,420 | 239,019 |
| 0.02 | 89,204 | 206,235 |
| 0.05 | 156,235 | 139,204 |
This box is not part of the main path. No later step uses it. It does not change your results.
The minor allele frequency (MAF) is how often the less common version of a variant occurs. --maf 0.01 removes variants with a MAF below 1%. A rare variant has few carriers, so its test has little power and gives unstable estimates. A higher limit removes more rare variants and keeps a cleaner set. A very high limit also removes real, common signals and shrinks the data a lot. Each trial starts from the cohort saved at 4.2 and changes the limit only.
# Optional. Each trial starts from the same input and changes one threshold only.
thresholds <- c(0.001, 0.005, 0.01, 0.02, 0.05)
trial <- threshold_counts(cfg, guided_path(cfg, "4.2"), "--maf", thresholds)
trial$course_value <- trial$threshold == 0.01
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/s4-2_state --maf 0.02 --make-just-pvar --out results/trials/s4-3_trial --threads 2 --memory 2048
The log file results/trials/s4-3_trial.log states how many variants were removed. To repeat the trial, change the number after --maf and use a new --out name. PLINK 2 uses the founders to calculate the frequency when the sample table has family information. Our samples are all founders, so this makes no difference here.
The expected result of the trials:
| Threshold | Variants removed | Variants remaining |
|---|---|---|
| 0.001 | 33,951 | 261,488 |
| 0.005 | 47,184 | 248,255 |
| 0.01 (course value) | 56,420 | 239,019 |
| 0.02 | 89,204 | 206,235 |
| 0.05 | 156,235 | 139,204 |
How to read it. At 0.01 the course removes 56,420 variants. At 0.05 it would remove 156,235, which is more than half of the 295,439 variants that enter this step. Going from 0.01 to 0.001 keeps 22,469 more variants (the difference 56,420 minus 33,951). Many of them have only a handful of carriers.
Expected plot. For --maf, the horizontal axis shows the threshold and the vertical axis shows the number of variants removed. A red diamond marks the course value (0.01), where 56,420 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.