Skip to content

Instantly share code, notes, and snippets.

@iam28th
Last active November 16, 2023 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iam28th/49a245427ea2b8ed5f1f9889c13468bf to your computer and use it in GitHub Desktop.
Save iam28th/49a245427ea2b8ed5f1f9889c13468bf to your computer and use it in GitHub Desktop.
Shuffle single end reads in fastq file
#!/bin/sh
# Usage: ./shuf_se.sh <reads1>
# The output file 1_shuffled.fastq contains shuffled reads.
# For shuffling PE reads:
# https://gist.github.com/iam28th/418dc7d5048067af194a76ffb5840c90
input="$1"
awk '{
# read 4 lines
lines[1] = $0;
for (i = 2; i <= 4; ++i)
getline lines[i];
# and print them tab-separated on a single line
for (i = 1; i <= 4; ++i)
printf("%s%s", lines[i], i == 4 ? "'"\n"'" : "'"\t"'")
}' "$input" | \
# shuffle
shuf | \
# replace all tabs back to newlines
tr '\t' '\n' > 1_shuffled.fastq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment