scripts/export/rfam_xml_dumper.py
def add_hierarchical_fields(xml_tree_node, tax_tree_dict, name_dict):
    """
    Expands the cross references xml tree by adding hierarchical references
    for the ncbi ids in valid_ncbi_ids

    xml_tree_node:  An existing xml tree node to expand with hierarchical
                    fields
    tax_tree_dict:  Species taxonomy tree dictionary as generated by
                    get_family_tax_tree
    name_dict:  NCBI's name dictionary as returned by read_ncbi_names_dmp
    """

    # add a new hierarchical ref for every tax_id in the family
    for tax_id in tax_tree_dict.keys():
        hfields = ET.SubElement(xml_tree_node, "hierarchical_field",
                                name="taxonomy_lineage")

        # fetch lineage
        lineage = tax_tree_dict[tax_id]
        tax_tree = lineage[::-1]

        for tax_tree_node in tax_tree:
            # create the root node
            if tax_tree_node == '1':
                # need to create one root node in order for the xml dump to
                # validate
                ET.SubElement(hfields, "root", label="root").text = '1'
            else:
                # skip root while creating child nodes
                if tax_tree_node != '1':
                    ET.SubElement(
                        hfields, "child", label=name_dict[tax_tree_node]).text = tax_tree_node

    Expands the cross references xml tree by adding hierarchical references
    for the ncbi ids in valid_ncbi_ids

    xml_tree_node:  An existing xml tree node to expand with hierarchical
                    fields
    tax_tree_dict:  Species taxonomy tree dictionary as generated by
                    get_family_tax_tree
    name_dict:  NCBI's name dictionary as returned by read_ncbi_names_dmp
    
Expands the cross references xml tree by adding hierarchical references
for the ncbi ids in valid_ncbi_ids

An existing xml tree node to expand with hierarchical
fields
tax_tree_dict:  Species taxonomy tree dictionary as generated by
get_family_tax_tree
name_dict:  NCBI's name dictionary as returned by read_ncbi_names_dmp
Expands the cross references xml tree by adding hierarchical references for the ncbi ids in valid_ncbi_ids An existing xml tree node to expand with hierarchical fields tax_tree_dict : Species taxonomy tree dictionary as generated by get_family_tax_tree name_dict : NCBI ' s name dictionary as returned by read_ncbi_names_dmp
def add_hierarchical_fields(xml_tree_node, tax_tree_dict, name_dict):
    for tax_id in tax_tree_dict.keys():
        hfields = ET.SubElement(xml_tree_node, "hierarchical_field",
                                name="taxonomy_lineage")
        lineage = tax_tree_dict[tax_id]
        tax_tree = lineage[::-1]
        for tax_tree_node in tax_tree:
            if tax_tree_node == '1':
                ET.SubElement(hfields, "root", label="root").text = '1'
            else:
                if tax_tree_node != '1':
                    ET.SubElement(
                        hfields, "child", label=name_dict[tax_tree_node]).text = tax_tree_node
def add_hierarchical_fields ( xml_tree_node , tax_tree_dict , name_dict ) : for tax_id in tax_tree_dict . keys ( ) : hfields = ET . SubElement ( xml_tree_node , "hierarchical_field" , name = "taxonomy_lineage" ) lineage = tax_tree_dict [ tax_id ] tax_tree = lineage [ : : - 1 ] for tax_tree_node in tax_tree : if tax_tree_node == '1' : ET . SubElement ( hfields , "root" , label = "root" ) . text = '1' else : if tax_tree_node != '1' : ET . SubElement ( hfields , "child" , label = name_dict [ tax_tree_node ] ) . text = tax_tree_node
Expands the cross references xml tree by adding hierarchical references
for the ncbi ids in valid_ncbi_ids
Expands the cross references xml tree by adding hierarchical references for the ncbi ids in valid_ncbi_ids
"""
    Expands the cross references xml tree by adding hierarchical references
    for the ncbi ids in valid_ncbi_ids

    xml_tree_node:  An existing xml tree node to expand with hierarchical
                    fields
    tax_tree_dict:  Species taxonomy tree dictionary as generated by
                    get_family_tax_tree
    name_dict:  NCBI's name dictionary as returned by read_ncbi_names_dmp
    """ # add a new hierarchical ref for every tax_id in the family # fetch lineage # create the root node # need to create one root node in order for the xml dump to # validate # skip root while creating child nodes
xml_tree_node
tax_tree_dict
name_dict