Reference
Bioinformatics file formats, explained
What each format stores, how to read it, the coordinate system it uses and the mistakes that catch people out.
FASTA
Plain text for DNA, RNA or protein sequences. Each record starts with a header line beginning with >; the first word is the identifier and the rest is an optional description. Sequence lines follow, usually wrapped at 60 to 80 characters.
>seq1 example nucleotide sequence
ATGGCGTACGTTAGCCTAGGCTAACGTAGCTAGGCTAACGATCGATCGTAGCTAGCTAGGATC
GATCGGCTAGCTAACG
>seq2 a second record
MKTAYIAKQRQISFVKSHFSRQ
- Common extensions:
.fa,.fasta,.fna(nucleotides) and.faa(amino acids). - Index a large FASTA with
samtools faidxto extract regions quickly. - Lowercase bases in genome FASTA files often mark soft-masked repeats; they are still valid sequence.
- Watch for duplicate identifiers and Windows line endings, which break many tools.
FASTQ and quality scores
Raw reads with a quality score for every base, in four-line records: a header beginning with @, the sequence, a separator line beginning with +, and the quality string, which has one character per base.
@read_001 sample=A lane=1
GATTTGGGGTTCAAAGCAGTATCGATCAAATAGT
+
IIIIIIIIIIIIIIIIIIIIIII?????55555+
Each quality character encodes a Phred score: Q = ASCII code − 33 (the Phred+33 or "Sanger" encoding used by all modern instruments). Q is defined as −10·log10(P), where P is the probability that the base call is wrong.
| Phred score | Character | Error probability | Base-call accuracy |
|---|---|---|---|
| Q10 | + | 1 in 10 | 90% |
| Q20 | 5 | 1 in 100 | 99% |
| Q30 | ? | 1 in 1,000 | 99.9% |
| Q40 | I | 1 in 10,000 | 99.99% |
- Paired-end data come as two files (often
_R1and_R2) whose records must stay in the same order. - FASTQ files are usually gzipped:
.fastq.gzor.fq.gz. - Files from Illumina pipelines before version 1.8 may use Phred+64 instead.
- Decode any quality string with the Phred quality converter.
SAM, BAM and CRAM
Aligned reads. SAM is tab-separated text; BAM is the same information compressed in binary; CRAM compresses further by storing differences from the reference, so you need that same reference to read it. Header lines begin with @: @HD (version and sort order), @SQ (reference sequences), @RG (read groups) and @PG (programs used).
@HD VN:1.6 SO:coordinate
@SQ SN:ref LN:45
r001 99 ref 7 30 8M2I4M1D3M = 37 39 TTAGATAAAGGATACTG *
That record (from the SAM specification) is read r001, aligned to ref at position 7 with flag 99 and CIGAR 8M2I4M1D3M. Every alignment line has eleven mandatory columns:
| # | Field | Meaning |
|---|---|---|
| 1 | QNAME | Read (query) name |
| 2 | FLAG | Bitwise flag; see the table below or the SAM flag decoder |
| 3 | RNAME | Reference sequence (chromosome) name |
| 4 | POS | 1-based leftmost mapping position |
| 5 | MAPQ | Mapping quality (Phred-scaled confidence in the position) |
| 6 | CIGAR | How the read aligns; see the CIGAR explainer |
| 7 | RNEXT | Reference name of the mate (= if the same) |
| 8 | PNEXT | Position of the mate |
| 9 | TLEN | Observed template (fragment) length |
| 10 | SEQ | Read sequence |
| 11 | QUAL | Phred+33 base qualities (* if absent) |
Optional fields follow as TAG:TYPE:VALUE, for example NM:i:2 (edit distance), AS:i: (alignment score) and RG:Z: (read group).
FLAG bits
| Bit | Hex | Meaning |
|---|---|---|
| 1 | 0x1 | Read is paired |
| 2 | 0x2 | Mapped in a proper pair |
| 4 | 0x4 | Read unmapped |
| 8 | 0x8 | Mate unmapped |
| 16 | 0x10 | Read on the reverse strand |
| 32 | 0x20 | Mate on the reverse strand |
| 64 | 0x40 | First read in the pair |
| 128 | 0x80 | Second read in the pair |
| 256 | 0x100 | Secondary alignment |
| 512 | 0x200 | Fails quality checks |
| 1024 | 0x400 | PCR or optical duplicate |
| 2048 | 0x800 | Supplementary alignment |
CIGAR operations
| Op | Meaning | Consumes read | Consumes reference |
|---|---|---|---|
| M | Alignment match (sequence match or mismatch) | Yes | Yes |
| I | Insertion relative to the reference | Yes | No |
| D | Deletion from the reference | No | Yes |
| N | Skipped region (an intron, in spliced alignments) | No | Yes |
| S | Soft clip (bases kept in SEQ but not aligned) | Yes | No |
| H | Hard clip (bases removed from SEQ) | No | No |
| P | Padding | No | No |
| = | Sequence match | Yes | Yes |
| X | Sequence mismatch | Yes | Yes |
- Sort BAM files by coordinate and index them (
.baior.csi) before region queries or viewing in IGV. - POS is 1-based in SAM text; inside binary BAM it is stored 0-based, and tools convert for you.
VCF and BCF
Genetic variants and genotypes. Meta-information lines start with ## and define the INFO, FORMAT and FILTER fields used below them; a single header line starting with #CHROM names the columns.
##fileformat=VCFv4.2
##contig=<ID=chr1,length=248956422>
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total depth">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT sample1
chr1 10468 . C T 62 PASS DP=35 GT 0/1
chr1 20345 . GTC G 48 PASS DP=27 GT 1/1
| Column | Meaning |
|---|---|
| CHROM, POS | Chromosome and 1-based position |
| ID | Identifier such as a dbSNP rs number, or . |
| REF, ALT | Reference allele and comma-separated alternate alleles |
| QUAL | Phred-scaled confidence that a variant exists at the site |
| FILTER | PASS, or the names of filters the site failed |
| INFO | Site-level annotations as key=value pairs separated by ; |
| FORMAT | Keys for the per-sample columns, such as GT:AD:DP:GQ |
Genotypes: 0/0 homozygous reference, 0/1 heterozygous, 1/1 homozygous alternate, 1/2 two different alternate alleles and ./. missing. A | instead of / means the genotype is phased.
- Indels include the reference base before the event, so the deletion above removes
TC. - Compress with
bgzipand index withbcftools indexortabixfor region queries; BCF is the binary equivalent. - Normalise with
bcftools normbefore comparing call sets. See the bcftools cheat sheet.
BED
Genomic intervals, one per line, tab-separated. Three columns are required: chromosome, start and end. The start is 0-based and the end is exclusive, so the length of an interval is simply end − start.
chr1 999 2000 peak_1 500 +
chr1 4999 5100 peak_2 320 -
The first line covers 1-based positions 1,000 to 2,000 (1,001 bases). Optional columns 4 to 12 are name, score (0–1000), strand, thickStart, thickEnd, itemRgb, blockCount, blockSizes and blockStarts; the 12-column form (BED12) describes exon structures.
- Sort before merging or finding the closest feature:
sort -k1,1 -k2,2n. - Chromosome names must match your reference (
chr1versus1). - See the bedtools cheat sheet for overlaps and coverage.
GFF3 and GTF
Gene annotation: genes, transcripts, exons and coding sequences, with nine tab-separated columns: seqid, source, type, start, end, score, strand, phase and attributes. Coordinates are 1-based and inclusive. Phase (0, 1 or 2) applies to CDS features and gives the number of bases to skip to reach the next codon.
##gff-version 3
chr1 example gene 1000 9000 . + . ID=gene1;Name=EX1
chr1 example mRNA 1050 9000 . + . ID=mrna1;Parent=gene1
chr1 example exon 1050 1500 . + . Parent=mrna1
chr1 example CDS 1201 1500 . + 0 Parent=mrna1
GTF (also called GFF2.5) uses the same columns but writes attributes as key "value"; pairs and requires gene_id and transcript_id:
chr1 example exon 1050 1500 . + . gene_id "gene1"; transcript_id "mrna1";
- Use the annotation release that matches your reference assembly, and record its version.
- Aligners such as STAR and counters such as featureCounts usually expect GTF.
Coordinate systems
Off-by-one errors are among the most common bugs in bioinformatics. The same first 100 bases of chr1 are written differently in each format:
| Format | Numbering | Bases 1–100 of chr1 |
|---|---|---|
| BED | 0-based start, exclusive end | chr1 0 100 |
| GFF3 / GTF | 1-based, inclusive | chr1 … 1 100 |
| SAM (POS) and VCF (POS) | 1-based | POS 1 |
| Genome browsers (display) | 1-based, inclusive | chr1:1-100 |
| Python slicing | 0-based, exclusive end (like BED) | seq[0:100] |
To convert a 1-based inclusive region to BED, subtract 1 from the start and keep the end. To go back, add 1 to the BED start.
IUPAC nucleotide codes
| Code | Meaning | Complement |
|---|---|---|
| A | Adenine | T |
| C | Cytosine | G |
| G | Guanine | C |
| T | Thymine | A |
| U | Uracil | A |
| R | A or G (purine) | Y |
| Y | C or T (pyrimidine) | R |
| S | G or C (strong) | S |
| W | A or T (weak) | W |
| K | G or T (keto) | M |
| M | A or C (amino) | K |
| B | C, G or T | V |
| D | A, G or T | H |
| H | A, C or T | D |
| V | A, C or G | B |
| N | Any base | N |
The standard genetic code
Rows give the first base of the codon and columns the second; each cell lists the four possible third bases. ATG (methionine) is the usual start codon; TAA, TAG and TGA are stop codons. This is NCBI translation table 1.
| 1st | 2nd: T | 2nd: C | 2nd: A | 2nd: G |
|---|---|---|---|---|
| T | TTT Phe (F)TTC Phe (F)TTA Leu (L)TTG Leu (L) | TCT Ser (S)TCC Ser (S)TCA Ser (S)TCG Ser (S) | TAT Tyr (Y)TAC Tyr (Y)TAA StopTAG Stop | TGT Cys (C)TGC Cys (C)TGA StopTGG Trp (W) |
| C | CTT Leu (L)CTC Leu (L)CTA Leu (L)CTG Leu (L) | CCT Pro (P)CCC Pro (P)CCA Pro (P)CCG Pro (P) | CAT His (H)CAC His (H)CAA Gln (Q)CAG Gln (Q) | CGT Arg (R)CGC Arg (R)CGA Arg (R)CGG Arg (R) |
| A | ATT Ile (I)ATC Ile (I)ATA Ile (I)ATG Met (M) | ACT Thr (T)ACC Thr (T)ACA Thr (T)ACG Thr (T) | AAT Asn (N)AAC Asn (N)AAA Lys (K)AAG Lys (K) | AGT Ser (S)AGC Ser (S)AGA Arg (R)AGG Arg (R) |
| G | GTT Val (V)GTC Val (V)GTA Val (V)GTG Val (V) | GCT Ala (A)GCC Ala (A)GCA Ala (A)GCG Ala (A) | GAT Asp (D)GAC Asp (D)GAA Glu (E)GAG Glu (E) | GGT Gly (G)GGC Gly (G)GGA Gly (G)GGG Gly (G) |
Amino acids
| Amino acid | 3-letter | 1-letter | Side chain |
|---|---|---|---|
| Alanine | Ala | A | Nonpolar, aliphatic |
| Arginine | Arg | R | Positively charged |
| Asparagine | Asn | N | Polar, uncharged |
| Aspartate | Asp | D | Negatively charged |
| Cysteine | Cys | C | Polar, uncharged |
| Glutamate | Glu | E | Negatively charged |
| Glutamine | Gln | Q | Polar, uncharged |
| Glycine | Gly | G | Nonpolar, aliphatic |
| Histidine | His | H | Positively charged |
| Isoleucine | Ile | I | Nonpolar, aliphatic |
| Leucine | Leu | L | Nonpolar, aliphatic |
| Lysine | Lys | K | Positively charged |
| Methionine | Met | M | Nonpolar, aliphatic |
| Phenylalanine | Phe | F | Aromatic |
| Proline | Pro | P | Nonpolar, aliphatic |
| Serine | Ser | S | Polar, uncharged |
| Threonine | Thr | T | Polar, uncharged |
| Tryptophan | Trp | W | Aromatic |
| Tyrosine | Tyr | Y | Aromatic |
| Valine | Val | V | Nonpolar, aliphatic |
Two rarer amino acids, selenocysteine (Sec, U) and pyrrolysine (Pyl, O), are encoded by recoded stop codons in some organisms.