This is a test version of Biostars. For the public version, visit https://www.biostars.org.
bash script for catenating many paired end files

Hi friends!!! I have around 300 paired-end files from 150 samples (1 forward and 1 reverse read for each sample). I want to catenate respective forward and reverse reads for each of the samples. The samples are named like: SRR2155174_1.fastq SRR2155174_2.fastq SRR2155319_1.fastq SRR2155319_2.fastq. Can anyone please write me a bash script with loop or something so that they can be catenated automatically. I'm not much familiar with bash script.

Thanks and Regards,

DC7

catenation
cat *_1.fastq > concatenated_1.fastq
cat *_2.fastq > concatenated_2.fastq

should do it

When you say catenate do you mean you want to combine all forwards and all reverse reads into a single forward and a single reverse file, or do you want to combine R1 and R2 for each sample to get an interleaved fastq? Please try something, show the code, we will be happy to debug and guide you.

find . -type f -name "*_1.fastq" | while read line; do echo "pandaseq -F -f $line -r ${line/1.fastq/2.fastq} 1 > ${line/1.fastq/merged.fastq} 2 > ${line/1.fastq/merge_stats.txt}"; done

or

parallel --dry-run 'pandaseq -F -f {} -r {=s/_1/_2/=} 1 > {=s/_1.fastq//=}_merged.fastq 2 > {=s/_1.fastq//=}.merged_stats.txt' ::: *_1.fastq

1 answer

I would suggest you use a toolkit like BBtools to perform this. This option is referred to as interleaving fastq files:

https://jgi.doe.gov/data-and-tools/bbtools/bb-tools-user-guide/reformat-guide/

reformat.sh in1=read1.fq in2=read2.fq out=reads.fq

The above answer by user cpad0112will allow you to automate this action across the whole dataset.

Log in to answer this question.