Shi Ming Tan
Shi Ming Tan

Reputation: 1

Concatenate FASTQ files from 2 folders with the same structure

I am trying to concatenate FASTQ files that the same files in 2 different folders.

E.g.

Folder_A/Sample_10_DNA

contains

Sample_10_DNA_S7_L001_R1_001.fastq.gz,
Sample_10_DNA_S7_L001_R2_001.fastq.gz,
Sample_10_DNA_S7_L002_R2_001.fastq.gz,
Sample_10_DNA_S7_L002_R1_001.fastq.gz

and

Folder_B/Sample_10_DNA

contains

Sample_10_DNA_S7_L001_R1_001.fastq.gz
Sample_10_DNA_S7_L001_R2_001.fastq.gz
Sample_10_DNA_S7_L002_R2_001.fastq.gz
Sample_10_DNA_S7_L002_R1_001.fastq.gz

I have about 20 of these folders and am thinking of using the cat function to concatenate the FASTQ files using a BASH script. E.g.

cat Folder_A/Sample_10_DNA/Sample_10_DNA_S7_L001_R1_001.fastq.gz Folder_B/Sample_10/DNA_Sample_10_DNA_S7_L001_R1_001.fastq.gz >Folder_C/Sample_10_DNA/ample_10_DNA_S7_L001_R1_001.fastq.gz

Would appreciate any advice I can get. :)

Tried a Bash script but did not have the expertise to build it.

Upvotes: 0

Views: 118

Answers (1)

Tom Morris
Tom Morris

Reputation: 10540

You can use something along the lines of this for loop:

for filename in Folder_A/Sample_10_DNA/* ; do  
  base=$(basename $f)
  cat $filename Folder_B/Sample_10/$base > Folder_C/Sample_10_DNA/$base
done

Besides the for loop, the other key piece is the use of the basename command to get just the filename without the directory. You can collapse things to a 1-liner like this:

for filename in Folder_A/Sample_10_DNA/* ; do base=$(basename $f) ; cat $filename Folder_B/Sample_10/$base > Folder_C/Sample_10_DNA/$base ; done

Upvotes: 0

Related Questions