eduKateSG · Why Science?
Jump to one sequence interval without scanning a whole reference—while keeping byte offsets, line geometry and source identity perfectly aligned
Choose the closest route, then return to the full index whenever you need the wider evidence chain.
Science learning becomes powerful when students can tell a measured pattern from a model, a statistical decision from a mechanism, and a useful lead from a finished conclusion. An FAI file is a tab-delimited text index that enables efficient random access to well-formatted FASTA and FASTQ sequences. HTSlib documents five columns for FASTA—NAME, LENGTH, OFFSET, LINEBASES and LINEWIDTH—and a sixth QUALOFFSET for FASTQ. These fields let software calculate a byte position from a sequence coordinate and line layout. The index is tied to the exact source bytes: rewrapping lines, changing newlines, renaming records or rewriting the file can invalidate it even if the visible biological sequence seems unchanged. This guide supports Primary Science, PSLE Science, Secondary Science, O-Level Science and STEM education as a longform evidence-reading route; it is not medical advice, a laboratory protocol, an admission promise or a career guarantee.
Related eduKate reading: refget and globally identifiable reference sequences; BGZF and blocked compression for genomic data; SAM and human-readable sequence alignments; Science Learning Hub; Education Hub; STEM Education; Careers by Subject Capability.
Primary and official sources checked on 12 October 2026: Official HTSlib faidx file-format manual; Official samtools faidx command manual; Official SAM/BAM format specification for reference dictionary context; 2026 Singapore–Cambridge O-Level Biology syllabus; MOE G2/G3 Lower Secondary Science teaching and learning syllabus; 2026 MOE G2 Computing syllabus. Specifications, tools and recommendations can change, so preserve the dated documentation, exact source bytes, parser rules and software versions used.
A deeper reading route
FAI works because regularly wrapped text has predictable geometry. If each full sequence line contains the same number of bases and occupies a known number of bytes including its terminator, software can calculate how many complete lines precede a target position and how far into the next line to seek. It turns a large text file into something close to an addressable array without copying the sequences into the index.
NAME and LENGTH describe the logical sequence, while OFFSET, LINEBASES and LINEWIDTH describe its physical representation. OFFSET is the zero-based byte position of the first sequence base. LINEBASES counts bases per ordinary line; LINEWIDTH counts bytes, including newline bytes. Their difference commonly reveals LF versus CRLF but can also expose unusual terminators. These are byte facts, not genomic coordinates.
For FASTQ, QUALOFFSET adds the byte position of the first quality character. HTSlib requires quality lines to use the same wrapping as their corresponding sequence lines for indexing. Random access can then recover both a sequence interval and its quality substring. This capability does not solve ordinary paired-read lookup or validate the quality encoding.
The arithmetic is simple enough to audit. Convert the requested biological coordinate to the interface convention, calculate complete line blocks from LINEBASES, add newline bytes through LINEWIDTH and then add the within-line remainder to OFFSET. A single off-by-one, wrong newline width or coordinate convention can return letters that look believable because neighbouring sequence is also valid DNA.
Compression changes the address space. Plain FASTA uses ordinary byte offsets; bgzip-compressed FASTA can use additional .gzi information so a library maps uncompressed positions into BGZF blocks. The FAI and any compression index must match the exact object. Ordinary gzip cannot simply be treated as a seekable plain file.
Freshness is therefore a scientific integrity property. A stale .fai can keep the same filename and still point into the wrong record after rewrapping or edits. Robust workflows pair file and index hashes, rebuild after any rewrite, and compare indexed retrieval with a sequential parser at known boundaries.
Performance testing should distinguish index construction, cold-cache retrieval, warm-cache retrieval and complete scans. A tiny interval query may be dominated by storage latency, while a broad query can approach sequential reading cost. Remote storage adds range-request behaviour and object-version stability. Benchmarks should record interval width, file size, cache state, compression, hardware and returned sequence equality so speed remains interpretable rather than becoming a context-free headline.
Defensive implementations also bound every arithmetic operation. Corrupt lengths, offsets or line widths can produce overflow, seeks beyond the object or enormous allocations. A safe reader checks that fields are non-negative and internally possible, that OFFSET and QUALOFFSET lie within the source, and that the calculated final base does not exceed file size. Structural failure should be reported clearly instead of returning a plausible neighbouring substring.
Concurrency adds another practical layer. Several workers may safely read one immutable indexed reference, but replacing the FASTA or its index while queries are running can mix object generations. Atomic publication, immutable object versions and cache invalidation protect readers from pairing an old FAI with new bytes. A service should expose which object version answered a query so failures can be reproduced. That receipt should include the requested name, interval, source digest and index digest.
For students, FAI is a delightful coordinate puzzle. The index records where a chapter begins, how many letters fit on each printed line and how many bytes each line occupies. Mathematics then takes us directly to the requested character. The scientific lesson is equally important: an index is trustworthy only while it stays bound to the exact book edition.
| Stage | Question | Evidence | Responsible output |
|---|---|---|---|
| Describe | Which sequence and layout are indexed? | NAME, LENGTH, LINEBASES and LINEWIDTH | A logical and physical record model |
| Locate | Where do sequence or quality symbols begin? | OFFSET and optional QUALOFFSET | A byte-addressable start |
| Retrieve | Which bytes contain the requested interval? | Coordinate conversion and line arithmetic | An efficient subsequence result |
| Verify | Does the index still match the source? | Hashes, boundary tests and full-scan comparison | A trustworthy access path |
Inside this guide
1–12 · Foundations and design
- 1. Start with the access need
- 2. Use the official faidx description
- 3. Recognise the companion filename
- 4. Read five FASTA columns
- 5. Read the FASTQ sixth column
- 6. Interpret NAME
- 7. Interpret LENGTH
- 8. Interpret OFFSET
- 9. Interpret LINEBASES
- 10. Interpret LINEWIDTH
- 11. Explain the newline difference
- 12. Interpret QUALOFFSET
13–24 · Models and estimation
- 13. Require well-formatted FASTA
- 14. Require consistent terminators
- 15. Calculate complete lines
- 16. Calculate the within-line remainder
- 17. Assemble the byte address
- 18. Respect query coordinate syntax
- 19. Reject out-of-range requests
- 20. Preserve record order
- 21. Detect duplicate operational names
- 22. Bind to exact source bytes
- 23. Use hashes for freshness
- 24. Handle bgzip separately
25–36 · Diagnostics and interpretation
- 25. Do not treat ordinary gzip as BGZF
- 26. Compare with sequential retrieval
- 27. Check reference dictionary agreement
- 28. Connect to Primary Science
- 29. Connect to Secondary Science
- 30. Connect to mathematics
- 31. Connect to computing
- 32. Connect to pathways
- 33. Did you know?
- 34. Write a reader-ready indexing note
- 35. Build a validation ladder
- 36. Finish with a reproducible bundle
Section 1 of 36
1. Start with the access need
FAI is useful when a program needs arbitrary sequence regions from a large text reference without reading every preceding record.
Working checkpoint — FAI index: Name the file type, compression and coordinate interface first. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 2 of 36
2. Use the official faidx description
HTSlib defines faidx as an index enabling random access to FASTA and FASTQ files and documents the text index layout.
Working checkpoint — byte offset: Record the library and samtools versions used. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 3 of 36
3. Recognise the companion filename
The index typically appends .fai to the source filename, such as reference.fa.fai or reads.fastq.fai. Naming is convenience, not identity proof.
Working checkpoint — LINEBASES: Pair source and index with hashes rather than basenames alone. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 4 of 36
4. Read five FASTA columns
A FASTA FAI line has NAME, LENGTH, OFFSET, LINEBASES and LINEWIDTH separated by tabs.
Working checkpoint — LINEWIDTH: Validate exactly five fields and numeric bounds. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 5 of 36
5. Read the FASTQ sixth column
A FASTQ FAI adds QUALOFFSET, the byte position of the first quality symbol after the + line.
Working checkpoint — QUALOFFSET: Require the sixth field only for the correct source type. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 6 of 36
6. Interpret NAME
HTSlib uses the first word after the FASTA > or FASTQ @ header as NAME, skipping initial whitespace after the marker.
Working checkpoint — random access: Check uniqueness under this exact rule. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 7 of 36
7. Interpret LENGTH
LENGTH is the number of sequence bases in the record. It supports range validation and corresponds conceptually to LN in a matching SAM @SQ entry.
Working checkpoint — FAI index: Compare indexed lengths with a full parse and header dictionary. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 8 of 36
8. Interpret OFFSET
OFFSET is the zero-based byte position of the first sequence base, immediately after the header newline.
Working checkpoint — byte offset: Do not confuse it with a genomic coordinate or BGZF virtual offset. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 9 of 36
9. Interpret LINEBASES
LINEBASES is the number of sequence bases on each ordinary line, except that the final line may be shorter.
Working checkpoint — LINEBASES: Reject irregular internal wrapping. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 10 of 36
10. Interpret LINEWIDTH
LINEWIDTH is the number of bytes occupied by an ordinary sequence line including its line terminator.
Working checkpoint — LINEWIDTH: Measure bytes, not displayed characters. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 11 of 36
11. Explain the newline difference
With LF, LINEWIDTH is commonly LINEBASES plus one; with CRLF it is commonly plus two. Other consistent terminators can differ.
Working checkpoint — QUALOFFSET: Detect newline style per sequence. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 12 of 36
12. Interpret QUALOFFSET
For FASTQ, QUALOFFSET points to the first quality character after the + line newline. Quality line geometry must correspond to sequence wrapping.
Working checkpoint — random access: Check equal sequence and quality lengths before indexing. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 13 of 36
13. Require well-formatted FASTA
HTSlib requires sequence lines within each record to have equal length except the final line, though different records may use different widths.
Working checkpoint — FAI index: Validate every line, not a small sample. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 14 of 36
14. Require consistent terminators
Line termination must be consistent at least within each reference sequence for predictable byte arithmetic.
Working checkpoint — byte offset: Reject mixed LF and CRLF inside one record. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 15 of 36
15. Calculate complete lines
For a zero-based target position, integer division by LINEBASES gives the number of complete sequence lines before it.
Working checkpoint — LINEBASES: Test positions zero, one line boundary and the final base. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 16 of 36
16. Calculate the within-line remainder
The remainder after division by LINEBASES gives the target base’s position inside its sequence line.
Working checkpoint — LINEWIDTH: Keep coordinate conversion separate from byte arithmetic. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 17 of 36
17. Assemble the byte address
Add OFFSET, complete lines multiplied by LINEWIDTH and the within-line remainder to obtain the uncompressed byte location.
Working checkpoint — QUALOFFSET: Audit the formula with a tiny hand-written FASTA. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 18 of 36
18. Respect query coordinate syntax
Command-line region syntax can be one-based and inclusive even though OFFSET is zero-based bytes and internal calculations may use zero-based positions.
Working checkpoint — random access: Document each boundary conversion explicitly. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 19 of 36
19. Reject out-of-range requests
Positions beyond LENGTH, reversed intervals and unknown names should produce clear errors rather than clipped or empty scientific results.
Working checkpoint — FAI index: Test invalid ranges deliberately. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 20 of 36
20. Preserve record order
FAI lines normally follow source record order and are commonly sorted by OFFSET. Reordering the source without rebuilding changes offsets.
Working checkpoint — byte offset: Compare index order with the FASTA scan. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 21 of 36
21. Detect duplicate operational names
Headers with unique full descriptions can still collide when only the first word is indexed. Retrieval by NAME then becomes unsafe.
Working checkpoint — LINEBASES: Fail indexing or rename through a documented mapping. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 22 of 36
22. Bind to exact source bytes
Rewrapping, changing line endings, editing descriptions or inserting records changes offsets even when selected sequences remain identical.
Working checkpoint — LINEWIDTH: Regenerate FAI after every source rewrite. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 23 of 36
23. Use hashes for freshness
File modification times and matching stems are weak evidence. Content hashes and sizes provide a stronger pairing between index and source.
Working checkpoint — QUALOFFSET: Store hash, size and creation command together. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 24 of 36
24. Handle bgzip separately
BGZF-compressed FASTA can support random access with faidx plus compression-aware mapping such as a .gzi index. Compressed and uncompressed offsets are different spaces.
Working checkpoint — random access: Validate all companion indexes against the exact BGZF file. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 25 of 36
25. Do not treat ordinary gzip as BGZF
A generic gzip stream may decompress successfully but lacks the blocked structure used for efficient seeking.
Working checkpoint — FAI index: Inspect the container instead of trusting .gz. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 26 of 36
26. Compare with sequential retrieval
Known intervals obtained through FAI should match a full parser applying the same coordinate convention.
Working checkpoint — byte offset: Test starts, line boundaries, record ends and ambiguous bases. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 27 of 36
27. Check reference dictionary agreement
FAI NAME and LENGTH can help build or compare SAM sequence dictionaries, but names alone do not establish exact sequence identity.
Working checkpoint — LINEBASES: Add sequence digests or refget identifiers. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 28 of 36
28. Connect to Primary Science
A catalogue listing each story’s start page and line width can guide pupils directly to one letter.
Working checkpoint — LINEWIDTH: Use a small fictional book and verify by counting. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 29 of 36
29. Connect to Secondary Science
FAI shows how careful measurement of layout enables fast access while leaving biological meaning in the underlying reference.
Working checkpoint — QUALOFFSET: Separate index correctness from sequence correctness. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 30 of 36
30. Connect to mathematics
Integer division, remainders, coordinate conversion and linear functions make the byte-address formula transparent.
Working checkpoint — random access: Derive one address by hand. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 31 of 36
31. Connect to computing
Text encodings, newlines, byte offsets, compression layers and validation show why representation details matter.
Working checkpoint — FAI index: Test LF, CRLF and malformed wrapping fixtures. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Section 32 of 36
32. Connect to pathways
Sequence indexing connects bioinformatics, algorithms, storage engineering and scientific data stewardship and can illuminate STEM pathways.
Working checkpoint — byte offset: Check current official qualifications separately. Read every retrieved region beside its coordinate convention, reference identifier and a sequential comparison.
For future study, connect arithmetic to bioinformatics and storage systems while checking pathways separately.
Section 33 of 36
33. Did you know?
Two FASTA files can contain the same concatenated sequence letters yet need different FAI offsets because one uses 60-base LF lines and another 80-base CRLF lines.
Working checkpoint — LINEBASES: Compare LINEBASES and LINEWIDTH before reusing an index. Preserve malformed and duplicate-name findings; successful common queries do not prove every boundary.
For scientific writing, report byte geometry, hashes, commands and equivalence tests.
Section 34 of 36
34. Write a reader-ready indexing note
Name source hash, format, compression, record naming rule, newline style, faidx version, commands and verified intervals.
Working checkpoint — LINEWIDTH: Keep the index and validation receipt beside the source. Separate index correctness from sequence identity, annotation correctness and biological meaning.
For students, ask how division and remainders locate a character in a regularly printed book.
Section 35 of 36
35. Build a validation ladder
Check fields, names, lengths, offsets, line geometry, optional qualities, compression companions and sequential equivalence.
Working checkpoint — QUALOFFSET: Stop at the first mismatched byte or base. Treat byte offsets, newlines, wrapping and exact object version as scientific inputs: one rewrite invalidates addresses.
For parents, ask whether the index was matched to exact source bytes.
Section 36 of 36
36. Finish with a reproducible bundle
Deliver source and FAI hashes, any .gzi, manifest, commands, boundary fixtures, comparison logs and reference identifiers.
Working checkpoint — random access: Make every retrieved interval traceable to exact bytes. Keep source and FAI hashes, name rules, lengths, offsets, line geometry, compression companions and tool versions together.
For a classroom model, index a fictional sequence with fixed line widths.
Contents · Previous section · Continue to the Science Learning Hub
