Module 7 · Plots and reporting · step 6 of 8
7.6Regional plot
Commands tested on Windows
In short
We draw three detailed regional plots, one for each region with genome-wide significant variants, on chromosomes 3, 9 and 12. Each plot shows the strength of each association and how closely its DNA pattern follows the lead variant, using a continuous colour scale.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: L2 has four genome-wide significant variants.
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.
1regions <- data.frame(label = c("L1", "L2", "L3"), chromosome = c("3", "9", "12"), position = c(163224115, 96426973, 120965921), lead = c("3:163224115:T:C", "9:96426973:A:G", "12:120965921:G:A"), ld = c("ld_chr3", "ld", "ld_chr12"), picture = c("regional_chr3.png", "regional.png", "regional_chr12.png"), expected = c(1L, 4L, 3L), stringsAsFactors = FALSE)2stats <- guided_summary_stats(cfg)regions$rs <- guided_variant_labels(cfg, regions$chromosome, regions$position, regions$lead)3for (i in seq_len(nrow(regions))) { report <- guided_path(cfg, "7.6", regions$ld[i]) run_plink(cfg, c("--pfile", guided_path(cfg, "5.7"), "--chr", regions$chromosome[i], "--from-bp", format(regions$position[i] - 500000, scientific = FALSE), "--to-bp", format(regions$position[i] + 500000, scientific = FALSE), "--r2-unphased", "--ld-snp", regions$lead[i], "--ld-window-kb", "500", "--ld-window-r2", "0", "--out", report))4 ld <- guided_table(paste0(report, ".vcor")) region <- stats[stats$chromosome == regions$chromosome[i] & abs(stats$base_pair_location - regions$position[i]) <= 500000 & valid_p(stats$p_value), ]5 r2_column <- grep("R2$", names(ld), value = TRUE) stopifnot(length(r2_column) == 1L)6 r2 <- as.numeric(ld[[r2_column]][match(region$variant_id, ld$ID_B)]) r2[region$variant_id == regions$lead[i]] <- 17 png(guided_path(cfg, "7.6", regions$picture[i]), width = 1500, height = 900, res = 150) plot_regional(region, r2, match(regions$lead[i], region$variant_id), regions$chromosome[i], regions$rs[i], paste0(regions$label[i], ": association and LD to the lead")) invisible(dev.off()) cat("The plot was saved to ", guided_path(cfg, "7.6", regions$picture[i]), "\n", sep = "")8 stopifnot(sum(region$p_value < 5e-8) == regions$expected[i])}# Course bookkeeping: records the counts for the next step. Do not change.guided_artifact_checkpoint(cfg, "7.6", c(paste0(guided_path(cfg, "7.6", "ld"), ".vcor"), guided_path(cfg, "7.6", "regional.png")), parent = "6.8")- Note 1: List the three regions, their lead variants, output names and the expected number of genome-wide significant variants.
- Note 2: Read the association results once and look up the rs number of each lead variant.
- Note 3: For each region, measure correlations with the lead within 500,000 DNA positions and draw the plot.
- Note 4: Read the correlation table and select the regional association results.
- Note 5: Find and check the column holding squared correlations.
- Note 6: Match each regional variant to its correlation with the lead variant.
- Note 7: Draw and save the regional plot with a continuous colour scale, the lead label and the significance line.
- Note 8: Check the number of regional variants with p-values below 0.00000005.
You need
The summary statistics file from step 6.8, the final cohort and the three lead variants 3:163224115:T:C, 9:96426973:A:G and 12:120965921:G:A from the clumps.
What we do
Look closely at the three regions with genome-wide significant variants: L1 on chromosome 3, L2 on chromosome 9 and L3 on chromosome 12. We draw one plot for each region. Each variant is coloured by its LD with the lead variant of its region.
Why
A regional plot (opens in a new tab) shows a small part of the genome. It shows three things together: the position, the strength of the association and the LD. L1 has only one genome-wide significant variant in this set of array variants, so its plot shows one isolated high point. L2 and L3 have several.
Nearby points with a high r^2 to the lead variant can carry the same association signal. Low LD, or several separate peaks, do not by themselves show several causal effects. We do not name genes and we do not add any other annotation here.
The colour scale is continuous. It runs from pale yellow, where r^2 is 0 and the two variants share no information, to dark purple, where r^2 is 1 and the genotypes are the same. Darker means more similar, so the plot is also readable in grey. The lead variant is a black diamond with its rs number. A grey cross means that PLINK gave no LD value for that variant. The value is not silently set to zero.
Illustration in preparation
What each option does
Command 1: measure correlation around the chromosome 3 lead
| Option or modifier | What it does |
|---|---|
| --pfile | Reads s5-7_state.pgen, s5-7_state.pvar and s5-7_state.psam, which hold the final cohort's DNA calls, variant information and sample information. |
| --chr | Selects chromosome 3 for the regional comparison. |
| --from-bp | Starts the selected GRCh38 interval at DNA position 162724115. |
| --to-bp | Ends the selected GRCh38 interval at DNA position 163724115. |
| --r2-unphased | Reports squared correlations between the numbers of copies of DNA versions at pairs of variants, without assigning copies to individual chromosomes. |
| --ld-snp | Pairs variant 3:163224115:T:C with the other selected variants to measure their correlation with it. |
| --ld-window-kb | Limits pairs to variants within 500 kilobases, or 500,000 DNA positions, of variant 3:163224115:T:C. |
| --ld-window-r2 | Sets the minimum reported squared correlation to 0 so weak correlations remain in the report. |
| --out | Starts output file names with s7-6_ld_chr3, including the correlation table s7-6_ld_chr3.vcor. |
Command 2: measure correlation around the chromosome 9 lead
| Option or modifier | What it does |
|---|---|
| --pfile | Reads s5-7_state.pgen, s5-7_state.pvar and s5-7_state.psam, which hold the final cohort's DNA calls, variant information and sample information. |
| --chr | Selects chromosome 9 for the regional comparison. |
| --from-bp | Starts the selected GRCh38 interval at DNA position 95926973. |
| --to-bp | Ends the selected GRCh38 interval at DNA position 96926973. |
| --r2-unphased | Reports squared correlations between the numbers of copies of DNA versions at pairs of variants, without assigning copies to individual chromosomes. |
| --ld-snp | Pairs variant 9:96426973:A:G with the other selected variants to measure their correlation with it. |
| --ld-window-kb | Limits pairs to variants within 500 kilobases, or 500,000 DNA positions, of variant 9:96426973:A:G. |
| --ld-window-r2 | Sets the minimum reported squared correlation to 0 so weak correlations remain in the report. |
| --out | Starts output file names with s7-6_ld, including the correlation table s7-6_ld.vcor. |
Command 3: measure correlation around the chromosome 12 lead
| Option or modifier | What it does |
|---|---|
| --pfile | Reads s5-7_state.pgen, s5-7_state.pvar and s5-7_state.psam, which hold the final cohort's DNA calls, variant information and sample information. |
| --chr | Selects chromosome 12 for the regional comparison. |
| --from-bp | Starts the selected GRCh38 interval at DNA position 120465921. |
| --to-bp | Ends the selected GRCh38 interval at DNA position 121465921. |
| --r2-unphased | Reports squared correlations between the numbers of copies of DNA versions at pairs of variants, without assigning copies to individual chromosomes. |
| --ld-snp | Pairs variant 12:120965921:G:A with the other selected variants to measure their correlation with it. |
| --ld-window-kb | Limits pairs to variants within 500 kilobases, or 500,000 DNA positions, of variant 12:120965921:G:A. |
| --ld-window-r2 | Sets the minimum reported squared correlation to 0 so weak correlations remain in the report. |
| --out | Starts output file names with s7-6_ld_chr12, including the correlation table s7-6_ld_chr12.vcor. |
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.
Expected result
Show the expected result
L2 has four genome-wide significant variants. L1 has one and L3 has three. Together they are the eight variants that we found at step 7.3. Each plot shows LD as a continuous colour from pale yellow (r^2 of 0) to dark purple (r^2 of 1). The lead variant is a labelled black diamond: rs1994750 for L1, rs10820598 for L2 and rs7953249 for L3. If an LD value is missing, the legend says "LD unavailable". The value is not silently set to zero. R saves three pictures as PNG files and prints the path of each one. It does not show the pictures in the console. To see them, open the files from the Files pane of RStudio (click the file name, then choose "View File").
The tested PLINK version is set in config.R and recorded in
software_versions.txt. Validation: the executable chunks, the comparisons with the expected results and the final plot checks passed on Windows.
If something goes wrong
If something goes wrong
Stop at the first error. Check the input file that R names and the previous step. Keep the command and the messages from the console. Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).
Quick check
Does the highest point always identify the causal variant?
Show the answer
No. The lead variant is the association with the smallest p-value among the sites that we tested. It may only mark a cause that we did not measure.
Files created
s7-6_ld.vcor, s7-6_ld_chr3.vcor, s7-6_ld_chr12.vcor, s7-6_regional.png (L2), s7-6_regional_chr3.png (L1), s7-6_regional_chr12.png (L3) and the regional analysis checkpoint.