code: def _collapse_to_cwl_record(samples, want_attrs, input_files):
      
      input_keys = sorted(list(set().union(*[d["cwl_keys"] for d in samples])), key=lambda x: (-len(x), tuple(x)))
      out = {}
      for key in input_keys:
          if key in want_attrs:
              key_parts = key.split("__")
              vals = []
              cur = []
              for d in samples:
                  vals.append(_to_cwl(tz.get_in(key_parts, d), input_files))
                  # Remove nested keys to avoid specifying multiple times
                  cur.append(_dissoc_in(d, key_parts) if len(key_parts) > 1 else d)
              samples = cur
              out[key] = vals
      return out
docs: Convert nested samples from batches into a CWL record, based on input keys.