This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bash Script Loop Help

Hello,

I'm trying to run hisat on loop and I've been trying to modify an existing loop I had set up but can't get it to work with my new file names.

My R1 is called WTCH_1_val_1.fastq and my R2 is called WTCH_2_val_2.fastq, where every time WTCH is actually a different value to distinguish the difference samples. This is the loop I was using so far when all of my samples were WTCH_1.fastq and WTCH_2.fastq

for f in `ls -1 *_1.fastq.gz | sed 's/_1.fastq.gz//' `
do
echo hisat2 -x mm10idx -1 ${f}_1.fastq.gz -2 ${f}_2.fastq.gz -S ${f}.bam
done

Could someone that is much better at this than I am please modify it for me? thanks

rnaseq bash loop

Just replace every instance of .fastq.gz with .fastq and it should work.

I've tried that but it doesnt work sadly, the echo returns:

hisat2 -x mm10idx -1 WTCHG_465974_296190_1_val_1.fq.gz -2 WTCHG_465974_296190_1_val_2.fq.gz -S WTCHG_465974_296190_1_val.bam

The loop as is thinks that the R2 finishes in "_1_val_2.fq.gz" but it finishes in "_2_val_2.fq.gz" the issue is the first _2 I think.

1 answer

Revise and clean up your post: you are using .fastq, .fastq.gz and .fq.gz, with no indication on which is the correct.

If your files are named ${whatever}_1_val_1.fastq.gz and ${whatever}_2_val_2.fastq.gz, then:

for f in `ls -1 *_1.fastq.gz | sed 's/_1_val_1.fastq.gz//' `
do
echo hisat2 -x mm10idx -1 ${f}_1_val_1.fastq.gz -2 ${f}_2_val_2.fastq.gz -S ${f}.bam
done

Sorry for the confusion, had mixed version of it. All sorted now with your post. Thanks alot! works like a charm.

Log in to answer this question.