Hi all, another noob question from me.

I finally finished that FASTA Splitter from my last post, which I will update soon.
My new task is to Chunk a Fasta File into well... chunks still in Python too.

    FileInput = input('What is full address of the file you need to work with? ' )
    FileOutPut = input('What is the address of the Directory you want saving to?')
    OrganismOI = input('What organism  are you looking at? ')
    ChunkSize = int(input("What is the chunk size (in kb) you want? "))
    
    Chunk = ChunkSize*1000
    Counter = 0
    FileName = FileOutPut + '/' + OrganismOI + str(Counter) + '.fa''
    
    FILE = open(FileInput, 'r')
    File = FILE.read()
    FileSize = len(File)
    print(str(FileSize) + ' is the length of the file in bp.') 
    #This also includes Fasta TitleNumber
    print('Final Number of Files to be expected is ' + str(FileSize / Chunk) + '.')
    
    for chunk in File:
        Save = open(FileName, 'w')
        Save.write(File[:Chunk])
        Save.close()

For the life of me, as soon as it comes to loops, I die inside. No matter how much I read or practise it just isn't going in. 
This script is supposed to go through the original FASTA file, and every chunk (ChunkSize, being user defined) spit out a file containing that chunk and called OrganismOI + counter (Supposed to count file numbers). Once again and always, help is very much appreciated.
If I can then add a co-ordinate system ill be set for not.
If anyone has any books or materials that could feasibly help me out learning this stuff then please send it my why. Would the BioStar handbook be a sensible purchase?

Again thanks everyone.
Hi,
try this [link](https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks). (just load the genome as string and pass with to one of the implementations of `chunker` from the link).

If you have **very** low RAM or **very** long genome then you could do something like:

    f = open(bare_fasta, 'r'):
    l = f.readline()
    to_write = []
    c = 0
    i = 0
    threshold = 50000
    while l:
      to_write.append(l)
      c += len(l)-1
      if c > threshold:
        with open('fout{}'.format(i), 'w') as o:
             o.write(''.join(to_write))
             i += 1
             to_write = []
             c = 0
      l = f.readline()
    with open('fout{}'.format(i), 'w') as o:
      o.write(''.join(to_write))

This will split your original fast into chunks by whole lines just after the total number of nucleotides exceeded defined threshold. Be aware that this expects FASTA file with many lines. NOT one long line.