Skip to content

04. Aligning RNA Reads to the Genome

Even cleaned FASTQ files do not say which gene a read came from. You must find each read’s original position in the reference genome before you can count reads by gene. The output of this lesson is an aligned BAM file.

Question for this lesson: How do you put short RNA reads back in the correct positions in the genome?

Imagine having a code fragment without knowing which repository and line it came from. You search the entire codebase for the closest match, then attach a file and line address. Alignment has the same structure: it is a search and address-assignment operation.

InputSearch referenceProcessingOutput
Short FASTQ readsReference genome + GTFSearch candidate locations and select the best matchBAM with coordinates and confidence

1. Alignment: finding the original position of a short read

Section titled “1. Alignment: finding the original position of a short read”

Alignment is the process of placing each FASTQ read back onto a reference genome. The introns have already been removed from mature mRNA, so one RNA-seq read can span two exons that are far apart in the genome. This requires a splice-aware aligner that can split a read across those positions.

Suppose a read joins the end of EXON1 to the beginning of EXON2. The genome contains a long intron between those regions, so a simple substring search fails.

read: ...ACCTG | GAACT...
genome: ...ACCTG | <long intron> | GAACT...
result: align the first part to exon 1 and the second to exon 2

A splice-aware aligner permits a large gap during its search and uses known exon boundaries and candidate junctions to record the two pieces as one read. The structure resembles creating a source map across files, but repeats and base-calling errors can leave more than one plausible location.

Splice-aware alignment diagram: an intron is removed from pre-mRNA to form mRNA, and a short read from that mRNA is split across two exons during alignment

A read from mature mRNA can span two exons separated by an intron. Tools such as STAR and HISAT2 split the read and align each part to the correct position.

STAR and HISAT2 are representative tools. More important than the tool name is using matching reference-genome and GTF versions, and distinguishing reads that align confidently to one location from reads that align ambiguously to several. Just as addresses fail when code and its source map come from different versions, genomic coordinates and gene boundaries can disagree when the genome and GTF versions do not match.

The alignment stage of the RNA-seq exercise runs STAR and inspects Log.final.out, the genome BAM, and the transcriptome BAM together.

See the RNA-seq aligners reference for the differences between STAR and HISAT2, how indexes work, multi-mapping, and how to read the output.

Because RNA reads come from mature RNA with introns removed, one read may align in separate pieces to two exons in the genome. Splice-aware aligners such as STAR and HISAT2 handle this gap.

FASTQ for alignment + reference genome and GTF → splice-aware alignment → BAM

The next lesson, Converting reads into an expression matrix, turns the reads in a BAM file into gene-level expression values.