MGHome page

GWAS course

Course map

0 of 64 steps done

Start with step 0.1Install R

Saved in this browser only.

Step 1.10

Module 1 · From DNA to array data · step 10 of 11

1.10The formats you will meet most often

Related pages: File formats (small example files for every format) and Lecture slides.

In short

We read small invented examples to learn what common genetic file fields mean. We examine example conversion commands without running them, so we can understand what conversions preserve and what they may lose.

What you do

Read this page. There is no code to run.

Command

No code to run. This is a reading-only step. The shell examples are in the "Example syntax, do not run" boxes.

You need

Step 1.9 and the linked invented examples. No classroom data or password is needed.

What we do

Reading, about 9 minutes. You can come back to it later.

Read fields in tiny invented examples. Conversion commands below are examples to read, not instructions to run.

Why

The files in examples/formats (opens in a new tab) are labelled invented example. S1 to S4 are invented samples. S3 has unknown sex. Five two-allele SNPs have invented GRCh38-style positions on chromosomes 1, 2 and X. One genotype is missing. S1 is male and has one allele copy at these X sites. Two reads belong to the separate 60-base contig toy1.

A header (opens in a new tab) describes a file before its records. Magic bytes (opens in a new tab) are patterns that identify some binary encodings. The supplied binary files have .hex.txt companions showing their first bytes.

FASTQ

Open the read example (opens a file viewer). Each read occupies four lines.

FieldMeaning
Identifier lineStarts with @, then the read name and an optional description.
Sequence lineThe measured DNA bases.
Separator lineStarts with +.
Quality lineOne quality character per sequence base.

Phred quality (opens in a new tab) describes an estimated base-error probability. In Phred+33 encoding, I means quality 40.

Common mistakes

  • The quality line must have the same length as the sequence.
  • Base quality describes a base call, not confidence in its genomic placement.

Alignment software takes reads and a reference, then produces alignment records.

FASTA and FAI

Open the reference (opens a file viewer) and its index (opens a file viewer).

FieldMeaning
FASTA headerStarts with > and names the sequence, here toy1.
FASTA sequenceThe bases belonging to that named sequence.
FAI nameThe sequence identifier.
FAI lengthNumber of bases in the sequence.
FAI offsetByte position of the first sequence base, counting from zero.
FAI line basesNumber of sequence bases per full line.
FAI line widthBytes per full line, including newline characters.

Common mistakes

  • Changing FASTA line breaks can invalidate its byte offsets.
  • A reference name alone does not prove that two sequences match.

SAM, BAM, CRAM and unaligned BAM

Read the SAM example (opens a file viewer). BAM stores the same logical fields in binary. CRAM compresses read records, often against a reference. uBAM (opens in a new tab) stores reads before genomic alignment.

FieldMeaning
@HDHeader line giving the format version and declared sort order.
@SQHeader line naming a reference sequence and its length.
@COHeader comment.
QNAMERead name.
FLAGBit flags (opens in a new tab) combining alignment properties.
RNAMEReference name, or * without a placement.
POSOne-based alignment start, or zero without a placement.
MAPQMapping quality, distinct from individual base qualities.
CIGAROperations describing how read and reference bases align.
RNEXTMate reference name; * when unavailable.
PNEXTMate position; zero when unavailable.
TLENTemplate length; zero when unavailable.
SEQRead bases.
QUALEncoded base qualities.
Optional tagsExtra fields written as TAG:TYPE:VALUE.

The example reads are unpaired. FLAG zero means an unpaired forward alignment with no flags set. A CIGAR (opens in a new tab) of 4M1I5M describes four aligned bases, one inserted read base, then five aligned bases.

Common mistakes

  • A BAM file can be unaligned. Its extension does not prove genomic placement.
  • CIGAR M does not distinguish a matching base from a mismatch.
  • CRAM may need the exact reference used to encode it. Its index must match the current file.
<details><summary>Example syntax, do not run</summary>
samtools view -b -o reads.bam invented_example_alignments.sam
samtools sort -o sorted.bam reads.bam
samtools index sorted.bam

view -b writes BAM. -o names the output. sort orders records by coordinate. index creates the region index. These operations do not call variants.

</details>

VCF and gVCF

Read the multi-sample VCF (opens a file viewer), gVCF (opens a file viewer) and dosage VCF (opens a file viewer). Lines beginning with ## declare metadata. A single-hash header names the columns.

FieldMeaning
CHROMChromosome or contig name.
POSOne-based position of the first reference base.
IDVariant identifier.
REFReference allele.
ALTAlternative allele or alleles.
QUALVariant quality.
FILTERFilter status; PASS means no listed filter failed.
INFOSite annotations declared in the header.
FORMATNames and order of fields in each sample column.
Sample columnsValues for that sample, following FORMAT.
GT (sample field)Allele indices (opens in a new tab): zero is REF and one is the first ALT.
DS (sample field)Dosage (opens in a new tab), the expected ALT count.
GP (sample field)Genotype probabilities (opens in a new tab).
R2 (INFO field)An imputation-quality annotation whose definition depends on its producer.
END (INFO field)Last included position of a gVCF reference block.

A dot marks missing information. 0/1 means REF/first ALT; ./. is missing. A slash leaves allele order unknown. A vertical bar records phase (opens in a new tab), the arrangement across chromosome copies. A gVCF reference block uses <NON_REF> and END to represent a non-variant stretch.

For diploid calls, GP lists 0/0,0/1,1/1. Then DS = GP(0/1) + 2 * GP(1/1). For S1 on X, GP lists 0,1 and DS equals GP(1).

Common mistakes

  • PASS does not prove a correct genotype.
  • REF/ALT order must agree with the stated genome build.
  • Rounding dosage discards uncertainty. A dosage of one need not be a certain heterozygote.
<details><summary>Example syntax, do not run</summary>
plink2 --vcf invented_example_multisample.vcf --double-id --update-sex invented_example_plink2.psam --make-pgen --out converted

--vcf selects the input. --double-id sets both PLINK identifiers from each sample name. --update-sex reads sex metadata. --make-pgen creates the native trio. --out sets its prefix. To import DS instead of calls, --vcf additionally needs the documented dosage=DS modifier.

</details>

Illumina Final Report, IDAT and GTC

Open the Final Report (opens a file viewer). IDAT holds earlier scanner intensities. GTC holds binary calls and related measurements. DRAGEN Array (opens in a new tab) can convert GTC to VCF.

FieldMeaning
[Header]Introduces file information.
[Data]Introduces the measurement table.
SNP NameArray marker identifier.
Sample IDSample identifier.
Allele1 - ForwardFirst called allele on the declared forward strand.
Allele2 - ForwardSecond called allele on that strand.
GC ScoreCalling confidence.
XFirst illustrative normalised intensity.
YSecond illustrative normalised intensity.

Common mistakes

  • GC Score is not a disease probability.
  • "Forward" is Illumina's dbSNP (opens in a new tab)-based forward strand. It is not always the GRCh38 plus strand. See 2.5.
  • Actual exports can select different columns. Check the header before importing.
  • Missing calls use - here. Strand labels need the matching manifest and the checks at 2.5.

Conversion to analysis files depends on the selected export columns and manifest.

PLINK 1 text and binary sets

Inspect PED (opens a file viewer), MAP (opens a file viewer), TPED (opens a file viewer), TFAM (opens a file viewer), BIM (opens a file viewer) and FAM (opens a file viewer). The binary PLINK BED (opens a file viewer) stores calls. Compare it with UCSC BED (opens a file viewer), a text interval file: the shared extension is a classic source of confusion.

FieldMeaning
FIDFamily identifier in FAM, TFAM and PED.
IIDIndividual identifier in those files.
Father IDFather identifier; zero means unknown.
Mother IDMother identifier; zero means unknown.
SexIn FAM/TFAM/PED: 1 male, 2 female, 0 unknown.
PhenotypeIn case-control data, 1 is control and 2 is case. -9 is missing.
Allele pairsTwo alleles per variant in PED, or per sample in TPED; 0 0 means missing.
ChromosomeFirst variant field in MAP, TPED and BIM.
Variant IDSecond variant field.
Genetic distanceDistance in centimorgans (opens in a new tab), units based on inherited chromosome exchanges. Zero when no genetic map is supplied.
Base-pair positionFourth variant field, counting from one.
A1 and A2Two extra BIM fields naming the stored alleles.
BED bytesPacked calls; this variant-major file starts 6c 1b 01.

Common mistakes

  • Keep each companion set together and preserve its sample and variant order.
  • PLINK 1.9 often uses A1/A2 as minor/major labels. Those describe sample frequencies, not genomic REF/ALT.
  • A PLINK BED cannot be read as a UCSC interval table.
<details><summary>Example syntax, do not run</summary>
plink2 --bfile invented_example_plink1 --make-pgen --out converted

--bfile reads the BED/BIM/FAM prefix. --make-pgen creates PGEN/PVAR/PSAM. --out sets the new prefix.

</details>

PLINK 2 native sets

Read PVAR (opens a file viewer) and PSAM (opens a file viewer) alongside PGEN (opens a file viewer).

FieldMeaning
PVAR CHROMChromosome.
PVAR POSOne-based position.
PVAR IDVariant identifier.
PVAR REFReference allele.
PVAR ALTAlternative allele.
PVAR FILTEROptional filter status, included in this example.
PSAM FIDFamily identifier.
PSAM IIDIndividual identifier.
PSAM SEXSex code; NA means unknown here.
PGEN bytesGenotypes and optionally dosages; starts 6c 1b, then storage-mode information.

Common mistakes

  • A reference allele imported from BIM can remain provisional. Conversion does not check it against GRCh38.
  • Column names matter. Read the PVAR and PSAM headers rather than assuming an order.

BGEN

Inspect the BGEN bytes (opens a file viewer) and sample table (opens a file viewer). This BGEN 1.2 example encodes the supplied calls as certainty, with eight bits per probability.

FieldMeaning
Binary headerVariant/sample counts and encoding flags.
bgen signatureFormat marker at byte offset 16.
Variant recordsVariant identifiers, chromosome, position and alleles.
Probability dataEncoded genotype probabilities and chromosome-copy counts.
ID_1, ID_2The two identifiers in the sample table.
missingFraction of missing calls in this export.
sexSex code; NA is unknown here.
Sample type rowSecond row declaring column types.
.bgi companionIndex used to retrieve variants from the matching BGEN.

Common mistakes

  • Do not assume allele order. Declare the order documented by the producer.
  • BGEN layout and probability precision affect decoding. Use the specification (opens in a new tab).
  • An index must match the BGEN file it describes.
<details><summary>Example syntax, do not run</summary>
plink2 --bgen invented_example.bgen ref-first --sample invented_example.sample --make-pgen --out converted

--bgen selects the file. ref-first declares that its first allele is reference. --sample supplies sample descriptions. --make-pgen and --out select the output trio and prefix.

</details>

Summary statistics

Open the summary table (opens a file viewer). Its effects and uncertainties are invented. Step 6.8 creates the classroom table.

FieldMeaning
chromosomeChromosome label.
base_pair_locationOne-based position.
variant_idVariant identifier.
effect_alleleAllele whose effect is reported (opens in a new tab).
other_alleleThe other allele.
effect_allele_frequencyFraction of called alleles (opens in a new tab) matching the effect allele.
odds_ratioEffect on disease odds (opens in a new tab), the probability of disease divided by the probability of no disease.
betaNatural logarithm (opens in a new tab) of the odds ratio.
standard_errorUncertainty of beta (opens in a new tab) on its log-odds scale.
p_valueEvidence against the tested null model (opens in a new tab) of no association.
nNumber of samples with a called genotype in this example.

Common mistakes

  • Read beta with its effect allele, scale and genome build.
  • A missing effect is not zero.
  • GWAS-SSF (opens in a new tab) submissions also need defined study metadata.

References: FASTQ, PMID 20015970 (opens in a new tab); SAM/BAM, PMID 19505943 (opens in a new tab); CRAM, PMID 21245279 (opens in a new tab); CRAM 3.1, PMID 34999766 (opens in a new tab); VCF, PMID 21653522 (opens in a new tab); GATK, PMID 20644199 (opens in a new tab); PLINK, PMID 17701901 (opens in a new tab); second-generation PLINK, PMID 25722852 (opens in a new tab); SAMtools/BCFtools, PMID 33590861 (opens in a new tab); BGEN, DOI 10.1101/308296 (opens in a new tab).

Expected result

Show the expected result

You can explain the header and fields of each example. The genotype files describe five variants, four samples and one missing genotype.

If something goes wrong

If something goes wrong

A binary file will not look like a readable table. Use the description and byte view shown next to the example. The illustrative conversion outputs are not needed for any later step.

Quick check

An imputed sample has probabilities 0.1, 0.8, 0.1. What is its ALT dosage, and is that a certain heterozygous call?

Show the answer

The dosage is 0.8 + 2 * 0.1 = 1. It is not certainty: the two homozygous possibilities still have probability 0.1 each.

Files created

None. The supplied examples are separate reading aids.