code: def _collapse_by_bam_variantcaller(samples):
      
      by_bam = collections.OrderedDict()
      for data in (x[0] for x in samples):
          work_bam = utils.get_in(data, ("combine", "work_bam", "out"), data.get("align_bam"))
          variantcaller = get_variantcaller(data)
          if isinstance(work_bam, list):
              work_bam = tuple(work_bam)
          key = (multi.get_batch_for_key(data), work_bam, variantcaller)
          try:
              by_bam[key].append(data)
          except KeyError:
              by_bam[key] = [data]
      out = []
      for grouped_data in by_bam.values():
          cur = grouped_data[0]
          cur.pop("region", None)
          region_bams = cur.pop("region_bams", None)
          if region_bams and len(region_bams[0]) > 1:
              cur.pop("work_bam", None)
          out.append([cur])
      return out
docs: Collapse regions to a single representative by BAM input, variant caller and batch.