This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to subset reads from fastq file to use as test file on a script

I know this question already exists here in Biostars, (see https://www.biostars.org/p/6544/#361743) but it has very old answers (the majority being from 7 years ago), so I wanted to update it.

Context: I created a script that recognises the extension of my file and: 1) if it is fastq, it maps it using Bowtie2; 2) if it's BAM, it does something else. I want to test my script with test files that are small enough for the program to run as fast as possible so I can correct it, but I only've got my original samples (big, human ChIP-seq data). (Bash script, Linux, Bash 4).

The question: I want to know how can I take a subset of reads from the fastq and make a test file with it. It has to be small enough for the program to run fast, but reasonable enough to get mapped without causing errors that might distract me from debugging my script. Which is the current best practice for this? Thank you!

bash fastq subset sample

Given a compressed fastq which you probably already have from whatever source:

zcat file.fastq.gz | head -n (multiplier of 4)

By the way, it is good practice to reference (provide links) threads you mention in questions. I am sure they contain helpful material.

2 answers

I believe the answer remains seqtk - c.f. A: Selecting Random Pairs From Fastq?

Even though the other comments and answers are ok as well, I selected this one because it was simple, fast and effective. Thanks!

Use reformat.sh from BBMap suite.

Sampling parameters:

reads=-1                Set to a positive number to only process this many INPUT reads (or pairs), then quit.
skipreads=-1            Skip (discard) this many INPUT reads before processing the rest.
samplerate=1            Randomly output only this fraction of reads; 1 means sampling is disabled.
sampleseed=-1           Set to a positive number to use that prng seed for sampling (allowing deterministic sampling).
samplereadstarget=0     (srt) Exact number of OUTPUT reads (or pairs) desired.
samplebasestarget=0     (sbt) Exact number of OUTPUT bases desired.

Log in to answer this question.