def export_panels(adapter, panels, versions=None, build='<STR_LIT>'):
if versions and (len(versions) != len(panels)):<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT>headers = []<EOL>build_string = ("<STR_LIT>")<EOL>headers.append(build_string.format(build))<EOL>header_string = ("<STR_LIT>")<EOL>contig_string = ("<STR_LIT>")<EOL>bed_string = ("<STR_LIT>")<EOL>panel_geneids = set()<EOL>chromosomes_found = set()<EOL>hgnc_geneobjs = []<EOL>for i,panel_id in enumerate(panels):<EOL><INDENT>version = None<EOL>if versions:<EOL><INDENT>version = versions[i]<EOL><DEDENT>panel_obj = adapter.gene_panel(panel_id, version=version)<EOL>if not panel_obj:<EOL><INDENT>LOG.warning("<STR_LIT>".format(panel_id, version))<EOL>continue<EOL><DEDENT>headers.append(header_string.format(<EOL>panel_obj['<STR_LIT>'],<EOL>panel_obj['<STR_LIT:version>'],<EOL>panel_obj['<STR_LIT:date>'].date(),<EOL>panel_obj['<STR_LIT>'],<EOL>))<EOL>for gene_obj in panel_obj['<STR_LIT>']:<EOL><INDENT>panel_geneids.add(gene_obj['<STR_LIT>'])<EOL><DEDENT><DEDENT>gene_objs = adapter.hgncid_to_gene(build=build)<EOL>for hgnc_id in panel_geneids:<EOL><INDENT>hgnc_geneobj = gene_objs.get(hgnc_id)<EOL>if hgnc_geneobj is None:<EOL><INDENT>LOG.warn("<STR_LIT>", hgnc_id)<EOL>continue<EOL><DEDENT>chrom = hgnc_geneobj['<STR_LIT>']<EOL>start = hgnc_geneobj['<STR_LIT:start>']<EOL>chrom_int = CHROMOSOME_INTEGERS.get(chrom)<EOL>if not chrom_int:<EOL><INDENT>LOG.warn("<STR_LIT>", chrom)<EOL>continue<EOL><DEDENT>hgnc_geneobjs.append((chrom_int, start, hgnc_geneobj))<EOL>chromosomes_found.add(chrom)<EOL><DEDENT>hgnc_geneobjs.sort(key=lambda tup: (tup[<NUM_LIT:0>], tup[<NUM_LIT:1>]))<EOL>for chrom in CHROMOSOMES:<EOL><INDENT>if chrom in chromosomes_found:<EOL><INDENT>headers.append(contig_string.format(chrom))<EOL><DEDENT><DEDENT>headers.append("<STR_LIT>")<EOL>for header in headers:<EOL><INDENT>yield header<EOL><DEDENT>for hgnc_gene in hgnc_geneobjs:<EOL><INDENT>gene_obj = hgnc_gene[-<NUM_LIT:1>]<EOL>gene_line = bed_string.format(gene_obj['<STR_LIT>'], gene_obj['<STR_LIT:start>'],<EOL>gene_obj['<STR_LIT:end>'], gene_obj['<STR_LIT>'],<EOL>gene_obj['<STR_LIT>'])<EOL>yield gene_line<EOL><DEDENT>
Export all genes in gene panels

    Exports the union of genes in one or several gene panels to a bed like format with coordinates.

    Args:
        adapter(scout.adapter.MongoAdapter)
        panels(iterable(str)): Iterable with panel ids
        bed(bool): If lines should be bed formated