This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split Fastq File In Small Fastq Files - Windows

Hi All,

Is there anyway I can split large FASTQ files into small FASTQ files with defined number of reads under windows environment, I know there are multiple option for unix but did not find anything for windows ?

best Deep

split fastq windows

5 answers

or use some freeware like gsplit. Be remember to give the lines in mutiples of 4 [4 lines per read].

install http://www.cygwin.org , and use split

If you're familiar with R, you can use the ShortRead library to break the file up into smaller files. It's only a few lines of code. The example below takes a fastq file, breaks it up into sets of 1 million reads, writing the results to incrementally named smaller files:

library(ShortRead)

# set the file (.gz files also work)
yourFile <- "foo.fastq"
fileBaseName <- sub(".fastq$","",yourFile)
# iterate over fastq file
f <- FastqStreamer(yourFile, 1000000)
file_index <- 0
while (length(fq <- yield(f))) {
  newName <- paste(fileBaseName, "_", file_index,".fastq", sep="")
  writeFastq(fq,file=newName)
  file_index <- file_index + 1
}
close(f)

This is good if file is to be finally processed in R, but for a series of large fastq files, it won't be efficient like as compare to split.

You should be able to do this with Powershell, if you don't want to install Cygwin. Use a read count and a modulus operation on four lines, as Sukhdeep suggests.

Hi

i am very glad to use this short program. but I like to know how I will change the output file folder. For e.g. have the big FastqFile in folder E:/Sequencing/input/ERR127_1.fastq.gz now I want to make it small 1000000 reads/file and want to save it in folder E:/Sequencing/output how I will do that ? I did

# set the file (.gz files also work)
FastqFile <- "./Sequencing/ERR127306_1.fastq.gz"
fileBaseName <- sub(".fastq$","", FastqFile)
# iterate over fastq file
f <- FastqStreamer(FastqFile, 1000000)
file_index <- 0
while (length(fq <- yield(f))) {
  newName <- paste(Sequencing/output, "/", fileBaseName, "_", file_index,".fastq", sep="")
  writeFastq( fq, file=newName)
  file_index <- file_index + 1
}
close(f)

i am getting this error

Error in eval(expr, envir, enclos) : object 'Sequencing' not found
> close(f)

how to fix it? plz reply I need your help

Please don't post new questions as answers. Deleting.

Log in to answer this question.