<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _to_cwldata(key, val, get_retriever):
 """Convert nested dictionary into CWL data, flatening and marking up files. Moves file objects to the top level, enabling insertion in CWL inputs/outputs. """

    out = []
    if isinstance(val, dict):
        if len(val) == 2 and "base" in val and "indexes" in val:
            if len(val["indexes"]) > 0 and val["base"] == val["indexes"][0]:
                out.append(("%s__indexes" % key, _item_to_cwldata(val["base"], get_retriever)))
            else:
                out.append((key, _to_cwlfile_with_indexes(val, get_retriever)))
        # Dump shared nested keys like resources as a JSON string
        elif key in workflow.ALWAYS_AVAILABLE or key in workflow.STRING_DICT:
            out.append((key, _item_to_cwldata(json.dumps(val), get_retriever)))
        elif key in workflow.FLAT_DICT:
            flat = []
            for k, vs in val.items():
                if not isinstance(vs, (list, tuple)):
                    vs = [vs]
                for v in vs:
                    flat.append("%s:%s" % (k, v))
            out.append((key, _item_to_cwldata(flat, get_retriever)))
        else:
            remain_val = {}
            for nkey, nval in val.items():
                cur_nkey = "%s__%s" % (key, nkey)
                cwl_nval = _item_to_cwldata(nval, get_retriever)
                if isinstance(cwl_nval, dict):
                    out.extend(_to_cwldata(cur_nkey, nval, get_retriever))
                elif key in workflow.ALWAYS_AVAILABLE:
                    remain_val[nkey] = nval
                else:
                    out.append((cur_nkey, cwl_nval))
            if remain_val:
                out.append((key, json.dumps(remain_val, sort_keys=True, separators=(',', ':'))))
    else:
        out.append((key, _item_to_cwldata(val, get_retriever)))
    return out