This is a test version of Biostars. For the public version, visit https://www.biostars.org.
For loop in bash script

Hi all,

I'm expecting to get 17 different paired-end fastq files (34 in total), so I want to make a bash script to just run my code through all the fastq files in a directory at once. How can I change the name of the input and output files each time the script runs though each file? So when it moves to the file_002, all names have file_002 at the beginning instead of file_001 and so on. And also, when merging the R1 and R2 reads how can I make that it only merges the corresponding files with a loop?

for file in directory_name
do
 pear -f file_001_R1.fastq.gz -r file_001_R2.fastq.gz -o file_001.fastq
 cutadapt -g TGATAACAATTGGAGCAGCCTC...GGATCGACCAAGAACCAGCA -o file_001_barcode.fastq file_001.fastq
 cutadapt -g GTGTACAAATAATTGTCAAC...CTGTCTCTTATACACATCTC -o file_001_UMI.fastq file_001.fastq
 seqkit concat file_001_barcode.fastq file_001_UMI.fastq > file_001_concatenation.fastq
done

Thank you

bash

You could try something like this:

i=1

for file in *; do
    pear -f file_00$i_R1.fastq.gz -r file_00$i_R2.fastq.gz -o file_00$i.fastq
    cutadapt -g TGATAACAATTGGAGCAGCCTC...GGATCGACCAAGAACCAGCA -o file_00$i_barcode.fastq file_001.fastq
    cutadapt -g GTGTACAAATAATTGTCAAC...CTGTCTCTTATACACATCTC -o file_001_UMI.fastq file_00$i.fastq
    seqkit concat file_00$i_barcode.fastq file_00$i_UMI.fastq > file_00$i_concatenation.fastq

    let i++

done

0 answers

No answers yet.

Log in to answer this question.