import logging
import subprocess

from pbrdna.utils import which, is_executable

log = logging.getLogger(__name__)

VALID_COMMANDS = frozenset(['fastq.info', 'align.seqs', 'chimera.uchime',
                            'screen.seqs', 'remove.seqs', 'filter.seqs', 
                            'summary.seqs', 'dist.seqs', 'unique.seqs',
                            'trim.seqs', 'pre.cluster', 'cluster', 
                            'set.logfile'])

NUMPROC_COMMANDS = frozenset(['align.seqs', 'chimera.uchime', 'screen.seqs',
                              'filter.seqs', 'dist.seqs'])

VALID_PARAMS = frozenset(['fasta', 'fastq', 'qfile', 'reference', 'name',
                          'flip', 'start', 'end', 'minlength', 'processors',
                          'vertical', 'trump', 'calc', 'output', 'phylip', 'method',
                          'accnos', 'countends', 'qaverage', 'diffs', 'name'])

class MothurCommand(object):
    """
    A class for representing individual Mothur Commands
    """
    def __init__(self, command, parameters):
        # Validate the selected Mothur Command
        try:
            assert command.lower() in VALID_COMMANDS
            self._command = command.lower()
        except AssertionError:
            ValueError("Invalid Mothur command")
        # Validate the arguments for the command
        self._parameters = {}
        for param, value in parameters.iteritems():
            try: 
                assert param in VALID_PARAMS
                self.parameters[param] = value
            except AssertionError:
                ValueError('Invalid Mothur argument')

    @property
    def command(self):
        return self._command

    @property
    def parameters(self):
        return self._parameters

    @property
    def parameterString(self):