# Path: dark/reads.py
# def addFASTACommandLineOptions(parser):
#     """
#     Add standard command-line options to an argparse parser.
# 
#     @param parser: An C{argparse.ArgumentParser} instance.
#     """
# 
#     parser.add_argument(
#         '--fastaFile', type=open, default=sys.stdin, metavar='FILENAME',
#         help=('The name of the FASTA input file. Standard input will be read '
#               'if no file name is given.'))
# 
#     parser.add_argument(
#         '--readClass', default='DNARead', choices=readClassNameToClass,
#         metavar='CLASSNAME',
#         help=('If specified, give the type of the reads in the input. '
#               'Possible choices: %s.' % ', '.join(readClassNameToClass)))
# 
#     # A mutually exclusive group for either --fasta, --fastq, or --fasta-ss
#     group = parser.add_mutually_exclusive_group()
# 
#     group.add_argument(
#         '--fasta', default=False, action='store_true',
#         help=('If specified, input will be treated as FASTA. This is the '
#               'default.'))
# 
#     group.add_argument(
#         '--fastq', default=False, action='store_true',
#         help='If specified, input will be treated as FASTQ.')
# 
#     group.add_argument(
#         '--fasta-ss', dest='fasta_ss', default=False, action='store_true',
#         help=('If specified, input will be treated as PDB FASTA '
#               '(i.e., regular FASTA with each sequence followed by its '
#               'structure).'))
# 
# def parseFASTACommandLineOptions(args):
#     """
#     Examine parsed command-line options and return a Reads instance.
# 
#     @param args: An argparse namespace, as returned by the argparse
#         C{parse_args} function.
#     @return: A C{Reads} subclass instance, depending on the type of FASTA file
#         given.
#     """
#     # Set default FASTA type.
#     if not (args.fasta or args.fastq or args.fasta_ss):
#         args.fasta = True
# 
#     readClass = readClassNameToClass[args.readClass]
# 
#     if args.fasta:
#         from dark.fasta import FastaReads
#         return FastaReads(args.fastaFile, readClass=readClass)
#     elif args.fastq:
#         from dark.fastq import FastqReads
#         return FastqReads(args.fastaFile, readClass=readClass)
#     else:
#         from dark.fasta_ss import SSFastaReads
#         return SSFastaReads(args.fastaFile, readClass=readClass)


import sys
import argparse
from os.path import join, exists
from os import mkdir, rename
from math import log10
from dark.reads import (addFASTACommandLineOptions,
                        parseFASTACommandLineOptions)
    (args.fastq and 'fastq') or
    (args.fasta_ss and 'fasta-ss'))

# Note: we may be reading the FASTA input from stdin, so we cannot read it
# more than once (and I don't want to store it all because it may be very
# large). That's why we do a second phase of processing to renumber the
# files we created if --numeric is used (and --noLeadingZeroes is not).

count = 0
for count, read in enumerate(parseFASTACommandLineOptions(args), start=1):
    id_ = read.id.split()[0]
    if args.numeric:
        base = '%d.fasta' % count
    else:
        id_ = read.id.split()[0]
        base = '%s.fasta' % id_
    if args.verbose:
        print('Writing', base)
    filename = join(args.outDir, base)
    if not args.force and exists(filename):
        print('Will not overwrite pre-existing file "%s". Use --force to '
              'make me. Exiting.' % filename, file=sys.stderr)
        sys.exit(1)
    with open(filename, 'w') as fp:
        print(read.toString(saveAs), end='', file=fp)

# Rename numeric filenames to have leading zeroes.
if count and args.numeric and not args.noLeadingZeroes:
    width = int(log10(count)) + 1
    if width > 1:

# Path: dark/reads.py
# def addFASTACommandLineOptions(parser):
#     """
#     Add standard command-line options to an argparse parser.
# 
#     @param parser: An C{argparse.ArgumentParser} instance.
#     """
# 
#     parser.add_argument(
#         '--fastaFile', type=open, default=sys.stdin, metavar='FILENAME',
#         help=('The name of the FASTA input file. Standard input will be read '
#               'if no file name is given.'))
# 
#     parser.add_argument(
#         '--readClass', default='DNARead', choices=readClassNameToClass,
#         metavar='CLASSNAME',
#         help=('If specified, give the type of the reads in the input. '
#               'Possible choices: %s.' % ', '.join(readClassNameToClass)))
# 
#     # A mutually exclusive group for either --fasta, --fastq, or --fasta-ss
#     group = parser.add_mutually_exclusive_group()
# 
#     group.add_argument(
#         '--fasta', default=False, action='store_true',
#         help=('If specified, input will be treated as FASTA. This is the '
#               'default.'))
# 
#     group.add_argument(
#         '--fastq', default=False, action='store_true',
#         help='If specified, input will be treated as FASTQ.')
# 
#     group.add_argument(
#         '--fasta-ss', dest='fasta_ss', default=False, action='store_true',
#         help=('If specified, input will be treated as PDB FASTA '
#               '(i.e., regular FASTA with each sequence followed by its '
#               'structure).'))
# 
# def parseFASTACommandLineOptions(args):
#     """
#     Examine parsed command-line options and return a Reads instance.
# 
#     @param args: An argparse namespace, as returned by the argparse
#         C{parse_args} function.
#     @return: A C{Reads} subclass instance, depending on the type of FASTA file
#         given.
#     """
#     # Set default FASTA type.
#     if not (args.fasta or args.fastq or args.fasta_ss):
#         args.fasta = True
# 
#     readClass = readClassNameToClass[args.readClass]
# 
#     if args.fasta:
#         from dark.fasta import FastaReads
#         return FastaReads(args.fastaFile, readClass=readClass)
#     elif args.fastq:
#         from dark.fastq import FastqReads
#         return FastqReads(args.fastaFile, readClass=readClass)
#     else:
#         from dark.fasta_ss import SSFastaReads
#         return SSFastaReads(args.fastaFile, readClass=readClass)


# Path: bin/fasta-split-by-id.py
import sys
import argparse
from os.path import join, exists
from os import mkdir, rename
from math import log10
from dark.reads import (addFASTACommandLineOptions,
                        parseFASTACommandLineOptions)

    (args.fastq and 'fastq') or
    (args.fasta_ss and 'fasta-ss'))

# Note: we may be reading the FASTA input from stdin, so we cannot read it
# more than once (and I don't want to store it all because it may be very
# large). That's why we do a second phase of processing to renumber the
# files we created if --numeric is used (and --noLeadingZeroes is not).

count = 0
for count, read in enumerate(parseFASTACommandLineOptions(args), start=1):
    id_ = read.id.split()[0]
    if args.numeric:
        base = '%d.fasta' % count
    else:
        id_ = read.id.split()[0]
        base = '%s.fasta' % id_
    if args.verbose:
        print('Writing', base)
    filename = join(args.outDir, base)
    if not args.force and exists(filename):
        print('Will not overwrite pre-existing file "%s". Use --force to '
              'make me. Exiting.' % filename, file=sys.stderr)
        sys.exit(1)
    with open(filename, 'w') as fp:
        print(read.toString(saveAs), end='', file=fp)

# Rename numeric filenames to have leading zeroes.
if count and args.numeric and not args.noLeadingZeroes:
    width = int(log10(count)) + 1
    if width > 1:

        if args.verbose: