MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 2.2

Module 2 · Files and formats · step 2 of 8

2.2Convert to PLINK 2 native format

Commands tested on Windows

In short

We convert the laboratory files to the format that PLINK 2 uses for this course. We check that the conversion keeps every sample and variant, a place in the DNA where people can differ.

Do this

You should see: The 2,016 samples and 299,523 variants are all kept.

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.

1out <- guided_path(cfg, "2.2")2run_plink(cfg, c("--bfile", cfg$input, "--make-pgen", "--out", out), paste0(out, c(".pgen", ".pvar", ".psam")))3stopifnot(all(guided_counts(out) == c(2016, 299523)))# Course bookkeeping: records the counts for the next step. Do not change.guided_source_checkpoint(cfg)
  1. Note 1: Choose the name for the converted files.
  2. Note 2: Convert the laboratory files to the native PLINK 2 format.
  3. Note 3: Check that all 2,016 samples and 299,523 variants remain.

You need

You need the original matched files that you checked at 2.1.

What we do

We convert the matched BED, BIM and FAM files to PGEN, PVAR and PSAM files.

Why

PGEN stores the genotypes. PVAR describes the variants (the sites). PSAM describes the samples. These three files are the native format (opens in a new tab) of PLINK 2. The BED, BIM and FAM files stay useful for older programs. Neither format records the genome build. The conversion must keep the same samples and variants in the same order.

What each option does

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

Reads the BED, BIM and FAM laboratory files named sim2026_lab in data/course/lab_export.

--make-pgen

Writes the data as PGEN, PVAR and PSAM files, the native PLINK 2 format.

--out

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

The 2,016 samples and 299,523 variants are all kept. PLINK can mark the reference allele (opens in a new tab) (REF) as provisional. This happens because a BED file does not say which allele matches the genome reference.

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

Does converting BED to PGEN automatically convert GRCh37 coordinates to GRCh38?

Show the answer

No. The storage format and the genome assembly are two separate properties.

Files created

s2-2_state.pgen/.pvar/.psam, and the command and console logs in the output folder.