def _prepare_summary(evolve_file, ssm_file, cnv_file, work_dir, somatic_info):
    """Prepare a summary with gene-labelled heterogeneity from PhyloWGS predictions.
    """
    out_file = os.path.join(work_dir, "%s-phylowgs.txt" % somatic_info.tumor_name)
    if not utils.file_uptodate(out_file, evolve_file):
        with file_transaction(somatic_info.tumor_data, out_file) as tx_out_file:
            with open(tx_out_file, "w") as out_handle:
                ssm_locs = _read_ssm_locs(ssm_file)
                cnv_ssms = _read_cnv_ssms(cnv_file)
                for i, (ids, tree) in enumerate(_evolve_reader(evolve_file)):
                    out_handle.write("* Tree %s\n" % (i + 1))
                    out_handle.write("\n" + "\n".join(tree) + "\n\n")
                    for nid, freq, gids in ids:
                        genes = _gids_to_genes(gids, ssm_locs, cnv_ssms, somatic_info.tumor_data)
                        out_handle.write("%s\t%s\t%s\n" % (nid, freq, ",".join(genes)))
                    out_handle.write("\n")
    return out_file
Prepare a summary with gene-labelled heterogeneity from PhyloWGS predictions.