MGHome page

Teaching · Practical course

From DNA to genotypes: arrays, IDAT files, Final Report and PLINK

Twenty-one slides. Use the slide view in class, or read the page view on any screen. The examples are the invented files of the File formats page.

  1. Slide 1 of 21

    From DNA to genotypes: arrays, IDAT files, Final Report and PLINK

    • GWAS practical course
    • How the data of a genotyping array become files that PLINK can read

    File formats and example files

    Speaker notes

    Welcome. In this lesson we follow one small dataset from the scanner to PLINK 2. The files are invented: 4 people and 8 variants. You can open all of them on the File formats page.

    The aim is simple. When you receive data from a laboratory, you should know what each file is, who made it and what it can and cannot tell you.

  2. Slide 2 of 21

    Association studies: allele frequencies in cases and controls

    • Case: a person with the disease. Control: a person without it.
    • Count one allele in both groups.
    • If the frequency differs more than chance allows, the variant is associated.
    Invented exampleAllele GAllele A
    Cases300700
    Controls200800
    Two stacked bars side by side, one for cases and one for controls. Each bar is split into allele G and allele A. The share of G is larger in the cases than in the controls.
    Speaker notes

    An allele is one version of a variant. In a case-control study we count how often one allele is seen in the cases and in the controls.

    With the invented numbers, the odds of carrying G in the cases are 300 to 700. In the controls they are 200 to 800. The odds ratio is (300 x 800) / (700 x 200), which is about 1.7.

    The association test asks if a difference this large could happen by chance. The course does this with logistic regression in module 6.

  3. Slide 3 of 21

    Candidate-gene and agnostic (GWAS) approach

    RowCandidate geneGWAS
    QuestionIs this gene linked to the disease?Which regions of the genome are linked?
    Variants testedA few, chosen from biologyHundreds of thousands to millions
    HypothesisNeeded before the studyNot needed
    ThresholdUsual 0.05, with few testsAbout 5e-8, because of many tests
    Speaker notes

    The candidate approach starts from a gene that we already suspect. It can only find what we already think of.

    A genome-wide study makes no assumption. We test the whole genome and let the data point to regions. This is why it found many unexpected loci.

    Testing so many variants needs a strict threshold. About one million independent common variants exist in people of European ancestry, so 0.05 / 1,000,000 gives 5e-8 (Pe'er et al. 2008).

    Reference

    • Pe'er I, Yelensky R, Altshuler D, Daly MJ. Genet Epidemiol 2008;32:381-385. doi:10.1002/gepi.20303
  4. Slide 4 of 21

    Genetic architecture: GWAS targets common, low-penetrance variants

    • Common variants (frequent in the population) with a small effect on risk.
    • Rare variants with a large effect are found better by sequencing and family studies.
    • One variant rarely explains a disease. Many small effects add up.
    A plot with allele frequency on the horizontal axis, from very rare to common, and effect size on the vertical axis, from small to large. A diagonal band runs from rare variants with a large effect (sequencing and family studies) to common variants with a small effect (GWAS). The top right is marked unlikely and the bottom left hard to detect.
    Speaker notes

    Penetrance is the chance that a person who carries a variant gets the disease. A common variant in a GWAS usually raises risk only a little.

    Most variants found by GWAS confer small increments in risk and explain only part of the inherited risk of a disease (Manolio et al. 2009). This is the 'missing heritability' problem.

    Our course simulates this: the strongest signals are common variants with moderate effects.

    Reference

    • Manolio TA, Collins FS, Cox NJ, et al. Nature 2009;461:747-753. doi:10.1038/nature08494
  5. Slide 5 of 21

    Discovery and replication

    • Discovery: find signals in a first sample.
    • Replication: test the same variants in an independent sample.
    • A real signal should appear again, in the same direction.
    Speaker notes

    A very small p-value can still be a false positive, for example from a hidden batch effect or from ancestry. A second sample, collected and genotyped separately, protects us.

    Often the two samples are analysed together afterwards in a meta-analysis. Our course stops at the discovery scan, but the checks you learn (quality control, ancestry, lambda) are what make replication possible.

  6. Slide 6 of 21

    Linkage disequilibrium and tagging SNPs

    • Nearby variants are inherited together in blocks.
    • A tag SNP stands for its neighbours.
    • So about 700,000 markers are enough to cover the common variation, and imputation can fill in the rest.
    A row of variants along a chromosome. Two blocks of neighbouring variants, each with its own colour, are marked LD block. In each block one larger variant is marked tag SNP.

    Step 3.4, LD pruning

    Speaker notes

    Linkage disequilibrium (LD) means that alleles of nearby variants are correlated, because a stretch of DNA is passed on as a whole across generations.

    If two variants are in strong LD, genotyping one tells us most of what the other would say. The array measures a well-chosen set of tag SNPs.

    Imputation uses a reference panel of fully sequenced people to infer the variants that were not measured. This is an optional module (A) in the course. In module 3, step 3.4 uses LD to prune variants.

  7. Slide 7 of 21

    The genotyping array: beads, probes, two colours

    • A chip with many tiny wells. Each bead carries copies of one probe.
    • A probe is a short piece of DNA that sits right before the variant.
    • One labelled base is added. The scanner reads its colour: green or red.
    A bead in a well, with short probe strands attached. One probe is enlarged. It pairs with the sample DNA up to the variant, and a labelled base, glowing green, is added next to the variant.
    Speaker notes

    The array does not read the DNA letters one by one. It asks one question for each chosen variant: which of the two alleles is present?

    The details of the chemistry depend on the product (Infinium assay). For this course it is enough to remember that the answer is a colour, and that the colour is measured as light.

    Our example array has 8 variants. A real array, such as the one simulated in the course, has about 300,000 to 700,000.

  8. Slide 8 of 21

    IDAT files: intensities only

    • Two files for each sample: one Grn and one Red.
    • They hold light intensities, not genotypes.
    • The name is the chip barcode, the position and the channel.
    200000000001_R01C01_Grn.idat
    200000000001_R01C01_Red.idat
    
    IlluminaID  Mean   SD   NBeads
    10600007    10776  194  5
    10600020    4806   330  12

    IDAT example files

    Speaker notes

    For every bead type the file gives the mean intensity, the standard deviation and the number of beads that were measured.

    The name 200000000001_R01C01_Grn.idat reads: BeadChip 200000000001, row 01, column 01, green channel. The sample sheet links this position to a person, here S01.

    The numbers above are invented. In R you can read a real IDAT file with the package illuminaio.

  9. Slide 9 of 21

    From intensities to genotypes

    • Manifest + cluster file + IDAT files go into the calling program.
    • The algorithm is GenCall. The result is one GTC file for each sample.
    • Programs: GenomeStudio or DRAGEN Array.
    A scatter plot with the intensity of allele A on the horizontal axis and the intensity of allele B on the vertical axis. Three clouds of points: AA at the lower right, AB in the middle and BB at the upper left. A few grey points near the origin are marked no call.

    Manifest and GTC

    Speaker notes

    The manifest tells which probe is which variant. The cluster file says where the AA, AB and BB groups usually fall for each variant.

    GenCall places each sample in this picture and gives a genotype with a confidence value, the GC Score.

    A GTC file is binary: it holds the calls, the scores and the normalised intensities. You do not read it by hand.

  10. Slide 10 of 21

    The Final Report

    • A text file made by GenomeStudio from the GTC files.
    • A header, then a [Data] table with the columns you choose.
    • Three layouts: one file for each sample, one long table, or a matrix.
    LayoutShapeIn the course
    One file per sampleSNPs in rowsUsed
    All samples, longOne row per SNP and sampleSame columns
    MatrixSNPs in rows, samples in columnsCompact

    Final Report example files

    Speaker notes

    Typical columns: SNP Name, Sample ID, Allele1 - Plus, Allele2 - Plus, Allele1 - Top, Allele2 - Top, GC Score, Chr, Position.

    Allele1 and Allele2 are not REF and ALT. They are just the two letters of the genotype.

    The Final Report holds no phenotype: sex and case or control status come from the sample sheet.

  11. Slide 11 of 21

    Reading genotypes

    • A call below GC Score 0.15 becomes a no call.
    • In our example, sample S02 at 22:22001617 has GC Score 0.12, so it is a no call.
    You seeMeaning
    A AHomozygous: two copies of the same allele
    A GHeterozygous: one copy of each
    - -No call: the genotype was not assigned
    Speaker notes

    The GC Score runs from 0 to 1. The default threshold of 0.15 is Illumina's usual choice. Calls below it are not trusted.

    A no call is not a third genotype. It means that we do not know. PLINK writes it as missing, and we will measure how many are missing for every sample and variant in modules 3 and 4.

  12. Slide 12 of 21

    Why not keep a text table?

    • About 730,000 SNPs for 130 samples is about 4.5 GB of text.
    • That is 130 files, each read from start to end for every question.
    • A PLINK .bed file stores the same genotypes in about 24 MB.
    Speaker notes

    The sum for the .bed file: two bits for each genotype, so one variant takes ceil(130 / 4) = 33 bytes, and 730,000 variants x 33 bytes is about 24 million bytes (23 MiB). The text is about 190 times larger.

    A Final Report writes every letter, every score and every column again for every sample. It is easy to read and very wasteful.

    Binary formats use only the information that analysis needs. For genotypes of two alleles, two bits are enough for each genotype. The next slides show how.

    A text file is still useful for looking at a few rows, and for passing data between programs that do not share a binary format.

  13. Slide 13 of 21

    PLINK 1.9 and PLINK 2

    • The course uses PLINK 2.
    RowPLINK 1.9PLINK 2
    Binary files.bed .bim .fam.pgen .pvar .psam (and it still reads .bed)
    Text files--file for .ped/.map--pedmap for .ped/.map
    Writes .ped--recode--export ped
    Column 5 of .bimMinor allele by defaultALT
    Speaker notes

    PLINK 2 is a rewrite, not a small update. It is faster, and its binary format can hold imputed dosages and variants with more than two alleles.

    It also reads the older .bed files, so data from any source can enter.

    The course tested PLINK 2 v2.0.0-b.1.4. R runs the commands for you and shows the PLINK command on its own.

  14. Slide 14 of 21

    .bed: two bits for each genotype

    • Binary. It starts with 3 fixed bytes: 6c 1b 01.
    • Then one block for each variant, 2 bits for each sample.
    BitsGenotype
    00Homozygous for allele 1 (column 5 of .bim)
    01Missing
    10Heterozygous
    11Homozygous for allele 2 (column 6)
    6c 1b 01 8e 2b ce 3a ce 1b c6 ce
    
    8e = 10 00 11 10   (S04 S03 S02 S01)
                      S01 = 10 = heterozygous (A/G)

    The .bed file, byte by byte

    Speaker notes

    Our file has 4 people, so one byte holds all the genotypes of one variant: 4 x 2 bits = 8 bits. The whole file is 11 bytes: 3 for the header and 8 for the variants.

    Read the byte from the right. The two lowest bits belong to the first sample in the .fam file. Byte 4 is 8e, which is 10001110. S01 has 10, so it is heterozygous at 1:1000123, as in the Final Report.

    The page File formats decodes every byte.

  15. Slide 15 of 21

    .bim and .fam, column by column

    • .fam: family, individual, father, mother, sex (1 male, 2 female), phenotype (1 control, 2 case).
    .bim columnExampleMeaning
    11Chromosome
    21:1000123Variant name
    30Genetic distance (not used)
    41000123Position
    5GAllele 1 (A1)
    6AAllele 2 (A2)

    .bed, .bim and .fam files

    Speaker notes

    Allele order matters. PLINK 1.9 puts the minor allele in column 5, so the order can change from one dataset to another. PLINK 2 keeps ALT in column 5 and REF in column 6.

    A text .fam row of our example is: S01 S01 0 0 2 2. Zeros for father and mother mean that they are not in the dataset.

    In our example, PLINK 2 chose REF and ALT from the data. The VCF marks this with the flag PR, provisional reference.

  16. Slide 16 of 21

    .lgen and .ped: text formats

    • .lgen: one line for each person and variant. It looks like a Final Report.
    • .ped: one line for each person, with two columns for each variant.
    • Use them to look at genotypes, or to move data in from other software.
    S01 S01 1:1000123 A G          (.lgen)
    S01 S01 0 0 2 2  A G  C C  A T ...   (.ped)

    .lgen and .ped example files

    Speaker notes

    The .lgen format is the easiest bridge from a Final Report to PLINK, because it has the same shape. A no call becomes 0 0.

    A .ped file is compact to read for a few variants, and becomes huge for real data: two characters for every allele, variant and person. Do not analyse with it.

  17. Slide 17 of 21

    From Final Reports to .bed, .bim and .fam

    source("scripts/final_report_to_lgen.R")
    final_report_to_lgen("04_final_report", "04_final_report/sample_sheet.csv", "example")
    • source(): Load the function final_report_to_lgen() from scripts/final_report_to_lgen.R. Run both lines in R, from the folder examples/formats/array_to_plink of the course.
    • folder: First option: "04_final_report", the folder with the Final Report files.
    • sample sheet: Second option: the path of the sample sheet, "04_final_report/sample_sheet.csv", which gives sex and case or control status.
    • output name: Third option: "example", the start of the names of the new files. It writes example.lgen, example.map and example.fam.
    plink2 --lfile example --make-bed --out example
    • --lfile example: Read the long-format files example.lgen, .map and .fam.
    • --make-bed: Write the PLINK binary files .bed, .bim and .fam.
    • --out example: Start the names of the new files with example. PLINK also writes example.log.
    plink2 --bfile input --make-pgen --out out
    • --bfile input: Read input.bed, input.bim and input.fam. This is the command of step 2.2 of the course.
    • --make-pgen: Write the PLINK 2 files .pgen, .pvar and .psam.
    • --out out: Start the names of the new files with out.

    Step 2.2, convert to PLINK 2 format

    Speaker notes

    The first step is a small R function, not a PLINK command. The same conversion is also available as a Python script, to run from a terminal in the same folder: python scripts/final_report_to_lgen.py 04_final_report 04_final_report/sample_sheet.csv example. The three values are the same.

    In the course R starts PLINK for you with run_plink(), and shows the PLINK command on its own line. The options are the same as here.

    Always read the log. It says how many samples and variants PLINK found, and it is the first place to look when something looks wrong.

    The two first commands of this slide are the ones we tested on the example files, with PLINK 2. Step 2.2 starts from the .bed files that the laboratory sent.

  18. Slide 18 of 21

    PLINK 2 binary and VCF

    • .pgen: PLINK 2 binary. It holds dosages, phase and more than two alleles.
    • VCF: the common text format for variants. Imputation servers read it.
    • We will meet VCF again at imputation (optional module A).
    plink2 --bfile example --export vcf id-paste=iid --out example
    • --export vcf: Write a VCF file.
    • id-paste=iid: Use only the sample name (S01), not the pasted name S01_S01.

    PLINK 2 and VCF example files

    Speaker notes

    A VCF has one line for each variant and one column for each sample. The genotype 0/1 means one REF allele and one ALT allele.

    A VCF holds no sex. To go back from VCF to PLINK 2 you give a .psam file, because PLINK needs the sex for chromosome X: plink2 --vcf example.vcf --psam example.psam --make-pgen --out example.

  19. Slide 19 of 21

    Pitfalls

    • Allele1 and Allele2 are not REF and ALT.
    • Strand: Plus or Top. A/T and C/G variants look the same on both strands.
    • Genome build: the course uses GRCh38. Never mix builds.
    Two parallel DNA strands drawn as horizontal lines, the plus strand on top and the opposite strand below, joined by rungs. At one highlighted position the variant reads A/G on the plus strand and T/C on the opposite strand.

    Step 2.5, alleles and strandStep 2.6, genome builds

    Speaker notes

    An A/G variant on one strand is T/C on the other. We can tell which strand from the letters, because A/G is not the same as C/T. But an A/T variant is A/T on both strands, and C/G is C/G on both. Strand cannot be read from the letters. These are the strand-ambiguous SNPs.

    Module 2 handles strand and genome build before any analysis: step 2.5 (alleles and strand) and step 2.6 (genome builds). Mixing GRCh37 and GRCh38 puts variants at the wrong place.

  20. Slide 20 of 21

    Quality control in nine steps

    StepWhat it checks
    3.2Sample call rate (after rough cleaning at 3.1)
    3.3Recorded sex and genetic sex
    3.5Heterozygosity
    3.6Relatives and duplicates
    3.7Batch effects
    4.1Variant call rate
    4.2Differential missingness
    4.3Allele frequency
    4.4Hardy-Weinberg

    Module 3, sample QCModule 4, variant QC

    Speaker notes

    Quality control has two parts. First the samples (module 3), then the variants (module 4). The order matters.

    Step 3.1 is a rough cleaning with a loose cut before the main call rate check at step 3.2, so we count them together. Step 3.4 prepares the variants for the checks that follow and removes nothing.

    Each step has its own page with the PLINK command, the expected numbers and the reason for the threshold.

  21. Slide 21 of 21

    What we will do

    • Module 2: 2,016 wells and 299,523 variants converted and checked.
    • Modules 3 and 4: 1,844 samples and 238,513 variants after quality control.
    • Module 5: ancestry, leaving 1,811 samples.
    • Modules 6 and 7: the association scan, the QQ plot and the Manhattan plot.

    Start module 0File formats

    Speaker notes

    The numbers are from the simulated course data, and they are the ones you will see on your own screen.

    At the end you will have a summary statistics file, a Manhattan plot, a QQ plot and a short report with its limits. Start with module 0 to install the programs.