Module 3 · Sample quality control · step 3 of 8
3.3Recorded and genetic sex
Commands tested on Windows
In short
We compare recorded sex with patterns in the X and Y chromosome calls. We remove flagged wells from this teaching analysis because a mismatch needs review before the sample is used.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: Eight flagged wells are removed. 1,963 samples remain. 520 sites are labelled PAR1 or PAR2.
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.
1split <- guided_path(cfg, "3.3", "par")report <- guided_path(cfg, "3.3", "sexcheck")2run_plink(cfg, c("--pfile", guided_path(cfg, "3.2"), "--split-par", "b38", "--make-pgen", "--out", split))3run_plink(cfg, c("--pfile", split, "--check-sex", "max-female-xf=0.2", "min-male-xf=0.8", "max-female-ycount=100", "min-male-ycount=1000", "--out", report))4sexcheck <- guided_table(paste0(report, ".sexcheck"))bad <- sexcheck$IID[sexcheck$STATUS != "OK"]remove_file <- guided_list(bad, guided_path(cfg, "3.3", "remove.txt"), TRUE)5run_plink(cfg, c("--pfile", split, "--remove", remove_file, "--make-pgen", "--out", guided_path(cfg, "3.3")))# Course bookkeeping: records the counts for the next step. Do not change.ops <- guided_replay_lists(cfg, "3.3", "3.2", extra = data.frame(option = "--split-par", value = "b38"))guided_register(cfg, "3.3", "3.2", 1963, 296360, operations = ops)- Note 1: Choose names for the chromosome files and sex report.
- Note 2: Label the regions shared by the X and Y chromosomes.
- Note 3: Compare recorded sex with the X and Y chromosome results.
- Note 4: Read the report and list samples that need to be removed.
- Note 5: Save the dataset without the flagged samples.
You need
State 3.2 and the recorded sex that we joined to the data at step 2.7.
What we do
We move the pseudo-autosomal regions (opens in a new tab) (PARs) out of the rest of the X chromosome. We then compare the recorded sex of each person with the X and Y patterns in the DNA. Finally, we review the wells where the two do not agree.
Why
The sex chromosomes (opens in a new tab) are X and Y. The PARs are small regions that exist on both X and Y. They can swap material (recombine) like other chromosomes. A man therefore has two copies of them. We must not treat these two copies as the single X of a man.
PLINK computes an X inbreeding coefficient, called F (opens in a new tab). It shows how homozygous (opens in a new tab) the X looks. Homozygous means that both copies of a site carry the same allele. PLINK also counts the Y calls. These two values can show that the recorded sex does not fit the DNA.
A flagged well can have several causes. It can be a sample swap, an unusual karyotype (opens in a new tab) (an unusual number of sex chromosomes), poor calls or incomplete records. A flag is not a clinical diagnosis.
In this simulation, we remove the flagged wells for the main teaching analysis.
What each option does
Command 1: label the shared X and Y regions
| Option or modifier | What it does |
|---|---|
| --pfile | Reads the PGEN, PVAR and PSAM input files that share the given name prefix. |
| --split-par | Uses GRCh38 boundaries (b38) to label the shared regions of X and Y separately. |
| --make-pgen | Saves a new dataset as PGEN, PVAR and PSAM files. |
| --out | Sets the shared beginning of the output file names. |
Command 2: compare recorded sex with DNA
| Option or modifier | What it does |
|---|---|
| --pfile | Reads the PGEN, PVAR and PSAM input files that share the given name prefix. |
| --check-sex | Compares recorded sex with X chromosome patterns and the number of observed Y calls. |
| Modifier of --check-sex: max-female-xf | Sets 0.2 as the largest accepted X chromosome F value for a recorded female. F measures how homozygous the X chromosome looks, meaning how often the two copies carry the same DNA letter. |
| Modifier of --check-sex: min-male-xf | Sets 0.8 as the smallest accepted X chromosome F value for a recorded male. F measures how homozygous the X chromosome looks. Values near 1 are expected when there is only one X chromosome, as in males. |
| Modifier of --check-sex: max-female-ycount | Accepts at most 100 observed Y calls for a recorded female. |
| Modifier of --check-sex: min-male-ycount | Requires at least 1000 observed Y calls for a recorded male. |
| --out | Sets the shared beginning of the output file names. |
Command 3: remove samples flagged by the sex check
| Option or modifier | What 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.
bin/plink2
bin/plink2
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
Eight flagged wells are removed. 1,963 samples remain. 520 sites are labelled PAR1 or PAR2. The number of variants does not change.
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
Sex mismatch and unusual X or Y patterns. This includes one simulated XXY-like profile (a person with two X chromosomes and one Y chromosome). Do not infer a real diagnosis from a course threshold.
Quick check
Should we correct a sex mismatch automatically by changing the recorded sex?
Show the answer
No. First review the identity of the sample, the genotype quality and the source records.
Files created
The PAR fileset, the .sexcheck report, the review and removal list, and s3-3_state.*.