<p>Your original question mentioned concatenating things, which is not what you want (that would result in all of the reads from the _2 files being after all of those in _1). What you want is to merge overlapping paired end reads. There are a variety of tools available for that, from <a href="https://ccb.jhu.edu/software/FLASH/" rel="nofollow noreferrer">flash</a> to <a href="https://jgi.doe.gov/data-and-tools/bbtools/bb-tools-user-guide/bbmerge-guide/" rel="nofollow noreferrer">bbmerge</a>. The general structure then is:</p>
<pre><code>for R1 in *_1.fastq ; do
    sampleName=${R1%%_1.fastq}
    some command with ${sampleName}_1.fastq and ${sampleName}_2.fastq producing ${sampleName}.fastq
done
</code></pre>
<p>You can figure out the <code>some command ...</code> portion yourself.</p>

CC BY-SA 4.0
2020-07-07T07:15:48.873Z
2020-07-07T07:15:48.873Z
Devon Ryan
<p>I have around 300 paired-end files from 150 samples (1 forward and 1 reverse read for each sample). I want to merge (by sequence overlap) respective forward and reverse reads for each of the samples. The samples are named e.g. <strong>SRR2155174_1.fastq SRR2155174_2.fastq SRR2155319_1.fastq SRR2155319_2.fastq.</strong> Can anyone please help me write a bash script to do this?</p>

CC BY-SA 4.0
2020-07-04T21:06:48.907Z
Hi @CHANDRA7, we do understand "paired ends", we'd like to know reaad-length, coverage, genome - don't have to but it is polite. HOWEVER, whilst there is serious level coding skill on the site fior e.g. bash/awk and its not hard (even I code this one)... this is not a code writing service and you will need to at least make an attempt at a line of code .I suspect you want to concatenate e.g. `SRR2155174_1.fastq SRR2155174_2.fastq > SRR2155174_12.fastq'. Please at least try (hint a bash do loop) - someone can code the regex part.
M__
CC BY-SA 4.0
2020-07-04T23:54:40.863Z
Since you have many files it may be helpful to use tools like snakemake to run automatically, although as previous comments said the question has been answered elsewhere.
Phoenix Mu
CC BY-SA 4.0
2020-07-06T07:40:50.693Z
Why do you want to concatenate them? That's almost never the right thing to do.
Devon Ryan
CC BY-SA 4.0
2020-07-07T07:05:52.163Z
Respected @DevonRyan , I am doing microbial profiling of metagenomic WGS sequence with metaPhlan software which can't generate contigs. But they can do profiling while we catenate the forward and reverse reads. Due to its short marker sequences it can do profiling from unpaired reads and probably average out. Please check this: https://groups.google.com/forum/#!topic/metaphlan-users/aclhwUcgWkk . And please let me know if I have wrong understanding.
CHANDA7
<fastq>
Bash script for automatic overlap merging of respective paired-end reads from samples
# Bash script for automatic overlap merging of respective paired-end reads from samples

(Asked by: username_0 on 2020-07-04)

I have around 300 paired-end files from 150 samples (1 forward and 1 reverse read for each sample). I want to merge (by sequence overlap) respective forward and reverse reads for each of the samples. The samples are named e.g. **SRR2155174\_1.fastq SRR2155174\_2.fastq SRR2155319\_1.fastq SRR2155319\_2.fastq.** Can anyone please help me write a bash script to do this?

**Tags:** fastq
> **Comments:**
> **username_1**: Hi @CHANDRA7, we do understand "paired ends", we'd like to know reaad-length, coverage, genome - don't have to but it is polite. HOWEVER, whilst there is serious level coding skill on the site fior e.g. bash/awk and its not hard (even I code this one)... this is not a code writing service and you will need to at least make an attempt at a line of code .I suspect you want to concatenate e.g. `SRR2155174_1.fastq SRR2155174_2.fastq > SRR2155174_12.fastq'. Please at least try (hint a bash do loop) - someone can code the regex part.  
> **username_2**: Since you have many files it may be helpful to use tools like snakemake to run automatically, although as previous comments said the question has been answered elsewhere.  
> **username_3**: Why do you want to concatenate them? That's almost never the right thing to do.  
> **username_0**: Respected @DevonRyan , I am doing microbial profiling of metagenomic WGS sequence with metaPhlan software which can't generate contigs. But they can do profiling while we catenate the forward and reverse reads. Due to its short marker sequences it can do profiling from unpaired reads and probably average out. Please check this: https://groups.google.com/forum/#!topic/metaphlan-users/aclhwUcgWkk . And please let me know if I have wrong understanding.  

---

## 1 answers

### Answer by username_3 on 2020-07-07. Score: 1

Your original question mentioned concatenating things, which is not what you want (that would result in all of the reads from the _2 files being after all of those in _1). What you want is to merge overlapping paired end reads. There are a variety of tools available for that, from flash to bbmerge. The general structure then is:
for R1 in *_1.fastq ; do
    sampleName=${R1%%_1.fastq}
    some command with ${sampleName}_1.fastq and ${sampleName}_2.fastq producing ${sampleName}.fastq
done

You can figure out the some command ... portion yourself.


---

