Lecture 8 · Module II · BU1.3
October 25, 2026
Note
Last week: clean reads. Today: an address for every read. Space Ranger runs STAR for Visium — so this is not a detour.
| Field | Value |
|---|---|
| Sample | SRR8836894 — GSM3702795, PC9 control, GSE129221 |
| Layout | paired-end, 2 × 150 bp |
| Reads | 5,000 pairs |
| Reference | GRCh38 |
| Annotation | Ensembl 115 — 6,661 genes, 44,417 transcripts |
| Tools | STAR 2.7.11b · samtools 1.19.2 · featureCounts 2.1.1 |
Note
We run FastQC, trim with fastp, and check the result before alignment. Everything today uses this one sample — the alignment numbers on the slides are the numbers you will see in your notebook.
Three questions. Sixty seconds each. Write your answer before I reveal it.
Reading the answer twice teaches you nothing. Getting it wrong once and correcting it does.
@SRR8836894.1 1/1
GTCGGAGCACATCTTGCTGGCCCAGGTGTTCAGCAAGATGGAGCAGGTGTCTGGCGTG
+
+AFAI<FFF77<AF-AAF7FAAJJJ7JFAJ-FFF-FF--7---F<<F<AJJFFAFJJAJ-
Line 4 is a quality string. In it, the character I appears.
I mean?ASCII table (excerpt) — use it to decode I:
| ASCII | 70 | 71 | 72 | 73 | 74 |
|---|---|---|---|---|---|
| Char | F |
G |
H |
I |
J |
I mean? From the table, I is ASCII 73. Phred+33: 73 − 33 = Q40.\[P(\text{error}) = 10^{-Q/10} = 10^{-4}\]
Note
A trimmer edits line 2 and line 4 together. Editing only one corrupts the record.
Does this require trimming? If yes, exactly what — and what do you leave alone?
Trim adapters and the low-quality tail. Do not trim the whole read.
In this lecture, the trimming is already done — we inherit the cleaned files.
Important
Trimming is not a ritual. The plot is the evidence. A clean library does not need aggressive trimming — and over-trimming creates “too short” reads that never align.
After trimming:
R1 has 4,998,000 records.R2 has 5,000,000 records.Can you align these two files together?
No. STAR reads mate 1 and mate 2 together, record by record. Unequal counts mean the pairing is broken.
First check:
Usual cause: the trimmer ran in single-end mode, or one mate was filtered out.
Note
Before alignment, prove the two files still describe the same fragments. This is a 5-second check that saves an hour.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
1. Review: Clean Reads, Clean Decisions
lecture-08-data.tar.gz; unpack it into data/.Important
Trim adapters and the 3′ tail — not the whole read.
Come back when: trimmed mates have equal line counts and the MultiQC report is open.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
2. The Alignment Problem
A read is a 150-letter fragment. The genome is 3 billion letters.
ACGTAGCTTAGTTGCACGTAACGTAWhere does this read belong?
2. The Alignment Problem
Alignment = the position and strand where that fragment best matches the reference.
Note
“Where does it map?” is not one question. It is where, how well, and how sure.
2. The Alignment Problem
Important
One mismatch breaks an exact match — even when the read is biologically correct.
2. The Alignment Problem
Millions of bases occur in many places. One read can have dozens of equally good homes.
Note
Exact matching returns many hits; the aligner must choose.
2. The Alignment Problem
Every read has a reverse complement. The search must consider both orientations.
Note
A perfect match on the reverse strand is still a perfect match.
2. The Alignment Problem
150 bp against 3 Gbp.
Important
Naive search: 3 Gbp × 50 M reads. Impossible. The index makes it possible.
2. The Alignment Problem
The read is contiguous. The genome is not.
An RNA-seq read can span an exon–exon junction. The aligner must split the read and invent an intron — not reject it as a bad match.
2. The Alignment Problem
| Genome aligner | Pseudo-aligner | |
|---|---|---|
| Examples | STAR, HISAT2 | salmon, kallisto |
| Output | BAM with coordinates | counts, no BAM |
| Splicing | explicit junctions | k-mer compatibility |
| Use here | QC, IGV, counting, Space Ranger | fast expression estimates |
Note
We need a BAM: it is the object we QC, the object we count, and the object Space Ranger produces. That is why we use STAR.
2. The Alignment Problem
40M + intron + 60M. The aligner searches for the gap — it does not reject the read.2. The Alignment Problem
The aligner must find a short, imperfect, possibly split match in 3 billion letters.
Note
Next: how STAR solves it — the suffix index, the maximal mappable prefix, and the stitch across introns.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
3. STAR 101
STAR indexes every suffix of the genome, finds the longest exact prefix of each read, extends it, and stitches the pieces across introns.
Note
Dobin et al., Bioinformatics 2013. “Ultrafast” is not magic — it is an uncompressed index held in RAM.
3. STAR 101
Four moves — for every read:
3. STAR 101
| Input | What it is | Why STAR needs it |
|---|---|---|
| FASTA | the genome sequence | the text being searched |
| GTF | exons, transcripts, genes | known splice junctions + gene models |
| Index | a precomputed search structure | the difference between hours and seconds |
Next: how STAR builds and uses the index.
3. STAR 101
genomeGenerate cell in the background.tail -f data/star_index/Log.out once, to prove it is alive.STAR --runMode genomeGenerate \
--genomeDir data/star_index \
--genomeFastaFiles data/ref/Homo_sapiens.GRCh38.dna.primary_assembly.sub.fa \
--sjdbGTFfile data/gtf/Homo_sapiens.GRCh38.sub.gtf \
--sjdbOverhang 149 --genomeSAindexNbases 12 \
--genomeSAsparseD 1 --runThreadN 2
# full nohup ... & command is in the notebook3. STAR 101
Ours: 181 Mb → 180 million rows, built once by genomeGenerate.
3. STAR 101
3. STAR 101
Read GTACGT against the sorted list: one pass, narrowed at every letter.
That is why STAR aligns 5,000 read pairs in 23 s, not hours.
3. STAR 101
The list is held in RAM, whole, for the entire run.
| reference | index on disk |
|---|---|
| 181 Mb (chr17/21/22) | 1.7 GB |
| whole genome (3.1 Gb) | ~28 GB |
--genomeSAsparseD trades memory for lookup speed:
1 — store every position: measured 1.4 GB (our run)2 — store every second: measured 638 MB, slower lookup3. STAR 101
STAR takes the read and finds the longest sequence that matches the reference exactly — the maximal mappable prefix (MMP), called seed1.
Everything past seed1 is left unmapped, for now.
3. STAR 101
STAR then searches only the unmapped part of the read and finds its MMP: seed2.
seed2 lands far downstream, between a donor and an acceptor site — the two ends of an intron. The gap between seed1 and seed2 is the intron this read spliced over.
Searching one unmapped piece at a time is what makes STAR fast.
3. STAR 101
A seed does not have to be long to be useful. It only has to be unique enough to anchor the search.
A seed that appears everywhere anchors nothing: STAR only uses seeds that map to fewer than 10,000 places in the genome (--seedMultimapNmax 10000, STAR’s default, which we left alone).
3. STAR 101
If the rest of the read has no exact match — a mismatch, an indel, a low-quality base — the previous seeds are extended, base by base, scoring every base added.
The red bar is a mismatch accepted during extension.
3. STAR 101
When extension does not give a good alignment, the end of the read is soft clipped: adapter, poor quality, or contaminating sequence.
The clipped bases are not thrown away: they stay in the record, marked S in the CIGAR, outside the aligned blocks.
3. STAR 101
Seeds are clustered around anchor seeds — seeds that map to one place only — then stitched into one alignment, scored by mismatches, indels, and gaps.
The dashed line in the stitched read is the intron.
Important
Stitching is what makes STAR splice-aware.
A DNA aligner would stop at the exon boundary; STAR starts a second search.
3. STAR 101
| piece | meaning |
|---|---|
110M |
110 bp aligned to exon 1 |
7018N |
7,018 bp skipped — an intron |
40M |
40 bp aligned to exon 2 |
the read never loses bases; the genome skips them
N is RNA-seq’s signature
3. STAR 101
| annotated | novel | |
|---|---|---|
| source | GTF, baked into the index | found by the reads |
| cost | cheap, already known | must earn its place |
| control | --sjdbGTFfile |
--alignSJoverhangMin 8 |
| trust | high | lower, needs support |
Known junctions are the difference between a fast alignment and a search through every possible intron. --sjdbOverhang = read length − 1 = 149.
3. STAR 101
3. STAR 101
| flag | value | what it controls |
|---|---|---|
--genomeSAindexNbases |
12 | lookup prefix; default 14 segfaults |
--genomeSAsparseD |
1 | dense suffix array: more RAM, faster |
--sjdbGTFfile |
GTF | known junctions in the index |
--sjdbOverhang |
149 | exon sequence flanking each junction |
--outFilterMultimapNmax |
20 | maximum loci reported per read |
--outFilterType |
BySJout |
junction-consistency filter |
--outSAMtype |
BAM SortedByCoordinate |
sorted output, ready to index |
--alignSJoverhangMin |
8 | minimum overhang at a novel junction (default 5) |
--alignSJDBoverhangMin |
1 | minimum overhang at an annotated junction (default 3) |
BySJout is a junction-consistency filter, not a uniqueness filter. A read can be unique and still be filtered if its junction is implausible.
3. STAR 101
The index decides what the aligner can find. The run decides what the file reports.
BySJout, overhang minimums 8 and 1, sorted BAM: four choices about what survives into the file.Important
The flags you did not set are decisions too. --seedMultimapNmax 10000 is STAR’s default, so every stitch step that maps fewer than 10,000 places is allowed. --runThreadN 16 is not a default: it is your machine.
3. STAR 101
tail data/star_index/Log.out and ls -lh data/star_index — confirm the build finished.sample.Log.progress.out while it runs (~83 s).sample.Log.final.out and leave it on screen.Come back when the final log is generated. We will read it together.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
4. Reading a BAM
| Format | What it is | When you meet it |
|---|---|---|
| SAM | plain text, one line per alignment | debugging, samtools view |
| BAM | binary, compressed, indexable | the working format |
| CRAM | reference-compressed | long-term archives |
Note
BAM is the interchange format: IGV reads it, featureCounts reads it, GATK reads it, Space Ranger writes it. Learn one, and the rest of the course can read the file.
4. Reading a BAM
@HD VN:1.6 SO:coordinate
@SQ SN:17 LN:83257441
@SQ SN:21 LN:46709983
@SQ SN:22 LN:50818468
@PG ID:STAR PN:STAR VN:2.7.11b
CL:STAR --runMode alignReads --genomeDir data/star_index ...
@HD — file format and sort order.@SQ — the reference dictionary: names and lengths.@PG — the exact command that made the file.Important
The BAM remembers how it was made. That is reproducibility you do not have to reconstruct from memory.
4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
QNAME is the read’s name. Mates share it: SRR8836894.3781 appears twice in our BAM, once per end of the pair.FLAG is a sum of bits: 99 = 1 + 2 + 32 + 64. Paired, proper pair, mate on the forward strand, this record is read 1.FLAG gets its own slide.4. Reading a BAM
the bits sum to the number: 99 = 1 + 2 + 32 + 64
4, 8: unmapped, no mate — special cases; 512, 1024: secondary, duplicate
2, 4, 8, 512, 1024 are mutually exclusive; 1, 16, 32, 64, 128 combine freely
99 and 147 are the normal pair, and they are exactly half of our BAM: 300 + 300. If you remember two numbers, remember those.
4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
RNAME is the contig as STAR wrote it: 17, not chr17.POS is 1-based, the leftmost aligned base: 79100.POS is the left end of the first block. This record ends at 86267; POS + read length is not the end.4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
MAPQ answers: how much do you trust this placement?MAPQ 3, 76 are MAPQ 1 — they fit in more than one place, and STAR is telling you.MAPQ is not a bad read. It is an honest read.MAPQ gets the next slide, with the distribution.
4. Reading a BAM
MAPQ |
measured in our BAM |
|---|---|
| 255 | one place — 1,106 primary records |
| 124 records below | shown in the figure |
124 primary records are lower than 255: 48 at MAPQ 3, 76 at MAPQ 1
Log.final.out counts them: 553 uniquely mapped (11.06%), 62 mapped to multiple loci (1.24%)
Low MAPQ is honesty, not failure: the read fits in more than one place, and STAR is telling you so. The NH tag, at the end of the record, is where STAR writes that number down.
4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
110M7018N40M: 110 aligned, 7,018 skipped, 40 aligned.N is the intron. The genome jumps; the read loses nothing.79100–86267, measured from the record. CIGAR gets its own slide, with the figure.4. Reading a BAM
M aligned · I insert in read · D delete from reference · N intron · S soft-clip
5M10I = five aligned, ten inserted: an insertion
S bases are in the SEQ but not counted in POS
Important
N is not a deletion. The read did not lose 7,018 bases — the genome skips them. That is a spliced alignment.
You will see this arc in IGV, Section 5.
4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
RNEXT is the mate’s contig. = means the same chromosome as this record.PNEXT is the mate’s POS: 79158, 58 bases to the right.147, 52M7018N97M1S, ending 86324. Same read name, same intron, opposite end of the fragment.4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
TLEN 7225 is the fragment: leftmost start 79100 to rightmost end 86324, counted across the intron.+7225 on flag 99, -7225 on flag 147.POS — 79158 - 79100 is 58. TLEN is what library prep calls fragment size.4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
SEQ is the read, 150 bases. It includes bases the aligner did not match: the mate’s 52M7018N97M1S aligns 149 and soft-clips 1.QUAL is one character per base, same length as SEQ: # ) - 7 < A F J in our BAM.# is Q2, J is Q41.4. Reading a BAM
| QNAME | FLAG | RNAME | POS | MAPQ | CIGAR | RNEXT | PNEXT | TLEN | SEQ | QUAL | tags |
|---|---|---|---|---|---|---|---|---|---|---|---|
| SRR8836894.3781 | 99 | 17 | 79100 | 255 | 110M7018N40M | = | 79158 | 7225 | GGCACAATGGCT… | AAFFFJJFAAJ<… | NH:i:1 AS:i:282 … |
NH:i:1 — the number of loci STAR found. This is why MAPQ drops: NH:i:2 records carry MAPQ 3, NH:i:3 and NH:i:4 carry MAPQ 1.AS:i:282 — STAR’s alignment score for this record.HI:i:1 — hard-clip count STAR records for the read.nM:i:7 — STAR’s own mismatch-related count. Comparing aligned bases to chr17.fa gives 4 mismatches, so nM is not just “mismatches”; read it as STAR’s count, not a base-by-base tally.Tags come after the 11 mandatory fields, on the same line. samtools view prints them.
4. Reading a BAM
| what you ask | column | example |
|---|---|---|
| which read? | QNAME |
SRR8836894.3781 |
| pair? mate? mapped? | FLAG |
99 |
| where? | RNAME, POS |
17, 79100 |
| how sure? | MAPQ |
255 |
| what shape? | CIGAR |
110M7018N40M |
| bases, quality | SEQ, QUAL |
150 letters, Phred |
| mate position | RNEXT, PNEXT |
=, 79158 |
| fragment length | TLEN |
7225 |
4. Reading a BAM
.baisamtools view file region become instant.Important
samtools idxstats and region queries need the .bai. Without it, they fail with “random alignment retrieval only works for indexed BAMs.” Build the index; do not work around it.
4. Reading a BAM
| File | What it is | Use today |
|---|---|---|
*.Aligned.sortedByCoord.out.bam |
sorted alignments | yes |
*.Log.final.out |
summary metrics | yes |
*.Log.out |
every parameter and step | debugging |
*.Log.progress.out |
live progress | while it runs |
*.SJ.out.tab |
splice junctions | yes |
_STARtmp/ |
temporary sort files | delete after success |
Note
Three files carry the lecture: the BAM (evidence), Log.final.out (the aligner’s opinion), and SJ.out.tab (where the introns are).
4. Reading a BAM
| Flag | What it buys you |
|---|---|
--readFilesCommand zcat |
align .fastq.gz directly — no manual decompression |
--outReadsUnmapped Fastx |
write the unmapped reads, so you can BLAST them and find contamination |
--quantMode GeneCounts |
STAR counts per gene itself — an alternative to featureCounts |
--outSAMattrRGline |
read groups, needed downstream by GATK (not by counting) |
Note
None of these change the concepts. They are the difference between a notebook and a production pipeline.
4. Reading a BAM
samtools view -H — find @PG and the exact command.samtools view | head -1 — decode FLAG, CIGAR, MAPQ.samtools view | awk '$6 ~ /N/' | head -3 — find a spliced read.samtools view -c vs samtools view -c -F 256 — how many records are primary?Come back when you can decode one record out loud.
4. Reading a BAM
4. Reading a BAM
NH:i:1.1418N in the CIGAR: 84 bp exon, 1,418 bp intron, 66 bp exon, and 84 + 66 = 150 bp of read.Tip
TLEN 3589 spans from this read’s start (1,875,710) to its mate’s end (1,879,298). It is the insert size — which the next section will use as a QC check.
4. Reading a BAM
The record states where, how, and how well. Every claim can be re-derived from the columns.
17 1875710 is the address: chromosome, then 1-based start.99 is the shape: paired, proper, first of the pair, mate on the reverse.84M1418N66M is the geometry: exon, intron, exon.255 with NH:i:1 is the confidence: one locus, STAR’s top score.3589 is the pair: this read’s start to its mate’s end.Important
This record is SRR8836894.3116 from our own STAR run, not an invented example. Its mate reads 147 17 1878996 255 66M153N84M, the same pair seen from the other side.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
5. QC: Trust, but Verify
Log.final.out — how many reads mapped, how well, how many splices, how many were discarded.
The BAM itself — flagstat, idxstats, MAPQ, insert size, coverage. What actually landed.
Five questions:
5. QC: Trust, but Verify
Log.final.out, Annotated| Field | Ours | What it tells you |
|---|---|---|
| Number of input reads | 5,000 | fragments in |
| Uniquely mapped reads % | 11.06% | the headline number |
| % of reads mapped to multiple loci | 1.24% | repeats / ambiguity |
| % of reads unmapped: too short | small | over-trimming signal |
| Number of splices: Total | 443 | how much splicing was found |
| Mismatch rate per base | see log | wrong reference / contamination signal |
Important
Read it top to bottom. Every line is a failure mode with a number attached.
5. QC: Trust, but Verify
5,000 input fragments
× (11.06% unique + 1.24% multi) = 615 fragments
× 2 mates = 1,230 primary records
+ 242 secondary = 1,472 records
samtools flagstat says: 1,472 total · 1,230 primary · 242 secondary.
Important
STAR counts fragments (pairs). flagstat counts records (mates). 11% of 5,000 is not 553 records — it is 553 fragments, which is 1,106 mates, plus multi-mappers.
5. QC: Trust, but Verify
flagstat, Annotated| Line | Ours | Meaning |
|---|---|---|
| in total | 1,472 | every record in the BAM |
| primary | 1,230 | one per fragment |
| secondary | 242 | extra loci for multi-mappers |
| duplicates | 0 | not marked; meaningless at this depth |
| properly paired | 1,230 (100%) | over primary, not input |
| read1 / read2 | 615 / 615 | the pair is balanced |
Note
100% properly paired sounds perfect because it is measured over the reads that made it into the BAM. It says nothing about the 89% that did not map.
5. QC: Trust, but Verify
idxstats and the 3-Chromosome Reality| Contig | Length | Mapped |
|---|---|---|
17 |
83,257,441 | 830 |
21 |
46,709,983 | 378 |
22 |
50,818,468 | 264 |
* |
— | 0 |
Important
The arithmetic closes against flagstat. That is the single best end-to-end check in the notebook: if these do not match, one of your assumptions is wrong.
5. QC: Trust, but Verify
Expect a spike at 255 (unique) and a small tail at 0–3 (multi-mapping).
Note
MAPQ answers “how many places could this read come from?” — not “how correct is this base?”
5. QC: Trust, but Verify
samtools stats | grep “insert size”. A sharp peak is healthy. A bizarre spread means a library or pairing problem.
Coverage should be even across the gene. A slope means degraded RNA or a library-prep bias.
A few genes dominating the reads usually means rRNA contamination. chrM is absent from our reference, so we cannot see it here.
Reads should not pile onto one strand unless the protocol is stranded. A strong skew means the wrong library chemistry.
At 5,000 pairs these are concepts, not measurements. Qualimap and RNA-SeQC do them properly at real depth.
5. QC: Trust, but Verify
| Symptom | Usual cause | First check |
|---|---|---|
| Unique rate very low | wrong reference / contig naming / rRNA | @SQ names vs FASTA/GTF |
| Many “too many loci” | repeats, rRNA, short reads | --outFilterMultimapNmax, FastQC |
| Mismatch > 2–3% | wrong species/assembly, contamination | reference build |
| Many “too short” | over-trimming | trim settings, read length |
| 5′/3′ bias | degraded RNA / library | RIN, coverage plot |
| Duplicates > 50% | PCR over-amplification | only meaningful at real depth |
Note
One number is never a diagnosis. The red flag is a pattern across logs, not a single threshold.
5. QC: Trust, but Verify
No. The denominator is the reference, not the sample.
Tools for real data: Qualimap (5′/3′, duplication, coverage), MultiQC (aggregates logs), IGV (eyes on a locus).
5. QC: Trust, but Verify
chr21:8,210,178–8,219,821 — 9,645 bp, 74 records.
149M1S, 88M62S, 114M36S.Unassigned_NoFeatures seen with eyes.A log gives the average. The locus shows what the average is hiding.
5. QC: Trust, but Verify
chr22:39,313,952–39,318,985 — gene RPL3, 14 records, 7 junction arcs.
N in the CIGAR — you decoded one in Section 4.Note
Load BAM + .bai · FASTA · GTF. Read the arcs, not just the pileup.
5. QC: Trust, but Verify
samtools index — build the .bai.samtools flagstat, idxstats, stats | grep "insert size".featureCounts — then read the .summary rows, not just the matrix.Come back when the arithmetic closes.
5. QC: Trust, but Verify
2% uniquely mapped. 70% “too many loci.”
What is going on?
5. QC: Trust, but Verify
Option 2: the reads match many places in the genome.
Repeats or rRNA: many loci match, so STAR reports “too many loci” instead of guessing. Too-short reads are reported as “too short”, and a missing contig gives unmapped reads, not a loci warning.
The wrong reference produces the same signature.
5. QC: Trust, but Verify
95% mapped. 40% mismatch rate.
What do you suspect?
5. QC: Trust, but Verify
Option 3: the reference does not match the reads.
40% mismatch means the reference is not the species, or not the assembly version, the reads came from. Duplicates do not raise the mismatch rate, and soft-clipped bases are not counted as mismatches.
5. QC: Trust, but Verify
Properly paired: 60%. Insert sizes huge.
What is broken?
MAPQ is too low5. QC: Trust, but Verify
Option 1: the library.
Long fragments and lost proper pairs are library prep and pairing. Look at the insert size distribution before you blame the aligner: missing introns show up in CIGAR, not in FLAG.
5. QC: Trust, but Verify
10% of all reads land on one small contig.
Most likely?
5. QC: Trust, but Verify
Option 3: contamination, or a contig the aligner cannot resolve.
A small contig carrying 10% of the reads is rRNA, adapter, or spike-in. It can also be a collapsed repeat: every copy maps to one place. Size and pairing do not explain a pile-up on a small contig.
1. Review: Clean Reads, Clean Decisions
2. The Alignment Problem
3. STAR 101
4. Reading a BAM
5. QC: Trust, but Verify
6. From BAM to Counts
6. From BAM to Counts
-t exon is what to count, -g gene_id is what to report-p --countReadPairs counts the pair, not the two reads6. From BAM to Counts
6. From BAM to Counts
BAM ──► fragment ──► overlaps an exon? ──► gene_id
│
├── no → Unassigned_NoFeatures
├── many → Unassigned_Ambiguity
└── multi → Unassigned_MultiMapping
Important
featureCounts’ own defaults, printed in its setting block: Multimapping reads: not counted, Multi-overlapping reads: not counted, Min overlapping bases : 1. A fragment that touches two genes is not split between them.
6. From BAM to Counts
448 assigned, 288 unassigned, 736 total
every unassigned fragment is named by cause: multi-mapping, ambiguity, no features
Unassigned_MappingQuality is 0: STAR’s lowest MAPQ here is 1, and the default -q 0 filters nothing
6. From BAM to Counts
-s-s changed-s 0 unstranded · -s 1 forward · -s 2 reverse
the simulated library is unstranded, so -s 0 keeps 448 pairs
forcing -s 1 gives 270 and -s 2 gives 267: 40% of the data thrown away
Important
The wrong -s is the most common “my matrix looks wrong” bug. Check your library, not the tutorial you copied the command from.
6. From BAM to Counts
Chr and Start list one entry per exon, separated by semicolons6. From BAM to Counts
Note
The matrix is the numerator. The summary is the diagnosis. 183 + 74 + 31 is not noise: it says multimapping, overlapping genes, intergenic sequence, in that order. If Assigned is low, the problem is usually alignment or annotation — not counting.
6. From BAM to Counts
A FASTQ record knows its letters. It does not know where it came from.
Important
Today is not “run a tool.” Today is read what the tool produces and decide whether to believe it.
6. From BAM to Counts
igv.png, igv_splice.png): captured for this course from our own STAR BAM, on IGV (Broad Institute, MIT license), Human GRCh38/hg38 with the Ensembl subset GTF loaded.lecture-08/scripts/. The bam_*.png and fc_*.png figures are measured from our own STAR run and our own featureCounts run, not drawn by hand.Log.progress files.featureCounts — genes × samplesImportant
Everything downstream inherits the BAM. A mapping you did not verify becomes a PCA you cannot interpret.
“A FASTQ record knows its letters. It does not know where it came from. Align the reads, and the features appear — exon, intron, gene, count.”
Fighting Cancer with Transcriptomics · Lecture 8