This is not a very memory friendly way of counting sequences from a multi fasta, any ideas to improve this?

    generator = SeqIO.parse("test_fasta.fasta","fasta")
    sizes = [len(rec) for rec in SeqIO.parse("test_fasta.fasta", "fasta")]

I'm avoiding using tools like grep since I want to make this more portable

Standard Python will be faster than BioPython:

    fh = open("test_fasta.fasta")
    n = 0
    for line in fh:
        if line.startswith(">"):
            n += 1
    fh.close()

or shorter and possibly faster:

    num = len([1 for line in open("test_fasta.fasta") if line.startswith(">")])

