Batch File For Loop Help
Hello I’m trying to run bowtie for a several files using a loop so I don’t have to repeat the command over and over. The loop looks something like this:
mm10="GenomeFolder/Bowtie2Index/genome"
for (( i = 76; i <= 79; i++ ))
do
bowtie2 -x $mm10 -1 SRR51363$i_1.fastq.gz -2 SRR51363$i_2.fastq.gz
done
The problem is that I can’t use the $i variable in between SRR51363 and _1.fastq.gz, It causes an error. Any adivce on the right syntax? I tried to google this but it’s hard to describe this problem I’m having. Thank you!
• 23 views
Put curly braces around variable names, and quotes around words:
mm10="GenomeFolder/Bowtie2Index/genome"
for (( i = 76; i <= 79; i++ ))
do
bowtie2 -x "${mm10}" -1 "SRR51363${i}_1.fastq.gz" -2 "SRR51363${i}_2.fastq.gz"
done
Curly braces in this context prevent variable names from being expanded incorrectly. Quotes allow files and paths to contain spaces and special characters. While the latter may not be an issue here for this specific example, it is a good habit to get into.
$ seq 76 1 79 | while read line; do echo SRR51363${line}_1.fastq.gz SRR51363${line}_2.fastq.gz; done
SRR5136376_1.fastq.gz SRR5136376_2.fastq.gz
SRR5136377_1.fastq.gz SRR5136377_2.fastq.gz
SRR5136378_1.fastq.gz SRR5136378_2.fastq.gz
SRR5136379_1.fastq.gz SRR5136379_2.fastq.gz
$ parallel --dry-run bowtie -x mm10 -1 SRR51363{}_1.fastq.gz -2 SRR51363{}_2.fastq.gz ::: {76..79}
bowtie -x mm10 -1 SRR5136376_1.fastq.gz -2 SRR5136376_2.fastq.gz
bowtie -x mm10 -1 SRR5136377_1.fastq.gz -2 SRR5136377_2.fastq.gz
bowtie -x mm10 -1 SRR5136378_1.fastq.gz -2 SRR5136378_2.fastq.gz
bowtie -x mm10 -1 SRR5136379_1.fastq.gz -2 SRR5136379_2.fastq.gz
Traffic: 1146 users visited in the last hour
Read more here: Source link