# Path: anoisetools/sff.py
# FLOW_ORDER = 'TACG'
# READ_BEGIN = 'TCAG'
# def cumsum(iterable):
# def find_clip(seqrecord):
# def flow_to_seq(flowgram, flow_order=FLOW_ORDER):
# def bases_from_flows(seq_record):
# def flows_to_string(seq_record):
# 
# Path: anoisetools/anoiseio.py
# class AnoiseRawReader(object):
# class AnoiseRawWriter(object):
#     def __init__(self, fp):
#     def __iter__(self):
# def _record_to_anoise_raw(seq_record):
#     def __init__(self, fp, identifier):
#     def _header(self):
#     def write(self, record):
#     def write_records(self, records):
#     def _copy_to_output(self):
#     def close(self):
# def _read_count(read_name):
# def read_mapping(fp):
# def merge_mapping(snoise_map, pnoise_map):
# 
# Path: anoisetools/util.py
# _AMBIGUOUS_MAP = {
#        'R': '[GA]',
#        'Y': '[TC]',
#        'K': '[GT]',
#        'M': '[AC]',
#        'S': '[GC]',
#        'W': '[AT]',
#        'B': '[GTC]',
#        'D': '[GAT]',
#        'H': '[ACT]',
#        'V': '[GCA]',
#        'N': '[AGCT]',
# }
# def ambiguous_pattern(sequence_str):
# def ambiguous_regex(sequence_str):


import argparse
import math
import re
import shutil
import sys
import tempfile
from anoisetools import sff, anoiseio, util
# Default maximum flows to keep
DEFAULT_MAX_FLOWS = 720

FLOWGRAM_SIZE = 4

def build_parser(subparsers):
    """
    Given an ArgumentParser, adds options taken by ``clean``
    """
    parser = subparsers.add_parser("clean",
            help='Clean flowgrams prior to running AmpliconNoise')
    parser.description = """Clean flowgrams prior to
processing with AmpliconNoise: enforce minimum length, remove invalid data,
trim."""
    parser.add_argument('--min-flows', type=int,
            help="Minimum length to accept sequence"
            " default: %(default)s", default=DEFAULT_MIN_FLOWS)
    parser.add_argument('--max-flows', type=int,
            help="Maximum length to trim sequences to "
            "default: %(default)s", default=DEFAULT_MAX_FLOWS)
    parser.add_argument('primer', metavar='PRIMER',
            help="Primer sequence (ambiguous bases accepted)",
            type=util.ambiguous_pattern)
    parser.add_argument('--max-empty',
            type=int, default=0, help="""Maximum empty flowgrams (default: %(default)s)""")
    parser.add_argument('outname', metavar="OUTNAME",
            help="base name for output files - OUTNAME.fa and OUTNAME.dat")
    parser.add_argument('--input', metavar='INPUT', default=sys.stdin,
            type=argparse.FileType('r'),
            help='Input data file (default: stdin)')

# Path: anoisetools/sff.py
# FLOW_ORDER = 'TACG'
# READ_BEGIN = 'TCAG'
# def cumsum(iterable):
# def find_clip(seqrecord):
# def flow_to_seq(flowgram, flow_order=FLOW_ORDER):
# def bases_from_flows(seq_record):
# def flows_to_string(seq_record):
# 
# Path: anoisetools/anoiseio.py
# class AnoiseRawReader(object):
# class AnoiseRawWriter(object):
#     def __init__(self, fp):
#     def __iter__(self):
# def _record_to_anoise_raw(seq_record):
#     def __init__(self, fp, identifier):
#     def _header(self):
#     def write(self, record):
#     def write_records(self, records):
#     def _copy_to_output(self):
#     def close(self):
# def _read_count(read_name):
# def read_mapping(fp):
# def merge_mapping(snoise_map, pnoise_map):
# 
# Path: anoisetools/util.py
# _AMBIGUOUS_MAP = {
#        'R': '[GA]',
#        'Y': '[TC]',
#        'K': '[GT]',
#        'M': '[AC]',
#        'S': '[GC]',
#        'W': '[AT]',
#        'B': '[GTC]',
#        'D': '[GAT]',
#        'H': '[ACT]',
#        'V': '[GCA]',
#        'N': '[AGCT]',
# }
# def ambiguous_pattern(sequence_str):
# def ambiguous_regex(sequence_str):


# Path: anoisetools/scripts/clean.py
import argparse
import math
import re
import shutil
import sys
import tempfile
from anoisetools import sff, anoiseio, util

# Default maximum flows to keep
DEFAULT_MAX_FLOWS = 720

FLOWGRAM_SIZE = 4

def build_parser(subparsers):
    """
    Given an ArgumentParser, adds options taken by ``clean``
    """
    parser = subparsers.add_parser("clean",
            help='Clean flowgrams prior to running AmpliconNoise')
    parser.description = """Clean flowgrams prior to
processing with AmpliconNoise: enforce minimum length, remove invalid data,
trim."""
    parser.add_argument('--min-flows', type=int,
            help="Minimum length to accept sequence"
            " default: %(default)s", default=DEFAULT_MIN_FLOWS)
    parser.add_argument('--max-flows', type=int,
            help="Maximum length to trim sequences to "
            "default: %(default)s", default=DEFAULT_MAX_FLOWS)
    parser.add_argument('primer', metavar='PRIMER',
            help="Primer sequence (ambiguous bases accepted)",
            type=util.ambiguous_pattern)
    parser.add_argument('--max-empty',
            type=int, default=0, help="""Maximum empty flowgrams (default: %(default)s)""")
    parser.add_argument('outname', metavar="OUTNAME",
            help="base name for output files - OUTNAME.fa and OUTNAME.dat")
    parser.add_argument('--input', metavar='INPUT', default=sys.stdin,
            type=argparse.FileType('r'),
            help='Input data file (default: stdin)')

    return parser