# Path: anoisetools/run.py
# def run(self, command, mpi=True, suppress_stdout=True,
#         suppress_stderr=True, **kwargs):
#     """
#     Run the specified command
#     """
# 
#     if not (self.temp_dir and os.path.isdir(self.temp_dir)):
#         raise ValueError("Missing temporary directory: "
#                 "{0}".format(self.temp_dir))
# 
#     if mpi:
#         command = self._mpi_command(command)
# 
#     outputs = [i for i in ('stderr', 'stdout') if i not in kwargs]
#     for i in ('stderr', 'stdout'):
#         if not i in kwargs:
#             kwargs[i] = tempfile.SpooledTemporaryFile()
# 
#     # Convert args to strings
#     command = map(str, command)
# 
#     logging.info("Running: %s", " ".join(command))
#     try:
#         p = subprocess.Popen(command, cwd=self.temp_dir, **kwargs)
#         p.wait()
#         if p.returncode:
#             raise subprocess.CalledProcessError("Error", p.returncode)
#     except subprocess.CalledProcessError, e:
#         if 'stderr' in outputs:
#             kwargs['stderr'].seek(0)
#             stderr = kwargs['stderr'].read()
#         else:
#             stderr = ''
#         if 'stdout' in outputs:
#             kwargs['stdout'].seek(0)
#             stdout = kwargs['stdout'].read()
#         else:
#             stdout = ''
# 
#         logging.error("Error running '%s': returned with %s.\nstdout:\n%s\nstderr:%s",
#                 ' '.join(command), p.returncode, stdout, stderr)
#         raise SystemExit(1)


import logging
import os
import os.path
from anoisetools import run



def build_parser(subparsers):
    parser = subparsers.add_parser("seqnoise", help="Run SeqNoise",
            parents=[run.base_parser()])

    snoise_opts = parser.add_argument_group("SeqNoise Options")
    snoise_opts.add_argument('-s', '--sigma', type=float,
            default=30.0, help="""Sigma (see Quince et al)
            [default: %(default)s]""")
    snoise_opts.add_argument('-c', '--cutoff', type=float,
            default=0.08, help="""Initial cutoff (see Quince et al) [default:
            %(default)s]""")
    snoise_opts.add_argument('-rin', '--lookup-file',
            help="""Lookup file""")

    parser.add_argument('-v', '--verbose', default=logging.INFO,
        action="store_const", const=logging.DEBUG)

    parser.add_argument('fasta_file', help="""PyroNoised fasta file""")
    parser.add_argument('mapping_file', help="""PyroNoise .mapping file""")


# Path: anoisetools/run.py
# def run(self, command, mpi=True, suppress_stdout=True,
#         suppress_stderr=True, **kwargs):
#     """
#     Run the specified command
#     """
# 
#     if not (self.temp_dir and os.path.isdir(self.temp_dir)):
#         raise ValueError("Missing temporary directory: "
#                 "{0}".format(self.temp_dir))
# 
#     if mpi:
#         command = self._mpi_command(command)
# 
#     outputs = [i for i in ('stderr', 'stdout') if i not in kwargs]
#     for i in ('stderr', 'stdout'):
#         if not i in kwargs:
#             kwargs[i] = tempfile.SpooledTemporaryFile()
# 
#     # Convert args to strings
#     command = map(str, command)
# 
#     logging.info("Running: %s", " ".join(command))
#     try:
#         p = subprocess.Popen(command, cwd=self.temp_dir, **kwargs)
#         p.wait()
#         if p.returncode:
#             raise subprocess.CalledProcessError("Error", p.returncode)
#     except subprocess.CalledProcessError, e:
#         if 'stderr' in outputs:
#             kwargs['stderr'].seek(0)
#             stderr = kwargs['stderr'].read()
#         else:
#             stderr = ''
#         if 'stdout' in outputs:
#             kwargs['stdout'].seek(0)
#             stdout = kwargs['stdout'].read()
#         else:
#             stdout = ''
# 
#         logging.error("Error running '%s': returned with %s.\nstdout:\n%s\nstderr:%s",
#                 ' '.join(command), p.returncode, stdout, stderr)
#         raise SystemExit(1)


# Path: anoisetools/scripts/seqnoise.py
import logging
import os
import os.path
from anoisetools import run




def build_parser(subparsers):
    parser = subparsers.add_parser("seqnoise", help="Run SeqNoise",
            parents=[run.base_parser()])

    snoise_opts = parser.add_argument_group("SeqNoise Options")
    snoise_opts.add_argument('-s', '--sigma', type=float,
            default=30.0, help="""Sigma (see Quince et al)
            [default: %(default)s]""")
    snoise_opts.add_argument('-c', '--cutoff', type=float,
            default=0.08, help="""Initial cutoff (see Quince et al) [default:
            %(default)s]""")
    snoise_opts.add_argument('-rin', '--lookup-file',
            help="""Lookup file""")

    parser.add_argument('-v', '--verbose', default=logging.INFO,
        action="store_const", const=logging.DEBUG)

    parser.add_argument('fasta_file', help="""PyroNoised fasta file""")
    parser.add_argument('mapping_file', help="""PyroNoise .mapping file""")


    return parser