code: def _merge_metrics(samples, out_dir):
      
      logger.info("summarize metrics")
      out_dir = utils.safe_makedir(os.path.join(out_dir, "report", "metrics"))
      sample_metrics = collections.defaultdict(dict)
      for s in samples:
          s = _add_disambiguate(s)
          m = tz.get_in(['summary', 'metrics'], s)
          if isinstance(m, six.string_types):
              m = json.loads(m)
          if m:
              for me in m.keys():
                  if isinstance(m[me], list) or isinstance(m[me], dict) or isinstance(m[me], tuple):
                      m.pop(me, None)
              sample_metrics[dd.get_sample_name(s)].update(m)
      out = []
      for sample_name, m in sample_metrics.items():
          sample_file = os.path.join(out_dir, "%s_bcbio.txt" % sample_name)
          with file_transaction(samples[0], sample_file) as tx_out_file:
              dt = pd.DataFrame(m, index=['1'])
              dt.columns = [k.replace(" ", "_").replace("(", "").replace(")", "") for k in dt.columns]
              dt['sample'] = sample_name
              dt['rRNA_rate'] = m.get('rRNA_rate', "NA")
              dt['RiP_pct'] = "%.3f" % (int(m.get("RiP", 0)) / float(m.get("Total_reads", 1)) * 100)
              dt = _fix_duplicated_rate(dt)
              dt.transpose().to_csv(tx_out_file, sep="\t", header=False)
          out.append(sample_file)
      return out
docs: Merge metrics from multiple QC steps