scout/export/panel.py
def export_gene_panels(adapter, panels, version=None):
    """Export the genes of a gene panel
    
    Takes a list of gene panel names and return the lines of the gene panels.
    Unlike export_panels this function only export the genes and extra information, 
    not the coordinates.
    
    Args:
        adapter(MongoAdapter)
        panels(list(str))
        version(float): Version number, only works when one panel
    
    Yields:
        gene panel lines
    """
    if version and len(panels) > 1:
        raise SyntaxError("Version only possible with one panel")

    bed_string = ("{0}\t{1}\t{2}\t{3}\t{4}\t{5}")
    
    headers = []

    # Dictionary with hgnc ids as keys and panel gene information as value.
    panel_geneobjs = dict()

    for panel_id in panels:
        panel_obj = adapter.gene_panel(panel_id, version=version)
        if not panel_obj:
            LOG.warning("Panel %s could not be found", panel_id)
            continue

        for gene_obj in panel_obj['genes']:
            panel_geneobjs[gene_obj['hgnc_id']] = gene_obj

    if len(panel_geneobjs) == 0:
        return

    headers.append('#hgnc_id\thgnc_symbol\tdisease_associated_transcripts\t'
                    'reduced_penetrance\tmosaicism\tdatabase_entry_version')

    for header in headers:
        yield header

    for hgnc_id in panel_geneobjs:
        gene_obj = panel_geneobjs[hgnc_id]
        gene_line = bed_string.format(
            gene_obj['hgnc_id'], gene_obj['symbol'],
            ','.join(gene_obj.get('disease_associated_transcripts', [])),
            gene_obj.get('reduced_penetrance', ''),
            gene_obj.get('mosaicism', ''),
            gene_obj.get('database_entry_version', ''),
        )
        yield gene_line
def export_gene_panels(adapter, panels, version=None):
    """Export the genes of a gene panel
    
    Takes a list of gene panel names and return the lines of the gene panels.
    Unlike export_panels this function only export the genes and extra information, 
    not the coordinates.
    
    Args:
        adapter(MongoAdapter)
        panels(list(str))
        version(float): Version number, only works when one panel
    
    Yields:
        gene panel lines
    """
    if version and len(panels) > 1:
        raise SyntaxError("Version only possible with one panel")

    bed_string = ("{0}\t{1}\t{2}\t{3}\t{4}\t{5}")
    
    headers = []

    # Dictionary with hgnc ids as keys and panel gene information as value.
    panel_geneobjs = dict()

    for panel_id in panels:
        panel_obj = adapter.gene_panel(panel_id, version=version)
        if not panel_obj:
            LOG.warning("Panel %s could not be found", panel_id)
            continue

        for gene_obj in panel_obj['genes']:
            panel_geneobjs[gene_obj['hgnc_id']] = gene_obj

    if len(panel_geneobjs) == 0:
        return

    headers.append('#hgnc_id\thgnc_symbol\tdisease_associated_transcripts\t'
                    'reduced_penetrance\tmosaicism\tdatabase_entry_version')

    for header in headers:
        yield header

    for hgnc_id in panel_geneobjs:
        gene_obj = panel_geneobjs[hgnc_id]
        gene_line = bed_string.format(
            gene_obj['hgnc_id'], gene_obj['symbol'],
            ','.join(gene_obj.get('disease_associated_transcripts', [])),
            gene_obj.get('reduced_penetrance', ''),
            gene_obj.get('mosaicism', ''),
            gene_obj.get('database_entry_version', ''),
        )
        yield gene_line
Export the genes of a gene panel
    
    Takes a list of gene panel names and return the lines of the gene panels.
    Unlike export_panels this function only export the genes and extra information, 
    not the coordinates.
    
    Args:
        adapter(MongoAdapter)
        panels(list(str))
        version(float): Version number, only works when one panel
    
    Yields:
        gene panel lines