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.
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.
| Command | Purpose | Files it creates |
|---|---|---|
| bwa index ref.fa | Index for the BWA aligner | .amb, .ann, .bwt, .pac, .sa |
| samtools faidx ref.fa | Lightweight FASTA index for random base lookup | .fai |
| STAR --runMode genomeGenerate | Index for the STAR RNA-seq aligner | a 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
bwa index ref.fa create?