bashshellbioinformatics

Merging fastq files with same barcode in two different folders to another folder


I had two run of same sample ran twice one nanopore platform. Now I would like to merge each run generated 96 barcoded files.

So my files in the folders are as such from barcode01 to barcode96

RUN1                       RUN2
barcode01_filt.fastq.gz             barcode01_filt.fastq.gz 

Now i would like to merge each if them to one single file into another folder.The output Im looking for is merged barcode for RUN1 and RUN2 into another folder RUN3 with the same name barcode01_filt.fastq.gz

Any suggestion or help would be really appreciated.

UPDATE

So Im breaking down the problem into small pieces. First I have put both the run into a folder.

Now Im looking for the files in both the folder

find Cov1_run/ -name "*filt.fastq.gz" 

The next step would be if there is a name match in both the folder then merge them.

the output of the above find command

Cov1_run/RUN2/barcode05_filt.fastq.gz
Cov1_run/RUN2/barcode68_filt.fastq.gz
Cov1_run/RUN2/barcode34_filt.fastq.gz
Cov1_run/RUN2/barcode82_filt.fastq.gz
Cov1_run/RUN2/barcode61_filt.fastq.gz
Cov1_run/RUN2/barcode69_filt.fastq.gz
Cov1_run/RUN2/barcode18_filt.fastq.gz

Cov1_run/RUN1/barcode05_filt.fastq.gz
    Cov1_run/RUN/barcode68_filt.fastq.gz
    Cov1_run/RUN1/barcode34_filt.fastq.gz
    Cov1_run/RUN1/barcode82_filt.fastq.gz
    Cov1_run/RUN1/barcode61_filt.fastq.gz
    Cov1_run/RUN1/barcode69_filt.fastq.gz
    Cov1_run/RUN1/barcode18_filt.fastq.gz

So now I have to match like if both the names are same then merge them into a same name but in a different folder

RUN1 barcode05_filt.fastq.gz and RUN2 barcode05_filt.fastq.gz

Solution

  • Untested and conceptual because too large for comment:

    cd RUN1
    
    for fa in *.fastq.gz ; do
        # Deduce name of friend 
        fb="../RUN2/$fa"
        if [ -f "$fb" ] ; then
           cat "$fa" "$fb" > "../RUN3/$fa"
        fi
    done