Exemple #1
0
  def checkParameterSets(self, data, allowTermination, name, isTool):
    success = True

    # Define the allowed attributes.
    allowedAttributes                = {}
    allowedAttributes['id']          = (str, True, True, 'id')
    allowedAttributes['description'] = (str, True, True, 'description')
    allowedAttributes['data']        = (list, True, False, None)

    # Define the allowed attributes in the data section of the parameter set.
    allowedDataAttributes           = {}
    allowedDataAttributes['id']     = (str, True, True, 'id')
    allowedDataAttributes['values'] = (list, True, True, 'values')

    # The parameter set definitions differ slightly between tools and pipelines. For tools, the argument is
    # provided as the means of identifying the node for which the supplied values apply. For pipelines, it is
    # the node within the pipeline that is supplied.
    if isTool: allowedDataAttributes['argument'] = (str, True, True, 'argument')
    else: allowedDataAttributes['node']          = (str, True, True, 'nodeId')

    # Loop over all of the defined parameter sets.
    for parameterSet in data:

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(parameterSet, allowTermination): return False

      # Check that the node has a valid ID. This is required for help messages.
      id = methods.checkForId(parameterSet, name, 'parameter sets', allowTermination, isTool)
      if not id: return False

      # Define a set of information to be used in help messages.
      helpInfo = (name, 'parameter sets', id)

      # Define a structure to hold the data.
      attributes = parameterSetData()

      # Check the attributes.
      success, attributes = methods.checkAttributes(parameterSet, allowedAttributes, attributes, allowTermination, helpInfo)

      # Loop over all of the data supplied with the parameter set and check the validity.
      for dataSet in parameterSet['data']:

        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(dataSet, allowTermination): return False

        # Define a structure to hold the information for each argument.
        dataAttributes = parameterSetArguments()

        # Check the attributes.
        success, dataAttributes = methods.checkAttributes(dataSet, allowedDataAttributes, dataAttributes, allowTermination, helpInfo)

        # Append this argument to the main parameter set attributes.
        attributes.data.append(dataAttributes)

      # Store the parameter set data.
      #TODO RROR
      if attributes.id in self.sets: print('parameterSets.checkParameterSets - REPEAT', attributes.id); exit(0)
      self.sets[attributes.id] = attributes

    return success
  def checkArguments(self, category, arguments, allowedAttributes, isInput, isOutput):

    # Loop over all of the input arguments and check their validity.
    for argumentInformation in arguments:

      # Define a set of information to be used in help messages.
      helpInfo = (self.name, 'arguments', category)

      # Define a class to store task attribtues.
      attributes = argumentAttributes()

      # Check all the supplied attributes.
      self.success, attributes = methods.checkAttributes(argumentInformation, allowedAttributes, attributes, self.allowTermination, helpInfo)

      # Check that the argument name is unique.
      if attributes.longFormArgument in self.arguments:
        if self.allowTermination: self.errors.repeatedLongFormArgument(helpInfo, attributes.longFormArgument)
        else:
          self.success = False
          return

      # Define the argument category.
      attributes.category = category

      # Store the attributes for the argument.
      if isInput: attributes.isInput = True
      elif isOutput: attributes.isOutput = True
      self.arguments[attributes.longFormArgument] = attributes
  def checkTopLevelInformation(self, data):

    # Define the allowed general attributes.
    allowedAttributes                       = {}
    allowedAttributes['arguments']          = (dict, True, False, None)
    allowedAttributes['argument delimiter'] = (str, False, True, 'delimiter')
    allowedAttributes['argument order']     = (list, False, True, 'argumentOrder')
    allowedAttributes['categories']         = (list, True, True, 'categories')
    allowedAttributes['configuration type'] = (str, True, False, None)
    allowedAttributes['description']        = (str, True, True, 'description')
    allowedAttributes['developmental']      = (bool, False, True, 'isDevelopmental')
    allowedAttributes['executable']         = (str, True, True, 'executable')
    allowedAttributes['hide tool']          = (bool, False, True, 'isHidden')
    allowedAttributes['id']                 = (str, True, True, 'id')
    allowedAttributes['parameter sets']     = (list, True, False, None)
    allowedAttributes['modifier']           = (str, False, True, 'modifier')
    allowedAttributes['path']               = (str, True, True, 'path')
    allowedAttributes['precommand']         = (str, False, True, 'precommand')
    allowedAttributes['R packages']         = (list, False, True, 'rPackages')
    allowedAttributes['tools']              = (list, True, True, 'requiredCompiledTools')
    allowedAttributes['url']                = (str, False, True, 'url')
    allowedAttributes['web page']           = (dict, False, True, 'webPage')

    # Define a set of information to be used in help messages.
    helpInfo = (self.name, None, None)

    # Check the attributes against the allowed attributes and make sure everything is ok.
    self = methods.checkAttributes(data, allowedAttributes, self, self.allowTermination, helpInfo)
  def checkDefinedEdges(self, data):

    if 'connect nodes' not in data: return True

    # Define the allowed attributes.
    allowedAttributes             = {}
    allowedAttributes['argument'] = (str, True, False, None)
    allowedAttributes['source']   = (str, True, False, None)
    allowedAttributes['target']   = (str, True, False, None)

    # Loop over all the defined definitions.
    for i, information in enumerate(data['connect nodes']):

      # Define a set of information to be used in help messages.
      helpInfo = (self.name, 'connect nodes', str(i))

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(information, self.allowTermination): return

      # Define the attributes object.
      attributes = edgeDefinitions()

      # Check the attributes conform to expectations.
      self.success, attributes = methods.checkAttributes(information, allowedAttributes, attributes, self.allowTermination, helpInfo)

      # Store the connection.
      attributes.source   = str(information['source'])
      attributes.target   = str(information['target'])
      attributes.argument = str(information['argument'])
      self.connections.append(attributes)
  def checkSharedNodeTasks(self):

    # Define the allowed nodes attributes.
    allowedAttributes                        = {}
    allowedAttributes['node id']             = (str, False, True, 'externalNodeId')
    allowedAttributes['stub extension']      = (str, False, True, 'stubExtension')
    allowedAttributes['task']                = (str, True, True, 'task')
    allowedAttributes['task argument']       = (str, False, True, 'taskArgument')

    # Loop over all of the defined nodes.
    for nodeId in self.sharedNodeAttributes:
      for node in self.sharedNodeAttributes[nodeId].nodes:

        # Define a set of information to be used in help messages.
        helpInfo = (self.name, 'shared nodes', nodeId)

        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(node, self.allowTermination): return

        # Define the attributes object.
        attributes = nodeTaskAttributes()
  
        # Check that the supplied attributes are valid.
        self.success, attributes = methods.checkAttributes(node, allowedAttributes, attributes, self.allowTermination, helpInfo)

        #TODO INCLUDE A CHECK TO ENSURE THAT AN ALLOWED COMBINATION OF FIELDS IS PRESENT. IN PARTICULAR,
        # IF THE TASK POINTS TO A PIPELINE RATHER THAN A TOOL, ENSURE THAT THE NODE ID IS PRESENT AND NOT
        # THE TASK ARGUMENT.

        # Store the attributes.
        self.sharedNodeAttributes[nodeId].sharedNodeTasks.append(attributes)
  def validate(self, data):

    # Define the allowed input argument attributes.
    allowedAttributes = {}
    allowedAttributes['data type']           = (str, True, True, 'dataType')
    allowedAttributes['description']         = (str, False, True, 'description')
    allowedAttributes['long form argument']  = (str, True, True, 'longFormArgument')
    allowedAttributes['short form argument'] = (str, True, True, 'shortFormArgument')
    allowedAttributes['values']              = (list, True, True, 'values')

    # Loop over all of the defined gkno arguments.
    for identifier in data:

      # Define a set of information to be used in help messages.
      helpInfo = ('gknoConfiguration', 'gkno options', identifier)

      # Check all the supplied attributes.
      attributes = gknoArgumentAttributes()
      success, attributes = methods.checkAttributes(data[identifier], allowedAttributes, attributes, True, helpInfo)

      # Check that the argument name is unique.
      #TODO ERROR
      if attributes.longFormArgument in self.arguments: print('gknoConfiguration.validate - 1', attributes.longFormArgument); exit(0)
      if attributes.shortFormArgument in self.shortForms: print('gknoConfiguration.validate - 2', attributes.shortFormArgument); exit(0)

      # Store the attributes for the argument.
      self.arguments[attributes.longFormArgument]   = attributes
      self.shortForms[attributes.shortFormArgument] = attributes.longFormArgument
      self.options[str(identifier)]                 = gknoArgumentAttributes()
      self.options[identifier].longFormArgument     = attributes.longFormArgument
      self.options[identifier].shortFormArgument    = attributes.shortFormArgument
  def checkPipelineTasks(self, data):

    # Define the allowed general attributes.
    allowedAttributes                                  = {}
    allowedAttributes['consolidate divisions']         = (bool, False, True, 'consolidate')
    allowedAttributes['input is stream']               = (bool, False, True, 'isInputStream')
    allowedAttributes['input stream instruction set']  = (str, False, True, 'inputStreamInstructionSet')
    allowedAttributes['greedy argument']               = (str, False, True, 'greedyArgument')
    allowedAttributes['greedy task']                   = (bool, False, True, 'isGreedy')
    allowedAttributes['omit from reduced plot']        = (bool, False, True, 'omitFromReducedPlot')
    allowedAttributes['output to stream']              = (bool, False, True, 'isOutputStream')
    allowedAttributes['output stream instruction set'] = (str, False, True, 'outputStreamInstructionSet')
    allowedAttributes['pipeline']                      = (str, False, True, 'pipeline')
    allowedAttributes['task']                          = (str, True, True, 'task')
    allowedAttributes['tool']                          = (str, False, True, 'tool')

    for taskInformation in data:

      # Define a set of information to be used in help messages.
      #helpInfo = (self.name, 'pipeline tasks', taskInformation)
      helpInfo = (self.name, 'pipeline tasks', None)

      # Define a class to store task attribtues.
      attributes = taskAttributes()

      # Check all the supplied attributes.
      self.success, attributes = methods.checkAttributes(taskInformation, allowedAttributes, attributes, self.allowTermination, helpInfo)
      if not self.success: return False

      # Check that the task name is unique.
      if attributes.task in self.pipelineTasks:
        if self.allowTermination: self.errors.repeatedTaskName(self.name, attributes.task)
        else:
          self.success = False
          return

      # Store the attributes for the task.
      self.pipelineTasks[attributes.task] = attributes

      # Get the tool or pipeline associated with the task.
      tool     = self.getTaskAttribute(attributes.task, 'tool')
      pipeline = self.getTaskAttribute(attributes.task, 'pipeline')

      # Each task must define either a tool or a pipeline. Check that one and only one is defined. 
      #TODO ERROR
      if not tool and not pipeline: print('pipeline.checkPipelineTasks - 5'); exit(0)
      if tool and pipeline: print('pipeline.checkPipelineTasks - 6'); exit(0)

      # If this is a tool, store the tool.
      if tool:
        self.allTools.append(tool)
        self.allTasks.append(attributes.task)
      
      # Checking if the tool or pipeline is valid is performed later when all pipelines
      # have been evaluated. If a task points to a pipeline, set the hasPipelineAsTask 
      # variable to True.
      if pipeline:
        self.requiredPipelines.append((attributes.task, pipeline))
        self.hasPipelineAsTask = True
  def checkArguments(self, data):

    # If there is not information on unique graph nodes, return.
    if 'arguments' not in data: return

    # Define the allowed nodes attributes.
    allowedAttributes                        = {}
    allowedAttributes['description']         = (str, True, True, 'description')
    allowedAttributes['hide in help']        = (bool, False, True, 'hideInHelp')
    allowedAttributes['linked argument']     = (str, False, True, 'linkedArgument')
    allowedAttributes['long form argument']  = (str, True, True, 'longFormArgument')
    allowedAttributes['node id']             = (str, True, True, 'nodeId')
    allowedAttributes['required']            = (bool, False, True, 'isRequired')
    allowedAttributes['short form argument'] = (str, True, True, 'shortFormArgument')

    # Loop over all of the argument categories.
    for category in data['arguments']:

      # Loop over all arguments in the category.
      for argumentInformation in data['arguments'][category]:
  
        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(argumentInformation, self.allowTermination): return
  
        # Check that the node has a long form argument. This is required for help messages.
        longFormArgument = methods.checkForLongFormArgument(argumentInformation, self.allowTermination)
        if not longFormArgument: return
  
        # Define a set of information to be used in help messages.
        helpInfo = (self.name, 'arguments -> ' + category, longFormArgument)
  
        # Define the attributes object and add the help category.
        attributes          = pipelineArguments()
        attributes.category = category
  
        # Check the attributes conform to expectations.
        self.success, attributes = methods.checkAttributes(argumentInformation, allowedAttributes, attributes, self.allowTermination, helpInfo)
  
        # If the long form argument already exists, there is a problem. All arguments must be unique.
        if longFormArgument in self.longFormArguments: self.errors.repeatedLongFormArgument(helpInfo)
  
        # Also check that the node id is not the name of a task.
        shortFormArgument = attributes.shortFormArgument
        if shortFormArgument in self.shortFormArguments: self.errors.repeatedShortFormArgument(helpInfo)

        # If the argument shares a name with a pipeline task.
        if longFormArgument.strip('-') in self.pipelineTasks: self.errors.argumentIsTask(longFormArgument, shortFormArgument, isLongForm = True)
        if shortFormArgument.strip('-') in self.pipelineTasks: self.errors.argumentIsTask(longFormArgument, shortFormArgument, isLongForm = False)

        # Store the attributes.
        self.longFormArguments[longFormArgument]   = attributes
        self.shortFormArguments[shortFormArgument] = longFormArgument
  def checkUniqueNodes(self, data):

    # If there is not information on unique graph nodes, return.
    if 'unique graph nodes' not in data: return

    # Define the allowed nodes attributes.
    allowedAttributes                             = {}
    allowedAttributes['delete files']             = (bool, False, True, 'isDelete')
    allowedAttributes['evaluate command']         = (dict, False, True, 'evaluateCommand')
    allowedAttributes['id']                       = (str, True, True, 'id')
    allowedAttributes['omit from reduced plot']   = (bool, False, True, 'omitFromReducedPlot')
    allowedAttributes['node id']                  = (str, False, True, 'nodeId')
    allowedAttributes['task']                     = (str, True, True, 'task')
    allowedAttributes['task argument']            = (str, False, True, 'taskArgument')

    # Loop over all of the defined nodes.
    for uniqueNode in data['unique graph nodes']:

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(uniqueNode, self.allowTermination): return

      # Check that the node has a valid ID. This is required for help messages.
      id = methods.checkForId(uniqueNode, self.name, 'unique graph nodes', self.allowTermination, isTool = False)
      if not id: return

      # Define a set of information to be used in help messages.
      helpInfo = (self.name, 'unique graph nodes', id)

      # Define the attributes object.
      attributes = uniqueGraphNodes()

      # Check the attributes conform to expectations.
      self.success, attributes = methods.checkAttributes(uniqueNode, allowedAttributes, attributes, self.allowTermination, helpInfo)

      # If the nodeId already exists in the attributes, a node of this name has already been seen. All 
      #nodes must have a unique name.
      if attributes.id in self.uniqueNodeAttributes: self.errors.repeatedNodeId(helpInfo)

      # Also check that the node id is not the name of a task.
      if attributes.id in self.allTasks: self.errors.nodeIdIsTaskId('unique', helpInfo)

      # Store the attributes.
      self.uniqueNodeAttributes[attributes.id] = attributes
  def checkTopLevelInformation(self, data):

    # Define the allowed general attributes.
    allowedAttributes                       = {}
    allowedAttributes['id']                 = (str, True, True, 'id')
    allowedAttributes['arguments']          = (dict, True, False, None)
    allowedAttributes['description']        = (str, True, True, 'description')
    allowedAttributes['development']        = (bool, False, True, 'isDevelopment')
    allowedAttributes['categories']         = (list, True, True, 'categories')
    allowedAttributes['configuration type'] = (str, True, False, None)
    allowedAttributes['connect nodes']      = (list, False, False, None)
    allowedAttributes['import arguments']   = (str, False, True, 'importArgumentsFromTool')
    allowedAttributes['parameter sets']     = (list, True, False, None)
    allowedAttributes['pipeline tasks']     = (list, True, False, None)
    allowedAttributes['shared graph nodes'] = (list, False, False, None)
    allowedAttributes['unique graph nodes'] = (list, False, False, None)

    # Define a set of information to be used in help messages.
    helpInfo = (self.name, None, None)

    # Check the attributes against the allowed attributes and make sure everything is ok.
    self.success, self = methods.checkAttributes(data, allowedAttributes, self, self.allowTermination, helpInfo)
  def checkTerminationInstructions(self, data):

    # If there are not termination instructions, return.
    if 'terminate pipeline' not in data: return

    # Define the allowed attributes.
    allowedAttributes                       = {}
    allowedAttributes['condition']          = (str, False, True, 'condition')
    allowedAttributes['consolidating task'] = (str, False, True, 'consolidatingTask')
    allowedAttributes['delete tasks']       = (list, False, True, 'deleteTasks')
    allowedAttributes['replace nodes']      = (list, False, True, 'replaceNodes')

    # Define a set of information to be used in help messages.
    helpInfo = (self.name, 'terminate pipeline', None)

    # Define the attributes object.
    attributes = terminationInstructions()

    # Check the attributes conform to expectations.
    self.success, attributes = methods.checkAttributes(data['terminate pipeline'], allowedAttributes, attributes, self.allowTermination, helpInfo)

    # Store the attributes.
    self.terminatePipeline = attributes