#!/usr/bin/env python

from TriAnnot.TriAnnotTaskParameters import *

class ProteinMaker (TriAnnotTaskParameters):

    def __init__(self):
        pass

    def retrieveTaskParameters(self, xmlElt):
        # Call the retrieveTaskParameters method of the parent class
        errorsList = super(self.__class__, self).retrieveTaskParameters(xmlElt)

        # Initializations
        proteinSequenceName = self.parameters['protein_sequence_file']

        # Store the name of the sequence that will be generated by this tool
        if proteinSequenceName in TriAnnotTaskParameters.generatedSequencesTaskId:
            errorsList.append("Task #%s wants to create a protein sequence file named <%s> but this sequence file must already be created by a previous task !" % (self.taskId, proteinSequenceName))
        else:
            TriAnnotTaskParameters.generatedSequencesTaskId[proteinSequenceName] = {'taskIdentifier': self.taskId, 'sequenceType': 'protein', 'generatedBy': 'ProteinMaker'}
            self.logger.debug("Sequence <%s> has been added to the list of sequences that will be generated during the pipeline execution" % (proteinSequenceName))

        return errorsList


    def checkTaskParameters(self):
        # Call the checkTaskParameters method of the parent class
        errorsList = super(self.__class__, self).checkTaskParameters()

        # Check task specific parameters
        if self.parameters.has_key('useGeneModelData') and self.parameters['useGeneModelData'] == 'yes':
            if not self.parameters.has_key('geneModelGffFile') or self.parameters['geneModelGffFile'] is None:
                errorsList.append("Task %s - Gene Model data must be used (<useGeneModelData> parameter set to yes) but there is no Gene Model GFF file defined (with the <geneModelGffFile> parameter).." % self.taskDescription)

        if self.parameters.has_key('geneModelGffFile') and self.parameters['geneModelGffFile'] is not None:
            if not self.parameters.has_key('useGeneModelData') or self.parameters['useGeneModelData'] == 'no':
                errorsList.append("Task %s - A Gene Model GFF file has been selected but the <useGeneModelData> switch is set to <no> (or not defined) !" % self.taskDescription)

        if self.parameters.has_key('rejectedTags') and self.parameters['rejectedTags'] is not None:
            if not self.parameters.has_key('useGeneModelData') or self.parameters['useGeneModelData'] == 'no':
                errorsList.append("Task %s - The <rejectedTags> parameters has been used but the <useGeneModelData> switch is set to <no> (or not defined) !" % self.taskDescription)

        return errorsList
