The bioinformatics file-format zoo · Subtopic 3 of 3 · 8 min
GFF, GTF & BED: annotations and intervals
In the file-format zoo you met files that store DNA letters and sequencing reads. Now let's zoom in on a different job: annotation. Annotation simply means labeling where interesting features sit along a genome. A genome is the full string of DNA letters for an organism, and a feature is a meaningful stretch of it, like a gene (a segment that carries instructions) or an exon (a piece of a gene). Annotation files answer one question: what positions does this feature occupy?
GFF and GTF: describing features
GFF stands for General Feature Format and GTF stands for Gene Transfer Format. Both are plain text files where each line describes one feature, and the columns on that line are separated by tabs (invisible spacing characters). The columns you care about most are the sequence name (which chromosome or piece of DNA), the feature type (gene, exon, or CDS, which is the protein-coding part), the start and end positions, and the strand. The strand is written as a plus or a minus and tells you which of the two DNA directions the feature is read in. GTF is just a stricter, more rule-bound version of GFF, used a lot for genes and transcripts.
chr1 ensembl gene 1000 9000 . + . ID=gene1;Name=EXAMPLE1Reading that line left to right: the feature lives on chr1, it was recorded by a source called ensembl, its type is gene, it starts at position 1000 and ends at position 9000, the dot means a score is not given, the plus is the strand, the second dot is another optional field, and the last column holds extra details like the gene's name. One line, one feature.
BED: plain intervals
Sometimes you don't need all that detail, you just want a list of intervals, meaning start-to-end stretches on the genome. BED is the format for that. A BED file can have as few as three columns: the chromosome, the start position, and the end position. That is it. Because it is so lean, BED is quick to read and very popular for marking regions of interest. Let's peek at the first two lines of one with the head command, where -2 means show the first 2 lines.
head -2 genes.bedchr1 999 9000
chr1 11999 14409
Watch out: BED and GFF count positions differently. BED starts counting from 0, while GFF starts counting from 1. That is why the very same gene begins at 1000 in the GFF line above but at 999 in the BED file. The end number, 9000, matches in both because of how BED measures its intervals. When you compare files from the two formats, remember this off-by-one difference so you don't accidentally shift every feature by one letter. It is a classic beginner trap.
Try it yourself: each line in a BED file is one feature, so counting lines counts features. Run wc -l genes.bed and read the number it prints. wc means word count, and the -l flag tells it to count lines instead of words. If it prints '42 genes.bed', your file holds 42 intervals. Heads-up if you try the same on a GFF file: those often begin with header lines that start with a # symbol, and wc -l counts those too, so the line count can be larger than the actual number of features.