'Recursively expand flat list of inputs into "tree" form of flat list
(| using to nest to new levels) structure and expand dataset
information as proceeding to populate self.required_files.'

def __process_raw_inputs(self, tool_inputs, raw_inputs, parent_context=None):

    parent_context = (parent_context or RootParamContext())
    expanded_inputs = {}
    for (key, value) in tool_inputs.items():
        if isinstance(value, galaxy.tools.parameters.grouping.Conditional):
            cond_context = ParamContext(name=value.name, parent_context=parent_context)
            case_context = ParamContext(name=value.test_param.name, parent_context=cond_context)
            raw_input = case_context.extract_value(raw_inputs)
            case_value = (raw_input[1] if raw_input else None)
            case = self.__matching_case_for_value(value, case_value)
            if case:
                for (input_name, input_value) in case.inputs.items():
                    case_inputs = self.__process_raw_inputs({input_name: input_value}, raw_inputs, parent_context=cond_context)
                    expanded_inputs.update(case_inputs)
                if (not (value.type == 'text')):
                    expanded_case_value = self.__split_if_str(case.value)
                if (case_value is not None):
                    processed_value = _process_simple_value(value.test_param, expanded_case_value)
                    expanded_inputs[case_context.for_state()] = processed_value
        elif isinstance(value, galaxy.tools.parameters.grouping.Section):
            context = ParamContext(name=value.name, parent_context=parent_context)
            for (r_name, r_value) in value.inputs.items():
                expanded_input = self.__process_raw_inputs({context.for_state(): r_value}, raw_inputs, parent_context=context)
                if expanded_input:
                    expanded_inputs.update(expanded_input)
        elif isinstance(value, galaxy.tools.parameters.grouping.Repeat):
            repeat_index = 0
            while True:
                context = ParamContext(name=value.name, index=repeat_index, parent_context=parent_context)
                updated = False
                for (r_name, r_value) in value.inputs.items():
                    expanded_input = self.__process_raw_inputs({context.for_state(): r_value}, raw_inputs, parent_context=context)
                    if expanded_input:
                        expanded_inputs.update(expanded_input)
                        updated = True
                if (not updated):
                    break
                repeat_index += 1
        else:
            context = ParamContext(name=value.name, parent_context=parent_context)
            raw_input = context.extract_value(raw_inputs)
            if raw_input:
                (name, param_value, param_extra) = raw_input
                if (not (value.type == 'text')):
                    param_value = self.__split_if_str(param_value)
                if isinstance(value, galaxy.tools.parameters.basic.DataToolParameter):
                    if (not isinstance(param_value, list)):
                        param_value = [param_value]
                    map((lambda v: self.__add_uploaded_dataset(context.for_state(), v, param_extra, value)), param_value)
                    processed_value = param_value
                elif isinstance(value, galaxy.tools.parameters.basic.DataCollectionToolParameter):
                    assert ('collection' in param_extra)
                    collection_def = param_extra['collection']
                    for (name, value, extra) in collection_def.collect_inputs():
                        require_file(name, value, extra, self.required_files)
                    processed_value = collection_def
                else:
                    processed_value = _process_simple_value(value, param_value)
                expanded_inputs[context.for_state()] = processed_value
    return expanded_inputs
