示例#1
0
    def __module_from_dict( self, trans, step_dict, secure ):
        """ Create a WorkflowStep model object and corresponding module
        representing type-specific functionality from the incoming dictionary.
        """
        step = model.WorkflowStep()
        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if "uuid" in step_dict and step_dict['uuid'] != "None":
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]

        step_type = step_dict.get("type", None)
        if step_type == "subworkflow":
            subworkflow = self.__load_subworkflow_from_step_dict(
                trans, step_dict
            )
            step_dict["subworkflow"] = subworkflow

        module = module_factory.from_dict( trans, step_dict, secure=secure )
        module.save_to_step( step )

        annotation = step_dict[ 'annotation' ]
        if annotation:
            annotation = sanitize_html( annotation, 'utf-8', 'text/html' )
            self.add_item_annotation( trans.sa_session, trans.get_user(), step, annotation )

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        return module, step
示例#2
0
    def __module_from_dict(self, trans, step_dict, exact_tools=False):
        """ Create a WorkflowStep model object and corresponding module
        representing type-specific functionality from the incoming dictionary.
        """
        step = model.WorkflowStep()
        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if "uuid" in step_dict and step_dict['uuid'] != "None":
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]

        step_type = step_dict.get("type", None)
        if step_type == "subworkflow":
            subworkflow = self.__load_subworkflow_from_step_dict(
                trans, step_dict)
            step_dict["subworkflow"] = subworkflow

        module = module_factory.from_dict(trans,
                                          step_dict,
                                          exact_tools=exact_tools)
        module.save_to_step(step)

        annotation = step_dict['annotation']
        if annotation:
            annotation = sanitize_html(annotation, 'utf-8', 'text/html')
            self.add_item_annotation(trans.sa_session, trans.get_user(), step,
                                     annotation)

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        return module, step
示例#3
0
 def build_module(self, trans, payload={}):
     """
     POST /api/workflows/build_module
     Builds module models for the workflow editor.
     """
     inputs = payload.get('inputs', {})
     trans.workflow_building_mode = workflow_building_modes.ENABLED
     module = module_factory.from_dict(trans, payload)
     if 'tool_state' not in payload:
         module_state = {}
         populate_state(trans,
                        module.get_inputs(),
                        inputs,
                        module_state,
                        check=False)
         module.recover_state(module_state)
     return {
         'label': inputs.get('__label', ''),
         'annotation': inputs.get('__annotation', ''),
         'name': module.get_name(),
         'tool_state': module.get_state(),
         'inputs': module.get_all_inputs(connectable_only=True),
         'outputs': module.get_all_outputs(),
         'config_form': module.get_config_form(),
         'post_job_actions': module.get_post_job_actions(inputs)
     }
示例#4
0
    def build_module(self, trans, payload={}):
        """
        POST /api/workflows/build_module
        Builds module details including a tool model for the workflow editor.
        """
        tool_id = payload.get("tool_id", None)
        tool_version = payload.get("tool_version", None)
        tool_inputs = payload.get("inputs", None)
        annotation = payload.get("annotation", "")

        # load tool
        tool = self._get_tool(tool_id, tool_version=tool_version, user=trans.user)

        # initialize module
        trans.workflow_building_mode = True
        module = module_factory.from_dict(trans, {"type": "tool", "tool_id": tool.id, "tool_state": None})

        # create tool model and default tool state (if missing)
        tool_model = module.tool.to_json(trans, tool_inputs, is_workflow=True)
        module.state.inputs = copy.deepcopy(tool_model["state_inputs"])
        return {
            "tool_model": tool_model,
            "tool_state": module.get_state(),
            "data_inputs": module.get_data_inputs(),
            "data_outputs": module.get_data_outputs(),
            "tool_errors": module.get_errors(),
            "form_html": module.get_config_form(),
            "annotation": annotation,
            "post_job_actions": module.get_post_job_actions(tool_inputs),
        }
示例#5
0
    def __module_from_dict( self, trans, step_dict, secure ):
        """ Create a WorkflowStep model object and corresponding module
        representing type-specific functionality from the incoming dictionary.
        """
        step = model.WorkflowStep()
        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if "uuid" in step_dict and step_dict['uuid'] != "None":
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]
        module = module_factory.from_dict( trans, step_dict, secure=secure )
        module.save_to_step( step )

        workflow_outputs_dicts = step_dict.get("workflow_outputs", [])
        for workflow_output_dict in workflow_outputs_dicts:
            output_name = workflow_output_dict["output_name"]
            workflow_output = model.WorkflowOutput(
                step,
                output_name,
            )
            step.workflow_outputs.append(workflow_output)

        annotation = step_dict[ 'annotation' ]
        if annotation:
            annotation = sanitize_html( annotation, 'utf-8', 'text/html' )
            self.add_item_annotation( trans.sa_session, trans.get_user(), step, annotation )

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        return module, step
示例#6
0
    def build_module( self, trans, payload={}):
        """
        POST /api/workflows/build_module
        Builds module details including a tool model for the workflow editor.
        """
        tool_id         = payload.get( 'tool_id', None )
        tool_version    = payload.get( 'tool_version', None )
        tool_inputs     = payload.get( 'inputs', None )
        annotation      = payload.get( 'annotation', '' )

        # load tool
        tool = self._get_tool( tool_id, tool_version=tool_version, user=trans.user )

        # initialize module
        trans.workflow_building_mode = True
        module = module_factory.from_dict( trans, {
            'type'          : 'tool',
            'tool_id'       : tool.id,
            'tool_state'    : None
        } )

        # create tool model and default tool state (if missing)
        tool_model = module.tool.to_json(trans, tool_inputs, is_workflow=True)
        module.state.inputs = copy.deepcopy(tool_model['state_inputs'])
        return {
            'tool_model'        : tool_model,
            'tool_state'        : module.get_state(),
            'data_inputs'       : module.get_data_inputs(),
            'data_outputs'      : module.get_data_outputs(),
            'tool_errors'       : module.get_errors(),
            'form_html'         : module.get_config_form(),
            'annotation'        : annotation,
            'post_job_actions'  : module.get_post_job_actions(tool_inputs)
        }
示例#7
0
 def __get_tool_extensions(self, trans, tool_id):
     """
     Get the input and output extensions of a tool
     """
     payload = {'type': 'tool', 'tool_id': tool_id, '_': 'true'}
     inputs = payload.get('inputs', {})
     trans.workflow_building_mode = workflow_building_modes.ENABLED
     module = module_factory.from_dict(trans, payload)
     if 'tool_state' not in payload:
         module_state = {}
         populate_state(trans,
                        module.get_inputs(),
                        inputs,
                        module_state,
                        check=False)
         module.recover_state(module_state)
     inputs = module.get_all_inputs(connectable_only=True)
     outputs = module.get_all_outputs()
     input_extensions = list()
     output_extensions = list()
     for i_ext in inputs:
         input_extensions.extend(i_ext['extensions'])
     for o_ext in outputs:
         output_extensions.extend(o_ext['extensions'])
     return input_extensions, output_extensions
示例#8
0
 def build_module( self, trans, payload={}):
     """
     POST /api/workflows/build_module
     Builds module details including a tool model for the workflow editor.
     """
     tool_id         = payload.get( 'tool_id', None )
     tool_version    = payload.get( 'tool_version', None )
     tool_inputs     = payload.get( 'inputs', None )
     annotation      = payload.get( 'annotation', '' )
     
     # load tool
     tool = self._get_tool( tool_id, tool_version=tool_version, user=trans.user )
     
     # initialize module
     trans.workflow_building_mode = True
     module = module_factory.from_dict( trans, {
         'type'          : 'tool',
         'tool_id'       : tool.id,
         'tool_state'    : None
     } )
     
     # create tool model and default tool state (if missing)
     tool_model = module.tool.to_json(trans, tool_inputs, is_dynamic=False)
     module.state.inputs = copy.deepcopy(tool_model['state_inputs'])
     return {
         'tool_model'        : tool_model,
         'tool_state'        : module.get_state(),
         'data_inputs'       : module.get_data_inputs(),
         'data_outputs'      : module.get_data_outputs(),
         'tool_errors'       : module.get_errors(),
         'form_html'         : module.get_config_form(),
         'annotation'        : annotation,
         'post_job_actions'  : module.get_post_job_actions(tool_inputs)
     }
示例#9
0
    def __module_from_dict(self, trans, step_dict, secure):
        """ Create a WorkflowStep model object and corrsponding module representing
        type-specific functionality from the incoming dicitionary.
        """
        step = model.WorkflowStep()

        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if "uuid" in step_dict:
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]
        module = module_factory.from_dict(trans, step_dict, secure=secure)
        module.save_to_step(step)

        annotation = step_dict['annotation']
        if annotation:
            annotation = sanitize_html(annotation, 'utf-8', 'text/html')
            self.add_item_annotation(trans.sa_session, trans.get_user(), step,
                                     annotation)

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        return module, step
示例#10
0
    def __module_from_dict(self, trans, steps, steps_by_external_id, step_dict,
                           **kwds):
        """ Create a WorkflowStep model object and corresponding module
        representing type-specific functionality from the incoming dictionary.
        """
        step = model.WorkflowStep()
        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if step_dict.get("uuid", None) and step_dict['uuid'] != "None":
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]
        step_type = step_dict.get("type", None)
        if step_type == "subworkflow":
            subworkflow = self.__load_subworkflow_from_step_dict(
                trans, step_dict)
            step_dict["subworkflow"] = subworkflow

        module = module_factory.from_dict(trans, step_dict, **kwds)
        self.__set_default_label(step, module, step_dict.get('tool_state'))
        module.save_to_step(step)

        annotation = step_dict['annotation']
        if annotation:
            annotation = sanitize_html(annotation, 'utf-8', 'text/html')
            self.add_item_annotation(trans.sa_session, trans.get_user(), step,
                                     annotation)

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        # Create the model class for the step
        steps.append(step)
        steps_by_external_id[step_dict['id']] = step
        if 'workflow_outputs' in step_dict:
            workflow_outputs = step_dict['workflow_outputs']
            found_output_names = set([])
            for workflow_output in workflow_outputs:
                # Allow workflow outputs as list of output_names for backward compatiblity.
                if not isinstance(workflow_output, dict):
                    workflow_output = {"output_name": workflow_output}
                output_name = workflow_output["output_name"]
                if output_name in found_output_names:
                    raise exceptions.ObjectAttributeInvalidException(
                        "Duplicate workflow outputs with name [%s] found." %
                        output_name)
                if not output_name:
                    raise exceptions.ObjectAttributeInvalidException(
                        "Workflow output with empty name encountered.")
                found_output_names.add(output_name)
                uuid = workflow_output.get("uuid", None)
                label = workflow_output.get("label", None)
                m = step.create_or_update_workflow_output(
                    output_name=output_name,
                    uuid=uuid,
                    label=label,
                )
                trans.sa_session.add(m)
        return module, step
示例#11
0
    def __module_from_dict( self, trans, steps, steps_by_external_id, step_dict, **kwds ):
        """ Create a WorkflowStep model object and corresponding module
        representing type-specific functionality from the incoming dictionary.
        """
        step = model.WorkflowStep()
        # TODO: Consider handling position inside module.
        step.position = step_dict['position']
        if step_dict.get("uuid", None) and step_dict['uuid'] != "None":
            step.uuid = step_dict["uuid"]
        if "label" in step_dict:
            step.label = step_dict["label"]
        step_type = step_dict.get("type", None)
        if step_type == "subworkflow":
            subworkflow = self.__load_subworkflow_from_step_dict(
                trans, step_dict
            )
            step_dict["subworkflow"] = subworkflow

        module = module_factory.from_dict( trans, step_dict, **kwds )
        self.__set_default_label( step, module, step_dict.get( 'tool_state' ) )
        module.save_to_step( step )

        annotation = step_dict[ 'annotation' ]
        if annotation:
            annotation = sanitize_html( annotation, 'utf-8', 'text/html' )
            self.add_item_annotation( trans.sa_session, trans.get_user(), step, annotation )

        # Stick this in the step temporarily
        step.temp_input_connections = step_dict['input_connections']

        # Create the model class for the step
        steps.append( step )
        steps_by_external_id[ step_dict[ 'id' ] ] = step
        if 'workflow_outputs' in step_dict:
            workflow_outputs = step_dict['workflow_outputs']
            found_output_names = set([])
            for workflow_output in workflow_outputs:
                # Allow workflow outputs as list of output_names for backward compatiblity.
                if not isinstance(workflow_output, dict):
                    workflow_output = {"output_name": workflow_output}
                output_name = workflow_output["output_name"]
                if output_name in found_output_names:
                    raise exceptions.ObjectAttributeInvalidException("Duplicate workflow outputs with name [%s] found." % output_name)
                if not output_name:
                    raise exceptions.ObjectAttributeInvalidException("Workflow output with empty name encountered.")
                found_output_names.add(output_name)
                uuid = workflow_output.get("uuid", None)
                label = workflow_output.get("label", None)
                m = step.create_or_update_workflow_output(
                    output_name=output_name,
                    uuid=uuid,
                    label=label,
                )
                trans.sa_session.add(m)
        return module, step
示例#12
0
 def build_module(self, trans, payload={}):
     """
     POST /api/workflows/build_module
     Builds module models for the workflow editor.
     """
     inputs = payload.get('inputs', {})
     module = module_factory.from_dict(trans, payload)
     module_state = {}
     populate_state(trans, module.get_inputs(), inputs, module_state, check=False)
     module.recover_state(module_state)
     return {
         'label'             : inputs.get('__label', ''),
         'annotation'        : inputs.get('__annotation', ''),
         'name'              : module.get_name(),
         'tool_state'        : module.get_state(),
         'data_inputs'       : module.get_data_inputs(),
         'data_outputs'      : module.get_data_outputs(),
         'config_form'       : module.get_config_form(),
         'post_job_actions'  : module.get_post_job_actions(inputs)
     }
示例#13
0
 def build_module( self, trans, payload={} ):
     """
     POST /api/workflows/build_module
     Builds module models for the workflow editor.
     """
     inputs = payload.get( 'inputs', {} )
     module = module_factory.from_dict( trans, payload )
     module_state = {}
     populate_state( trans, module.get_inputs(), inputs, module_state, check=False )
     module.recover_state( module_state )
     return {
         'label'             : inputs.get( '__label', '' ),
         'annotation'        : inputs.get( '__annotation', '' ),
         'name'              : module.get_name(),
         'tool_state'        : module.get_state(),
         'data_inputs'       : module.get_data_inputs(),
         'data_outputs'      : module.get_data_outputs(),
         'config_form'       : module.get_config_form(),
         'post_job_actions'  : module.get_post_job_actions( inputs )
     }
示例#14
0
 def build_module(self, trans, payload={}):
     """
     POST /api/workflows/build_module
     Builds module models for the workflow editor.
     """
     inputs = payload.get('inputs', {})
     trans.workflow_building_mode = workflow_building_modes.ENABLED
     module = module_factory.from_dict(trans, payload)
     if 'tool_state' not in payload:
         module_state = {}
         populate_state(trans, module.get_inputs(), inputs, module_state, check=False)
         module.recover_state(module_state)
     return {
         'label'             : inputs.get('__label', ''),
         'annotation'        : inputs.get('__annotation', ''),
         'name'              : module.get_name(),
         'tool_state'        : module.get_state(),
         'inputs'            : module.get_all_inputs(connectable_only=True),
         'outputs'           : module.get_all_outputs(),
         'config_form'       : module.get_config_form(),
         'post_job_actions'  : module.get_post_job_actions(inputs)
     }
示例#15
0
 def _workflow_from_dict(self, trans, data, source=None):
     """
     RPARK: copied from galaxy.webapps.galaxy.controllers.workflows.py
     Creates a workflow from a dict. Created workflow is stored in the database and returned.
     """
     # Put parameters in workflow mode
     trans.workflow_building_mode = True
     # Create new workflow from incoming dict
     workflow = model.Workflow()
     # If there's a source, put it in the workflow name.
     if source:
         name = "%s (imported from %s)" % (data["name"], source)
     else:
         name = data["name"]
     workflow.name = name
     # Assume no errors until we find a step that has some
     workflow.has_errors = False
     # Create each step
     steps = []
     # The editor will provide ids for each step that we don't need to save,
     # but do need to use to make connections
     steps_by_external_id = {}
     # Keep track of tools required by the workflow that are not available in
     # the local Galaxy instance.  Each tuple in the list of missing_tool_tups
     # will be ( tool_id, tool_name, tool_version ).
     missing_tool_tups = []
     # First pass to build step objects and populate basic values
     for key, step_dict in data["steps"].iteritems():
         # Create the model class for the step
         step = model.WorkflowStep()
         steps.append(step)
         steps_by_external_id[step_dict["id"]] = step
         # FIXME: Position should be handled inside module
         step.position = step_dict["position"]
         module = module_factory.from_dict(trans, step_dict, secure=False)
         if module.type == "tool" and module.tool is None:
             # A required tool is not available in the local Galaxy instance.
             missing_tool_tup = (step_dict["tool_id"], step_dict["name"], step_dict["tool_version"])
             if missing_tool_tup not in missing_tool_tups:
                 missing_tool_tups.append(missing_tool_tup)
         module.save_to_step(step)
         if step.tool_errors:
             workflow.has_errors = True
         # Stick this in the step temporarily
         step.temp_input_connections = step_dict["input_connections"]
         # Save step annotation.
         # annotation = step_dict[ 'annotation' ]
         # if annotation:
         # annotation = sanitize_html( annotation, 'utf-8', 'text/html' )
         # ------------------------------------------ #
         # RPARK REMOVING: user annotation b/c of API
         # self.add_item_annotation( trans.sa_session, trans.get_user(), step, annotation )
         # ------------------------------------------ #
         # Unpack and add post-job actions.
         post_job_actions = step_dict.get("post_job_actions", {})
         for name, pja_dict in post_job_actions.items():
             model.PostJobAction(
                 pja_dict["action_type"], step, pja_dict["output_name"], pja_dict["action_arguments"]
             )
     # Second pass to deal with connections between steps
     for step in steps:
         # Input connections
         for input_name, conn_dict in step.temp_input_connections.iteritems():
             if conn_dict:
                 conn = model.WorkflowStepConnection()
                 conn.input_step = step
                 conn.input_name = input_name
                 conn.output_name = conn_dict["output_name"]
                 conn.output_step = steps_by_external_id[conn_dict["id"]]
         del step.temp_input_connections
     # Order the steps if possible
     attach_ordered_steps(workflow, steps)
     # Connect up
     stored = model.StoredWorkflow()
     stored.name = workflow.name
     workflow.stored_workflow = stored
     stored.latest_workflow = workflow
     stored.user = trans.user
     # Persist
     trans.sa_session.add(stored)
     trans.sa_session.flush()
     return stored, missing_tool_tups
示例#16
0
 def _workflow_from_dict(self, trans, data, source=None):
     """
     RPARK: copied from galaxy.webapps.galaxy.controllers.workflows.py
     Creates a workflow from a dict. Created workflow is stored in the database and returned.
     """
     # Put parameters in workflow mode
     trans.workflow_building_mode = True
     # Create new workflow from incoming dict
     workflow = model.Workflow()
     # If there's a source, put it in the workflow name.
     if source:
         name = "%s (imported from %s)" % (data['name'], source)
     else:
         name = data['name']
     workflow.name = name
     # Assume no errors until we find a step that has some
     workflow.has_errors = False
     # Create each step
     steps = []
     # The editor will provide ids for each step that we don't need to save,
     # but do need to use to make connections
     steps_by_external_id = {}
     # Keep track of tools required by the workflow that are not available in
     # the local Galaxy instance.  Each tuple in the list of missing_tool_tups
     # will be ( tool_id, tool_name, tool_version ).
     missing_tool_tups = []
     # First pass to build step objects and populate basic values
     for key, step_dict in data['steps'].iteritems():
         # Create the model class for the step
         step = model.WorkflowStep()
         steps.append(step)
         steps_by_external_id[step_dict['id']] = step
         # FIXME: Position should be handled inside module
         step.position = step_dict['position']
         module = module_factory.from_dict(trans, step_dict, secure=False)
         if module.type == 'tool' and module.tool is None:
             # A required tool is not available in the local Galaxy instance.
             missing_tool_tup = (step_dict['tool_id'], step_dict['name'],
                                 step_dict['tool_version'])
             if missing_tool_tup not in missing_tool_tups:
                 missing_tool_tups.append(missing_tool_tup)
         module.save_to_step(step)
         if step.tool_errors:
             workflow.has_errors = True
         # Stick this in the step temporarily
         step.temp_input_connections = step_dict['input_connections']
         # Save step annotation.
         #annotation = step_dict[ 'annotation' ]
         #if annotation:
         #annotation = sanitize_html( annotation, 'utf-8', 'text/html' )
         # ------------------------------------------ #
         # RPARK REMOVING: user annotation b/c of API
         #self.add_item_annotation( trans.sa_session, trans.get_user(), step, annotation )
         # ------------------------------------------ #
         # Unpack and add post-job actions.
         post_job_actions = step_dict.get('post_job_actions', {})
         for name, pja_dict in post_job_actions.items():
             model.PostJobAction(pja_dict['action_type'], step,
                                 pja_dict['output_name'],
                                 pja_dict['action_arguments'])
     # Second pass to deal with connections between steps
     for step in steps:
         # Input connections
         for input_name, conn_dict in step.temp_input_connections.iteritems(
         ):
             if conn_dict:
                 conn = model.WorkflowStepConnection()
                 conn.input_step = step
                 conn.input_name = input_name
                 conn.output_name = conn_dict['output_name']
                 conn.output_step = steps_by_external_id[conn_dict['id']]
         del step.temp_input_connections
     # Order the steps if possible
     attach_ordered_steps(workflow, steps)
     # Connect up
     stored = model.StoredWorkflow()
     stored.name = workflow.name
     workflow.stored_workflow = stored
     stored.latest_workflow = workflow
     stored.user = trans.user
     # Persist
     trans.sa_session.add(stored)
     trans.sa_session.flush()
     return stored, missing_tool_tups