This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split Fastq File Into Different Files Only Comprising One Chromosome Each

Hi All,

I need to split my fastq file that is composed of 30 chromosomes into 30 different files containing each the information from one chromosome. Technically, I need to split this kind of file into separated one:

@chr1
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnatgctgggtgatctttagtcnnnnnnnnnn
nnnnnnnnnnnnnnnnatggggtcatgtacacacacacattggatannnnnnnnnnnnnn
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnatgctgggtgatctttagtcnnnnnnnnnn
..
@chr2
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnatgctgggtgatctttagtcnnnnnnnnnn
nnnnnnnnnnnnnnnnatggggtcatgtacacacacacattggatannnnnnnnnnnnnn
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnatgctgggtgatctttagtcnnnnnnnnnn
..

I tried to use:

awk '/^@chr1$/,/^+$/' consensus.fastq | perl -pe "s/@/>/ ; s/\+//" > chr1.fasta

but that gives me this:

@chr1
nnnnnagtnnnnnnnnnnnnnnnnnnnnnttgcnnnnnnnnnnnnnnnnnnnnnngcnnn
nnnntgaaannnnnnnnnnnntcnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

Did somebody had already this kind of problems? Could somebody gives me some advice?

Thanks a lot!

Nath

fastq

Thanks a lot Keith!

I downloaded the software and it worked perfectly!

Cheers, Nath

Nath, you should have appended this as a comment to the previous question rather than as a separate answer. If Keith's answer is spot on for you, consider checking the tick box on his answer, so that this becomes the 'accepted answer'.

Ok, thanks Daniel! Sorry, it is the first time I used this kind of forum. Thank a lot for your advice! Nath

Isn't it a little harsh to downvote a new user with a rep of 19 for an honest mistake?

Hi ALL,

I tried using seqretsplit to split a fastq file because I do not have enough memory to load the entire file into fastq. I used:

seqretsplit -sformat fastq-illumina -osformat fastq ../r17_s6_sequence.fq

However, the number of output files were as many as the number sequences. Is there any flag which can be used to specify how many files and therefore how many sequences would each file contain?

Many thanks

Please create a new question for this since it is not an answer but another question.

1 answer

If you have EMBOSS installed

seqretsplit -sformat fastq-sanger -osformat fastq file.fastq

will give you one Fastq record per file. The files will be named after the sequence ID, so chr1.fastq, chr2.fastq etc. Note that you should use -sformat fastq-sanger, fastq-illumina or fastq-solexa, depending on which encoding your file uses. See this question on Fastq format.

To get Fasta output (you don't explicitly ask for it, but your code implies it), simply change the -osformat argument.

seqretsplit -sformat fastq-sanger -osformat fasta file.fastq

Log in to answer this question.