# 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)

parser.add_argument(
    '--force', default=False, action='store_true',
    help='If given, overwrite pre-existing files.')

parser.add_argument(
    '--saveAs', choices=('fasta', 'fastq', 'fasta-ss'),
    help=('The output format. The default is to match the input format, '
          'so there is usually no need to specify this option. It can be '
          'used to force conversion from FASTQ to FASTA'))

addFASTACommandLineOptions(parser)
args = parser.parse_args()
reads = parseFASTACommandLineOptions(args)

if not exists(args.outDir):
    mkdir(args.outDir)

saveAs = (
    args.saveAs or
    (args.fasta and 'fasta') or
    (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

# 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)


parser.add_argument(
    '--force', default=False, action='store_true',
    help='If given, overwrite pre-existing files.')

parser.add_argument(
    '--saveAs', choices=('fasta', 'fastq', 'fasta-ss'),
    help=('The output format. The default is to match the input format, '
          'so there is usually no need to specify this option. It can be '
          'used to force conversion from FASTQ to FASTA'))

addFASTACommandLineOptions(parser)
args = parser.parse_args()
reads = parseFASTACommandLineOptions(args)

if not exists(args.outDir):
    mkdir(args.outDir)

saveAs = (
    args.saveAs or
    (args.fasta and 'fasta') or
    (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):