code: def _combine_qc_samples(samples):
      
      by_bam = collections.defaultdict(list)
      for data in [utils.to_single_data(x) for x in samples]:
          batch = dd.get_batch(data) or dd.get_sample_name(data)
          if not isinstance(batch, (list, tuple)):
              batch = [batch]
          batch = tuple(batch)
          by_bam[(dd.get_align_bam(data) or dd.get_work_bam(data), batch)].append(data)
      out = []
      for data_group in by_bam.values():
          data = data_group[0]
          alg_qc = []
          qc = {}
          metrics = {}
          for d in data_group:
              qc.update(dd.get_summary_qc(d))
              metrics.update(dd.get_summary_metrics(d))
              alg_qc.extend(dd.get_algorithm_qc(d))
          data["config"]["algorithm"]["qc"] = alg_qc
          data["summary"]["qc"] = qc
          data["summary"]["metrics"] = metrics
          out.append([data])
      return out
docs: Combine split QC analyses into single samples based on BAM files.