MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 2.7

Module 2 · Files and formats · step 7 of 8

2.7Add phenotype and covariates

Commands tested on Windows

In short

We match disease status, age and recorded sex to each laboratory well by its identifiers. We save the information table and add disease status and sex to the DNA files so later checks use the right person's information.

Do this

You should see: All 2,016 wells are matched, and 296,510 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.

1metadata <- guided_metadata(cfg)2pheno <- metadata[c("FID", "IID", "SEX", "Age", "Disease")]names(pheno)[1] <- "#FID"pheno_file <- guided_path(cfg, "2.7", "phenotypes.tsv")3guided_write(pheno, pheno_file)4run_plink(cfg, c("--pfile", guided_path(cfg, "2.5"), "--update-sex", pheno_file,  "--pheno", pheno_file, "--pheno-name", "Disease", "--make-pgen", "--out", guided_path(cfg, "2.7")))5stopifnot(all(guided_counts(guided_path(cfg, "2.7")) == c(2016, 296510)))# Course bookkeeping: records the counts for the next step. Do not change.ops <- data.frame(option = c("--update-sex", "--pheno", "--pheno-name"), value = c(pheno_file, pheno_file, "Disease"))guided_register(cfg, "2.7", "2.5", 2016, 296510, operations = ops)
  1. Note 1: Match the sample sheet to each person's disease status, age and recorded sex.
  2. Note 2: Select and name the columns for the sample information file.
  3. Note 3: Save the sample information table.
  4. Note 4: Add recorded sex and disease status to a new copy of the DNA files.
  5. Note 5: Check that all 2,016 samples and 296,510 variants remain.

You need

You need the corrected files from 2.5, and the sample sheet and phenotype table from 0.5.

What we do

We join the extra information to each well by its identity. A well that holds a labelled technical replicate gets the information of the original person.

Why

The phenotype (opens in a new tab) is the outcome that we study. Here the variable Disease is 1 for controls and 2 for cases. A case is a person with the disease and a control is a person without it.

Age is a covariate (opens in a new tab). A covariate is a measured variable that the model uses to account for other influences.

Recorded sex is supplied for the sex check. We never guess it from the row order.

A technical replicate (opens in a new tab) is the same person measured in a second well. It inherits the information of the original person. It stays a separate well until the duplicate review.

What each option does

Each option, with the modifiers under the option they belong to.
Option or modifierWhat it does
--pfile

Reads the corrected PGEN, PVAR and PSAM files named results/guided/s2-5_state.

--update-sex

Loads recorded sex from s2-7_phenotypes.tsv by matching the sample identifiers.

--pheno

Reads the table s2-7_phenotypes.tsv containing the sample identifiers and disease status.

--pheno-name

Selects the Disease column as the outcome: 1 means a control without the disease and 2 means a case with the disease.

--make-pgen

Saves PGEN, PVAR and PSAM files with recorded sex and disease status in the sample table.

--out

Starts the joined file names with results/guided/s2-7_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.

Command

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

All 2,016 wells are matched, and 296,510 variants remain. There are 2,000 people before we remove low-quality wells, relatives and ancestry outliers.

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 message. Check the input file named in the message. Check that the previous step finished. Keep the command and the console output (the text printed in R). Do not use files from a different version of the dataset. See troubleshooting (opens in a new tab).

Quick check

Why must you join labelled replicate wells to their original person before you assign the phenotype?

Show the answer

The phenotype describes the person. The rows of the export describe measured wells.

Files created

s2-7_phenotypes.tsv and the native s2-7_state files.