##################################
#                                #
# Last modified 09/06/2011       # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import sys
import string
import math
from sets import Set

def run():

    if len(sys.argv) < 2:
        print 'usage: python %s fasta outputfileprefix ' % sys.argv[0]
        sys.exit(1)
    
    input = sys.argv[1]
    outfileDict = {}

    lineslist = open(input)
    for line in lineslist:
        if line.startswith('>'):
            readID=line
            continue
        else:
            sequence=line.strip()
            length=len(sequence)
            if outfileDict.has_key(length):
                pass
            else:
                outfileDict[length]=open(sys.argv[1]+'.'+str(length)+'mers.fasta','w')
            outfileDict[length].write(readID)
            outfileDict[length].write(sequence + '\n')
        
    for length in outfileDict.keys():
        outfileDict[length].close()
   
run()
