def get_ancestor_terms(go_term, go_dag, include_go_term=True):
    """ Find all ancestors of the given term
    
    Optionally, based on `include_go_term`, `go_term` itself will be
    included in the returned set.
    
    Parameters
    ----------
    go_term : string
        The GO term. Example: "GO:0008150"
        
    go_dag : goatools.obo_parser.GODag
        The Gene Ontology DAG, parsed from the source obo file
        
    include_go_term : bool
        Whether to incldue `go_term` itself in the set of ancestors
        
    Returns
    -------
    ancestors : set
        The set of ancestors for this term. If `include_go_term` is True, then
        this set will also include `go_term`.
    """
    paths = go_dag.paths_to_top(go_term)
    
    all_ancestors = {go_term}
    if paths is not None:
        all_ancestors = {
            term.id for path in paths for term in path
        }

    if not include_go_term:
        all_ancestors.remove(go_term)
        
    return all_ancestors