#/usr/bin/python

from cogent.app.util import CommandLineApplication, ResultPath
from cogent.app.parameters import ValuedParameter

class MinimalFormatDb(CommandLineApplication):
    """Example APPC """
    
    _command = "formatdb"
    _parameters = {\
        '-i':ValuedParameter(Prefix='-',Name='i',Delimiter=' ',IsPath=True),
        '-o':ValuedParameter(Prefix='-',Name='o',Delimiter=' ',Value='T'),
        '-p':ValuedParameter(Prefix='-',Name='p',Delimiter=' ',Value='F')\
        }
    _input_handler = "_input_as_parameter"
    
    def _input_as_parameter(self,data):
        self.Parameters['-i'].on(data)
        return ''
    
    def _get_result_paths(self,data):
        """ """
        result = {}
        result['log'] = ResultPath(\
         Path=self.WorkingDir+'formatdb.log',IsWritten=True)
         
        if self.Parameters['-p'].Value == 'F':
            extensions = ['nhr','nin','nsi','nsq','nsd']
        else:
            extensions = ['phr','pin','psi','psq','psd']
            
        for extension in extensions:
            result[extension] = ResultPath(\
             Path=data+ '.' + extension,\
             IsWritten=True)
        return result