Reference Genomes and Indexing

Before an aligner can place a single read, it builds an index of the reference, the same way a textbook has an index so you do not read every page to find one word. Here is what a reference FASTA is, why the index matters, and the files each tool creates.

🟢 Beginner ⏱️ ~30 min 🌐 Just reading

Before you start

  • A first look at how NGS produces reads helps; start with How NGS works.
  • Any term new? The Glossary has it.

Learning objectives

By the end of this lesson you will be able to: describe what a reference FASTA holds, explain why aligners need an index for fast lookup, name the tools that build indexes (bwa index, samtools faidx, STAR) and the files they create, and understand why the genome must be paired with matching annotation and the correct build.

What a reference FASTA is

A reference genome is distributed as a FASTA file: plain text, one header line per chromosome (starting with >) followed by the sequence. It is the agreed-upon backbone that your reads get compared against during alignment.

# ref.fa  -- a reference FASTA
>chr1
ACGTACGTACGTTTGGCCAA...
>chr2
TTGGCCAAACGTACGTACGT...

A FASTA on its own is just a long string of letters. To actually search it quickly, the aligner first turns it into an index.

1Why aligners need an index

A sequencing run produces millions of short reads, and each one must be located somewhere in a genome of billions of bases. Scanning the whole genome for every read would be hopelessly slow. So aligners build an index first: a precomputed data structure that lets them jump straight to candidate locations, exactly like the index at the back of a book lets you find a topic without reading every page.

reads reference The index says where each read belongs, so no full scan is needed.
Reads (blue) are placed onto the reference (purple) by jumping to candidate spots via the index, not by scanning the whole genome each time.

2The tools and the files they make

Different aligners use different index structures, so each ships its own index builder. You run the indexer once per reference, then reuse the index for every alignment.

CommandPurposeFiles it creates
bwa index ref.faIndex for the BWA aligner.amb, .ann, .bwt, .pac, .sa
samtools faidx ref.faLightweight FASTA index for random base lookup.fai
STAR --runMode genomeGenerateIndex for the STAR RNA-seq alignera genome directory of index files

Two different "indexes"

The .fai from samtools is a small lookup table so tools can grab any region instantly; the bwa index files are a larger structure the aligner needs to place reads. You often build both, because many pipelines use samtools alongside the aligner.

3Worked example: build the indexes

Here is the minimal setup before aligning with BWA. Run these once for a given reference.

# build the BWA index -> ref.fa.amb .ann .bwt .pac .sa
bwa index ref.fa

# build the samtools FASTA index -> ref.fa.fai
samtools faidx ref.fa

# check the files that were created
ls ref.fa*
# ref.fa  ref.fa.amb  ref.fa.ann  ref.fa.bwt  ref.fa.fai  ref.fa.pac  ref.fa.sa

4Match the genome, annotation, and build

The reference rarely travels alone. To know which gene or exon a read landed in, you pair the FASTA with an annotation file (a GTF or GFF) that lists feature coordinates. The catch: the annotation coordinates only make sense on the exact same build, and the chromosome names must match too. Mixing a hg38 FASTA with an hg19 GTF, or chr1 against 1, gives silently wrong results.

Why STAR needs the GTF at index time

STAR can take the annotation GTF when it builds the index, so it knows where splice junctions are and can map reads that span exon boundaries. That only works if the FASTA and GTF are the same build with matching chromosome names.

Check your understanding

Why do aligners build an index of the reference before aligning?
Right. An index is like a book index: it lets the aligner find where a read belongs fast, without scanning billions of bases every time.
Which command builds a lightweight FASTA index (.fai) for random region lookup?
Correct. samtools faidx makes the small .fai index. bwa index and STAR build larger structures for their own aligners.
Which set of files does bwa index ref.fa create?
Right. bwa index produces .amb, .ann, .bwt, .pac and .sa. The .fai comes from samtools faidx; .bam/.bai are alignment outputs.
What is a reference genome distributed as?
Correct. The reference is a FASTA: a header line per sequence (starting with >) followed by the bases. FASTQ holds reads; VCF holds variants.
Why must the annotation GTF match the genome build and chromosome naming?
Exactly. A GTF's coordinates are tied to one build, and chr1 must match chr1. Mixing builds or naming styles gives wrong gene assignments with no error.
Next in Track 2

Read alignment →