# 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)
# 
# def recordToString(record):
#     f = fastqRecordToString if hasattr(record,"desc") else fastaRecordToString
#     return f(record)
# 
# def fastaRecordToString(record):
#     return "\n".join([">"+record.name,record.seq])
# 
# def seqlen(record):
#     '''Gets the sequence length for a seqio record'''
#     return len(record.seq)
# 
# 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
# 
# def openerFromExtension(filename, default=None):
#     '''Get an open function from a file's
#     extension
#     default is the default opener, None by default
#     returns:
#        (open_func, filename_with_extension_removed)
#     '''
#     arr = filename.split(".")
#     
#     if arr[-1] == "gz":
#         import gzip
#         return (gzip.open, ".".join(arr[:-1]))
# 
#     return (default, filename)
# 
# Path: misc.py
# def defdef(default):
#     ''' Defined or Default
#     Returns a function that checks if its parameter is defined
#     If defined it returns the value otherwise it sets it to the 
#     default value
#     '''
#     return lambda x: x if bool(x) else default


import sys
import os
from itertools import starmap, chain, imap
from operator import itemgetter
from seqio import iteratorFromExtension, recordToString, fastaRecordToString, seqlen
from nucio import fileIterator, openerFromExtension
from args import parseArgs, getHelpStr, argflag, CLArgument
from misc import defdef
#!/usr/bin/env python



description = ("Usage: partition.py [-options] "
               "<reads_per_file (int)> <files_per_dir (int)> <input.{fa,fq}> [input2.{fa,fq} ...]")

argument_list = [["sameformat", "samefmt", argflag, False,
                  ("Output files will be in the same format "
                   "as the input files. By default they are converted "
                   "to fasta.")],
                 ["minlen", "minlen", int, 1,
                  ("Only output reads that are greater than or equal to 'minlen' "
                   "Default: 1")]]

arguments = map(CLArgument._make, argument_list)


# 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)
# 
# def recordToString(record):
#     f = fastqRecordToString if hasattr(record,"desc") else fastaRecordToString
#     return f(record)
# 
# def fastaRecordToString(record):
#     return "\n".join([">"+record.name,record.seq])
# 
# def seqlen(record):
#     '''Gets the sequence length for a seqio record'''
#     return len(record.seq)
# 
# 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
# 
# def openerFromExtension(filename, default=None):
#     '''Get an open function from a file's
#     extension
#     default is the default opener, None by default
#     returns:
#        (open_func, filename_with_extension_removed)
#     '''
#     arr = filename.split(".")
#     
#     if arr[-1] == "gz":
#         import gzip
#         return (gzip.open, ".".join(arr[:-1]))
# 
#     return (default, filename)
# 
# Path: misc.py
# def defdef(default):
#     ''' Defined or Default
#     Returns a function that checks if its parameter is defined
#     If defined it returns the value otherwise it sets it to the 
#     default value
#     '''
#     return lambda x: x if bool(x) else default


# Path: partition.py
import sys
import os
from itertools import starmap, chain, imap
from operator import itemgetter
from seqio import iteratorFromExtension, recordToString, fastaRecordToString, seqlen
from nucio import fileIterator, openerFromExtension
from args import parseArgs, getHelpStr, argflag, CLArgument
from misc import defdef

#!/usr/bin/env python



description = ("Usage: partition.py [-options] "
               "<reads_per_file (int)> <files_per_dir (int)> <input.{fa,fq}> [input2.{fa,fq} ...]")

argument_list = [["sameformat", "samefmt", argflag, False,
                  ("Output files will be in the same format "
                   "as the input files. By default they are converted "
                   "to fasta.")],
                 ["minlen", "minlen", int, 1,
                  ("Only output reads that are greater than or equal to 'minlen' "
                   "Default: 1")]]

arguments = map(CLArgument._make, argument_list)


if not len(sys.argv) > 1: