<p>I have 1000 fasta files that have simulated reads, and I want to split each of these 1000 files into separate files (one per chromosome) as I need this for some further analysis. The header lines look like this &gt;chr1:startpos:endpos.</p>

<p>I wrote this code (<a href="https://gist.github.com/ethanagbaker/6e40c58127b7ca8b9242">https://gist.github.com/ethanagbaker/6e40c58127b7ca8b9242</a>) in Python, and it works, but it is very slow (ie it has been running for more than 24 hours on a cluster). This seems like it should be a really quick thing to do. Is there a better way to be doing this?</p>

<p>Thanks!</p>

    $ pip install pyfaidx
    $ faidx -x sequences.fa

Or you can use the `Fasta` class and write your own script to do the same thing. Your code is slow because it is opening a bunch of files in a loop, and then opening (the same files?) and reading them completely to get the sequences. Indexed file access will be orders of magnitude faster.