<p>You can drastically simplify your effort because FASTQ files are simple text files; therefore, standard UNIX test file tools work:</p>

<pre class="lang-bash prettyprint-override"><code>cat refs/*.fastq &gt; combined.fastq
</code></pre>

<p>And this even works with <code>.fastq.gz</code> files — no unzipping required.</p>

<hr>

<p>Apart from this, your R code contains several errors. For instance, your variable names change throughout, and you’re using the <code>fsep</code> parameter wrongly. In fact it’s unclear to me what the code is supposed to do. At an approximation (and untested), the following should work:</p>

<pre class="lang-r prettyprint-override"><code>fastq_dir = file.path(getwd(), "refs")
fastq_files = dir(fastq_dir, pattern = "\\.fastq$", full.names = TRUE)
outfile = file.path(dirname(fastq_dir), "combined.fastq")

for (file in fastq_files) {
    fq = readFastq(file)
    writeFastq(fq, outfile, mode = "a")
}
</code></pre>

<p>This is equivalent to running the shell command shown above, just in a more convoluted way (parsing and re-generating the FASTQ files).</p>

CC BY-SA 3.0
2018-02-15T04:45:52.290Z
@Konard : Thanks for pointing out my mistake. As I am beginner so my codes are not as much good. I have changes this. Can you tell me what is the proper use of fsep. I though using file path, fsep is the way to choose only specific type of file (may be I am wrong). And how can I use cat within for loop because it is giving `unexpected symbol` error by trying `cat fq > combine.fastq` Thanks again. I'll try my best to improve. keep pointing my mistakes. :)
Lot_to_learn
CC BY-SA 3.0
2018-02-14T10:09:54.423Z
2018-02-14T10:20:59.917Z
2018-02-14T10:20:59.917Z
Konrad Rudolph
<p>Currently I have 4 fastq file for each patient as WES data. For WES pipeline, I want to combine those fastq files. I am using writeFastq from ShortRead package in Bioconductor.But I think this function is not working properly. </p>

<p>The reason of my doubt is the the size the next step is quality check using FastQC tool. This tool is working on individual file but not on combined file and shows the error that ID line doesn't start with "@" . So I want to know what are the other effective tool for combining multiple fastq files without any loss of information. </p>

<p>Let me know if I am doing something wrong. Thanks</p>

<p><strong>[EDIT-1]</strong> : The codes for combining multiple fastq files into one is as follows:</p>

<pre><code>reference_fastq = file.path(paste(getwd(),"refs",sep = "/", collapse = " "), fsep = ".fasta")
fastqDir &lt;- file.path(dataDir, fsep = ".fastq")
outfile_temp &lt;- paste(dirname(dataDir),basename(fastqDir),    paste(basename(fastqDir),"combined","fastq", sep = "."),sep = "/", collapse = " ")
fls &lt;- list.files(fastqDir, "fastq$", full=TRUE)
for (fl in fls) {
  fq &lt;- readFastq(fl)
  writeFastq(fq,outfile_temp, mode="a")
}
</code></pre>

<p>First four lines of my fastq file (one of 4 indivual file) are as follows :</p>

<pre><code>@D00239:185:C9KELANXX:2:2201:1088:2107 1:N:0:TCCTGAGC
GTACAAGAAGCATAACATCAGCATGTGTTTTGGTGAGAACCTTAGGAAGTTTGCAATCATGACAGAAGGTGAAGG
+
/&lt;BBBFFFBFFFFFFFFFFFBF&lt;FFBF&lt;B&lt;FFFFFFFFFFB/B/&lt;////&lt;&lt;&lt;FF&lt;B&lt;FF&lt;FFFFFFFFF/FFFFF
</code></pre>

<p>First four lines of combines fastq file are as follows: </p>

<pre><code>@D00239:185:C9KELANXX:2:2201:1088:2107 1:N:0:TCCTGAGC
GTACAAGAAGCATAACATCAGCATGTGTTTTGGTGAGAACCTTAGGAAGTTTGCAATCATGACAGAAGGTGAAGG
+
/&lt;BBBFFFBFFFFFFFFFFFBF&lt;FFBF&lt;B&lt;FFFFFFFFFFB/B/&lt;////&lt;&lt;&lt;FF&lt;B&lt;FF&lt;FFFFFFFFF/FFFFF
</code></pre>

<p>It is pretty clear that combined fastq file is also starting wiht proper identifier but why FastQC tool is saying that identifier '@' is missing. Here is the screen shot of the error message:</p>

<p><a href="https://i.sstatic.net/aZ3E2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aZ3E2.png" alt="Screen shot of error message"></a></p>

<p>Thanks.</p>

CC BY-SA 3.0
2018-02-14T07:07:17.283Z
Can you please show the first and last lines of the input FASTQ files, and the first and last line of whatever writeFastq has created?
gringer
CC BY-SA 3.0
2018-02-14T07:47:49.633Z
Could you paste the command you used from ShortRead to combine the files? (And the version of the package, just in case there is a bug in that version). If you have the fastq files compressed you can simply `cat` them to a new .tar.gz file and you'll have them combined
llrs
CC BY-SA 3.0
2018-02-14T09:58:54.673Z
@Lot, please instead of images paste the text in code formatting. Also could you, answer to gringer?
llrs
CC BY-SA 3.0
2018-02-15T04:08:51.353Z
@gringer: I have shown the first 4 lines of input fastq file and output fastq file. What else you want to check..let me know.
Lot_to_learn
CC BY-SA 3.0
2018-02-15T04:10:34.943Z
@Llopis: Actually I tried to copy the text instead the image but I am working on server and on right click after text selection, I did not find any option like copy. That's why I took screen shot. Sorry for this.
Lot_to_learn
CC BY-SA 3.0
2018-02-15T04:15:08.857Z
@Llopis: ShortRead package version is 1.28.0, R version 3.4.3 and bioconductor version is 3.2.
Lot_to_learn
CC BY-SA 3.0
2018-02-15T09:10:37.000Z
You have a 2 year's old version of Bioconductor, you might be interested in upgrading it (just in case some other errors are already solved in the updated version).
llrs
<r><bioconductor><sequence-analysis>
Combine Fastq by writeFastq is not working properly
# Combine Fastq by writeFastq is not working properly

(Asked by: username_0 on 2018-02-14)

Currently I have 4 fastq file for each patient as WES data. For WES pipeline, I want to combine those fastq files. I am using writeFastq from ShortRead package in Bioconductor.But I think this function is not working properly. 
The reason of my doubt is the the size the next step is quality check using FastQC tool. This tool is working on individual file but not on combined file and shows the error that ID line doesn't start with "@" . So I want to know what are the other effective tool for combining multiple fastq files without any loss of information. 
Let me know if I am doing something wrong. Thanks
[EDIT-1] : The codes for combining multiple fastq files into one is as follows:
reference_fastq = file.path(paste(getwd(),"refs",sep = "/", collapse = " "), fsep = ".fasta")
fastqDir <- file.path(dataDir, fsep = ".fastq")
outfile_temp <- paste(dirname(dataDir),basename(fastqDir),    paste(basename(fastqDir),"combined","fastq", sep = "."),sep = "/", collapse = " ")
fls <- list.files(fastqDir, "fastq$", full=TRUE)
for (fl in fls) {
  fq <- readFastq(fl)
  writeFastq(fq,outfile_temp, mode="a")
}

First four lines of my fastq file (one of 4 indivual file) are as follows :
@D00239:185:C9KELANXX:2:2201:1088:2107 1:N:0:TCCTGAGC
GTACAAGAAGCATAACATCAGCATGTGTTTTGGTGAGAACCTTAGGAAGTTTGCAATCATGACAGAAGGTGAAGG
+
/
First four lines of combines fastq file are as follows: 
@D00239:185:C9KELANXX:2:2201:1088:2107 1:N:0:TCCTGAGC
GTACAAGAAGCATAACATCAGCATGTGTTTTGGTGAGAACCTTAGGAAGTTTGCAATCATGACAGAAGGTGAAGG
+
/
It is pretty clear that combined fastq file is also starting wiht proper identifier but why FastQC tool is saying that identifier '@' is missing. Here is the screen shot of the error message:

Thanks.

**Tags:** r, bioconductor, sequence-analysis
> **Comments:**
> **username_1**: Can you please show the first and last lines of the input FASTQ files, and the first and last line of whatever writeFastq has created?  
> **username_2**: Could you paste the command you used from ShortRead to combine the files? (And the version of the package, just in case there is a bug in that version). If you have the fastq files compressed you can simply `cat` them to a new .tar.gz file and you'll have them combined  
> **username_2**: @Lot, please instead of images paste the text in code formatting. Also could you, answer to gringer?  
> **username_0**: @gringer: I have shown the first 4 lines of input fastq file and output fastq file. What else you want to check..let me know.  
> **username_0**: @Llopis: Actually I tried to copy the text instead the image but I am working on server and on right click after text selection, I did not find any option like copy. That's why I took screen shot. Sorry for this.  
> **username_0**: @Llopis: ShortRead package version is 1.28.0, R version 3.4.3 and bioconductor version is 3.2.  
> **username_2**: You have a 2 year's old version of Bioconductor, you might be interested in upgrading it (just in case some other errors are already solved in the updated version).  

---

## 1 answers

### Answer by username_3 on 2018-02-14. Score: 4

You can drastically simplify your effort because FASTQ files are simple text files; therefore, standard UNIX test file tools work:
cat refs/*.fastq > combined.fastq

And this even works with .fastq.gz files — no unzipping required.

Apart from this, your R code contains several errors. For instance, your variable names change throughout, and you’re using the fsep parameter wrongly. In fact it’s unclear to me what the code is supposed to do. At an approximation (and untested), the following should work:
fastq_dir = file.path(getwd(), "refs")
fastq_files = dir(fastq_dir, pattern = "\\.fastq$", full.names = TRUE)
outfile = file.path(dirname(fastq_dir), "combined.fastq")

for (file in fastq_files) {
    fq = readFastq(file)
    writeFastq(fq, outfile, mode = "a")
}

This is equivalent to running the shell command shown above, just in a more convoluted way (parsing and re-generating the FASTQ files).

> **Comments:**
> **username_0**: @Konard : Thanks for pointing out my mistake. As I am beginner so my codes are not as much good. I have changes this. Can you tell me what is the proper use of fsep. I though using file path, fsep is the way to choose only specific type of file (may be I am wrong). And how can I use cat within for loop because it is giving `unexpected symbol` error by trying `cat fq > combine.fastq` Thanks again. I'll try my best to improve. keep pointing my mistakes. :)  

---

