This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to subsample from multiple fastq files using seqtk command

I have multiple fastq files like this:

TK273759_R1.fastq
TK273760_R1.fastq
TK273761_R1.fastq
TK273762_R1.fastq
TK273763_R1.fastq

I used this command to subsample 500000 reads from those files:

seqtk sample -s100 not_bear_dna/{i}_R1.fastq 500000 > subsample/{i}_R1.fastq

I get this error:

[E::stk_sample] failed to open the input file/stream.

I am not sure what I am doing wrong here, it works for a single fastq file but not for all. Here's my command when I subsample from only one fastq file:

sample -s100 not_bear_dna/TK273759_R1.fastq 500000 > subsample/TK273759_R1.fastq

I appreciate your kind help!

seqtk

You have not shown us your full command - it looks like the seqtk command is part of a loop.

This is the full command I used:

seqtk sample -s100 not_bear_dna/{i}_R1.fastq 500000 > subsample/{i}_R1.fastq

If it's outside a loop, $i probably does not have the value you think it does. Please do not run commands blindly, understand what each part of it does.

1 answer

Are you doing something like:

for i in `ls *_R1.fastq`; do seqtk sample ${i} 500000 > subsample/${i}  ; done

I've moved GenoMax's comment to an answer. Please accept it to provide closure to the post

Log in to answer this question.