Module 6 · Association · step 8 of 8
6.8Create the summary statistics file
Commands tested on Windows
In short
We save the scan results in a standard table with one row per tested variant and a separate file explaining its columns. We read the saved table back and check its values and counts so the next plots use a verified file.
Do this
- Paste in the RStudio ConsoleThe R command in the Command section below
You should see: The summary statistics file has 236,815 rows, one for each tested variant.
Command
Module setup, needed before this step
R: module setup
source("R/guided.R")cfg <- guided_init()R command
Type or paste into the RStudio console.
1results <- guided_association(guided_path(cfg, "6.4", "association"))stats <- guided_standardise_scan(results)2guided_check_summary(stats, rows = nrow(results))stats_file <- guided_summary_path(cfg)3guided_write_summary(stats, stats_file)dictionary_file <- guided_path(cfg, "6.8", "gwas_summary_statistics_columns.tsv")guided_write(guided_summary_dictionary(), dictionary_file)# Read the file back, as the plots will, and check that nothing was lost.4saved <- guided_summary_stats(cfg)guided_check_summary(saved, rows = nrow(results))stopifnot(isTRUE(all.equal(saved, stats)))5first_summary <- read.delim(guided_path(cfg, "6.7", "summary.tsv"))finite <- valid_p(saved$p_value)stopifnot(sum(finite) == first_summary$finite_tests, sum(saved$p_value[finite] < 5e-8) == first_summary$genome_wide)print(head(saved, 5))print(c(rows = nrow(saved), finite_tests = sum(finite), missing_p_values = sum(is.na(saved$p_value)), genome_wide = sum(saved$p_value[finite] < 5e-8)))# Course bookkeeping: records the counts for the next step. Do not change.guided_artifact_checkpoint(cfg, "6.8", c(stats_file, dictionary_file), parent = "6.7")check_step("6.8", data_dir = cfg$out, work_dir = cfg$out)- Note 1: Read the scan and arrange its results in the standard columns.
- Note 2: Check the columns and values and choose the summary file name.
- Note 3: Save the summary table and a file explaining each column.
- Note 4: Read the saved table and check that it matches the original results.
- Note 5: Compare test counts with the saved scan summary and print the checked results.
You need
The association scan from 6.4 and the summary from 6.7.
What we do
Save the results of the association scan in one clearly named file with standard columns. Write a second file that explains every column in plain words.
Why
The raw PLINK output is long and uses PLINK column names. A summary statistics file is the standard way to share GWAS results. It has one row for each tested variant and no data about individual people. Colleagues use it to plot results, to combine several studies into one analysis (a meta-analysis) and to look up a variant. This file keeps only the eleven columns that others expect, with the same names in the same order. From now on we build the Manhattan plot (opens in a new tab) and the QQ plot (opens in a new tab) from this file, not from the raw scan output.
Each column has one clear meaning. Read the table before you use the file.
| Column | What it is | What values look like | A common mistake |
|---|---|---|---|
chromosome | The chromosome of the variant. | 1 to 22, then X, Y or MT. | Treating it as a number. X is text. |
base_pair_location | The position on the chromosome, in base pairs, on genome build GRCh38 (opens in a new tab). | A whole number such as 96426973. | Comparing it with positions from another genome build. |
variant_id | The name of the variant in this course. | 9:96426973:A:G: chromosome, position and the two alleles. | Expecting an rs number. This course does not use rs numbers as identifiers. |
effect_allele | The allele whose copies the model counted. PLINK calls it A1. | One letter, such as A. | Assuming it is the minor allele or the ALT allele. By definition it is neither. |
other_allele | The other allele of the variant. | One letter, such as G. | Swapping the two alleles. The odds ratio then points the other way. |
effect_allele_frequency | How common the effect allele is in the analysed samples. | A number from 0 to 1, such as 0.2. | Reading it as the minor allele frequency (MAF (opens in a new tab)). It can be above 0.5. |
odds_ratio | The odds ratio per copy of the effect allele. | A positive number. Above 1 means higher odds of disease with each copy. | Reading it as a risk ratio. |
beta | The natural logarithm of the odds ratio. It is the effect size on the log odds scale. | A number that can be negative, zero or positive, such as 0.18. Above 0 means higher odds of disease. It is NA when the odds ratio is NA. | Mixing it up with the odds ratio. beta is log(odds_ratio). An odds ratio of 1 gives a beta of 0. |
standard_error | The standard error of beta, the natural logarithm of the odds ratio. | A small positive number, such as 0.09. | Using it as the standard error of the odds ratio itself. It belongs to beta. |
p_value | The p-value of the additive test. | A number above 0 and at most 1. A test that failed is NA. | Replacing NA with 1 or 0. A missing result stays missing. |
n | The number of samples used for this variant. | A whole number up to 1,811. | Assuming every variant uses all samples. Missing genotypes lower it. |
To get the 95% confidence interval of an odds ratio, use exp(beta +/- 1.96 * standard_error). The standard error is on the log scale, so the formula starts from beta, the logarithm of the odds ratio.
The file is plain text with a header row. Tabs separate the columns. It uses UTF-8 encoding (a standard way to store text characters) and decimal points. It holds only results for each variant. It has no genotypes and no sample IDs. Even so, it stays in your results folder. Do not share it outside the course unless your instructor says so.
PLINK terminal equivalent. Optional: you do not need it for the course.
Not applicable. This step needs no PLINK operation. The R chunk is the complete command.
R reads or calculates the values it shows. It does not change the genotype files.
Expected result
Show the expected result
The summary statistics file has 236,815 rows, one for each tested variant. It has the eleven columns in the order of the table above. The checks stop the step with an error if a column name, a p-value or an odds ratio breaks the rules. The first row is 1:858952:G:A, with effect allele A, other allele G, odds ratio 1.03471, beta about 0.034 and n = 1807. beta is calculated from the odds ratio that PLINK writes, so it is the logarithm of that rounded value. No p-value is missing in this dataset. Eight p-values are below 0.00000005, as at 6.7. The file is about 22 MB. The column file has one row for each of the eleven columns. The last table shows matches for both files in the 6.8 checkpoint.
If PLINK could not calculate a p-value, the file would show NA. It would never show 0 or 1.
The tested PLINK version is defined in config.R and recorded in
software_versions.txt. Validation: executable chunks passed on Windows; main test counts and significance match the expected values.
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. If R says that the scan output is missing, run step 6.4 first. If a check names a column or a value, do not edit the file by hand. Run the step again. Keep the command and the console log. Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).
Quick check
A colleague wants the 95% confidence interval for an odds ratio. Which column do they use with beta, and on which scale?
Show the answer
They use standard_error. It is the standard error of beta, the natural logarithm of the odds ratio. They calculate the interval on the log scale and then convert it back with exp().
Files created
In the folder results/guided/: s6-8_gwas_summary_statistics.tsv (the summary statistics file), s6-8_gwas_summary_statistics_columns.tsv (the column dictionary) and checkpoints/6.8/MANIFEST.tsv.