lh3 / seqtk

Toolkit for processing sequences in FASTA/Q formats
MIT License
1.37k stars 308 forks source link

seqtk sample in a loop #112

Closed SimonMorvan closed 6 years ago

SimonMorvan commented 6 years ago

Hello, I'm trying to subsample my fastq files with the seqtk sample function. My files are named SF_Sx_R1.fastq and SF_Sx_R2.fastq, x being a number. I've tried this loop: _for i in {1..10} ; do ./seqtk sample -s100 SF_S$i_R1.fastq 25 > R1_sub$i.fastq ; ./seqtk sample -s100 SF_S$i_R2.fastq 25 > R2sub$i.fastq ; done but it only creates empty fastq files. However, when I do _./seqtk sample -s100 SF_S1_R1.fastq 25 > R1sub1.fastq it works fine...

What am I doing wrong?

shenwei356 commented 6 years ago

It's a matter of shell variable. Since _ is a legal character in shell variable, $i_ is different from $i + _. You need use { and } for disambiguation, i.e., use ${i}_.

seqtk sample -s100 SF_S${i}_R1.fastq 25 > R1_sub$i.fastq ;
SimonMorvan commented 6 years ago

Thanks for your quick response, it works fine now :)

tseemann commented 6 years ago

@SimonMorvan can you close this issue please?

SimonMorvan commented 6 years ago

yes!