def parse_genes(genes):
    """Parse various gene information including:

    1. Species name (taxonomy name)
    2. Entrez gene ID
    3. Official symbol
    4. RefSeq IDs
    5. Offical full name

    Basically, just to go through the parsed xml data.... A big headache to figure it out...

    Return a list of dictionary.
    """
    gene_info_list = []
    for gene_data in genes:
        gene_info = {}
        # get entrez ID
        try:
            gene_info["entrez_id"] = gene_data["Entrezgene_track-info"]["Gene-track"]["Gene-track_geneid"]
        except __HOLE__:
            gene_info["entrez_id"] = ""
            continue
        gene_info["refseq_ids"] = []
        for comment in gene_data.get("Entrezgene_comments",[]):
            # look for refSeq annotation
            if comment.get("Gene-commentary_heading",None) == "NCBI Reference Sequences (RefSeq)":
                # get sub-comments
                for subcomment in comment.get("Gene-commentary_comment",[]):
                    for product in subcomment.get("Gene-commentary_products",[]):
                        if product.get("Gene-commentary_heading",None) == "mRNA Sequence":
                            gene_info["refseq_ids"].append(product.get("Gene-commentary_accession",""))
        # get properties
        gene_info["official_symbol"] = "" # optional
        gene_info["official_full_name"] = "" # optional
        for gene_property in gene_data.get("Entrezgene_properties",[]):
            if gene_property.get("Gene-commentary_label",None) == "Nomenclature":
                for sub_property in gene_property["Gene-commentary_properties"]:
                    if sub_property.get("Gene-commentary_label",None)  == "Official Symbol":
                        gene_info["official_symbol"] = sub_property.get("Gene-commentary_text","")
                    if sub_property.get("Gene-commentary_label",None)  == "Official Full Name":
                        gene_info["official_full_name"] = sub_property.get("Gene-commentary_text","")

        # get taxname
        try:
            gene_info["taxname"] = gene_data["Entrezgene_source"]["BioSource"]["BioSource_org"]["Org-ref"]["Org-ref_taxname"]
        except KeyError:
            gene_info["taxname"] = ""
            continue
        gene_info_list.append(gene_info)

    return gene_info_list
dataset/ETHPy150Open taoliu/taolib/Scripts/convert_gene_ids.py/parse_genes