# Combine Fastq by writeFastq is not working properly

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 + /<BBBFFFBFFFFFFFFFFFBF<FFBF<B<FFFFFFFFFFB/B/<////<<<FF<B<FF<FFFFFFFFF/FFFFF  First four lines of combines fastq file are as follows: @D00239:185:C9KELANXX:2:2201:1088:2107 1:N:0:TCCTGAGC GTACAAGAAGCATAACATCAGCATGTGTTTTGGTGAGAACCTTAGGAAGTTTGCAATCATGACAGAAGGTGAAGG + /<BBBFFFBFFFFFFFFFFFBF<FFBF<B<FFFFFFFFFFB/B/<////<<<FF<B<FF<FFFFFFFFF/FFFFF  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. • 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 Feb 14 '18 at 7:07 • 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 Feb 14 '18 at 7:47 • @Lot, please instead of images paste the text in code formatting. Also could you, answer to gringer? – llrs Feb 14 '18 at 9:58 • @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. Feb 15 '18 at 4:08 • @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. Feb 15 '18 at 4:10 ## 1 Answer 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) {
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).

• @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. :) Feb 15 '18 at 4:45