Skip to main content

2.4 GFF Format

GFF Format

GFF (General Feature Format) is a standard file format for storing genomic features and annotations. It describes genes, transcripts, exons, and other genomic elements.

Overview

GFF files contain information about:

  • Gene locations
  • Exon/intron structures
  • Regulatory elements
  • Repeat regions
  • Other genomic features

GFF Versions

GFF3 is the current standard (GFF1 and GFF2 are deprecated)

GFF3 Format Structure

GFF3 files are tab-delimited text files with 9 columns:

Basic Structure

##gff-version 3
chr1    Ensembl gene    1000    9000    .   +   .   ID=gene001;Name=GENE1
chr1    Ensembl mRNA    1000    9000    .   +   .   ID=mRNA001;Parent=gene001
chr1    Ensembl exon    1000    2000    .   +   .   ID=exon001;Parent=mRNA001
chr1    Ensembl exon    5000    6000    .   +   .   ID=exon002;Parent=mRNA001
chr1    Ensembl exon    8000    9000    .   +   .   ID=exon003;Parent=mRNA001

GFF3 Columns

Column Name Description
1 seqid Chromosome or scaffold name
2 source Program/database that generated the feature
3 type Feature type (gene, exon, CDS, etc.)
4 start Start position (1-based, inclusive)
5 end End position (1-based, inclusive)
6 score Confidence score (. if none)
7 strand + (forward), - (reverse), . (unknown)
8 phase For CDS: 0, 1, or 2 (reading frame)
9 attributes Semicolon-separated key=value pairs

Column Details

1. seqid (Sequence ID)

Chromosome or contig name:

chr1, chr2, chrX, scaffold_123

2. source

Source of annotation:

Ensembl, NCBI, StringTie, MAKER

3. type (Feature Type)

Common feature types:

  • gene - Gene
  • mRNA - Messenger RNA (transcript)
  • exon - Exon
  • CDS - Coding sequence
  • five_prime_UTR - 5’ UTR
  • three_prime_UTR - 3’ UTR
  • intron - Intron
  • start_codon - Start codon
  • stop_codon - Stop codon

4-5. start and end

Genomic coordinates (1-based, inclusive):

start=1000, end=2000 means positions 1000-2000 inclusive

6. score

Confidence or quality score:

., 0.95, 100

7. strand

+ (forward/plus strand)
- (reverse/minus strand)
. (not stranded or unknown)

8. phase

For CDS features only - reading frame offset:

  • 0 - First base is the first base of a codon
  • 1 - First base is the second base of a codon
  • 2 - First base is the third base of a codon

9. attributes

Key=value pairs separated by semicolons:

Required:

  • ID - Unique identifier for the feature
  • Parent - ID of parent feature (for hierarchical relationships)

Common optional:

  • Name - Human-readable name
  • Alias - Alternative name
  • Note - Free text description
  • Dbxref - Cross-reference to external database
  • Ontology_term - Gene Ontology term

Example:

ID=gene001;Name=ACTB;Dbxref=GeneID:60;Note=Actin beta

Hierarchical Relationships

GFF3 uses Parent-Child relationships:

gene
    └─ mRNA (Parent=gene)
            ├─ exon (Parent=mRNA)
            ├─ exon (Parent=mRNA)
            └─ CDS (Parent=mRNA)

Example:

chr1    .   gene    1000    9000    .   +   .   ID=gene001;Name=GENE1
chr1    .   mRNA    1000    9000    .   +   .   ID=mRNA001;Parent=gene001
chr1    .   exon    1000    2000    .   +   .   ID=exon001;Parent=mRNA001
chr1    .   CDS 1050    2000    .   +   0   ID=cds001;Parent=mRNA001
chr1    .   exon    5000    6000    .   +   .   ID=exon002;Parent=mRNA001
chr1    .   CDS 5000    6000    .   +   2   ID=cds002;Parent=mRNA001

Example: Complete Gene

##gff-version 3
chr1    Ensembl gene    11874   14409   .   +   .   ID=gene:ENSG00000223972;Name=DDX11L1;biotype=transcribed_unprocessed_pseudogene
chr1    Ensembl transcript  11874   14409   .   +   .   ID=transcript:ENST00000456328;Parent=gene:ENSG00000223972;Name=DDX11L1-202
chr1    Ensembl exon    11874   12227   .   +   .   ID=exon:ENSE00002234944;Parent=transcript:ENST00000456328
chr1    Ensembl exon    12613   12721   .   +   .   ID=exon:ENSE00003582793;Parent=transcript:ENST00000456328
chr1    Ensembl exon    13221   14409   .   +   .   ID=exon:ENSE00002312635;Parent=transcript:ENST00000456328

Working with GFF Files

View GFF file

less annotation.gff3
head -n 20 annotation.gff3

Count features by type

grep -v "^#" annotation.gff3 | cut -f3 | sort | uniq -c

Extract genes only

awk '$3 == "gene"' annotation.gff3 > genes.gff3

Extract features on specific chromosome

awk '$1 == "chr1"' annotation.gff3 > chr1_features.gff3

Extract features in a region

awk 'BEGIN{FS=OFS="\t"} { if($1 == "chr1" && $4 <= 1000000 && $5 >= 500000) {print}}' annotation.gff3 > annotations_chr1_500k-1M.gff3

Convert to BED format

# read and output tab delimited, filter for genes, print the columns and output in BED format
awk 'BEGIN{FS=OFS="\t"} ($3=="gene") {print $1,$4,$5,$9,$6,$7}' annotation.gff3 > genes.bed

Using GFF with Other Tools

bedtools

# Intersect features
bedtools intersect -a peaks.bed -b genes.gff -wa -wb

Best Practices

  1. Always include ##gff-version 3 at the top
  2. Use unique IDs for all features
  3. Maintain Parent-Child relationships consistently
  4. Use standard feature types from the Sequence Ontology
  5. Escape special characters in attributes (commas, semicolons, equals)
  6. Sort by chromosome and position for efficient processing

Additional Resources