File: fastq-interleave

package info (click to toggle)
last-align 963-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,380 kB
  • sloc: cpp: 41,136; python: 2,744; ansic: 1,240; makefile: 383; sh: 255
file content (22 lines) | stat: -rwxr-xr-x 518 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /bin/bash

test $# = 2 || {
    cat <<EOF
Usage: $0 x.fastq y.fastq
or:    $0 x.fastq.gz y.fastq.gz

Read 2 fastq files, and write them interleaved.  Keep just the first
word of header lines, and append "/1" and "/2" if they are otherwise
identical.  Assumes 1 fastq per 4 lines, i.e. no line wrapping.
EOF
    exit
}

fastqTab () {
    gzip -cdf "$@" |
	sed -e 's/^@  */@/' -e 's/ .*//' |
	paste - - - -
}

paste <(fastqTab "$1") <(fastqTab "$2") |
    awk '$1 == $5 {$1 = $1 "/1"; $5 = $5 "/2"} $1 = $1' OFS="\n"