def search_hierarchy(ID, hierarchy, options):

    gene_id = []
    transcript_id = []
    possible_transcript_id = []

    entry = hierarchy[ID]

    if entry['type'] == options.gene_type:
        gene_id.append(hierarchy[ID]['gene_id'])

        if not entry['type'] == options.transcript_type:
            transcript_id = [None]
            possible_transcript_id = [None]
        else:
            transcript_id = [entry['transcript_id']]
            possible_transcript_id = [None]

        return (gene_id, transcript_id, possible_transcript_id)

    for parent in entry['Parent']:

        new_gene_id, new_transcript_id, new_possible_transcript_id = search_hierarchy(
            parent, hierarchy, options)

        gene_id.extend(new_gene_id)
        transcript_id.extend(new_transcript_id)
        possible_transcript_id.extend(new_possible_transcript_id)

    if options.missing_gene:
        possible_transcript_id = [
            entry['transcript_id'] if x is None else x for x in possible_transcript_id]

    if len(gene_id) == 0 and options.missing_gene:
        gene_id = [entry['gene_id']]
        transcript_id = [None]
        possible_transcript_id = [None]
    elif len(gene_id) == 0 and not options.missing_gene:
        raise ValueError(
            "Root found without finding an object of type %s" % options.gene_type)

    if entry['type'] == options.transcript_type:
        transcript_id = [
            entry['transcript_id'] if x is None else x for x in transcript_id]

    assert len(gene_id) == len(transcript_id) and len(
        transcript_id) == len(possible_transcript_id)
    assert len(gene_id) > 0

    return gene_id, transcript_id, possible_transcript_id
Returns a three element tuple of lists.
dataset/ETHPy150Open CGATOxford/cgat/scripts/gff32gtf.py/search_hierarchy