Skip to content

Interleaving

github-actions[bot] edited this page Oct 31, 2026 · 1 revision

Interleaving

Paired reads come in two layouts. Most sequencers write two files, R1 and R2; some tools prefer one interleaved file, in which each mate 1 record is followed by its mate 2. interleave and deinterleave move between the two, checking every pair on the way.

R1 and R2 files on the left, one interleaved file on the right with mates alternating; interleave goes right, deinterleave goes left.

Figure 1. Two files and one interleaved file hold the same pairs in a different order.

Both commands validate every record and match the mates' names (Paired reads) before writing a pair. They never trim, reorder, or repair anything.

interleave

z-fastq interleave R1.fastq.gz R2.fastq.gz > interleaved.fastq
z-fastq interleave R1.fastq.gz R2.fastq.gz | gzip > interleaved.fastq.gz

The result goes to standard output as plain FASTQ; pipe it to gzip to compress it. Add --pair-names exact when the whole first word of each name must match.

deinterleave

z-fastq deinterleave --out1 R1.fastq --out2 R2.fastq interleaved.fastq.gz

The first record of each pair goes to --out1, the second to --out2. Both must be new files; z-fastq never overwrites one. A failure partway, such as a broken pair, leaves the two files partly written.

Inputs and failures

Each input may be plain, gzip, or - for standard input, with at most one -. The first broken record, mismatched name, or unequal record count stops the run with a nonzero exit status (Automation).

Wall time and peak memory of other interleaving tools relative to z-fastq, plain and gzip input.

Figure 2. Interleaving: time and peak memory relative to z-fastq. fqkit is faster on plain input, but it, seqtk, SeqFu, and fqtools also write output from broken pairs with exit status 0. The layout benchmark has the details and the same figure for deinterleaving.

Related pages

  • Paired reads: how mate names are matched.
  • Sampling: paired samples come out interleaved.
  • Recipes: an interleaved gzip file in one line.

Clone this wiki locally