This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Split multifasta file in individual sequence file

Hello I would like to split multifasta file into the individual file for each sequence in the file. I used the following code and it worked fine with file up to 500 sequences. I tried the same code with 1500 sequences multifasta file. Unfortunately, It didn't work with this and I received the following error message. code I tried?

 awk -F '>' '/^>/ {F=sprintf("%s.fasta", $2); print > F;next;} {print F;}' < dt123_nbxcs.fa

error I received

awk: cannot open "gi|353013051|gb|JH237239.1|:7759-7979.fasta" for output (Too many open files)

I wonder how can I do it other than awk?

multifasta

What if you add close(F) after print F; in the final block, i.e.

awk -F '>' '/^>/ {F=sprintf("%s.fasta", $2); print > F;next;} {print F; close(F)}' < dt123_nbxcs.fa

Thanks , It worked What I understand from this it will close after writing the sequence into a new file instead of keeping it in memory. Is it right or it has some other meaning?

1 answer

This question has already been asked and answered here.

seqkit split --by-id multi_fasta_file.fasta

Log in to answer this question.