Everything for Part 7
Download. Map. Interpret.
Get the ten-slide lesson and a small practice ZIP containing reference.fasta, reads.fastq.gz and a README with the complete commands.
Practice ZIP: about 8 KB · Slides: ten pages, about 130 KB
These are completely synthetic teaching files. Extract the outer ZIP and keep reads.fastq.gz compressed. Copy the two data files into your Part 7 folder; no real sequencing data or earlier practice downloads are needed.
Step 01 · Read placement
A reference gives the reads a coordinate system.
In Part 6, we considered whether reads needed cleaning. Now we ask where reads align on a chosen reference sequence. A read may align on either strand, contain a mismatch, or have no suitable alignment.
The reference is the comparison target you select. Alignment to it does not by itself prove the sample’s organism identity. Likewise, a high-quality read can remain unmapped when it does not match the reference under the selected settings.
- 1Choose a comparison
Use the supplied synthetic reference and reads.
- 2Place the reads
Record alignment positions, strand and differences.
- 3Review the evidence
Inspect mapped records and consider what remains unknown.
Step 02 · Follow the information
From FASTA and FASTQ to SAM, BAM and BAI.
- reference.fasta
- The selected reference DNA sequence, used as the coordinate system.
- reads.fastq.gz
- Compressed reads with base-call quality scores.
- mapped.sam
- Text-based alignment records produced by minimap2.
- mapped.sorted.bam
- Compressed binary alignments sorted by reference coordinate.
- mapped.sorted.bam.bai
- An index for efficient access to positions within the BAM.
Sorting changes the order of alignment records; it does not change the DNA sequences. The BAI is an index, rather than a second set of reads.
Step 03 · Ubuntu terminal
Install minimap2 and SAMtools once.
Open the Ubuntu environment you set up in Part 1 and run:
sudo apt update
sudo apt install minimap2 samtools -y
minimap2 --version
samtools --versionYour Ubuntu password may be requested. If both tools are already installed, check their versions and continue.
Step 04 · Keep the files together
Prepare a separate Part 7 folder.
mkdir -p ~/bioinformatics_training/part7
cd ~/bioinformatics_training/part7
explorer.exe .In the Windows Explorer window, copy reference.fasta and reads.fastq.gz from the extracted practice ZIP into this folder. Return to Ubuntu and check:
ls -lh reference.fasta reads.fastq.gzThe reference is 2,400 bases long. The FASTQ contains 300 reads of 100 bases each: 280 were constructed from two reference flanks and 20 are unrelated synthetic background reads. Some reference-derived reads are reverse-complemented or contain one substitution. These are data-design counts; the aligner’s output still needs checking.
Step 05 · Create the alignment
Map the single-end short reads.
minimap2 -ax sr reference.fasta reads.fastq.gz > mapped.sam-x sr selects minimap2’s short-read preset; -a requests SAM output. Together they appear as -ax sr. The > redirects the alignment output into mapped.sam. Progress messages may still appear in the terminal.
This exercise uses single-end short reads. Different sequencing data can require a different preset. Running this command again replaces the existing mapped.sam in the current folder.
Step 06 · Organise the alignments
Sort the BAM and create its index.
samtools sort -o mapped.sorted.bam mapped.sam
samtools index mapped.sorted.bamThe first command reads the SAM and writes a coordinate-sorted BAM. The second creates mapped.sorted.bam.bai. Both commands can finish without printing a success message.
Keep the reference, reads, sorted BAM and BAI together: you will use these files again for the next exercise.
Step 07 · Check the result
How many alignment records are mapped?
samtools flagstat mapped.sorted.bam
samtools view -c -F 4 mapped.sorted.bamflagstat summarises alignment records and their flags. In view -c -F 4, -c counts records and -F 4 excludes records flagged as unmapped. Secondary or supplementary alignments can make record counts differ from read counts in other datasets.
For this tested dataset there are no secondary or supplementary records, so the mapped record count also equals the number of mapped reads.
What happened in the tested exercise?
The supplied commands were run in Ubuntu 22.04 with minimap2 2.24-r1122 and SAMtools 1.13. All commands completed successfully, and the sorted BAM passed an integrity check.
| Check | Observed result | Interpretation |
|---|---|---|
| Input reads | 300 reads, all 100 bases | All FASTQ records have matching sequence and quality lengths. |
| Mapped | 280 / 300 (93.33%) | The reference-derived reads aligned under the tested settings. |
| Unmapped | 20 / 300 (6.67%) | The unrelated synthetic background reads did not align. |
samtools view -c -F 4 | 280 | No secondary or supplementary alignments were produced in this run. |
| Reference region 1051–1400 | No aligned reads across the designed gap | Most reads can map while part of the reference remains uncovered. |
On a small screen, scroll the table sideways.
Exact outputs can vary with software versions or settings. Compare your results with these observations and investigate differences.
Mapping rate describes the fraction of reads that align. Depth describes reads covering each position; breadth describes the fraction of reference positions covered. Part 8 will show how to measure the last two.
Step 08 · Ten-minute challenge
Explain the result in your own words.
- Run mapping, sorting and indexing from your Part 7 folder.
- Check the mapping summary and mapped record count.
- Explain what information is stored in FASTQ, SAM, BAM and BAI.
- Why does 93.33% mapping not establish complete reference coverage?
- Why does an unmapped read not automatically mean failed sequencing?
Check your reasoning
A read can have no suitable match to the selected reference despite having high base-call quality. Mapped reads can cluster in some regions and leave others without evidence. Interpret the mapping summary alongside the reference choice and the distribution of alignments.
If you get stuck
Share the command, error or result you are unsure about in the Part 7 LinkedIn discussion.
The terminal says “command not found”.
Run the installation commands inside Ubuntu and check the version of each tool. Windows PowerShell and Ubuntu are separate environments.
The reference or FASTQ cannot be found.
Check pwd and ls -lh. The two files must be in your Part 7 working folder, rather than only inside the downloaded ZIP or Windows Downloads folder.
Indexing fails or reports unsorted positions.
Run samtools sort -o mapped.sorted.bam mapped.sam successfully before indexing mapped.sorted.bam. Use the default coordinate sort for this exercise.
I get a different mapped count.
Confirm the exact file names, short-read preset and tool versions. Use a fresh exercise folder if an earlier run left different outputs. Inspect the preceding command’s messages before continuing.
Further reading: the official minimap2 documentation and the SAMtools guides for sort, index and view.
Coming next · Part 8
How much of the reference is covered?
Measure read depth and breadth of genome coverage using the alignments you created here.