<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _flatten_ancestors(self, include_part_of=True):
 """Determines and stores all ancestors of each GO term. Parameters include_part_of: bool, optional Whether to include ``part_of`` relations in determining ancestors. Returns ------- None """


        def get_all_ancestors(term):
            ancestors = set()
            for id_ in term.is_a:
                ancestors.add(id_)
                ancestors.update(get_all_ancestors(self.terms[id_]))
            if include_part_of:
                for id_ in term.part_of:
                    ancestors.add(id_)
                    ancestors.update(get_all_ancestors(self.terms[id_]))
            return ancestors

        for term in self.terms.values():
            term.ancestors = get_all_ancestors(term)