# Path: seqio.py
# def iteratorFromExtension(filename):
#     '''
#     Get a sequence file iterator 
#     Based on the file's extension
#     '''
#     ext = filename.split(".")[-1]
#     if ext in ["fasta", "fa"]:
#         return fastaIterator
#     elif ext in ["fastq", "fq", "txt"]:
#         return fastqIterator
#     raise Exception, "Unknown file extension %s for file %s" % (ext,filename)
# 
# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item


import sys
from itertools import imap
from seqio import iteratorFromExtension
from nucio import fileIterator
#!/usr/bin/env python





##Create Kmers

if not len(sys.argv) == 3:
    sys.exit("Usage: kmer.py k-size in.fa\n")

fn = sys.argv[2]
ksize = int(sys.argv[1])

for record in fileIterator(fn, iteratorFromExtension(fn)):
    seq = record.seq
    starts = range(len(seq)-ksize+1)
    kmers = imap(lambda start: seq[start:start+ksize], starts)

# Path: seqio.py
# def iteratorFromExtension(filename):
#     '''
#     Get a sequence file iterator 
#     Based on the file's extension
#     '''
#     ext = filename.split(".")[-1]
#     if ext in ["fasta", "fa"]:
#         return fastaIterator
#     elif ext in ["fastq", "fq", "txt"]:
#         return fastqIterator
#     raise Exception, "Unknown file extension %s for file %s" % (ext,filename)
# 
# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item


# Path: kmer.py
import sys
from itertools import imap
from seqio import iteratorFromExtension
from nucio import fileIterator

#!/usr/bin/env python





##Create Kmers

if not len(sys.argv) == 3:
    sys.exit("Usage: kmer.py k-size in.fa\n")

fn = sys.argv[2]
ksize = int(sys.argv[1])

for record in fileIterator(fn, iteratorFromExtension(fn)):
    seq = record.seq
    starts = range(len(seq)-ksize+1)
    kmers = imap(lambda start: seq[start:start+ksize], starts)

    for kmer in kmers: