Read CWL records, handling multiple nesting and batching cases.

def _read_cwl_record(rec):
    """Read CWL records, handling multiple nesting and batching cases.
    """
    keys = set([])
    out = []
    if isinstance(rec, dict):
        is_batched = all([isinstance(v, (list, tuple)) for v in rec.values()])
        cur = [{} for _ in range(len(rec.values()[0]) if is_batched else 1)]
        for k in rec.keys():
            keys.add(k)
            val = rec[k]
            val = val if is_batched else [val]
            for i, v in enumerate(val):
                v = _cwlvar_to_wdl(v)
                cur[i] = _update_nested(k.split("__"), v, cur[i])
        if is_batched:
            out.append(cur)
        else:
            assert len(cur) == 1
            out.append(cur[0])
    else:
        assert isinstance(rec, (list, tuple))
        for sub_rec in rec:
            sub_keys, sub_out = _read_cwl_record(sub_rec)
            keys |= sub_keys
            out.append(sub_out)
    return keys, out